SlideShare a Scribd company logo
1 of 23
OOPs in Java
Ranjith Sekar
Jun 2015
Agenda
 Class
 SOLID Principles
 Object
 OOPs Concepts
 Access Modifiers
 Variables
Class
 Blueprint/template/contract
 Properties/Characteristics/Attributes & Actions
 Creation of a class
 Only one public class per source file
 Can contain multiple non-public classes (inner-classes)
 Example: Mobile
 Attributes (model, manufacturer, cost, operating system etc.,)
 Actions (call, file transfer, etc.,)
SOLID Principles
How to identify and design a Class?
 SRP (Single Responsibility Principle)
 OCP (Open Closed Principle)
 LSP (Liskov Substitution Principle)
 ISP (Interface Segregation Principle)
 DIP (Dependency Inversion Principle)
Single Responsibility Principle (SRP)
 A class should have only one reason to change (responsibility)
 Separation of responsibilities
 How to Recognize a Break of the SRP?
 Class Has Too Many Dependencies
 Method Has Too Many Parameters
 The Test Class Becomes Too Complicated
 Class / Method is Long (200-250 LOC)
 Descriptive Naming
 Change In One Place Breaks Another
 How to make the design compliant with the Single Responsibility Principle
 TDD
 Code Coverage Metrics
 Refactoring and Design Patterns
 Clear Modularization of the System
Open Closed Principle (OCP)
 Minimal changes on existing code (tested already)
 Open for extension but closed for modifications
 Inheritance using Interface/class
 Decorator Design Pattern
Liskov Substitution Principle (LSP)
 Derived types must be completely substitutable for their base types.
 Subtypes must be replaceable for the super type references without affecting the program
execution.
 Program to Interface, not the Implementation
Interface Segregation Principle (ISP)
 Clients should not be forced to implement interfaces they don't use
 Create different interfaces based on the method groups
 it produce a flexible design
Dependency Inversion Principle (DIP)
 High-level modules should not depend on low-level modules. Both should depend on
abstractions.
 Abstractions should not depend on details. Details should depend on abstractions.
 High Level Classes --> Abstraction Layer --> Low Level Classes
Object
 Any Real world entity
 Instance of class
 Stores States in Variables & Behaviors in methods
 Constructors – initialize during object creation
 Static blocks
How to Create an Object?
 Using ‘new’ keyword
List<String> obj1 = new ArrayList<String>();
 Using Class.forName() method
MyClass obj2 = Class.forName(“com.mycompany.MyClass”);
 Cloning
Person p1 = new Person();
Person p2 =(Person) p1.clone();
 Deserialization
ObjectInputStream inStream = new ObjectInputStream(null);
MyClass object = (MyClass) inStream.readObject();
 Class Loader
MyClass classLoader = (MyClass ) this.getClass().getClassLoader().loadClass("com.mycompany.MyClass ")
.newInstance();
OOPs Concepts
 Abstraction
 Inheritance
 Encapsulation
 Polymorphism
 Association
 Aggregation
 Composition
Abstraction
 Def: An abstraction denotes the essential characteristics of an object that distinguish it from
all other kinds of object and thus provide crisply defined conceptual boundaries, relative to
the perspective of the viewer
 What it does instead how it does (television)
 Decompose complex systems into smaller components
 Interface & Abstract Classes
 When Should We Use Abstraction
 when we want to achieve abstraction of data or actions
 when functionality is exposed to another component
Inheritance
 extends keyword
 Inherits/Shares the attributes and methods (public or protected) of existing classes
 Code reusability
 One Super-Class -> Multiple Sub-Class => Supported
 One Sub-Class-> Multiple Super-Class (Multiple Inheritance) – NOT Supported
 Compile time
 Super-Class & Sub-Class Constructor
 ‘super’ keyword - access the overridden method in the super class
 IS-A Relationship
 Sub-Class has Same attribute/method as in Super-Class – No inherit occur
 Types
 Single Inheritance
 Multiple Inheritance
 Multi-Level Inheritance
 Hierarchical Inheritance
 Hybrid Inheritance
Encapsulation
 Hide the data & methods into Object
 Binding variables (instance variable) & methods into class
 Security
 Java Bean
 Also referred as ‘Block Box’
 private, public keyword
 Exposes only required things
 java.util.Hashtable
Polymorphism
 one name, many forms
 Overloading(compile-time/Static-binding)
 Method & operator overloading
 Overridding (run-time/Dynamic-binding)
 @Override annotation
 argument list & return type(covariant return type) must be same
 Final & private methods – Can’t Overridden
 Protected methods – can, but within package
 not applicable for static methods or variables (static and non-static)
 can throw any new unchecked (runtime) exception
 Public cannot be made default, but a default can be made public
 Shape Example (draw())
