2.Java Programming Day2
2.Java Programming Day2
Java Programming
• Lesson 3: Applets
• Lesson 8: Interfaces
• Lesson 9: Multi-Threading
Primitive Reference
byte Byte
char Character
short Short
int Integer
long Long
float Float
double Double
String s3 = Integer.toHexString(254);
System.out.println("254 is " + s3);
POSITIVE_INFINITY
str1 = null;
Stack
str1.anyMethod(); // ILLEGAL!
//Throws NullPointerException
• Unary Operators:
+ - ++ -- ! ~ ()
positive negative increment decrement boolean bitwise casting
complement inversion
Widening
(implicit casting)
Narrowing
char (requires explicit casting)
• Arithmetic Operators:
+ - * / %
add subtract multiply division modulo
• Assignment Operators:
= += -= *= /= %= &= |= ^=
• Relational Operators:
• Shift Operators:
>> << >>>
right shift left shift unsigned right shift
• Ternary Operator:
Stack myArr
System.out.println(myArr[2]);
myArr[3] = … ; // ILLEGAL!
//Throws ArrayIndexOutOfBoundsException
“Gosling”
namesArr[0] = new String(“Hello”);
namesArr[1] = new String(“James”); Stack
namesArr
namesArr[2] = new String(“Gosling”);
System.out.println(namesArr[1]);
if(myStr1.equals(sp1))
if(myStr1.equalsIgnoreCase(sp1))
if(myStr1 == sp1)
// Shallow Comparison (just compares the references)
• The ‘+’ and ‘+=‘ operators were overloaded for class String
to be used in concatenation.
“Hello”
String s1 = new String(“Hello”);
“Welcome”
String s2 = new String(“Hello”); Heap
“Hello”
String strP1 = “Welcome” ;
String strP2 = “Welcome” ;
print(“Pass”); print(“fail”);
switch(myVariable){ • byte
case value1: • short
…
… • int
break; • char
case value2:
… • enum
… • String “Java 7”
break;
default:
…
}
while (boolean_condition)
{
…
…
…
}
int x = 0;
while (x<10) {
System.out.println(x);
int x = 0;
x++;
}
false
x<10?
true
print(x);
x++;
int x = 0;
do{
int x = 0; System.out.println(x);
x++;
} while (x<10);
print(x);
x++;
false
x<10?
true
average /= samples.length;
• The following table illustrates these keywords and how they are
used.
synchronized - Yes -
1. * 2.
**
***
****
*****
******