Motto: Write once, run anywhere Sun Microsystem

Similar documents
Pemrograman Dasar. Basic Elements Of Java

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Java Interview Questions and Answers

An Overview of Java. overview-1

Chapter 1 Java Program Design and Development

AP Computer Science Java Subset

Java Programming Fundamentals

Fundamentals of Java Programming

Introduction to Java

Chapter 2 Introduction to Java programming

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

C++ INTERVIEW QUESTIONS

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 111 Classes I 1. Software Organization View to this point:

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Crash Course in Java

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Object Oriented Software Design

JavaScript: Control Statements I

Chapter 2: Elements of Java

ECE 122. Engineering Problem Solving with Java

Habanero Extreme Scale Software Research Project

Syllabus for CS 134 Java Programming

Object-Oriented Programming Lecture 2: Classes and Objects

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Java programming for C/C++ developers

Object Oriented Software Design

The C Programming Language course syllabus associate level

Variables, Constants, and Data Types

Computer Programming I

Explain the relationship between a class and an object. Which is general and which is specific?

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

The Java Virtual Machine (JVM) Pat Morin COMP 3002

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

Java CPD (I) Frans Coenen Department of Computer Science

CSC 551: Web Programming. Fall 2001

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Course Title: Software Development

Chapter 7D The Java Virtual Machine

CSC 551: Web Programming. Spring 2004

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

2 Introduction to Java. Introduction to Programming 1 1

Informatica e Sistemi in Tempo Reale

J a v a Quiz (Unit 3, Test 0 Practice)

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis

02 B The Java Virtual Machine

Java Programming. Binnur Kurt Istanbul Technical University Computer Engineering Department. Java Programming. Version 0.0.

D06 PROGRAMMING with JAVA. Ch3 Implementing Classes

Part I. Multiple Choice Questions (2 points each):

CSC 221: Computer Programming I. Fall 2006

Stack vs. Heap. Introduction to Programming. How the Stack Works. Primitive vs. Reference Types. Stack

Java SE 8 Programming

C Compiler Targeting the Java Virtual Machine

picojava TM : A Hardware Implementation of the Java Virtual Machine

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

CS 106 Introduction to Computer Science I

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

C++ Language Tutorial

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Unit Testing & JUnit

Programming Languages

Lecture 1 Introduction to Java

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

JavaScript. JavaScript: fundamentals, concepts, object model. Document Object Model. The Web Page. The window object (1/2) The document object

Habanero Extreme Scale Software Research Project

PL / SQL Basics. Chapter 3

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Basic Programming and PC Skills: Basic Programming and PC Skills:

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Introduction to Stacks

Example of a Java program

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Glossary of Object Oriented Terms

Java Programming Language

Chapter 13 Storage classes

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

University of Twente. A simulation of the Java Virtual Machine using graph grammars

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1

public static void main(string[] args) { System.out.println("hello, world"); } }

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Getting Started with the Internet Communications Engine

5 Arrays and Pointers

Description of Class Mutation Mutation Operators for Java

VB.NET Programming Fundamentals

Transcription:

Literature Pecinovský, Rudolf. 2009. Myslíme objektově v jazyku JAVA. 2nd ed. GRADA Publishing. Isaac Rabinovitch, Jacob Royal, Mark Hoeber, Scott Hommel, Sharon Zakhour, Tom Risser. 2007. JAVA 6 Výukový kurz. COMPUTER PRESS. Sun.The Java Tutorials. accessed August 24, 2014,http://download.oracle.com/javase/tutorial/. Eckel, Bruce. 2006. Thinking in Java. 4th ed. Prentice Hall, February 20. Barnes, David J., and Michael Kolling. 2008.Objects First With Java: A Practical Introduction Using BlueJ. 4th ed. Prentice Hall. Pecinovský, Rudolf. 2005. JAVA 5.0 Novinky jazyka a upgrade aplikací. Brno: Computer Press. http://knihy.pecinovsky.cz/java5novinky.

Motto: Write once, run anywhere Sun Microsystem

Demonstration of JAVA applications Desktop applications - http://wordrider.net/freerapid/download.html 3d application - http://www.bytonic.de/downloads/jake2_jogl1 1.jnlp Web application- https://www.edison.cz Mobile applications Others

JAVA is (not only) language Other languages based on JAVA platform exist: Scala JavaFX and others

Required/useful application Installed Java Development Kit (JDK) Eclipse professional IDE BlueJ educational IDE

Features of JAVA technology Multiplatform and portable Object Oriented It has simple language core is API Robust, Dynamic and Secure Multithreaded Support for distributed application

History 1992 - Oak language by Green Project 1995 Oak renamed to JAVA 1996 JDK 1.0 1997 JKD 1.1 - over 220,000 downloads occur in just three weeks 1999 Java 2 platform released 2004 jdk 1.5 (Java 2 Platform, Standard Edition 5) 2006 - jdk 1.6 2011 jdk 1.7 2014 jdk 1.8

Multiplatform and portable Java source code is compiled into machine code - Java Bytecode (.class files) format, that is platform independent. This machine code is executed on Java Virtual Machine (JVM) JVM is a machine that is implemented as software running in various operating systems. JVM specification provides concrete definitions for implementation of instruction set, register set, class file format, stack...

Keywords abstract const finally int public this boolean Continue float interface return throw break default for long short throws byte do goto native static transient case double if new strictfp try catch else implements package super void char extends import private switch volatile class final instanceof protected synchronized while

