SlideShare a Scribd company logo
JAVA
SUJIT MAJETY | 2 : OBJECT ORIENTED PROGRAMMING CONCEPTS
Course Description
 Naming Conventions
 Data Types
 Variables
 Data Hiding
 Abstraction
 Encapsulation
 IS-A relationship
 HAS-A relationship
 Method Signature
 Polymorphism
 Static
 Dynamic
 Constructors
 Wrapper Classes
Naming Conventions
 It is a rule to follow while naming an identifier (e.g. class, package, variable, method, etc.).
 By using them readability increases.
 Class name: should begin with uppercase and should be a noun.
 Interface name: should begin with uppercase and should be an adjective.
 Method name: should begin with lowercase and should be a proverb, second word first
character should be capital.
 Variable name: should begin with lowercase, second word first character should be a
capital.
 Package name: should be completely in lowercase.
 Constants name: should be completely in uppercase.
Data Types
 Java supports UNICODE character set. Hence, each character is represented in two bytes.
 In java every variable has a type, every expression has a type and all assignments should be
checked by the compiler for type compatibility. Hence, java is treated as strongly typed
language.
 We are having 8 primitive data types.
 These data types fall under 3 categories.
 Numeric Data types
 Character Data types
 Boolean Data types
Data Types (cont.)
 Numeric Data types
 Integer Data types
 Byte – 1 byte
 Short – 2 bytes
 Int – 4 bytes
 Long – 8 bytes
 Floating point Data types
 Float – 4 bytes
 Double – 8 bytes
 Character Data types
 char – 2 bytes
 Boolean Data Types
 Boolean – 1 bit
Variables
 Variable is name of a memory location.
Types of variables
There are three types of variables
 Local variables
 Variables that are declared inside a method
 Instance variables
 Variables declared in class outside the methods.
 Static variables
 Variables declared in class outside the methods with static keyword.
Data Hiding
 Providing security to the data. ie., No outsider can access the data.
 By using the private modifier, we can implement the data hiding mechanism.
class User
{
private String password = “password”;
}
Abstraction
 Is the process of hiding the unnecessary details and exposing only the essential
features of a particular object.
 Hiding internal implementation details & just highlight the set of services what
we are offering, is called “Abstraction”.
 E.g. Car.
 Logic of car is abstract to you.
 You just know how to use it.
 In the same way java methods
internal details need not be
known to you, still you can use it.
Encapsulation
 Encapsulation is the ability of an object to be a container for related properties and methods.
 E.g. Cars and their owners
 All the functions of cars are encapsulated with owners
 No one else can access it.
class Student{
private name;
public String getName(){
return name;
}
Public void setName(String name){
this.name=name;
}
}
IS-A Relationship
 Is nothing but inheritance
 By using extends keyword we can implement IS-A relationship.
 The main advantage of the IS-A relationship is re-usability.