Association
 Relationship between two objects (one-to-one, one-to-many, many-to-one, many-to-many)
 Example: Teacher & Student
 own lifecycle and there is no owner
 Both can exists without each other
Aggregation
 “Has-a” relationship
 Special form of Association
 One object is owner for other
 Example: Teacher & Department
 own lifecycle but child object can not belongs to another parent object
Composition
 Special form of Aggregation
 Child object dose not have their lifecycle
 All the child objects will be deleted if Parent object deleted
 Example: House & Room
OO design Principles & OO basic principles
Access Modifiers
 default
 Public
 Private
 protected
Variables
 Instance Variables (Non-Static Fields)
 Class Variables (Static Fields)
 Local Variables (method level variables)
Thank You All 

More Related Content

What's hot

Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Conceptsthinkphp
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - PolymorphismMudasir Qazi
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPTPooja Jaiswal
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPTkishu0005
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in JavaSpotle.ai
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keywordtanu_jaswal
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionPritom Chaki
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overridingRajab Ali
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop Kumar
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingAmit Soni (CTFL)
 
Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overridingJavaTportal
 

What's hot (20)

Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
concept of oops
concept of oopsconcept of oops
concept of oops
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaion
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
 
Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overriding
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 

Viewers also liked

Java oops and fundamentals
Java oops and fundamentalsJava oops and fundamentals
Java oops and fundamentalsjavaease
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the BasicsJussi Pohjolainen
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2Raghu nath
 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of javavinay arora
 
Java Course 2: Basics
Java Course 2: BasicsJava Course 2: Basics
Java Course 2: BasicsAnton Keks
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOPAnton Keks
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for DesignersR. Sosa
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
 
Core java Basics
Core java BasicsCore java Basics
Core java BasicsRAMU KOLLI
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basicsmhtspvtltd
 

Viewers also liked (20)

Java oops and fundamentals
Java oops and fundamentalsJava oops and fundamentals
Java oops and fundamentals
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
SOLID Java Code
SOLID Java CodeSOLID Java Code
SOLID Java Code
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the Basics
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of java
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java Course 2: Basics
Java Course 2: BasicsJava Course 2: Basics
Java Course 2: Basics
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOP
 
Java Basics
Java BasicsJava Basics
Java Basics
 
PALASH SL GUPTA
PALASH SL GUPTAPALASH SL GUPTA
PALASH SL GUPTA
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 
Java basics
Java basicsJava basics
Java basics
 
2. Basics of Java
2. Basics of Java2. Basics of Java
2. Basics of Java
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
Core java Basics
Core java BasicsCore java Basics
Core java Basics
 
Java basics
Java basicsJava basics
Java basics
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basics
 

Similar to OOPs in Java

Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptxSajidTk2
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)Khaled Anaqwa
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshowilias ahmed
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Fresherszynofustechnology
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindiappsdevelopment
 
Shuvrojit Majumder . 25900120006 Object Oriented Programming (PCC-CS 503) ...
Shuvrojit Majumder .  25900120006  Object Oriented Programming (PCC-CS 503)  ...Shuvrojit Majumder .  25900120006  Object Oriented Programming (PCC-CS 503)  ...
Shuvrojit Majumder . 25900120006 Object Oriented Programming (PCC-CS 503) ...ShuvrojitMajumder
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascriptUsman Mehmood
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2Usman Mehmood
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introductionsandeep54552
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 

Similar to OOPs in Java (20)

OOPS in Java
OOPS in JavaOOPS in Java
OOPS in Java
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptx
 
Oops
OopsOops
Oops
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Java session2
Java session2Java session2
Java session2
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1
 
Unit 3
Unit 3Unit 3
Unit 3
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
 
Csci360 20
Csci360 20Csci360 20
Csci360 20
 
Shuvrojit Majumder . 25900120006 Object Oriented Programming (PCC-CS 503) ...
Shuvrojit Majumder .  25900120006  Object Oriented Programming (PCC-CS 503)  ...Shuvrojit Majumder .  25900120006  Object Oriented Programming (PCC-CS 503)  ...
Shuvrojit Majumder . 25900120006 Object Oriented Programming (PCC-CS 503) ...
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 

Recently uploaded

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

