42
Java Session 2

Java OOP s concepts and buzzwords

Embed Size (px)

DESCRIPTION

Presented by: N.V.RajaSekhar Reddy www.technolamp.co.in Want more interesting... Watch and Like us @ https://www.facebook.com/Technolamp.co.in subscribe videos @ http://www.youtube.com/user/nvrajasekhar

Citation preview

Page 1: Java OOP s concepts and buzzwords

Java Session 2

Page 2: Java OOP s concepts and buzzwords

Contents…

Oops Concepts

Java features

Page 3: Java OOP s concepts and buzzwords

Oops Concepts

• Class

• Object

• Polymorphism

• Inheritance

• Encapsulation

• Abstraction

Page 4: Java OOP s concepts and buzzwords

OOP

Page 5: Java OOP s concepts and buzzwords

Polymorphism

Page 6: Java OOP s concepts and buzzwords

Polymorphism

• Polymorphism gives us the ultimate flexibility in extensibility. The ability to define more than one function with the same name is called Polymorphism.

• In java, c++ there are two type of polymorphism:

compile time polymorphism (overloading)

runtime polymorphism (overriding).

Page 7: Java OOP s concepts and buzzwords

Polymorphism 1

Page 8: Java OOP s concepts and buzzwords

Polymorphism 2

Page 9: Java OOP s concepts and buzzwords

Polymorphism 3

Page 10: Java OOP s concepts and buzzwords

Polymorphism 4

Page 11: Java OOP s concepts and buzzwords

Polymorphism 5

Page 12: Java OOP s concepts and buzzwords

Polymorphism 6

Page 13: Java OOP s concepts and buzzwords

Polymorphism 7

Page 14: Java OOP s concepts and buzzwords

Overloading

• Example of Overloading

     int add(int a,int b)     float add(float a,int b)     float add(int a ,float b)     void add(float a)     int add(int a)     void add(int a) //error conflict with

the method int add(int a)

Page 15: Java OOP s concepts and buzzwords

OverLoading Class BookDetails{

            String title;            String publisher;            float price;

setBook(String title){ } setBook(String title, String publisher)

{} setBook(String title, String publisher,float

price){ } }

Page 16: Java OOP s concepts and buzzwords

(overriding).

class BookDetails{            String title;

setBook(String title){ }

}

class ScienceBook extends BookDetails{

            setBook(String   title){}           //overriding

setBook(String title, String publisher,float price)

{ }  //overloading

}

Page 17: Java OOP s concepts and buzzwords

Difference Between Java & C++

• In C++,Method Overloading is an example of Static Polymorphism Method Overriding is an example of Run time Polymorphism

• In Java, Method overloading and Method overriding can be achieved using static methods , final methods,private methods are examples of Static Polymorphism.Instance method is an ex of Runtime Polymorphism.

Page 18: Java OOP s concepts and buzzwords

Inheritance

• Inheritance is the property which allows a Child class to inherit some properties from its parent class.

• In Java this is achieved by using extends keyword.

• Only properties with access modifier public and protected can be accessed in child class.

Page 19: Java OOP s concepts and buzzwords

Inheritance

Page 20: Java OOP s concepts and buzzwords

Inheritance 1

Page 21: Java OOP s concepts and buzzwords

Inheritance 2

Page 22: Java OOP s concepts and buzzwords

Inheritance 3

Page 23: Java OOP s concepts and buzzwords

Inheritance 4

Page 24: Java OOP s concepts and buzzwords

Inheritance public class Parent

{

public String parentName;public int parentage;public String familyName;}

public class Child extends Parent

{

public String childName;public int childAge;

public void printMyName()

{System.out.println(“ My name is “+ chidName+” “ +familyName);} }

Page 25: Java OOP s concepts and buzzwords

Inheritance is the process by which object of one class acquires the properties of another class.

Page 26: Java OOP s concepts and buzzwords

Encapsulation• Encapsulation means that all data members

(fields) of a class are declared private. Some methods may be private, too.

• The class interacts with other classes (called the clients of this class) only through the class’s constructors and public methods.

• Constructors and public methods of a class serve as the interface to class’s clients.

Page 27: Java OOP s concepts and buzzwords

Encapsulation• Encapsulation is the mechanism that binds together code

and the data if manipulates, and keeps both safe from outside interference and misuse.

• One way to think about encapsulation is as a protective wrapper that prevents the code and data from being arbitrarily accessed by other code defined outside the wrapper.

• Access to the code and data inside the wrapper is tightly controlled through a well-defined interface. Conclusion: The wrapping up of data and methods into a single unit (called class) is known as encapsulation.

Page 28: Java OOP s concepts and buzzwords

Abstraction

• Abstraction refers to the act of representing essential features without including the background details.

• hiding unnecessary data from the users and making the application as user friendly then it is called as abstrcation

ex:Any mail account the user is simply filling the form and he don't know ho it is developed.

Page 29: Java OOP s concepts and buzzwords

Difference Between Object-based Programming & Object-Oriented Programming

• Object Based Programming languages obeys all the features of OOPs except inheritence.Ex: Java Script,VB script.

• Object Oriented Programming languages obeys all the features of OOPs.Ex: C++,Java

Page 30: Java OOP s concepts and buzzwords

Buzz Words

· Simple· Secure · Portable· Object-oriented· Robust· Multithreaded· Architecture-neutral· Interpreted· High performance· Distributed · Dynamic 

Page 31: Java OOP s concepts and buzzwords

Simple

• Java is designed to be easy for the professional programmer to learn and use.

Page 32: Java OOP s concepts and buzzwords

Secure

• secure – programs are confined to the Java execution environment and can not access other parts of the computer.

Page 33: Java OOP s concepts and buzzwords

Secure

• Security problems like eavasdropping, Tampering and virus threats can be eliminated or minimized by using java on internet

Page 34: Java OOP s concepts and buzzwords

Portable

• If a program yields the same result on every machine, then that program is called portable. Java programs are portable. This is the result of java’s system independent nature.

Page 35: Java OOP s concepts and buzzwords

Object-oriented

• Java is pure Object oriented programming languages because it is satisfying oops features.

• Class, object, Abstraction, Inheritance, polymorphism, Encapsulation.

Page 36: Java OOP s concepts and buzzwords

Robust

• Robust means Strong. Java programs are strong and they don’t crash easily like c and c++.

why? Excellent Exception handling

Memory Management

Class loader sub system of JVM will allocate necessary memory for java program.

Garbage Collector de allocates the memory

Page 37: Java OOP s concepts and buzzwords

Multithreaded

• A thread represents an individual process to execute a group of statements. JVM uses several threads to execute different blocks of code. Creating multiple threads is called Multi threaded.

Page 38: Java OOP s concepts and buzzwords

Compiled and Interpreted

• Java Programs are compiled to generate byte code.

• This byte code can be downloaded and interpreted by the interpreter in JVM.

Page 39: Java OOP s concepts and buzzwords

High performance

• The problem with the interpreter is slow. To over come this problem, along with interpreter java soft people have introduced JIT (Just In Time) compiler.

• Which enhance the speed of execution.

Page 40: Java OOP s concepts and buzzwords

Distributed

• Java is designed for the distributed environment of the Internet. Because it handles TCP/IP protocols

• Java supports RMI (Remote Method Invocation).

• This feature enables a programmer to invoke methods across the network.

Page 41: Java OOP s concepts and buzzwords

Dynamic

• Before the development of java, only static texts used to be displayed in browser.

• Dynamic loading is possible using applet programming. Which are dynamically interacting programs on internet.

Page 42: Java OOP s concepts and buzzwords

Thank you…

to be contd…