Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Oriented Programming Lecture 2: BallWorld.

Similar presentations


Presentation on theme: "Object Oriented Programming Lecture 2: BallWorld."— Presentation transcript:

1 Object Oriented Programming Lecture 2: BallWorld

2 1 st Java A first Java program (outline) import java.lang.*; public class Test { public static void main(String [] args) { System.out.println("Hello"); }

3 Running Java is interpreted – The Java interpreter must be installed The Java ‘compiler’ is called ‘javac’ The Java interpreter is called ‘java’

4 Java 1 Declarations – Primitive types int 32 bit signed integer byte 8 bit signed integer short 16 bit signed integer long 64 bit signed integer float 32 bits double 64 bits char 16 bits (Unicode) boolean No typedef No struct, have class No (explicit) pointers (references instead)

5 String String is a built-in type (note the capital S) Many functions ‘+’ for concatenation ‘toString’ methods for conversion Conversions often automatic int x = 123; float y = 23.66f; System.out.print ("Hello " + x + " and " + y);

6 Java 2 Arrays are always dynamic (a.length) int [] a; int a[]; // alternative a = new int[10]; // allocate int i; for (i = 0; i < 10; i++) a[i] = ……; for (i = 9; i >= 0; i--) System.out.println( "a[" + i + "] = " + a[i]); a = null; // no deallocate

7 Java 2 Multi-dimensional arrays int [] [] a; int a[][]; // alternative a = new int[10][20]; a[1][7] =...; a = new int [10] []; a[0] = new int[10]; a[1] = new int[11];

8 Java 3 Statements are the same as C/C++ – if, switch (case, break), for, while – Assignment Expressions also similar to C/C++ – type cast using (char)10 style notation Routines as for C/C++ – return Exception handling used more often – throw, try and catch – see later

9 Exercises Chapter 4 Questions on page 63 – 2, 9 to 14 Exercises on pages 63-65 – 2 to 5 Write a program taking two integers as command line arguments and drawing an outline rectangle of ‘*’ characters of the given size. To be verified: Pg 63: Q 12-14 and the rectangle programming exercise


Download ppt "Object Oriented Programming Lecture 2: BallWorld."

Similar presentations


Ads by Google