WELCOME
INTRODUCTION
Object
oriented
programing
java
PRINCIPLES
 Encapsulation:
 Mechanism that binds code and the data together and keeps both safe from outside
interference and misuse.
 Inheritance:
 the process by which one object acquires the properties of another object.
 Polymorphism:
 One interface, multiple methods.
EXAMPLES
Encapsulation:
public class Student{
private String name;
public String getName(){
return name;
}
public void setName(String name){
this.name=name
}
}
class Test{
public static void main(String[] args){
Student s=new Student();
s.setname("vijay");
System.out.println(s.getName());
}
}
EXAMPLES
Inheritance:
class Employee{
float salary=40000;
}
class Programmer extends Employee{
int bonus=10000;
public static void main(String args[]){
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out.println("Bonus of Programmer is:"+p.bonus);
}
}
EXAMPLES
Polymorphism:
class Bike{
void run(){
System.out.println("running");
}
}
class Splender extends Bike{
void run(){
System.out.println("running safely with 60km");
}
public static void main(String args[]){
Bike b = new Splender();
b.run();
}
}
ABSTRACTION IN JAVA
Abstraction is a process of hiding the implementation details and showing only
functionality to the user.
Ways to achieve Abstraction:
Abstract class
Interface
 Abstract class:
A class that is declared as abstract is known as abstract class. It needs to be extended
and its method need to be implemented.
Example: abstract class Bike
{
}
Abstract method:
A method that is declared as abstract and does not have implementation is known as
abstract method.
Example: abstract void run( );
 Example: ( Abstract class )
abstract class Bike{
abstract void run();
}
class Honda4 extends Bike{
void run(){
System.out.println("running safely..");
}
public static void main(String args[]){
Bike obj = new Honda4();
obj.run();
}
} ref: http://www.javatpoint.com/abstract-class-in-java
INTERFACE IN JAVA
An interface in java is a blueprint of a class.
It has:
 Static constants
 Abstract methods
Reasons to use:
 Achieve fully abstraction
 To support the functionality of multiple inheritance
 To achieve loose coupling
Relationship between classes and interfaces:
ref: http://www.javatpoint.com/interface-in-java
EXCEPTION & EXCEPTION HANDLING
Exception is an abnormal condition.
In java, exception is an event that disrupts the normal flow of the program. It is an
object which is thrown at runtime.
Examples:
 ArithmaticException
 NullPointerException
 NumberFormatException e.t.c
And the process we use to handle those exceptions is called
Exception handling.
KEYWORDS
 We use five keywords to handle exceptions in java:
Try
Catch
Finally
Throw
Throws
General form of an exception-handling block:
try {
// block of code to monitor for errors
}
catch (ExceptionType1 exOb) {
// exception handler for ExceptionType1
}
catch (ExceptionType2 exOb) {
// exception handler for ExceptionType2
}
finally {
// block of code to be executed after try block ends
}
Thank you everybody !!!
Have a Good Day!
For contact: facebook.com/pritom.chaki.77
pritom.cse.diu@gamil.com

Object Orinted Programing(OOP) concepts \

  • 1.
  • 2.
  • 3.
    PRINCIPLES  Encapsulation:  Mechanismthat binds code and the data together and keeps both safe from outside interference and misuse.  Inheritance:  the process by which one object acquires the properties of another object.  Polymorphism:  One interface, multiple methods.
  • 4.
    EXAMPLES Encapsulation: public class Student{ privateString name; public String getName(){ return name; } public void setName(String name){ this.name=name } } class Test{ public static void main(String[] args){ Student s=new Student(); s.setname("vijay"); System.out.println(s.getName()); } }
  • 5.
    EXAMPLES Inheritance: class Employee{ float salary=40000; } classProgrammer extends Employee{ int bonus=10000; public static void main(String args[]){ Programmer p=new Programmer(); System.out.println("Programmer salary is:"+p.salary); System.out.println("Bonus of Programmer is:"+p.bonus); } }
  • 6.
    EXAMPLES Polymorphism: class Bike{ void run(){ System.out.println("running"); } } classSplender extends Bike{ void run(){ System.out.println("running safely with 60km"); } public static void main(String args[]){ Bike b = new Splender(); b.run(); } }
  • 7.
    ABSTRACTION IN JAVA Abstractionis a process of hiding the implementation details and showing only functionality to the user. Ways to achieve Abstraction: Abstract class Interface
  • 8.
     Abstract class: Aclass that is declared as abstract is known as abstract class. It needs to be extended and its method need to be implemented. Example: abstract class Bike { } Abstract method: A method that is declared as abstract and does not have implementation is known as abstract method. Example: abstract void run( );
  • 9.
     Example: (Abstract class ) abstract class Bike{ abstract void run(); } class Honda4 extends Bike{ void run(){ System.out.println("running safely.."); } public static void main(String args[]){ Bike obj = new Honda4(); obj.run(); } } ref: http://www.javatpoint.com/abstract-class-in-java
  • 10.
    INTERFACE IN JAVA Aninterface in java is a blueprint of a class. It has:  Static constants  Abstract methods Reasons to use:  Achieve fully abstraction  To support the functionality of multiple inheritance  To achieve loose coupling
  • 11.
    Relationship between classesand interfaces: ref: http://www.javatpoint.com/interface-in-java
  • 12.
    EXCEPTION & EXCEPTIONHANDLING Exception is an abnormal condition. In java, exception is an event that disrupts the normal flow of the program. It is an object which is thrown at runtime. Examples:  ArithmaticException  NullPointerException  NumberFormatException e.t.c And the process we use to handle those exceptions is called Exception handling.
  • 13.
    KEYWORDS  We usefive keywords to handle exceptions in java: Try Catch Finally Throw Throws
  • 14.
    General form ofan exception-handling block: try { // block of code to monitor for errors } catch (ExceptionType1 exOb) { // exception handler for ExceptionType1 } catch (ExceptionType2 exOb) { // exception handler for ExceptionType2 } finally { // block of code to be executed after try block ends }
  • 15.
    Thank you everybody!!! Have a Good Day! For contact: facebook.com/pritom.chaki.77 pritom.cse.diu@gamil.com