1 Java
1 Java
OPERATING SYSTEM 1
JAVA RUNTIME
ENVIRONMENT (JRE)
JAVA javac BYTE java JAVA VIRTUAL
APP CODE MACHINE (JVM)
.java .class
OPERATING SYSTEM 2
JAVA RUNTIME
ENVIRONMENT (JRE)
javac java
JAVA BYTE JAVA VIRTUAL
APP CODE MACHINE (JVM)
.java .class
OBJECT ORIENTED PROGRAMMING
– ENCAPSULATION
– INHERITANCE
–Simple Inheritance
–Multi Level Inheritance
–Multiple Inheritance
– ABSTRACTION / POLIMORPHISM
• SECURED
– DATA ENCAPSULATION
– NO POINTERS
– NO UNAUTHORISED CODE
JAVA
J2SE J2EE J2ME
Simple Programme in JAVA
import java.lang.*;
public class Hello
{
public static void main(String args[])
{
System.out.println(“Hello, Friend”);
}
}
How To Excecute a Programme
Set the path and classpath
PATH=%PATH%;c:\j2sdk1.4.0\bin
CLASSPATH=c:\j2sdk1.4.0\lib\tools.jar
Save
Hello.java
Compile
prompt:\> javac Hello.java
Execute
prompt:\> java Hello
Output
Hello, Friend
EXPRESSION
Expression:
An expression is a combination of
operators and operands.
c = a + b;
OPERANDS OPERATORS
VARIABLE
It is a reference to a value in the memory.
These are two types..
1. Instance Variables
Ex.: int a=5;
boolean b=false;
2. Reference Variables
Ex.: Circle c=new Circle();
Student stud=new Student();
Data Types
Type Memory Initials Value
• byte 1 byte 0
• short 2 bytes 0
• int 4 bytes 0
• long 8 bytes 0
• float 4 bytes 0.0
• double 8 bytes 0.0
• char 2 bytes nil
• boolean true / false false
Declaration of Variables
<data_type> <variable> = <initial_value>;
Example:
byte a = 5;
short b = 100;
int n = 5000;
long l = 10000;
float f = 5.5 f;
double d = 10.5; double d=10.5d;
char c = ‘a’;
boolean b = true;
OPERATORS
These are mainly categorized into 3 types as
– UNARY OPERATORS Ex: --, ++
– BINARY OPERATORS Ex: +, -, *, /
– TERNARY OPERATORS Ex: ? :
while(true)
while(condition)
{
{
Statements;
Statements;
if(condition)
inc/dec/conf stmt;
break;
}
}
Iterative Statements
Do..while statement:
do
{
Statements;
inc/dec/conf stmt;
} while(condition);
Iterative Statements
For statement:
while(condition)
{
for(initialisation; condition; inc/dec)
{
Statements;
}
inc/dec/conf stmt;
}
Iterative Statements
Nested Looping Statement:
while(condition)
{
do
{
Statements;
inc/dec/conf stmt;
} while(condition);
inc/dec/conf stmt;
}
Iterative Statements
Nested Looping Statement:
do
{
while(condition)
{
Statements;
inc/dec/conf stmt;
}
inc/dec/conf stmt;
} while(condition);
Iterative Statements
Nested Looping Statement:
do
{
for(initialisation; condition; inc/dec)
{
Statements;
}
inc/dec/conf stmt;
} while(condition);
break
while(true) for( ; ; )
{ {
statements; statements;
if(condition) if(condition)
break; break;
statements; statements;
} }
break
abc: for(int i=0; i<10; i++)
{
for(int j=0; j<10; j++)
{
statements;
if(condition)
break abc;
statements;
}
}
continue
while(true) for( ; ; )
{ {
statements; statements;
if(condition) if(condition)
continue; continue;
statements; statements;
} }
continue
abc: for(int i=0; i<10; i++)
{
for(int j=0; j<10; j++)
{
if(condition)
continue abc;
}
}