class A{
public void m1(){
…….
}
class B extends A{
public void m2(){
……...
}
HAS-A Relationship
 HAS-A relation ship is also known as composition or aggregation.
 There is no specific keyword to implement HAS-A relationship. We are using the new
keyword.
 The main advantage of Has-A relationship is Re-usability.
 And one disadvantage of HAS-A relationship is it increases dependency between the
classes and creates maintenance problems.
class car{
Engine e =new Engine();
}
class Engine{
// Engine specific functionality
}
Method Signature
 Method signature consists of name of the method & argument-list.
 The first line written in the method definition is said to be the method signature.
public void m1 (int i, float p)
m1(int ,float)
 The return type is not part of the method signature.
 Compiler will always use method signature while resolving method calls.
 With in the same class two methods with the same signature not allowed other wise we will get
compile time error.
Method Signature (cont..)
class A{
public void m1(int i){
}
public int m1(int i){
}
}
class Test{
public static void main(String[] args){
A a=new A();
}
Compile Error : method m1(int)
is already defined in class Test
Inheritance
 An object of a class acquiring the properties of an object of another class is called
inheritance.
 Uses :
 Method Overloading
 Code Reusability
 Types
 Single
 Multi Level
 Hierarchical
 Multiple
Inheritance (cont..)

Single
Class A
Class B
Class C
Class CClass B Interface C
Interface BInterface AClass A
Multilevel
Hierarchical Multiple
Polymorphism
 Polymorphism is brought up from a greek word which means having more forms.
 There are two types of polymorphism.
 Static Polymorphism
 Dynamic Polymorphism.
 Static polymorphism is achieved with the help of method overloading.
 Dynamic polymorphism is achieved with the help of method over riding.
Static Polymorphism
 Two methods are said to be overloaded iff method names are same but arguments
are different.
 This concept in java simplifies the programming.
 E.g. : System.out.println();
Dynamic Polymorphism
 Method overriding takes place between two IS-A relation dependant classes
having methods with the same signature and same name.
 Method over riding is also known as “runtime polymorphism or dynamic
polymorphism or late binding.
 Over riding method resolution is also known as “Dynamic method dispatch@.
 Rules :
 Method signatures must be matched.
 Parent class final method cannot be over ridden.
 Private methods are not visible in the child classes. Hence over riding concept is not applicable
for private methods.
Differences
Property Overloading Overriding
Arguments Must be different Must be same
Method Signature Must be different Must be same
Return type No restrictions Must be same until 1.4
Private, static & final
methods
Can be overloaded Cannot be overloaded
Access Modifiers No restrictions We can’t decrease scope
Throws Clause No restrictions We can decrease the size and
level for checked exceptions
Method Resolutions Always taken care by
compiler based on reference
type.
Always takes care by jvm
based on runtime object.
Constructors
 A special method in a class, having the same name as class without any return type.
 Constructor is executed when a class is instantiated, i.e. an object is created.
 Constructors cannot be called explicitly.
 Used to initialize an object i.e. initialize instance variables as well as class variables.
 Compiler provides default constructor if the programmer doesn’t provide a constructor.
 If a constructor is specified by the programmer, then compiler doesn’t provide the default
constructor.
 More than one constructor can be specified in a class, this concept is known as constructor
overloading.
 The default constructor initializes the instance variables and class variables with default values.
 To calculate dynamically how much memory is needed by the object, constructor is used.
Wrapper Classes
 Java uses primitive types, such as int, char, double to hold the basic data types
supported by the language.
 Sometimes it is required to create an object representation of these primitive types.
 These classes need to wrap the primitive types in a class.
 To satisfy this need, java provides classes that correspond to each of the primitive
types.
 Basically, these classes encapsulate, or wrap, the primitive types within a class.
 Thus, they are commonly referred to as type wrapper. Type wrapper are classes
that encapsulate a primitive type within an object.
 The wrapper types are Byte, Short, Integer, Long, Character, Boolean, Double,
Float.
Important Interview Questions
 What is hash code?
 How can you find the hash code of an object
 Can you declare class as private? Why?
 When is constructor called? Before or after creating the object?
 What is constructor overloading?
 Difference between float and double?
 Why do we need wrapper classes?
 What is boxing and unboxing?
Questions?

More Related Content

What's hot

Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- InheritanceJava programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
Jyothishmathi Institute of Technology and Science Karimnagar
 
C#
C#C#
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
Medhat Dawoud
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2eeShiva Cse
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
General OOP Concepts
General OOP ConceptsGeneral OOP Concepts
General OOP Concepts
Praveen M Jigajinni
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
Ahsan Raja
 
Unit 2
Unit 2Unit 2
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
Mudasir Qazi
 
Oops abap fundamental
Oops abap fundamentalOops abap fundamental
Oops abap fundamental
biswajit2015
 
OOP in C#
OOP in C#OOP in C#
OOP in C#
DevMix
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
BG Java EE Course
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).pptAlok Kumar
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
tigerwarn
 
Total oop in c# dot net
Total oop in c# dot netTotal oop in c# dot net
Total oop in c# dot net
Muhammad Naveed
 
Oops presentation java
Oops presentation javaOops presentation java
Oops presentation java
JayasankarPR2
 

What's hot (20)

Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- InheritanceJava programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
 
C#
C#C#
C#
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2ee
 
OOP java
OOP javaOOP java
OOP java
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
General OOP Concepts
General OOP ConceptsGeneral OOP Concepts
General OOP Concepts
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
Unit 2
Unit 2Unit 2
Unit 2
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
 
Oops abap fundamental
Oops abap fundamentalOops abap fundamental
Oops abap fundamental
 
OOP in C#
OOP in C#OOP in C#
OOP in C#
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Total oop in c# dot net
Total oop in c# dot netTotal oop in c# dot net
Total oop in c# dot net
 
Oops presentation java
Oops presentation javaOops presentation java
Oops presentation java
 

Viewers also liked

บทที่ 2 (ต่อ) ภาคปลาย.2555
บทที่ 2 (ต่อ) ภาคปลาย.2555บทที่ 2 (ต่อ) ภาคปลาย.2555
บทที่ 2 (ต่อ) ภาคปลาย.2555nuchida suwapaet
 
5 estruturas de controle
5 estruturas de controle5 estruturas de controle
5 estruturas de controlePAULO Moreira
 
Mood Board And Sketches
Mood Board And  SketchesMood Board And  Sketches
Mood Board And SketchesBonnie Scott
 
Mathematics(ME)(Khagendradewangan.blogspot.in)
Mathematics(ME)(Khagendradewangan.blogspot.in)Mathematics(ME)(Khagendradewangan.blogspot.in)
Mathematics(ME)(Khagendradewangan.blogspot.in)
KHAGENDRA KUMAR DEWANGAN
 
DevOps Boston - Heartbleed at Acquia
DevOps Boston - Heartbleed at AcquiaDevOps Boston - Heartbleed at Acquia
DevOps Boston - Heartbleed at Acquia
Marc Seeger
 
Teodor Balan School - November 2011
Teodor Balan School - November 2011Teodor Balan School - November 2011
Teodor Balan School - November 2011
Liliana Gheorghian
 
Etl tool
Etl toolEtl tool
Etl tool
Jinal Shah
 
Arquitetura de informação
Arquitetura de informaçãoArquitetura de informação
Arquitetura de informação
Princi Agência Web
 
Opendataday
OpendatadayOpendataday
Opendataday
Sandra Troia
 
Resumen
ResumenResumen
Resumen
Patty LóMar
 
Paseo por la ciencia 2016 Ficha Laura
Paseo por la ciencia 2016 Ficha LauraPaseo por la ciencia 2016 Ficha Laura
Paseo por la ciencia 2016 Ficha Laura
Aurora Santano Cañete
 
24 as-3-mensagens-angelicaspps3335
24 as-3-mensagens-angelicaspps333524 as-3-mensagens-angelicaspps3335
24 as-3-mensagens-angelicaspps3335O ÚLTIMO CHAMADO
 
Must welcome to chiayi county
Must welcome to chiayi countyMust welcome to chiayi county
Must welcome to chiayi county
MUSTHoover
 
งานโลหะแผ่น5 3
งานโลหะแผ่น5 3งานโลหะแผ่น5 3
งานโลหะแผ่น5 3Pannathat Champakul
 
Final report Traditional customs of four seasons_TeodorBalanSchool
Final report Traditional customs of four seasons_TeodorBalanSchoolFinal report Traditional customs of four seasons_TeodorBalanSchool
Final report Traditional customs of four seasons_TeodorBalanSchool
Liliana Gheorghian
 

Viewers also liked (20)

บทที่ 2 (ต่อ) ภาคปลาย.2555
บทที่ 2 (ต่อ) ภาคปลาย.2555บทที่ 2 (ต่อ) ภาคปลาย.2555
บทที่ 2 (ต่อ) ภาคปลาย.2555
 
Jamie's resume
Jamie's resumeJamie's resume
Jamie's resume
 
5 estruturas de controle
5 estruturas de controle5 estruturas de controle
5 estruturas de controle
 
Mood Board And Sketches
Mood Board And  SketchesMood Board And  Sketches
Mood Board And Sketches
 
Mathematics(ME)(Khagendradewangan.blogspot.in)
Mathematics(ME)(Khagendradewangan.blogspot.in)Mathematics(ME)(Khagendradewangan.blogspot.in)
Mathematics(ME)(Khagendradewangan.blogspot.in)
 
DevOps Boston - Heartbleed at Acquia
DevOps Boston - Heartbleed at AcquiaDevOps Boston - Heartbleed at Acquia
DevOps Boston - Heartbleed at Acquia
 
Teodor Balan School - November 2011
Teodor Balan School - November 2011Teodor Balan School - November 2011
Teodor Balan School - November 2011
 
Etl tool
Etl toolEtl tool
Etl tool
 
PLUG VLAVE - PIN-Layout1
PLUG VLAVE - PIN-Layout1PLUG VLAVE - PIN-Layout1
PLUG VLAVE - PIN-Layout1
 
Arquitetura de informação
Arquitetura de informaçãoArquitetura de informação
Arquitetura de informação
 
Romanos 10 palavra
Romanos 10   palavraRomanos 10   palavra
Romanos 10 palavra
 
Opendataday
OpendatadayOpendataday
Opendataday
 
Resumen
ResumenResumen
Resumen
 
Paseo por la ciencia 2016 Ficha Laura
Paseo por la ciencia 2016 Ficha LauraPaseo por la ciencia 2016 Ficha Laura
Paseo por la ciencia 2016 Ficha Laura
 
24 as-3-mensagens-angelicaspps3335
24 as-3-mensagens-angelicaspps333524 as-3-mensagens-angelicaspps3335
24 as-3-mensagens-angelicaspps3335
 
职业规划
职业规划职业规划
职业规划
 
Resume of Lenin Babu
Resume of Lenin BabuResume of Lenin Babu
Resume of Lenin Babu
 
Must welcome to chiayi county
Must welcome to chiayi countyMust welcome to chiayi county
Must welcome to chiayi county
 
งานโลหะแผ่น5 3
งานโลหะแผ่น5 3งานโลหะแผ่น5 3
งานโลหะแผ่น5 3
 
Final report Traditional customs of four seasons_TeodorBalanSchool
Final report Traditional customs of four seasons_TeodorBalanSchoolFinal report Traditional customs of four seasons_TeodorBalanSchool
Final report Traditional customs of four seasons_TeodorBalanSchool
 

Similar to Object Oriented Principles

Oop in kotlin
Oop in kotlinOop in kotlin
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
AnmolVerma363503
 
C# interview
C# interviewC# interview
C# interview
Thomson Reuters
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptx
SajidTk2
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
Arun Vasanth
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
Indu65
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
homeworkping9
 
Chapter 5 declaring classes & oop
Chapter 5 declaring classes  & oopChapter 5 declaring classes  & oop
Chapter 5 declaring classes & oopsshhzap
 
OCA Java SE 8 Exam Chapter 4 Methods Encapsulation
OCA Java SE 8 Exam Chapter 4 Methods EncapsulationOCA Java SE 8 Exam Chapter 4 Methods Encapsulation
OCA Java SE 8 Exam Chapter 4 Methods Encapsulation
İbrahim Kürce
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
G C Reddy Technologies
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
KunalYadav65140
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
RaazIndia
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2Rakesh Madugula
 
Introduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesIntroduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologies
TabassumMaktum
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2Raghu nath
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
Application package
Application packageApplication package
Application packageJAYAARC
 

Similar to Object Oriented Principles (20)

Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
 
Suga java training_with_footer
Suga java training_with_footerSuga java training_with_footer
Suga java training_with_footer
 
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
 
C# interview
C# interviewC# interview
C# interview
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptx
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
 
Chapter 5 declaring classes & oop
Chapter 5 declaring classes  & oopChapter 5 declaring classes  & oop
Chapter 5 declaring classes & oop
 
OCA Java SE 8 Exam Chapter 4 Methods Encapsulation
OCA Java SE 8 Exam Chapter 4 Methods EncapsulationOCA Java SE 8 Exam Chapter 4 Methods Encapsulation
OCA Java SE 8 Exam Chapter 4 Methods Encapsulation
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Introduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesIntroduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologies
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
 
Application package
Application packageApplication package
Application package
 

Recently uploaded

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

Object Oriented Principles

