SlideShare a Scribd company logo
Recall
• What is meant by OOP?
• What are classes and objects?
• What are the differences between OOP and Procedure oriented
Programming?
Introduction to OOP with java
Java
• Oop paradigm
Java is a computer programming language that is class-based, object-
oriented and makes maximum out of it
• “Write once run anywhere”
Java applications are typically compiled to bytecode (.class file) that can run
on any Java virtual machine(JVM) regardless of computer architecture
C Vs java
Syntax comparison
C Vs java
• int
• Char
• Float
• double
‚Exactly the same as of left side‛
Data Types
C Vs java
• Conditional control structures
– If
– If else
– Switch
• Loops
– for
– while
– Do while
‚Exactly the same as of left side‛
Control Structures
C Vs java
int sum(int a, int b)
{
Int c;
c=a + b
return c;
}
sum(12,13)
‚Exactly the same as of left side‛
functions
C Vs java
int a[] = {1000, 2, 3, 50};
int a[10];
int a[]={1,2,3,4}// not a preferred way
int[] a={1,2,3,4} //preferred way
int[] myList = new int[10];
Arrays
C Vs Java
Output
printf(“ value of a = %d”,a);
Printf(“a = %d and b= %d”,a,b);
Input
scanf(“%d ", &a);
Scanf(“%d”,&a,&b);
Output
System.out.println(“hello baabtra”);
Input
Scanner sc = new scanner(System.in);
int i = sc.nextInt();
(import java.util.Scanner)
Input / Output
Out
In
System
Println()
Print()
Write()
PrintStream
C Vs java
char str*+ = ‚hello‛;
‚String is character array‛
String str=‚Hello‛;
‚String is an object ‚
Strings
C Vs java
• As we are well aware c program
execution begins at main() function
Eg: main()
{
Printf(‚hello world‛);
printHello();
}
Same as C, differs that the main() will be
a member function of some class.
Name of the class and file should be
the same.
class myFirstProgram
{
public static void main(String[] args)
{
System.out.println(‚hello baabtra‛);
}
main() function
What’s New in java?
What’s New in java?
• OOP concepts
• JVM and Platform independency
• Automatic garbage collection
OOP Concept
• Object-oriented programming (OOP) is a style of programming
that focuses on using objects to design and build applications.
• Think of an object as a model of the concepts, processes, or
things in the real world that are meaningful to your application.
Objects in real World
Real World
Objects
Objects in real world
• Object will have an identity/name
 Eg: reynolds, Cello for pen. Nokia,apple for mobile
• Object will have different properties which describes them best
 Eg:Color,size,width
• Object can perform different actions
 Eg: writing,erasing etc for pen. Calling, texting for mobile
Objects
I have an identity:
I'm Volkswagen
I have different properties.
My color property is green
My no:of wheel property is 4
I can perform different actions
I can be drived
I can consume fuel
I can play Music
I have an identity:
I'm Suzuki
I have different properties.
My color property is silver
My no:of wheel property is 4
I can perform different actions
I can be drived
I can consume fuel
I can play Music
How these objects are created?
• All the objects in the real world are created out of a basic prototype
or a basic blue print or a base design
Objects in software World
Objects in the software world
• Same like in the real world we can create objects in computer
programming world
–Which will have a name as identity
–Properties to define its behaviour
–Actions what it can perform
How these objects are created
• We need to create a base design which defines the properties and
functionalities that the object should have.
• In programming terms we call this base design as Class
• Simply by having a class we can create any number of objects of
that type
Definition
• Class : is the base design of objects
• Object : is the instance of a class
• No memory is allocated when a class is created.
• Memory is allocated only when an object is created.
How to create class in Java
public class shape
{
private Int width;
private Int height;
public Int calculateArea()
{
return x*y
}
}
How to create class in Java
public class shape
{
private Int width;
private Int height;
public Int calculateArea()
{
return x*y
}
}
Is the access specifier
How to create class in Java
public class shape
{
private Int width;
private Int height;
public Int calculateArea()
{
return x*y
}
}
Is the keyword for
creating a class
How to create class in Java
public class shape
{
private Int width;
private Int height;
public Int calculateArea()
{
return x*y
}
}
Is the name of the class
How to create class in Java
public class shape
{
private Int width;
private Int height;
public Int calculateArea()
{
return x*y
}
}
Are two variable that
referred as the
properties. Normally
kept private and access
using getters and setters.
We will discuss getters
and setters later in this
slide
How to create class in Java
public class shape
{
private Int width;
private Int height;
public Int calculateArea()
{
return x*y
}
}
Is the only member
function of the class
How to create objects in java
shape rectangle = new shape();
rectangle.width=20;
recangle.height=35;
rArea=rectangle.calculateArea();
This is how we create an
object in java
rectangle
Height:
width:
calculateArea()
{
return height*width;
}
How to create objects in C++
shape rectangle = new shape();
rectangle.width=20;
recangle.height=35;
rArea=rectangle.calculateArea();
Is the class name
How to create objects in C++
shape rectangle = new shape();
rectangle.width=20;
recangle.height=35;
rArea=rectangle.calculateArea();
Is the object name which
we want to create
How to create objects in C++
shape rectangle = new shape();
rectangle.width=20;
recangle.height=35;
rArea=rectangle.calculateArea();
“new” is the keyword used
in java to create an object
How to create objects in C++
shape rectangle = new shape();
rectangle.width=20;
recangle.height=35;
rArea=rectangle.calculateArea();
What is this???
It looks like a function
because its having pair of
parentheses (). And also
its having the same name
of our class . But what is it
used for ??
We will discuss it soon .
Just leave it as it is for now
How to create objects in Java
shape rectangle = new shape();
rectangle.width=20;
recangle.height=35;
rArea=rectangle.calculateArea();
Setting up the property
values of object
“rectangle”
rectangle
width: 20
Height: 35
calculateArea()
{
return width*height;
}
How to create objects in Java
shape rectangle = new shape();
rectangle.width=20;
recangle.height=35;
rArea=rectangle.calculateArea();
Calling the method
calculateArea()
rectangle
width: 20
Height: 35
calculateArea()
{
return 20*35;
}
Example
Class : shape
Height:35
width:20
Object rectangle
calculateArea()
{
Return 20*35
}
Height:10
width:10
Object square
calculateArea()
{
Return 10*10;
}
Member variables
Height
width
Member function
calculateArea
{
return height*width;
}
What we just did was
• Created an object
shape rectangle = new shape();
• Same like we declare variable. eg: int a;
• And assigned values for it
recangle.height=35;
same like we assign variable value. eg: a=10;
Rectangle
Width:
Height:
calculateArea()
{
return
width*height;
}
Rectangle
width: 20
Height: 35
calculateArea()
{
return 20*35;
}
So, Can i assign values into an object at the time
of its creation(known as initialization)??
Something that we do with variables like int a=14;
So, Can i assign values into an object at the time
of its creation??
Something that we do with variables like int a=14;
‚Yes, you can . For that purpose we use something called
constructor‛
Constructors
• Constructors are just a method like any other methods in the
class but having the same name of the class.
• It is used to initialise the properties of an object
• will not have any return type, not even void
• If no user defined constructor is provided for a class, the implicit constructor
initializes the member variables to its default values
– numeric data types are set to 0
– char data types are set to null character(‘0’)
– boolean data types are set to false
– reference variables are set to null
public class shape
{
private Int width;
private Int height;
private Int calculateArea()
{
return x*y
}
}
How to create Constructors
public class shape
{
private Int width;
private Int height;
shape(int height,in width)
{
this.width=width;
this.height=height;
}
private Int calculateArea()
{
return x*y
}
}
Shape rectangle=new shape(20,35);
Constructor
Rectangle
width: 20
Height: 35
calculateArea()
{
return 20*35;
}
How to create Constructors
Access Specifier
• Access specifies defines the access rights for the statements or
functions that follows it until another access specifier or till the
end of a class.
• The three types of access specifiers are
–Private
–Public
–Protected
–default
Introduction to java and oop
Getters and Setters
• There are several occasion we need to validate the data when assigning values
into it
• For eg: rectangle.width=-10;
rectangle.height=-12;
• Suppose i want to check whether the user enters a negative value and if so i
wish to assign 0 to the properties
• In such scenarios we will create a method to do the above said actions
Rectangle
width: -10
Height: -12
calculateArea()
{
return -10*-12;
}
Getters and Setters
• Getters and setters are simply two function that gets and sets the value of
class properties.
• Setter
– Rectangle.width=15; // Normally this is how we set the values of class properties.
Rectangle.setWidth(15); // calling a method named ‚setWidth‛ so that the
method will set the property width to 15
• Getter
– Rectangle.width; // Normally this is how we get the values of class properties.
Rectangle.getWidth(); // calling a method named ‚getWidth‛ so that the method
will get the value of the property width
public class shape
{
private Int width;
private Int height;
Int calculateArea()
{
return x*y;
}
Public setWidth(int a)
{
if (a>0)
width=a;
else
width=0
}
Public Int getWidth()
{
return width
}
}
How to create getters and setters
public class shape
{
private Int width;
private Int height;
Int calculateArea()
{
return x*y;
}
Public setWidth(int a)
{
if (a>0)
width=a;
else
width=0
}
Public Int getWidth()
{
return width
}
}
How to create getters and setters
Setter function
public class shape
{
private Int width;
private Int height;
Int calculateArea()
{
return x*y;
}
Public setWidth(int a)
{
if (a>0)
width=a;
else
width=0
}
Public Int getWidth()
{
return width
}
}
How to create getters and setters
Getter function
OOP features
»Abstraction
»Encapsulation
»Polymorphism
»Inheritance
Abstraction
• Act of representing essential features only and hiding the implementation
details
• For example, a car would be made up of an Engine, but one does not need
to know how the diverse components work inside.
• In our example of class shape ; the users only have to create objects of type
shape like rectangle,square etc.
• And for finding out the area he dont really have to think about how the area
is calculated. He only need to know calling the method calculateArea will
reuslt him with the area.
Encapsulation
• Wrapping up of data(properties) and code(methods) into a single unit is
known as encapsulation
• Encapsulation also includes the process of hiding all the data and methods
within a class from outside world by restricting access to the object's
components.
• In programming languages, encapsulation is accomplished by using private
access specifier
Inheritance
• Is the process where one object acquires the properties of another.
• Inheritance is a type of relationship
– Ex: BMW is a Car
• Reusability of code – Methods and properties of parent class will be
accessible to child class
• In java inheritance is achieved by using keyword ‚extends‛
• Java supports only single inheritance
public class shape
{
protected Int width;
protected Int height;
Int calculateArea()
{
return x*y;
}
int drawShape()
{
system.out.println(“shape”)
}
}
public class threedimensionalshape extends shape
{
private Int depth;
Int calculateVolume()
{
return width*heigh*depth;
}
}
Example
Example
• Shape rectangle = new rectangle();
• threedimensionalshape cube =new threedimensionalshape()
Rectangle
Width:
Height:
calculateArea()
{
Return width*height
}
cube
Width:
Height:
depth
calculateArea()
{
Return width*height
}
Int calculateVolume()
{
return
width*height*depth;
}
Polymorphism
• Polymorphism is the ability to take more than one form using
the same name
– Eg : function overloading, Operator overloading(not supported in java)
• Functions can have same name but different implementations
• There are two types of polymorphism
–Static
–Dynamic
public class shape
{
Int calculateArea(int width, int height)
{
return width * width;
}
Float calculateArea(int radius)
{
return (22/7) * radius * radius
}
}
public class example
{
Public static void main{
shape sh =new shape();
System.out. Println(sh.calculateArea(20, 10));
System.out.println(sh.calculateArea(10));
}
}
Output:
200
314.28
Example – Static polymorphism
public class shape
{
Void drawShape()
{
system.out.println(“Shape”)
}
}
public class ThreeDshape extends shape
{
Void drawShape()
{
system.out.println(“3D shape”)
}
}
public class example
{
Public static void main{
shape sh =new shape();
ThreeDshape tds =new ThreeDshape ();
Sh.drawShape();
sh=tds;
Sh.drawShape;
}
}
Output:
Shape
3D shape
Example – Dynamic polymorphism
Static and Dynamic polymorphism
• Achieved using Overloading
• Signature difference
• Inheritance not required for
implementation
• Decision at compile time
• Early binding
• Achieved by Overriding
• Uses inheritance and virtual
functions
• Inheritance required for
implementation
• Decision at runtime
• Late binding
Questions?
‚A good question deserve a good grade…‛
End of day
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

More Related Content

What's hot (20)

3 tier architecture
3 tier architecture3 tier architecture
3 tier architecture
tahir khan
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
GirdharRatne
 
SUBQUERIES.pptx
SUBQUERIES.pptxSUBQUERIES.pptx
SUBQUERIES.pptx
RenugadeviR5
 
History of java'
History of java'History of java'
History of java'
deepthisujithra
 
Slide 4 dbms users
Slide 4 dbms usersSlide 4 dbms users
Slide 4 dbms users
Visakh V
 
Sql ppt
Sql pptSql ppt
Sql ppt
Anuja Lad
 
How java differs from c and c++
How java differs from c and c++How java differs from c and c++
How java differs from c and c++
shalinikarunakaran1
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
Balqees Al.Mubarak
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
Jin Castor
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
Rayhan Chowdhury
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
PRN USM
 
Python sqlite3
Python sqlite3Python sqlite3
Python sqlite3
Alexey Bovanenko
 
Aggregate Function - Database
Aggregate Function - DatabaseAggregate Function - Database
Aggregate Function - Database
Shahadat153031
 
Android ui dialog
Android ui dialogAndroid ui dialog
Android ui dialog
Krazy Koder
 
SQL commands
SQL commandsSQL commands
SQL commands
GirdharRatne
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
Intelligo Technologies
 
Data Manipulation Language
Data Manipulation LanguageData Manipulation Language
Data Manipulation Language
Jas Singh Bhasin
 
RandomAccessFile Quick Start
RandomAccessFile Quick StartRandomAccessFile Quick Start
RandomAccessFile Quick Start
Guo Albert
 
C language
C languageC language
C language
Priya698357
 
3 tier architecture
3 tier architecture3 tier architecture
3 tier architecture
tahir khan
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
GirdharRatne
 
Slide 4 dbms users
Slide 4 dbms usersSlide 4 dbms users
Slide 4 dbms users
Visakh V
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
Jin Castor
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
PRN USM
 
Aggregate Function - Database
Aggregate Function - DatabaseAggregate Function - Database
Aggregate Function - Database
Shahadat153031
 
Android ui dialog
Android ui dialogAndroid ui dialog
Android ui dialog
Krazy Koder
 
Data Manipulation Language
Data Manipulation LanguageData Manipulation Language
Data Manipulation Language
Jas Singh Bhasin
 
RandomAccessFile Quick Start
RandomAccessFile Quick StartRandomAccessFile Quick Start
RandomAccessFile Quick Start
Guo Albert
 

Viewers also liked (20)

Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
Raja Sekhar
 
Java
JavaJava
Java
Sneha Mudraje
 
Java Stack Traces
Java Stack TracesJava Stack Traces
Java Stack Traces
dbanttari
 
Linked list (java platform se 8 )
Linked list (java platform se 8 )Linked list (java platform se 8 )
Linked list (java platform se 8 )
charan kumar
 
Heap and stack space in java
Heap and stack space in javaHeap and stack space in java
Heap and stack space in java
Talha Ocakçı
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
Ye Win
 
Java buzzwords
Java buzzwordsJava buzzwords
Java buzzwords
ramesh517
 
Java Stack (Pilha)
Java Stack (Pilha)Java Stack (Pilha)
Java Stack (Pilha)
Samuel Santos
 
Zulu Embedded Java Introduction
Zulu Embedded Java IntroductionZulu Embedded Java Introduction
Zulu Embedded Java Introduction
Azul Systems Inc.
 
03 Java Language And OOP Part III
03 Java Language And OOP Part III03 Java Language And OOP Part III
03 Java Language And OOP Part III
Hari Christian
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Nochiketa Chakraborty
 
01 introduction to oop and java
01 introduction to oop and java01 introduction to oop and java
01 introduction to oop and java
রাকিন রাকিন
 
Java Collections Framework Inroduction with Video Tutorial
Java Collections Framework Inroduction with Video TutorialJava Collections Framework Inroduction with Video Tutorial
Java Collections Framework Inroduction with Video Tutorial
Marcus Biel
 
Stack, queue and hashing
Stack, queue and hashingStack, queue and hashing
Stack, queue and hashing
Dumindu Pahalawatta
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
Prof. Erwin Globio
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
Arzath Areeff
 
Difference between C++ and Java
Difference between C++ and JavaDifference between C++ and Java
Difference between C++ and Java
Ajmal Ak
 
Oop java
Oop javaOop java
Oop java
Minal Maniar
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
Senthil Kumar
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and Object
OUM SAOKOSAL
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
Raja Sekhar
 
Java Stack Traces
Java Stack TracesJava Stack Traces
Java Stack Traces
dbanttari
 
Linked list (java platform se 8 )
Linked list (java platform se 8 )Linked list (java platform se 8 )
Linked list (java platform se 8 )
charan kumar
 
Heap and stack space in java
Heap and stack space in javaHeap and stack space in java
Heap and stack space in java
Talha Ocakçı
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
Ye Win
 
Java buzzwords
Java buzzwordsJava buzzwords
Java buzzwords
ramesh517
 
Zulu Embedded Java Introduction
Zulu Embedded Java IntroductionZulu Embedded Java Introduction
Zulu Embedded Java Introduction
Azul Systems Inc.
 
03 Java Language And OOP Part III
03 Java Language And OOP Part III03 Java Language And OOP Part III
03 Java Language And OOP Part III
Hari Christian
 
Java Collections Framework Inroduction with Video Tutorial
Java Collections Framework Inroduction with Video TutorialJava Collections Framework Inroduction with Video Tutorial
Java Collections Framework Inroduction with Video Tutorial
Marcus Biel
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
Prof. Erwin Globio
 
Difference between C++ and Java
Difference between C++ and JavaDifference between C++ and Java
Difference between C++ and Java
Ajmal Ak
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
Senthil Kumar
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and Object
OUM SAOKOSAL
 
Ad

Similar to Introduction to java and oop (20)

Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
baabtra.com - No. 1 supplier of quality freshers
 
Class & Object - Intro
Class & Object - IntroClass & Object - Intro
Class & Object - Intro
PRN USM
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
mcollison
 
Core Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class pptCore Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class ppt
Mochi263119
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
java
javajava
java
jent46
 
Java is an Object-Oriented Language
Java is an Object-Oriented LanguageJava is an Object-Oriented Language
Java is an Object-Oriented Language
ale8819
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
Padma Kannan
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
Object and class
Object and classObject and class
Object and class
mohit tripathi
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
Class and Object.ppt
Class and Object.pptClass and Object.ppt
Class and Object.ppt
Genta Sahuri
 
9 cm604.14
9 cm604.149 cm604.14
9 cm604.14
myrajendra
 
Cso gaddis java_chapter6
Cso gaddis java_chapter6Cso gaddis java_chapter6
Cso gaddis java_chapter6
RhettB
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
Lakshmi Sarvani Videla
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
Shipra Swati
 
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
UNIT I 	OOP AND JAVA FUNDAMENTALS CONSTRUCTORUNIT I 	OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
mohanrajm63
 
Java
JavaJava
Java
Ranjitham N
 
Lecture 2 classes i
Lecture 2 classes iLecture 2 classes i
Lecture 2 classes i
the_wumberlog
 
Class & Object - Intro
Class & Object - IntroClass & Object - Intro
Class & Object - Intro
PRN USM
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
mcollison
 
Core Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class pptCore Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class ppt
Mochi263119
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
Java is an Object-Oriented Language
Java is an Object-Oriented LanguageJava is an Object-Oriented Language
Java is an Object-Oriented Language
ale8819
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
Padma Kannan
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
Class and Object.ppt
Class and Object.pptClass and Object.ppt
Class and Object.ppt
Genta Sahuri
 
Cso gaddis java_chapter6
Cso gaddis java_chapter6Cso gaddis java_chapter6
Cso gaddis java_chapter6
RhettB
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
UNIT I 	OOP AND JAVA FUNDAMENTALS CONSTRUCTORUNIT I 	OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
mohanrajm63
 
Ad

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
baabtra.com - No. 1 supplier of quality freshers
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
baabtra.com - No. 1 supplier of quality freshers
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
baabtra.com - No. 1 supplier of quality freshers
 
Blue brain
Blue brainBlue brain
Blue brain
baabtra.com - No. 1 supplier of quality freshers
 
5g
5g5g
5g
baabtra.com - No. 1 supplier of quality freshers
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
baabtra.com - No. 1 supplier of quality freshers
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
baabtra.com - No. 1 supplier of quality freshers
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
baabtra.com - No. 1 supplier of quality freshers
 

Recently uploaded (20)

Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 

Introduction to java and oop

  • 1. Recall • What is meant by OOP? • What are classes and objects? • What are the differences between OOP and Procedure oriented Programming?
  • 3. Java • Oop paradigm Java is a computer programming language that is class-based, object- oriented and makes maximum out of it • “Write once run anywhere” Java applications are typically compiled to bytecode (.class file) that can run on any Java virtual machine(JVM) regardless of computer architecture
  • 4. C Vs java Syntax comparison
  • 5. C Vs java • int • Char • Float • double ‚Exactly the same as of left side‛ Data Types
  • 6. C Vs java • Conditional control structures – If – If else – Switch • Loops – for – while – Do while ‚Exactly the same as of left side‛ Control Structures
  • 7. C Vs java int sum(int a, int b) { Int c; c=a + b return c; } sum(12,13) ‚Exactly the same as of left side‛ functions
  • 8. C Vs java int a[] = {1000, 2, 3, 50}; int a[10]; int a[]={1,2,3,4}// not a preferred way int[] a={1,2,3,4} //preferred way int[] myList = new int[10]; Arrays
  • 9. C Vs Java Output printf(“ value of a = %d”,a); Printf(“a = %d and b= %d”,a,b); Input scanf(“%d ", &a); Scanf(“%d”,&a,&b); Output System.out.println(“hello baabtra”); Input Scanner sc = new scanner(System.in); int i = sc.nextInt(); (import java.util.Scanner) Input / Output Out In System Println() Print() Write() PrintStream
  • 10. C Vs java char str*+ = ‚hello‛; ‚String is character array‛ String str=‚Hello‛; ‚String is an object ‚ Strings
  • 11. C Vs java • As we are well aware c program execution begins at main() function Eg: main() { Printf(‚hello world‛); printHello(); } Same as C, differs that the main() will be a member function of some class. Name of the class and file should be the same. class myFirstProgram { public static void main(String[] args) { System.out.println(‚hello baabtra‛); } main() function
  • 13. What’s New in java? • OOP concepts • JVM and Platform independency • Automatic garbage collection
  • 14. OOP Concept • Object-oriented programming (OOP) is a style of programming that focuses on using objects to design and build applications. • Think of an object as a model of the concepts, processes, or things in the real world that are meaningful to your application.
  • 17. Objects in real world • Object will have an identity/name  Eg: reynolds, Cello for pen. Nokia,apple for mobile • Object will have different properties which describes them best  Eg:Color,size,width • Object can perform different actions  Eg: writing,erasing etc for pen. Calling, texting for mobile
  • 18. Objects I have an identity: I'm Volkswagen I have different properties. My color property is green My no:of wheel property is 4 I can perform different actions I can be drived I can consume fuel I can play Music I have an identity: I'm Suzuki I have different properties. My color property is silver My no:of wheel property is 4 I can perform different actions I can be drived I can consume fuel I can play Music
  • 19. How these objects are created? • All the objects in the real world are created out of a basic prototype or a basic blue print or a base design
  • 21. Objects in the software world • Same like in the real world we can create objects in computer programming world –Which will have a name as identity –Properties to define its behaviour –Actions what it can perform
  • 22. How these objects are created • We need to create a base design which defines the properties and functionalities that the object should have. • In programming terms we call this base design as Class • Simply by having a class we can create any number of objects of that type
  • 23. Definition • Class : is the base design of objects • Object : is the instance of a class • No memory is allocated when a class is created. • Memory is allocated only when an object is created.
  • 24. How to create class in Java public class shape { private Int width; private Int height; public Int calculateArea() { return x*y } }
  • 25. How to create class in Java public class shape { private Int width; private Int height; public Int calculateArea() { return x*y } } Is the access specifier
  • 26. How to create class in Java public class shape { private Int width; private Int height; public Int calculateArea() { return x*y } } Is the keyword for creating a class
  • 27. How to create class in Java public class shape { private Int width; private Int height; public Int calculateArea() { return x*y } } Is the name of the class
  • 28. How to create class in Java public class shape { private Int width; private Int height; public Int calculateArea() { return x*y } } Are two variable that referred as the properties. Normally kept private and access using getters and setters. We will discuss getters and setters later in this slide
  • 29. How to create class in Java public class shape { private Int width; private Int height; public Int calculateArea() { return x*y } } Is the only member function of the class
  • 30. How to create objects in java shape rectangle = new shape(); rectangle.width=20; recangle.height=35; rArea=rectangle.calculateArea(); This is how we create an object in java rectangle Height: width: calculateArea() { return height*width; }
  • 31. How to create objects in C++ shape rectangle = new shape(); rectangle.width=20; recangle.height=35; rArea=rectangle.calculateArea(); Is the class name
  • 32. How to create objects in C++ shape rectangle = new shape(); rectangle.width=20; recangle.height=35; rArea=rectangle.calculateArea(); Is the object name which we want to create
  • 33. How to create objects in C++ shape rectangle = new shape(); rectangle.width=20; recangle.height=35; rArea=rectangle.calculateArea(); “new” is the keyword used in java to create an object
  • 34. How to create objects in C++ shape rectangle = new shape(); rectangle.width=20; recangle.height=35; rArea=rectangle.calculateArea(); What is this??? It looks like a function because its having pair of parentheses (). And also its having the same name of our class . But what is it used for ?? We will discuss it soon . Just leave it as it is for now
  • 35. How to create objects in Java shape rectangle = new shape(); rectangle.width=20; recangle.height=35; rArea=rectangle.calculateArea(); Setting up the property values of object “rectangle” rectangle width: 20 Height: 35 calculateArea() { return width*height; }
  • 36. How to create objects in Java shape rectangle = new shape(); rectangle.width=20; recangle.height=35; rArea=rectangle.calculateArea(); Calling the method calculateArea() rectangle width: 20 Height: 35 calculateArea() { return 20*35; }
  • 37. Example Class : shape Height:35 width:20 Object rectangle calculateArea() { Return 20*35 } Height:10 width:10 Object square calculateArea() { Return 10*10; } Member variables Height width Member function calculateArea { return height*width; }
  • 38. What we just did was • Created an object shape rectangle = new shape(); • Same like we declare variable. eg: int a; • And assigned values for it recangle.height=35; same like we assign variable value. eg: a=10; Rectangle Width: Height: calculateArea() { return width*height; } Rectangle width: 20 Height: 35 calculateArea() { return 20*35; }
  • 39. So, Can i assign values into an object at the time of its creation(known as initialization)?? Something that we do with variables like int a=14;
  • 40. So, Can i assign values into an object at the time of its creation?? Something that we do with variables like int a=14; ‚Yes, you can . For that purpose we use something called constructor‛
  • 41. Constructors • Constructors are just a method like any other methods in the class but having the same name of the class. • It is used to initialise the properties of an object • will not have any return type, not even void • If no user defined constructor is provided for a class, the implicit constructor initializes the member variables to its default values – numeric data types are set to 0 – char data types are set to null character(‘0’) – boolean data types are set to false – reference variables are set to null
  • 42. public class shape { private Int width; private Int height; private Int calculateArea() { return x*y } } How to create Constructors
  • 43. public class shape { private Int width; private Int height; shape(int height,in width) { this.width=width; this.height=height; } private Int calculateArea() { return x*y } } Shape rectangle=new shape(20,35); Constructor Rectangle width: 20 Height: 35 calculateArea() { return 20*35; } How to create Constructors
  • 44. Access Specifier • Access specifies defines the access rights for the statements or functions that follows it until another access specifier or till the end of a class. • The three types of access specifiers are –Private –Public –Protected –default
  • 46. Getters and Setters • There are several occasion we need to validate the data when assigning values into it • For eg: rectangle.width=-10; rectangle.height=-12; • Suppose i want to check whether the user enters a negative value and if so i wish to assign 0 to the properties • In such scenarios we will create a method to do the above said actions Rectangle width: -10 Height: -12 calculateArea() { return -10*-12; }
  • 47. Getters and Setters • Getters and setters are simply two function that gets and sets the value of class properties. • Setter – Rectangle.width=15; // Normally this is how we set the values of class properties. Rectangle.setWidth(15); // calling a method named ‚setWidth‛ so that the method will set the property width to 15 • Getter – Rectangle.width; // Normally this is how we get the values of class properties. Rectangle.getWidth(); // calling a method named ‚getWidth‛ so that the method will get the value of the property width
  • 48. public class shape { private Int width; private Int height; Int calculateArea() { return x*y; } Public setWidth(int a) { if (a>0) width=a; else width=0 } Public Int getWidth() { return width } } How to create getters and setters
  • 49. public class shape { private Int width; private Int height; Int calculateArea() { return x*y; } Public setWidth(int a) { if (a>0) width=a; else width=0 } Public Int getWidth() { return width } } How to create getters and setters Setter function
  • 50. public class shape { private Int width; private Int height; Int calculateArea() { return x*y; } Public setWidth(int a) { if (a>0) width=a; else width=0 } Public Int getWidth() { return width } } How to create getters and setters Getter function
  • 52. Abstraction • Act of representing essential features only and hiding the implementation details • For example, a car would be made up of an Engine, but one does not need to know how the diverse components work inside. • In our example of class shape ; the users only have to create objects of type shape like rectangle,square etc. • And for finding out the area he dont really have to think about how the area is calculated. He only need to know calling the method calculateArea will reuslt him with the area.
  • 53. Encapsulation • Wrapping up of data(properties) and code(methods) into a single unit is known as encapsulation • Encapsulation also includes the process of hiding all the data and methods within a class from outside world by restricting access to the object's components. • In programming languages, encapsulation is accomplished by using private access specifier
  • 54. Inheritance • Is the process where one object acquires the properties of another. • Inheritance is a type of relationship – Ex: BMW is a Car • Reusability of code – Methods and properties of parent class will be accessible to child class • In java inheritance is achieved by using keyword ‚extends‛ • Java supports only single inheritance
  • 55. public class shape { protected Int width; protected Int height; Int calculateArea() { return x*y; } int drawShape() { system.out.println(“shape”) } } public class threedimensionalshape extends shape { private Int depth; Int calculateVolume() { return width*heigh*depth; } } Example
  • 56. Example • Shape rectangle = new rectangle(); • threedimensionalshape cube =new threedimensionalshape() Rectangle Width: Height: calculateArea() { Return width*height } cube Width: Height: depth calculateArea() { Return width*height } Int calculateVolume() { return width*height*depth; }
  • 57. Polymorphism • Polymorphism is the ability to take more than one form using the same name – Eg : function overloading, Operator overloading(not supported in java) • Functions can have same name but different implementations • There are two types of polymorphism –Static –Dynamic
  • 58. public class shape { Int calculateArea(int width, int height) { return width * width; } Float calculateArea(int radius) { return (22/7) * radius * radius } } public class example { Public static void main{ shape sh =new shape(); System.out. Println(sh.calculateArea(20, 10)); System.out.println(sh.calculateArea(10)); } } Output: 200 314.28 Example – Static polymorphism
  • 59. public class shape { Void drawShape() { system.out.println(“Shape”) } } public class ThreeDshape extends shape { Void drawShape() { system.out.println(“3D shape”) } } public class example { Public static void main{ shape sh =new shape(); ThreeDshape tds =new ThreeDshape (); Sh.drawShape(); sh=tds; Sh.drawShape; } } Output: Shape 3D shape Example – Dynamic polymorphism
  • 60. Static and Dynamic polymorphism • Achieved using Overloading • Signature difference • Inheritance not required for implementation • Decision at compile time • Early binding • Achieved by Overriding • Uses inheritance and virtual functions • Inheritance required for implementation • Decision at runtime • Late binding
  • 61. Questions? ‚A good question deserve a good grade…‛
  • 63. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 64. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: [email protected]