Course information. Petr Hnětynka 2/2 Zk/Z

Similar documents
Course information. Petr Hnětynka 2/2 Zk/Z

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Index COPYRIGHTED MATERIAL

Introduction to Programming (Java) 2/12

Programming. Syntax and Semantics

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Introduction to Programming Using Java (98-388)

JAVA OPERATORS GENERAL

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

1 Shyam sir JAVA Notes

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java

CSC 1214: Object-Oriented Programming

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

: Primitive data types Variables Operators if, if-else do-while, while, for. // // First Java Program. public class Hello {

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Lecture 1: Overview of Java

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

3. Java - Language Constructs I

A flow chart is a graphical or symbolic representation of a process.

Operators and Expressions

CS 231 Data Structures and Algorithms, Fall 2016

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

13 th Windsor Regional Secondary School Computer Programming Competition

More Programming Constructs -- Introduction

Java Basic Programming Constructs

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

The Arithmetic Operators

Advanced programming for Java platform. Introduction

Lec 3. Compilers, Debugging, Hello World, and Variables

Operators in java Operator operands.

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Chettinad College of Engineering & Technology/II-MCA/ MC9235 Web Programming WEB PROGRAMMING DEPARTMENT OF MCA

B.V. Patel Institute of BMC & IT, UTU 2014

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

CS2141 Software Development using C/C++ C++ Basics

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

CT 229. Java Syntax 26/09/2006 CT229

Review of the C Programming Language for Principles of Operating Systems

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Language Fundamentals Summary

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Fall 2017 CISC124 9/16/2017

Operators. Java operators are classified into three categories:

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

PIC 20A The Basics of Java

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Getting started with Java

Java: framework overview and in-the-small features

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

CS260 Intro to Java & Android 03.Java Language Basics

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

Chapter 3: Operators, Expressions and Type Conversion

A variable is a name that represents a value. For

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Dynamic memory allocation (malloc)

Java Programming. Atul Prakash

Getting started with Java

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

A Java program contains at least one class definition.

CS11 Java. Fall Lecture 1

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Computers Programming Course 6. Iulian Năstac

Expressions & Flow Control

CompSci 125 Lecture 02

COT 3530: Data Structures. Giri Narasimhan. ECS 389; Phone: x3748

CMPT 125: Lecture 3 Data and Expressions

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Array. Prepared By - Rifat Shahriyar

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

The Java language has a wide variety of modifiers, including the following:

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Advanced Computer Programming

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 2

Exercises Software Development I. 05 Conversions and Promotions; Lifetime, Scope, Shadowing. November 5th, 2014

Introduction Basic elements of Java

Java Overview An introduction to the Java Programming Language

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Information Science 1

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Declaration and Memory

Review of the C Programming Language

Java in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure.

PROGRAMMING FUNDAMENTALS

Full file at

Introduction to Java

CSE 421 Course Overview and Introduction to Java

NOOTAN PADIA ASSIST. PROF. MEFGI, RAJKOT.

Pace University. Fundamental Concepts of CS121 1

Transcription:

JAVA Introduction

Course information Petr Hnětynka hnetynka@d3s.mff.cuni.cz http://d3s.mff.cuni.cz/~hnetynka/java/ 2/2 Zk/Z exam written test zápočet practical test in the lab zápočtový program "reasonable" size topic till 12. 1. 2018 by email homeworks 225 points (450 max) presence > 3 absences 315 points 2

Course information Virtual practical for repeated subscription and those who do not want to attend List of forbidden topics for the započtový program tick-tack-toe ( piškvorky ) battleships tetris homeworks for courses like Algorithms, Graphics,... always agree on the topic with a particular teaching assistant the practical at Mon 12:20 in English 3

Literature, links Everything about Java http://www.oracle.com/technetwork/java/ Java tutorial http://download.oracle.com/javase/tutorial/index.html Java Language Specification http://docs.oracle.com/javase/specs/ 4

Java object oriented (almost) all is object interpreted source code (.java) compiled to the bytecode bytecode (.class) interpreted by the virtual machine just-in-time compilation compilation of the bytecode to a native code before/during program execution platform independent programs run in the virtual machine Java 9 ahead-of-time compilation experimental support 5

