30
INTRODUCTION OF JAVA PRESENTED BY, RANJITHAM.N

Java

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Java

INTRODUCTION OF JAVA

PRESENTED BY,

RANJITHAM.N

Page 2: Java

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++.

Page 3: Java

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.

Page 4: Java

FEATURES OF JAVA:

• Simple• Secure • Portable• Object oriented• Multithreaded• High performance• Dynamic • interpreted

Page 5: Java

APPLICATIONS OF JAVA:• Java program can run on any PC or any operating system.

• Simple and Standalone.

• Mobile application.

• Enterprise.

• Web application

Page 6: Java

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.

Page 7: Java

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.

Page 8: Java

OBJECT ORIETNED PROGRAMMING CONCEPTS:

• Object• Class• Data abstraction • Data encapsulation• Polymorphism• Inheritance• Dynamic binding• Message communication

Page 9: Java

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.

Page 10: Java

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.

Page 11: Java

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.

Page 12: Java

TYPES OF INHERITANCE:

• Single inheritance• Multiple inheritance• Multilevel inheritance• Hierarchical inheritance• Hybrid inheritance.

Page 13: Java

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.

Page 14: Java

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.

Page 15: Java

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.

Page 16: Java

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; }

Page 17: Java

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; }

Page 18: Java

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.

Page 19: Java

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:

Page 20: Java

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() { … ... }

Page 21: Java

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

Page 22: Java

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"); } }

Page 23: Java

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

Page 24: Java

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);}}

Page 25: Java

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();}

Page 26: Java

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;}

Page 27: Java

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[]);}

Page 28: Java

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..

Page 29: Java

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()); }

Page 30: Java

THANK YOU