OOPs in Java

  • 1. OOPs in Java Ranjith Sekar Jun 2015
  • 2. Agenda  Class  SOLID Principles  Object  OOPs Concepts  Access Modifiers  Variables
  • 3. Class  Blueprint/template/contract  Properties/Characteristics/Attributes & Actions  Creation of a class  Only one public class per source file  Can contain multiple non-public classes (inner-classes)  Example: Mobile  Attributes (model, manufacturer, cost, operating system etc.,)  Actions (call, file transfer, etc.,)
  • 4. SOLID Principles How to identify and design a Class?  SRP (Single Responsibility Principle)  OCP (Open Closed Principle)  LSP (Liskov Substitution Principle)  ISP (Interface Segregation Principle)  DIP (Dependency Inversion Principle)
  • 5. Single Responsibility Principle (SRP)  A class should have only one reason to change (responsibility)  Separation of responsibilities  How to Recognize a Break of the SRP?  Class Has Too Many Dependencies  Method Has Too Many Parameters  The Test Class Becomes Too Complicated  Class / Method is Long (200-250 LOC)  Descriptive Naming  Change In One Place Breaks Another  How to make the design compliant with the Single Responsibility Principle  TDD  Code Coverage Metrics  Refactoring and Design Patterns  Clear Modularization of the System
  • 6. Open Closed Principle (OCP)  Minimal changes on existing code (tested already)  Open for extension but closed for modifications  Inheritance using Interface/class  Decorator Design Pattern
  • 7. Liskov Substitution Principle (LSP)  Derived types must be completely substitutable for their base types.  Subtypes must be replaceable for the super type references without affecting the program execution.  Program to Interface, not the Implementation
  • 8. Interface Segregation Principle (ISP)  Clients should not be forced to implement interfaces they don't use  Create different interfaces based on the method groups  it produce a flexible design
  • 9. Dependency Inversion Principle (DIP)  High-level modules should not depend on low-level modules. Both should depend on abstractions.  Abstractions should not depend on details. Details should depend on abstractions.  High Level Classes --> Abstraction Layer --> Low Level Classes
  • 10. Object  Any Real world entity  Instance of class  Stores States in Variables & Behaviors in methods  Constructors – initialize during object creation  Static blocks
  • 11. How to Create an Object?  Using ‘new’ keyword List<String> obj1 = new ArrayList<String>();  Using Class.forName() method MyClass obj2 = Class.forName(“com.mycompany.MyClass”);  Cloning Person p1 = new Person(); Person p2 =(Person) p1.clone();  Deserialization ObjectInputStream inStream = new ObjectInputStream(null); MyClass object = (MyClass) inStream.readObject();  Class Loader MyClass classLoader = (MyClass ) this.getClass().getClassLoader().loadClass("com.mycompany.MyClass ") .newInstance();
  • 12. OOPs Concepts  Abstraction  Inheritance  Encapsulation  Polymorphism  Association  Aggregation  Composition
  • 13. Abstraction  Def: An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer  What it does instead how it does (television)  Decompose complex systems into smaller components  Interface & Abstract Classes  When Should We Use Abstraction  when we want to achieve abstraction of data or actions  when functionality is exposed to another component
  • 14. Inheritance  extends keyword  Inherits/Shares the attributes and methods (public or protected) of existing classes  Code reusability  One Super-Class -> Multiple Sub-Class => Supported  One Sub-Class-> Multiple Super-Class (Multiple Inheritance) – NOT Supported  Compile time  Super-Class & Sub-Class Constructor  ‘super’ keyword - access the overridden method in the super class  IS-A Relationship  Sub-Class has Same attribute/method as in Super-Class – No inherit occur  Types  Single Inheritance  Multiple Inheritance  Multi-Level Inheritance  Hierarchical Inheritance  Hybrid Inheritance
  • 15. Encapsulation  Hide the data & methods into Object  Binding variables (instance variable) & methods into class  Security  Java Bean  Also referred as ‘Block Box’  private, public keyword  Exposes only required things  java.util.Hashtable
  • 16. Polymorphism  one name, many forms  Overloading(compile-time/Static-binding)  Method & operator overloading  Overridding (run-time/Dynamic-binding)  @Override annotation  argument list & return type(covariant return type) must be same  Final & private methods – Can’t Overridden  Protected methods – can, but within package  not applicable for static methods or variables (static and non-static)  can throw any new unchecked (runtime) exception  Public cannot be made default, but a default can be made public  Shape Example (draw())
  • 17. Association  Relationship between two objects (one-to-one, one-to-many, many-to-one, many-to-many)  Example: Teacher & Student  own lifecycle and there is no owner  Both can exists without each other
  • 18. Aggregation  “Has-a” relationship  Special form of Association  One object is owner for other  Example: Teacher & Department  own lifecycle but child object can not belongs to another parent object
  • 19. Composition  Special form of Aggregation  Child object dose not have their lifecycle  All the child objects will be deleted if Parent object deleted  Example: House & Room
  • 20. OO design Principles & OO basic principles
  • 21. Access Modifiers  default  Public  Private  protected
  • 22. Variables  Instance Variables (Non-Static Fields)  Class Variables (Static Fields)  Local Variables (method level variables)