History JDK 1.0 (1996) JDK 1.1 (1997) Inner classes Java 2 platform (2000) JDK 1.2, 1.3 changes in libraries only JDK 1.4 (2002) Assert JDK 5.0 (2004) changes in the language generics, annotations,... JDK 6 (2006) changes in libraries only JDK 7 (2011) (small) changes in the language JDK 8 (2014) big changes in the language lambdas, JDK 9 (2017) changes in the language modules,... 6

Java platform JSE standard edition JEE enterprise edition JME micro edition JEE JSE JME Java Card API 7

Obtaining Java http://www.oracle.com/technetwork/java/javase/ /downloads/index.html JDK compiler, virtual machine, debugger,... Windows, Linux, Solaris JRE without development tools (i.e. without compiler,...) Windows, Linux, Solaris documentation IDE Netbeans http://www.netbeans.org/ Eclipse http://www.eclipse.org/ IntelliJ IDEA https://www.jetbrains.com/idea/ Ant like the make program http://ant.apache.org/ Maven like Ant on Steroids http://mave.apache.org/ 8

Approx. time-line of the course Language classes, primitive types, programming constructions,... Basic tools Core classes from the std. library threads, collection, I/O,... 9

JAVA Language 10

Comments Comment /* comment */ // comment till the end of the line "documentation" comments (javadoc) /** comment */ 11

Objects Everything is object Object an instance of a class or array new instances via the operator new Everything defined in a class i.e. no functions outside classes (e.g. like in C++) Working with objects references no pointers String s; String s = new String("hello"); 12

References StringBuilder s1 = new StringBuilder("hello"); StringBuilder s2 = s1; s1.append(" world"); System.out.println(s2); // prints out "hello world" 13

Primitive types Exception not everything is object variables are not references fixed size, signed only int a = 10; Type Size Min Max Wrapper boolean - - - Boolean char 16-bit Unicode 0 Unicode 2 16-1 Character byte 8-bit -128 +127 Byte short 16-bit -2 15 +2 15-1 Short int 32-bit -2 31 +2 31-1 Integer long 64-bit -2 63 +2 63-1 Long float 32-bit IEEE754 IEEE754 Float double 64-bit IEEE754 IEEE754 Double 14

Primitive types variables int i1 = 42; int i2 = i1; i1 += 1; System.out.println(i2); // prints out 42 15

Primitive types Internal representation of integer types signed two's-complement integers example for byte 0 ~ 00000000 127 ~ 01111111-1 ~ 11111111-128 ~ 10000000 Floating point types allow representation of the NaN value (not-a-number) every comparison of NaNs is false 16

Autoboxing, autounboxing since Java 5 automated conversion between primitive types and corresponding wrappers int a = 5; Integer b = a; int c = b; // autoboxing // autounboxing 17

Arrays access checked at run-time definitions of arrays int[] iarray; int i2array[]; multidimensional array int[][] iiarray; instantiation of arrays only dynamically iarray = new int [10]; array length iarray.length 18

Object disposal garbage collector 19

Class definition class MyClass { /* class body */ } class body fields methods inner classes 20

Class: Fields class MyClass { int i; float f; boolean b; String s; }... MyClass m = new MyClass(); m.i = 5; m.f = 3.7; m.b = true; m.s = new String(); 21

Class: Fields Default values boolean false other primitive types 0 references null Warning local variables are not initialized compilation error 22

Class: Methods returntype methodname ( arguments ){ method body; } class MyClass { int pow2(int a) { return a*a; } } void nothing() {} 23

Class: Methods method call object.methodname(arguments) MyClass m = new MyClass(); int a = m.pow2(5); Arguments passed by value 24

enum Since Java 5 enum Planet { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE, PLUTO };... public Planet pl = MARS; 25

Packages namespaces package a set of classes related in some way like namespace in C#, C++ every class belongs to exactly one package an explicitly specified, or the default unnamed package package specification package nameofpackage; 26

Packages hierarchical names "reversed" internet domain name of a creator cz.cuni.mff.java.example01 org.w3c.dom full name of a class packagename.classname class from the same package "short" name classes from another package full name simplified usage by import import packagename.classname; import packagename.*; package java.lang always imported 27

Key-word static static fields and methods not connected with a particular instance (object) "class data", "class methods" class MyClass { static int i; } class MyClass2 { static void incr() { MyClass.i++; } } 28

