INTRODUCTION OF JAVA
PRESENTED BY,
RANJITHAM.N
INTRODUCTION TO JAVA:
• Java was originally developed by James Gosling at Sun
Microsystems .
• It was released in 1995.
• Java applications are typically compiled to Bytecode that can run on
any Java Virtual Machine.
• The language derives much of its syntax from C and C++.
WHAT IS JAVA?
• Java is a computer programming language.
• It is concurrent and written in the concept of Class and Object.
• Purely Object oriented programming.
• Platform independent.
FEATURES OF JAVA:
• Simple
• Secure
• Portable
• Object oriented
• Multithreaded
• High performance
• Dynamic
• interpreted
APPLICATIONS OF JAVA:
• Java program can run on any PC or any operating system.
• Simple and Standalone.
• Mobile application.
• Enterprise.
• Web application
HOW JAVA DIFFER FROM C++:
JAVA PROGRAMMING C++ PROGRAMMING
• Completely object oriented language. • partially object oriented language.
• It is portable. • It is non portable.
• Both compiler and interpreter are
used.
• Only compiler is used.
• Pointer is not used in java. • Pointer is used in c++.
• no global variable is present. • Global variable is present.
• Operator overloading is not possible. • Operator overloading is possible.
• Scope resolution operator is used. • Scope resolution operator is used.
HOW JAVA DIFFER FROM C:
JAVA PROGRAMMING C PROGRAMMING
• Object oriented language. • Function oriented language.
• It is built into long security. • It has limited security.
• Allocating memory by memory
function.
• Allocation of memory by new
function.
• Memory address is through pointers. • Memory address is through reference.
OBJECT ORIETNED PROGRAMMING CONCEPTS:
• Object
• Class
• Data abstraction
• Data encapsulation
• Polymorphism
• Inheritance
• Dynamic binding
• Message communication
OBJECT:
• Basic runtime entity.
• Represent user defined datatype.
• Object interact by sending messages to one another.
CLASS:
• Collection of similar objects.
• User defined datatype.
• Eg: Fruit.
DATA ABSTRACTION:
• The act of representing essential feautures without including the
background details.
• Insulation of the data from direct access by the program is called as
data hiding.
DATA ENCAPSULATION:
• Wrapping up of data and methods into a single unit.
INHERITANCE:
• Objects of one class acquired the properties of objects of another
class.
• Supports the concepts of hierarchical classification.
• Provides the idea of reusability.
• Can add additional features to an existing class without modifying
it.
TYPES OF INHERITANCE:
• Single inheritance
• Multiple inheritance
• Multilevel inheritance
• Hierarchical inheritance
• Hybrid inheritance.
POLYMORPHISM:
• Ability to take more than one form.
• Exhibit different behaviour in different instances.
• Single function name can be used to handle different number an
different types of arguments.
TYPES:
• Dynamic polymorphism.
• Static polymorphism.
DYNAMIC BINDING:
• The code assosiated with the given procedure call is not known
until the time of the call at runtime.
• Assosiated with the polymorphism an inheritance.
• A procedure call associated with a polymorphic reference depends
on the dynamic type of the reference.
MESSAGE COMMUNICATION:
• Program consists of a set of objects that communicate with each
other.
Involves the following basic steps:
• creating classes that define objects and their behaviour .
• creating objects from class definition.
• establishing communications among objects.
DEFINING THE CLASS:
• Once the class type has been defined,we can create the variables.
• Variables are termed as instances of classes.
SYNTAX:
class classname [extends superclassname]
{
fields declaration;
method declaration;
}
METHODS:
• Methods are declared inside the body of the class.
• Methods that are necessary to manipulate the data
contained in the class.
SYNTAX:
type methodname (parameter_list)
{
method_body;
}
METHOD DECLARATION:
• The name of the methods(method name).
• The type of the value the method returns(type).
• A list of parameters(parameter_list).
• The body of the method.
public class Cse
{
public void show()
{
System.out.println("Sample Method ");
}
public static void main(String args[])
{
Cse obj=new Cse1();
obj.show();
}
}
PROGRAM FOR METHOD DECLARATION:
FINALIZER METHODS:
• Java supports a concept called Finalization.
• Java runtime is an automatic garbage collecting system.
• Automatically frees up the memory resources used by the objects.
SYNTAX
protected void finalize()
{
…
...
}
ACCESS SPECIFIERS:
• It is restrict the place where we are using the member of the
class.
• It is used to access the member.
THREE TYPES:
• private
• protected
• public
STATIC:
• Can be called without objects.
• Initialization is not necessary.
• Static function can access only the static variables.
PROGRAM:
class sample
{
public static void main(String[] args) {
display(); }
static void display() {
System.out.println(“hai hello");
} }
STATIC MEMBER:
• The member that are declared static as shown above are static
member.
• Gets memory only in class area at the time of class loading.
• Memory efficient.
Types of static member:
• static variable
• static method
• static block
STATIC MEMBER:
class math
{
Static float mul(float x.float y)
{
return x*y;
}
Static float div(float x,float y)
{
return x/y;
}
}
class math
{
public void static main(string args[])
{
float a=math.mul(4.0.5.0);
float b=math.div(a,2.0);
System.out.println(“b=“+b);
}
}
STATIC VARIABLE
• Gets memory only in class area at the time of class loading.
• Memory efficient.
Class Stu
{
int rollnumber;
string name;
Static string name=“ITS”
Stu( int r.string n)
{
rollnumber=r;
name=n;
}
Void display()
{
System.out.println(“+rollnumber+”
”+name+””+college+”);
}
Public Static void main (string args[])
{
Stu s1=new stu(111,”karan”);
Stu s1=new stu(222”priya”);
S1.display();
S2.display();
}
STATIC METHOD:
• It belongs to the class rare than the object of the class .
• Invoked without the need for creating a instance of class.
• It can access static data member and can change value of it.
class Calculate
{
Static int cube(int x);
return x*x*x;
}
STATIC BLOCK:
 It is used to initialize the static data member.
 Executed before main method at the time of class loading.
Program:
class cse
{
Static { system.out.println(“static block is invoked”);}
public static main(string args[]);
}
CONSTRUCTOR:
• It is a special method where will invoke automatically when the time
of object creation.
Rules:
• Constructor name and the class name should be same.
• It wont have any return type.
• It is used to assign the value to the instance variable.
• It can be with parameter or without parameter..
PROGRAM FOR CONSTRUCTORS:
public class Cube1 {
int length;
int breadth;
int height;
public int getVolume() {
return (length * breadth * height);
}
Cube1() {
length = 10;
breadth = 10;
height = 10;
}
Cube1(int l, int b, int h) {
length = l;
breadth = b;
height = h;
}
public static void main(String[]
args) {
Cube1 cubeObj1, cubeObj2;
cubeObj1 = new Cube1();
cubeObj2 = new Cube1(10, 20, 30);
System.out.println(”Volume of
Cube1 is : ” +
cubeObj1.getVolume());
System.out.println(”Volume of
Cube1 is : ” +
cubeObj2.getVolume());
}
Java2

Java2

  • 1.
  • 2.
    INTRODUCTION TO JAVA: •Java was originally developed by James Gosling at Sun Microsystems . • It was released in 1995. • Java applications are typically compiled to Bytecode that can run on any Java Virtual Machine. • The language derives much of its syntax from C and C++.
  • 3.
    WHAT IS JAVA? •Java is a computer programming language. • It is concurrent and written in the concept of Class and Object. • Purely Object oriented programming. • Platform independent.
  • 4.
    FEATURES OF JAVA: •Simple • Secure • Portable • Object oriented • Multithreaded • High performance • Dynamic • interpreted
  • 5.
    APPLICATIONS OF JAVA: •Java program can run on any PC or any operating system. • Simple and Standalone. • Mobile application. • Enterprise. • Web application
  • 6.
    HOW JAVA DIFFERFROM C++: JAVA PROGRAMMING C++ PROGRAMMING • Completely object oriented language. • partially object oriented language. • It is portable. • It is non portable. • Both compiler and interpreter are used. • Only compiler is used. • Pointer is not used in java. • Pointer is used in c++. • no global variable is present. • Global variable is present. • Operator overloading is not possible. • Operator overloading is possible. • Scope resolution operator is used. • Scope resolution operator is used.
  • 7.
    HOW JAVA DIFFERFROM C: JAVA PROGRAMMING C PROGRAMMING • Object oriented language. • Function oriented language. • It is built into long security. • It has limited security. • Allocating memory by memory function. • Allocation of memory by new function. • Memory address is through pointers. • Memory address is through reference.
  • 8.
    OBJECT ORIETNED PROGRAMMINGCONCEPTS: • Object • Class • Data abstraction • Data encapsulation • Polymorphism • Inheritance • Dynamic binding • Message communication
  • 9.
    OBJECT: • Basic runtimeentity. • Represent user defined datatype. • Object interact by sending messages to one another. CLASS: • Collection of similar objects. • User defined datatype. • Eg: Fruit.
  • 10.
    DATA ABSTRACTION: • Theact of representing essential feautures without including the background details. • Insulation of the data from direct access by the program is called as data hiding. DATA ENCAPSULATION: • Wrapping up of data and methods into a single unit.
  • 11.
    INHERITANCE: • Objects ofone class acquired the properties of objects of another class. • Supports the concepts of hierarchical classification. • Provides the idea of reusability. • Can add additional features to an existing class without modifying it.
  • 12.
    TYPES OF INHERITANCE: •Single inheritance • Multiple inheritance • Multilevel inheritance • Hierarchical inheritance • Hybrid inheritance.
  • 13.
    POLYMORPHISM: • Ability totake more than one form. • Exhibit different behaviour in different instances. • Single function name can be used to handle different number an different types of arguments. TYPES: • Dynamic polymorphism. • Static polymorphism.
  • 14.
    DYNAMIC BINDING: • Thecode assosiated with the given procedure call is not known until the time of the call at runtime. • Assosiated with the polymorphism an inheritance. • A procedure call associated with a polymorphic reference depends on the dynamic type of the reference.
  • 15.
    MESSAGE COMMUNICATION: • Programconsists of a set of objects that communicate with each other. Involves the following basic steps: • creating classes that define objects and their behaviour . • creating objects from class definition. • establishing communications among objects.
  • 16.
    DEFINING THE CLASS: •Once the class type has been defined,we can create the variables. • Variables are termed as instances of classes. SYNTAX: class classname [extends superclassname] { fields declaration; method declaration; }
  • 17.
    METHODS: • Methods aredeclared inside the body of the class. • Methods that are necessary to manipulate the data contained in the class. SYNTAX: type methodname (parameter_list) { method_body; }
  • 18.
    METHOD DECLARATION: • Thename of the methods(method name). • The type of the value the method returns(type). • A list of parameters(parameter_list). • The body of the method.
  • 19.
    public class Cse { publicvoid show() { System.out.println("Sample Method "); } public static void main(String args[]) { Cse obj=new Cse1(); obj.show(); } } PROGRAM FOR METHOD DECLARATION:
  • 20.
    FINALIZER METHODS: • Javasupports a concept called Finalization. • Java runtime is an automatic garbage collecting system. • Automatically frees up the memory resources used by the objects. SYNTAX protected void finalize() { … ... }
  • 21.
    ACCESS SPECIFIERS: • Itis restrict the place where we are using the member of the class. • It is used to access the member. THREE TYPES: • private • protected • public
  • 22.
    STATIC: • Can becalled without objects. • Initialization is not necessary. • Static function can access only the static variables. PROGRAM: class sample { public static void main(String[] args) { display(); } static void display() { System.out.println(“hai hello"); } }
  • 23.
    STATIC MEMBER: • Themember that are declared static as shown above are static member. • Gets memory only in class area at the time of class loading. • Memory efficient. Types of static member: • static variable • static method • static block
  • 24.
    STATIC MEMBER: class math { Staticfloat mul(float x.float y) { return x*y; } Static float div(float x,float y) { return x/y; } } class math { public void static main(string args[]) { float a=math.mul(4.0.5.0); float b=math.div(a,2.0); System.out.println(“b=“+b); } }
  • 25.
    STATIC VARIABLE • Getsmemory only in class area at the time of class loading. • Memory efficient. Class Stu { int rollnumber; string name; Static string name=“ITS” Stu( int r.string n) { rollnumber=r; name=n; } Void display() { System.out.println(“+rollnumber+” ”+name+””+college+”); } Public Static void main (string args[]) { Stu s1=new stu(111,”karan”); Stu s1=new stu(222”priya”); S1.display(); S2.display(); }
  • 26.
    STATIC METHOD: • Itbelongs to the class rare than the object of the class . • Invoked without the need for creating a instance of class. • It can access static data member and can change value of it. class Calculate { Static int cube(int x); return x*x*x; }
  • 27.
    STATIC BLOCK:  Itis used to initialize the static data member.  Executed before main method at the time of class loading. Program: class cse { Static { system.out.println(“static block is invoked”);} public static main(string args[]); }
  • 28.
    CONSTRUCTOR: • It isa special method where will invoke automatically when the time of object creation. Rules: • Constructor name and the class name should be same. • It wont have any return type. • It is used to assign the value to the instance variable. • It can be with parameter or without parameter..
  • 29.
    PROGRAM FOR CONSTRUCTORS: publicclass Cube1 { int length; int breadth; int height; public int getVolume() { return (length * breadth * height); } Cube1() { length = 10; breadth = 10; height = 10; } Cube1(int l, int b, int h) { length = l; breadth = b; height = h; } public static void main(String[] args) { Cube1 cubeObj1, cubeObj2; cubeObj1 = new Cube1(); cubeObj2 = new Cube1(10, 20, 30); System.out.println(”Volume of Cube1 is : ” + cubeObj1.getVolume()); System.out.println(”Volume of Cube1 is : ” + cubeObj2.getVolume()); }