Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement Introduce “String” object Exercise 1 would be posted
Primitive data types in Java: byte (8 bits) short (16 bits) int (32 bits) long (64 bits) float (32 bit single precision) double (64 bit double precision) boolean (true/false value) char (16 bit Unicode character)
Examples of variable declaration(initialization is optional): boolean result = true; char capitalC = 'C'; byte b = 100; short s = 10000; int i = ;
Method declaration has 6 components modifier (public/private) return type method name parameter list exception list( will be discussed later ) method body
Example for method declaration: public int add(int a, int b) { return a+b; }
The ‘for’ loop: for( ; ; increment) { //program statements. }
If-then statement: if( ) { //program statements. } else { //program statements. }
If-then-else statement: if( ) { //program statements. } else if( ) { //program statements. } else { //program statements. }
‘String’ – the string class represents character strings. String str = “abc”; String str = new(“abc”);