static import since Java 5 import of static elements usage without the class name import static java.lang.math.pi; import static java.lang.math.tan;... tan(pi/4); 29

Local variables visibility { } int x=10; // x is visible { int y=11; // x and y are visible } // x is visible only { int x = 1; { int x = 2; // compile-time error }} 30

Classes and files every public class in a separated file the same name as the class + the.java extension packages ~ directories package packagename; import...; import...; public class ClassName {... } non-public classes (without public) visible from the same package only 31

Program package cz.cuni.mff.java.example01; public class Hello { public static void main(string[] args){ System.out.println("Hello world!"); } } save to directory.../cz/cuni/mff/java/example01 file Hello.java 32

Program compilation javac Hello.java creates Hello.class execution java cz.cuni.mff.java.example01.hello CLASSPATH list of directories, where the compiler/virtual machine looks for classes environment variable CLASSPATH arguments -cp, -classpath examples /home/petr/java/cz/cuni/mff/java/example01/hello.class java -cp /home/petr/java cz.cuni.mff.java.example01.hello 33

Modules since Java 9 a module a named collection of classes (and other elements) (a set of packeges) declares, which other modules it requires own packages exports the visibility (accessibility) of classes is changed module-info.java module com.foo.bar { requires com.foo.baz; exports com.foo.bar.alpha; exports com.foo.bar.beta; } 34

Modules since Java 9 MODULEPATH similar to CLASSPATH modules can be ignored without a module specified => a class is in the unnamed module requires all other modules exports all of its packages particularly for backward compatibility 35

Operators: assignment Assignment int i; int[] array; i = 4; array[4] = 5; 4 = i; // compile-time error Primitive types copying values Objects copying references not objects! 36

Operators: arithmetic unary + - binary + - * / % "short-cuts for assignment += -= *= /= %= increment and decrement prefix and postfix i-- i++ --i ++i overflows and underflows are silent no exception 37

Operators: comparison boolean result ==!= all types < > <= >= all primitive except boolean test what is printed out? Integer i1 = new Integer(1); Integer i2 = new Integer(1); if (i1 == i2) System.out.println("YES"); else System.out.println("NO"); 38

Operators: logical boolean result can be used on boolean only &&! short-circuit evaluation 39

Operators: bitwise can be used on short, int, long, char and boolean & ^ ~ short-cuts &= = ^= eager evaluation type boolean considered as 1-bit value operator ~ cannot be used on boolean 40

Operators: shifts can be used on short, int, long, char left shift << adds zeros to lower bits right shift >> if number positive ads zeros if number negative ads ones unsigned right shift >>> always adds zeros char, byte, short first converted to int result always int long result is long 41

Operators: misc Ternary operator int a; a = a > 0? a : 0; Operator comma only in the begging of the for cycle Operator + on String concatenates Strings if there is at least one String and only the + operators in an expression, then everything is converted to String and concatenated Cast int i = 1; long x = (long) i; No sizeof operator no need 42

Operators: priority unary + - ++ -- arithmetic and shift * / % + - << >> comparison > < >= <= ==!= logical and bitwise && & ^ ternary?: assignment = (shortcuts +=) In a case of the same priority, expression is evaluated from left 43

if - else if (boolean-expression) statement else statement else branch can be ommitted statement single statement, or block {...} 44

while, do - while while (boolean-expression) statement do statement while (boolean-expression); cycling while the boolean expression is true 45

for for (initialization; boolean-expression; step) statement in the initialization and step, operator comma can be used for (int i=1,j=1; i<5; i++, j=i*10) {... } 46

for (since Java 5) int[] arr = new int [10]; for (int i:arr) {... } arrays, or classes with the iterator 47

break, continue break stops a cycle execution continue stops the current round of a cycle and starts new one labels have meaning only with cycles label: outer-cycle { inner-cycle { break; continue; continue label; break label; }} 48

goto goto reserved, but not used http://xkcd.com/292/ 49

switch int a;... switch (a) { case 1: case 2: System.out.println("1, 2"); break; case 3: System.out.println("3"); break; default: System.out.println("3.."); } since Java 7, switch can be used with the String type 50

Java, winter Slides semester version 2017 J01.en.2017.01 This slides are licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. 51