Java Programming For Beginners
Java Programming For Beginners
Visit:www.quontrasolutions.com
Call :(404)900-9988
Java - General
Java
is:
Java - General
Java
How it works!
Compile-time Environment
Compile-time Environment
Class
Loader
Bytecode
Verifier
Java
Source
(.java)
Java
Compiler
Java
Class
Libraries
Java
Bytecodes
move locally
or through
network
Java
Interpreter
Just in
Time
Compiler
Runtime System
Java
Bytecode
(.class )
Operating System
Visit:www.quontrasolutions.com
Call :(404)900-9988 Hardware
Java
Virtual
machine
How it works!
Visit:www.quontrasolutions.com
Call :(404)900-9988
Java - Security
Pointer
Object-Oriented
Java
supports OOD
Polymorphism
Inheritance
Encapsulation
Java
Java Advantages
Visit:www.quontrasolutions.com
Call :(404)900-9988
Initialisation
Declarations
int index = 1.2;
// compiler error
boolean retOk = 1;
// compiler error
double fiveFourths = 5 / 4; // no error!
float ratio = 5.8f;
// correct
double fiveFourths = 5.0 / 4.0;
// correct
Visit:www.quontrasolutions.com
Call :(404)900-9988
Assignment
int a = 1, b = 2, c = 5
a=b=c
System.out.print(
a= + a + b= + b + c= + c)
Visit:www.quontrasolutions.com
Call :(404)900-9988
double myVal = a + b % d c * d / b;
Visit:www.quontrasolutions.com
Call :(404)900-9988
Flow of Control
Java executes one statement after the other
in the order they are written
Many Java statements are flow control
statements:
Alternation:
if, if else, switch
Looping:
for, while, do while
Escapes:
break, continue, return
Visit:www.quontrasolutions.com
Call :(404)900-9988
Or, alternatively:
if ( x < 10 ) { x = 10; }
Visit:www.quontrasolutions.com
Call :(404)900-9988
Relational Operators
==
!=
>=
<=
>
<
Equal (careful)
Not equal
Greater than or equal
Less than or equal
Greater than
Less than
Visit:www.quontrasolutions.com
Call :(404)900-9988
If else
Visit:www.quontrasolutions.com
Call :(404)900-9988
Nested if else
if ( myVal > 100 ) {
if ( remainderOn == true) {
myVal = mVal % 100;
}
else {
myVal = myVal / 100.0;
}
}
else
{
System.out.print(myVal is in range);
}
Visit:www.quontrasolutions.com
Call :(404)900-9988
else if
A Warning
WRONG!
if( i == j )
if ( j == k )
System.out.print(
i equals k);
else
System.out.print(
i is not equal
to j);
CORRECT!
if( i == j ) {
if ( j == k )
System.out.print(
i equals k);
}
else
System.out.print(
i is not equal to
j);
// Correct!
Visit:www.quontrasolutions.com
Call :(404)900-9988
Loop n times
for ( i = 0; i < n; n++ ) {
// this code body will execute n times
// ifrom 0 to n-1
}
Nested for:
for ( j = 0; j < 10; j++ ) {
for ( i = 0; i < 20; i++ ){
// this code body will execute 200 times
}
}
Visit:www.quontrasolutions.com
Call :(404)900-9988
while loops
while(response == 1) {
System.out.print( ID = + userID[n]);
n++;
response = readInt( Enter );
}
do { } while loops
do {
System.out.print( ID = + userID[n] );
n++;
response = readInt( Enter );
}while (response == 1);
Break
Continue
Visit:www.quontrasolutions.com
Call :(404)900-9988
Arrays
Visit:www.quontrasolutions.com
Call :(404)900-9988
myArray
=
Visit:www.quontrasolutions.com
Call :(404)900-9988
Declaring Arrays
int myArray[];
declares myArray to be an array of integers
myArray = new int[8];
sets up 8 integer-sized spaces in memory,
labelled myArray[0] to myArray[7]
int myArray[] = new int[8];
combines the two statements in one line
Visit:www.quontrasolutions.com
Call :(404)900-9988
Assigning Values
Visit:www.quontrasolutions.com
Call :(404)900-9988
Visit:www.quontrasolutions.com
Call :(404)900-9988
Arrays of Objects
Visit:www.quontrasolutions.com
Call :(404)900-9988
Student("Cathy", "Computing");
Visit:www.quontrasolutions.com
Call :(404)900-9988
Visit:www.quontrasolutions.com
Call :(404)900-9988