  • 1. JAVA SUJIT MAJETY | 2 : OBJECT ORIENTED PROGRAMMING CONCEPTS
  • 2. Course Description  Naming Conventions  Data Types  Variables  Data Hiding  Abstraction  Encapsulation  IS-A relationship  HAS-A relationship  Method Signature  Polymorphism  Static  Dynamic  Constructors  Wrapper Classes
  • 3. Naming Conventions  It is a rule to follow while naming an identifier (e.g. class, package, variable, method, etc.).  By using them readability increases.  Class name: should begin with uppercase and should be a noun.  Interface name: should begin with uppercase and should be an adjective.  Method name: should begin with lowercase and should be a proverb, second word first character should be capital.  Variable name: should begin with lowercase, second word first character should be a capital.  Package name: should be completely in lowercase.  Constants name: should be completely in uppercase.
  • 4. Data Types  Java supports UNICODE character set. Hence, each character is represented in two bytes.  In java every variable has a type, every expression has a type and all assignments should be checked by the compiler for type compatibility. Hence, java is treated as strongly typed language.  We are having 8 primitive data types.  These data types fall under 3 categories.  Numeric Data types  Character Data types  Boolean Data types
  • 5. Data Types (cont.)  Numeric Data types  Integer Data types  Byte – 1 byte  Short – 2 bytes  Int – 4 bytes  Long – 8 bytes  Floating point Data types  Float – 4 bytes  Double – 8 bytes  Character Data types  char – 2 bytes  Boolean Data Types  Boolean – 1 bit
  • 6. Variables  Variable is name of a memory location. Types of variables There are three types of variables  Local variables  Variables that are declared inside a method  Instance variables  Variables declared in class outside the methods.  Static variables  Variables declared in class outside the methods with static keyword.
  • 7. Data Hiding  Providing security to the data. ie., No outsider can access the data.  By using the private modifier, we can implement the data hiding mechanism. class User { private String password = “password”; }
  • 8. Abstraction  Is the process of hiding the unnecessary details and exposing only the essential features of a particular object.  Hiding internal implementation details & just highlight the set of services what we are offering, is called “Abstraction”.  E.g. Car.  Logic of car is abstract to you.  You just know how to use it.  In the same way java methods internal details need not be known to you, still you can use it.
  • 9. Encapsulation  Encapsulation is the ability of an object to be a container for related properties and methods.  E.g. Cars and their owners  All the functions of cars are encapsulated with owners  No one else can access it. class Student{ private name; public String getName(){ return name; } Public void setName(String name){ this.name=name; } }
  • 10. IS-A Relationship  Is nothing but inheritance  By using extends keyword we can implement IS-A relationship.  The main advantage of the IS-A relationship is re-usability. class A{ public void m1(){ ……. } class B extends A{ public void m2(){ ……... }
  • 11. HAS-A Relationship  HAS-A relation ship is also known as composition or aggregation.  There is no specific keyword to implement HAS-A relationship. We are using the new keyword.  The main advantage of Has-A relationship is Re-usability.  And one disadvantage of HAS-A relationship is it increases dependency between the classes and creates maintenance problems. class car{ Engine e =new Engine(); } class Engine{ // Engine specific functionality }
  • 12. Method Signature  Method signature consists of name of the method & argument-list.  The first line written in the method definition is said to be the method signature. public void m1 (int i, float p) m1(int ,float)  The return type is not part of the method signature.  Compiler will always use method signature while resolving method calls.  With in the same class two methods with the same signature not allowed other wise we will get compile time error.
  • 13. Method Signature (cont..) class A{ public void m1(int i){ } public int m1(int i){ } } class Test{ public static void main(String[] args){ A a=new A(); } Compile Error : method m1(int) is already defined in class Test
  • 14. Inheritance  An object of a class acquiring the properties of an object of another class is called inheritance.  Uses :  Method Overloading  Code Reusability  Types  Single  Multi Level  Hierarchical  Multiple
  • 15. Inheritance (cont..)  Single Class A Class B Class C Class CClass B Interface C Interface BInterface AClass A Multilevel Hierarchical Multiple
  • 16. Polymorphism  Polymorphism is brought up from a greek word which means having more forms.  There are two types of polymorphism.  Static Polymorphism  Dynamic Polymorphism.  Static polymorphism is achieved with the help of method overloading.  Dynamic polymorphism is achieved with the help of method over riding.
  • 17. Static Polymorphism  Two methods are said to be overloaded iff method names are same but arguments are different.  This concept in java simplifies the programming.  E.g. : System.out.println();
  • 18. Dynamic Polymorphism  Method overriding takes place between two IS-A relation dependant classes having methods with the same signature and same name.  Method over riding is also known as “runtime polymorphism or dynamic polymorphism or late binding.  Over riding method resolution is also known as “Dynamic method dispatch@.  Rules :  Method signatures must be matched.  Parent class final method cannot be over ridden.  Private methods are not visible in the child classes. Hence over riding concept is not applicable for private methods.
  • 19. Differences Property Overloading Overriding Arguments Must be different Must be same Method Signature Must be different Must be same Return type No restrictions Must be same until 1.4 Private, static & final methods Can be overloaded Cannot be overloaded Access Modifiers No restrictions We can’t decrease scope Throws Clause No restrictions We can decrease the size and level for checked exceptions Method Resolutions Always taken care by compiler based on reference type. Always takes care by jvm based on runtime object.
  • 20. Constructors  A special method in a class, having the same name as class without any return type.  Constructor is executed when a class is instantiated, i.e. an object is created.  Constructors cannot be called explicitly.  Used to initialize an object i.e. initialize instance variables as well as class variables.  Compiler provides default constructor if the programmer doesn’t provide a constructor.  If a constructor is specified by the programmer, then compiler doesn’t provide the default constructor.  More than one constructor can be specified in a class, this concept is known as constructor overloading.  The default constructor initializes the instance variables and class variables with default values.  To calculate dynamically how much memory is needed by the object, constructor is used.
  • 21. Wrapper Classes  Java uses primitive types, such as int, char, double to hold the basic data types supported by the language.  Sometimes it is required to create an object representation of these primitive types.  These classes need to wrap the primitive types in a class.  To satisfy this need, java provides classes that correspond to each of the primitive types.  Basically, these classes encapsulate, or wrap, the primitive types within a class.  Thus, they are commonly referred to as type wrapper. Type wrapper are classes that encapsulate a primitive type within an object.  The wrapper types are Byte, Short, Integer, Long, Character, Boolean, Double, Float.
  • 22. Important Interview Questions  What is hash code?  How can you find the hash code of an object  Can you declare class as private? Why?  When is constructor called? Before or after creating the object?  What is constructor overloading?  Difference between float and double?  Why do we need wrapper classes?  What is boxing and unboxing?