Aspects of Java Programming Object construction Method calling Data types Modification of an object state Class definition Java Flow Control Packages Exceptions and Exception Handling

Object, Type, and Class An Object is an distinguishable entity that has: Identity: a uniqueness which distinguishes it from all other objects Behavior: services it provides to another objects State: value of attributes held by an object A class is an abstraction of objects with similar implementation Class is definition of set of similar objects Every object is an instance of one class

Object responds to a message call

Return value and data types

Data type Primitive types only values: int is in [-2147483648, 2147483647 ] boolean is in {false, true} double is in [4.9*10-324, 1.7976931348623157*10 308 ] Object types reference to instance of class: type from JAVA (more than 18000) e.g. String defined by user e.g. Rectangle

Reference vs. instance Another instance is created only by operation new. Reference to the same instance is passed during assignment.

Peaceful destruction of an object When an object is no longer being used, it could release its memory space. Java virtual machine knows that it is not used whether no reference to it exists.

Garbage collector our friend The collection and freeing of memory is the responsibility of a thread of code called automatic garbage collector (GC). GC starts: low memory explicit start System.gc() The garbage collector keeps track of all memory allocated with the new key keyword and also tracks who has access to that memory. When the access count reaches zero, the memory can be collected and freed.

A Creation of customized object We could call constructors and method with

Parameterized methods

Overloading Definition of another constructor or method with same name is called overloading Overload method must differs with number or type of parameters Specific constructor or method is selected base on passed arguments

Class definition

Name of a class identifier It follows conventions Name should be noun, in mixed case with the first letter of each internal word capitalized.

Methods define behavior of objects Type of return value. void means that there is returned no value. parameters public class Tree { // //definition of method public void setposition(int x, int y) { trunk.setposition(x, y); crown.setposition(x, y); //...body of method } Method that returns value should contain return statement in its body. This statement ends method execution and result of followed expression is return value. public int getheight() { return crown.getheight() + trunk.getheight(); } // }

Attributes State of an object is based on value of its

Attributes defines possible states of objects Modifier of accessibility private accessibility is recommended public class Tree { // //definition of attributes private Rectangle trunk ; private Ellipse crown ; private int num = 7, count; // } Name of attribute. Init value of attribute. Type of attribute.

Accessor and mutator Accessor and mutator form one property. Using properties has benefits public class Rectangle { private int x; } public int getx() { return x; } Attributes are defined as private. It is accessible only by current class. public void setx(int x) { if (x < 0 x + šířka > PLÁTNO.getŠířka()) throw new IllegalArgumentException("X :" + x + " is out of range."); this.x = x; } Class defines method for reading accessors and writing mutators.

Class methods Named also as static. Class method is called directly on class.

Class attributes Named also as static. Class attribute is stored directly in class Their value is shared among of instances of class Modified usually by class method invocation.

A definition of class methods and attributes Class method and attribute is defined with modifier static before or after modifier of accessibility. public class Tree { //... //class attribute static private int step = 25; Access to class attribute step should be qualified with name of class due the name collision with name of parameter. //class method static public void setstep(int step) { Tree.step = step; } //... }

Local variables Defined inside body of a method. Visible after declaration and only inside given method. Destroyed when the method is leaved. Defined only type no other modifier. public Tree(int x, int y, int height, int width) { //local variable definition It have to be initialized int h3 = height / 3; before first using. } new Ellipse(x, y, width, h3*2, MyColor.GREEN); new Rectangle(x + 9*width/20, y + h3*2, width/10, h3, MyColor.BROWN);

Constants Preferred to using magic values. Class and instance attribute, method parameter and local variable defined with modifier final.

Constants literals Constant described by its value. //boolean literals boolean t = true, f = false; int decimal = 123, //decimal format of literal octal = 0173, //octal format of literal binary = 0b1111011, //binary format of literal hexa = 0x7b; //hexadecimal format of literal double d_1 = 12.3, //decimal format d_2 = 12., //decimal format d_3 =.12, //decimal format sl_1 =.314e+1, //semilogarithmic format sl_2 =.314e1, //semilogarithmic format sl_3 = 31.4e-1, //semilogarithmic format sl_4 = 3.14E0; //semilogarithmic format String str_1 = "Hello world!", //simple string str_2 = "Hello world!" + //string split on more lines "I am your friend." + "and my name is \"Joe Smith\"",//escape sequence \" represents " str_3 = "C:\\windows\\format.exe", //escape sequence \\ represents \ str_4 = "user joe\npass 123456\n"; //escape sequence \n represents new line Object obj = null; //represents variable without reference

Comments and documentation //comment on one line /** * Comment included in automatically generated HTML documentation (known as * JAVADOC). * {@code Tree} is demonstration class. Only method {@link Tree.moveDown(int)} is *defined. * @author koz01 * @version 0.1 * */ public class Tree { /** * Demonstration method * @param step description of arguments * @return description of return value * @throws IllegalArgumentException */ public boolean movedown(int step) throws IllegalArgumentException{ /* * Comment on one or more lines * There wil be placed some genuine implementation. */ return false; }

Class organization convention constant class attributes, other class attributes, constant instance attributes, class properties, other class methods, constructors, abstract methods, instance properties, other instance methods, private class methods, private instance methods, inner classes.

Binary operators Arithmetic operation + - * - for int and double operands. Division / and division residuum % - different for int and double. String concatenation +.

Unary operators

Assignment operators Simple assignment = For arithmetic operators exist composite assignment +=, -=, *=, /=, %=

Operator of increment and decrement Two different forms - prefix and postfix. increment ++ decrement --