java oop s concepts and buzzwords

Post on 20-May-2015

6.490 Views

Category:

Education

7 Downloads

Preview:

Click to see full reader

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

TRANSCRIPT

Java Session 2

Contents…

Oops Concepts

Java features

Oops Concepts

• Class

• Object

• Polymorphism

• Inheritance

• Encapsulation

• Abstraction

OOP

Polymorphism

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

Polymorphism 1

Polymorphism 2

Polymorphism 3

Polymorphism 4

Polymorphism 5

Polymorphism 6

Polymorphism 7

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)

OverLoading Class BookDetails{

            String title;            String publisher;            float price;

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

{} setBook(String title, String publisher,float

price){ } }

(overriding).

class BookDetails{            String title;

setBook(String title){ }

}

class ScienceBook extends BookDetails{

            setBook(String   title){}           //overriding

setBook(String title, String publisher,float price)

{ }  //overloading

}

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.

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.

Inheritance

Inheritance 1

Inheritance 2

Inheritance 3

Inheritance 4

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

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

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.

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.

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.

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

Buzz Words

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

Simple

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

Secure

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

Secure

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

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.

Object-oriented

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

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

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

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.

Compiled and Interpreted

• Java Programs are compiled to generate byte code.

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

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.

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.

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.

Thank you…

to be contd…

top related