Professional Documents
Culture Documents
Akhilesh Chandra
Session Objectives
Akhilesh Chandra
OOP PRINCIPLES
• ABSTRACTION
• ENCAPSULATION
• INHERITANCE
• POLYMORPHISM
Akhilesh Chandra
ENCAPSULATION
Akhilesh Chandra
INHERITANCE
Akhilesh Chandra
POLYMORPHISM
Akhilesh Chandra
Introduction to JAVA
Primary motivation behind:
• Platform neutral programming language
• Primarily developed as a cost efficient
solution for consumer Electronic devices .
• Later, came it’s importance on Internet.
• This caused the focus of Java to shift from
consumer electronics to Internet
programming.
Akhilesh Chandra
Similarities between Java and C++
Akhilesh Chandra
Importance of Java on Internet
• Two broad categories of objects those are
transmitted over Net:
– Passive information.
– Dynamic/active programs.
• Java addresses the security and portability
concerns that are involved in downloading
Dynamic programs over Internet , in the
form of Applets.
Akhilesh Chandra
How Java is Platform
Independent
WINDOWS UNIX
BYTE CODE
UNIX WINDOWS
SOLARIS SOLARIS
Akhilesh Chandra
Byte Code
Akhilesh Chandra
JVM Architecture
Class Loader
Akhilesh Chandra
Features of Java
• Simple
• Object Oriented
• Portable
• Robust
• Multi Threaded
• High Performance
• Distributed
• Dynamic
Akhilesh Chandra
// Example 1
class ex1
{
public static void main(String args[])
{
System.out.println("Hello World");
}
}
Akhilesh Chandra
DATA TYPES
Akhilesh Chandra
Integer types
• long 64 -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
Akhilesh Chandra
FLOATING-POINT
Akhilesh Chandra
class ex2
{
public static void main(String args[])
{
int num;
num = 100;
System.out.println("Number is " +num);
num = num * 2;
System.out.println("Number after change is " + num);
}
}
Akhilesh Chandra
/* To understand the scope of variable Example 3 */
class ex3{
public static void main(String args[])
{ int x;
x = 10;
if(x == 10)
{ int y=20;
System.out.println("X and Y are :"+ x + " " + y);
x = y * 2;
}
y =100; //Is it Accessible here
System.out.println("X is " +x);
Akhilesh Chandra
/* To demonstrate the life time of variables
Example 4 */
class ex4 {
public static void main(String args[])
{
int x;
for(x=0;x<3;x++)
{
int y =-1;
System.out.println("Y is : " +y);
y =100;
System.out.println("Y is now :" +y);
Akhilesh Chandra
} } }
/* To demonstrate some kind of error
Example 5*/
class ex5 {
public static void main(String args[])
{
int num =1;
{
int num =2; //Compile time error
System.out.println(num);
}
}
Akhilesh Chandra
Type Conversion
Akhilesh Chandra
Points regarding type
Compatibility
Akhilesh Chandra
Type Casting
• To have a conversion between two incompatible
types , we use casting.
• A cast is an explicit type conversion.
• General form :
– (target type) value;
Ex: Converting an int to byte
int a;
byte b = a; //gives an error
byte b= (byte)a; //resolves the error.
Akhilesh Chandra
Automatic Type Promotion
• In an Expression, automatic type promotion takes
place.
• Java automatically promotes each of the operands
to int , while evaluating an expression.
Ex: byte a = 40;
byte b = 50;
byte c = a * b; // Gives an error
int d = a * b; // This is valid.
Ex: byte b =50;
b = b* 2; // Is there any error?Try to resolve.
Akhilesh Chandra
Type Promotion Rules
Akhilesh Chandra