SlideShare a Scribd company logo
Spotle.ai Study Material
Spotle.ai/Learn
Class And Object
in Java
Spotle.ai Study Material
Spotle.ai/Learn
A class is a data type in Java that
defines a template or blueprint for
an object. In other words a class
refers to the category or type of
objects. So your cat Kitty is of
type cat, your red Mercedes is of
type car and your bank account is
of type savings account. A class
has variables defining properties
and methods defining behaviour
of its objects.
Class
Image Source: Wikipedia
2
Spotle.ai Study Material
Spotle.ai/Learn
Class Syntax
3
Public Class Cat
{
colour;
breed;
getBreed()
meow()
eat()
}
Variables
Methods
Name of
the class
Spotle.ai Study Material
Spotle.ai/Learn
A variable is a named
field containing
information associated
with the class or object.
For example the colour
variable of Class Cat
indicates the colour of
the specific cat. A
variable has a data type
indicating what type of
variable (number, text,
array, custom, etc) it is.
What Are Variables?
4
Colour
= Black
Colour
= White
Spotle.ai Study Material
Spotle.ai/Learn
Types Of Variables
5
Local
Variables
• A variable declared inside
a class method/
constructor is called a
local variable.
• Other methods in the
class are not aware of
these variables.
• For example, consider the
drink method of class Cat:
drink()
{float milk_qty = 10}
milk_qty is a local
variable of method
drink().
Instance
Variables
• Are variables declared
inside a class but outside
of any method or
constructor.
• These are called instance
variables because their
values are instance
specific and are not
shared among instances.
Eg. the colour variable of
the Class Cat.
Class
Variables
• Are variables declared
inside a class with the
keyword static.
• A single copy of a static
variable is shared among
all instances of a class.
• Static variables are used
to declare common
properties – for example
the number of legs of a
cat or the mileage of a
brand of cars.
Spotle.ai Study Material
Spotle.ai/Learn
What Is A Class?
6
What is your
colour?
But you cannothide your
no_of_legs. Thatis a static variablein Class Cat!
Instance And Static Variables
My colour is my
colour. None of
your colour!
Spotle.ai Study Material
Spotle.ai/Learn
Methods are used to describe
behaviour of the objects of a class.
A method is a set of statements
which is referred to by name and
can be invoked at any point in a
program. It performs a logical unit
of work.
For example get_mileage() method
in class Car is used to return a
specific car’s mileage. In our cat
example, meow() and drink_milk
are methods of the cat objects.
What Are Methods?
7
Meow()
Meow()
Spotle.ai Study Material
Spotle.ai/Learn
Public int getMileage()
{
return mileage;
}
Public void refuel(float fuel)
{
total_fuel = total_fuel + fuel;
}
Syntax Of A Method
8
Return type indicates
the data type of the
variable returned by a
method.
This indicates the
parameter with which
the method is invoked
from within a program.
This is the method
name.
The body of the
method describes the
functionality.
Spotle.ai Study Material
Spotle.ai/Learn
What Are Constructors?
9
Constructor is a block of code defined
in a class that initializes the newly
created object.
A constructor is structurally very
similar to an instance method in Java
but it is not a method as it doesn’t
have a return type.
A constructor is automatically called
when the instance of a class is
created.
Public class Cat
{
Cat()
{
System.out.println(“Meow !I
am a new Cat.”)
}
}
Definition Example
Spotle.ai Study Material
Spotle.ai/Learn
Types Of Constructors
10
If a class does not have
any constructor, Java
compiler inserts a default
constructor into the code.
A default constructor, for
class Cat, looks like this.
Note the body is empty:
Cat()
{
}
The default constructor is
not inserted if you
implement a constructor
for your class.
A no-argument
constructor is one that
takes no arguments or
parameters.
For example:
Cat()
{
System.out.println(“Meow
!I am a new Cat.”)
}
}
Default
Constructors
Parameterized
Constructors
No Argument
Constructors
A constructor with
arguments or parameters
is known as a
Parameterized
constructor.
For example:
Cat( String msg)
{
System.out.println(“Meow
!I am a new Cat with a
special message” + msg)
}
}
Spotle.ai Study Material
Spotle.ai/Learn
Class Syntax - Revisited
11
public class Cat
{
string colour;
string breed;
static no_of_legs = 4
Cat()
{
System.out.println(“Meow !I
I am a new Cat.”)
}
public void meow()
{
System.out.println(“Meow on demand!”);
}
}
Variables
Methods
Name of
the class
Constructors
Spotle.ai Study Material
Spotle.ai/Learn
What Is An Object?
Think of the class like the Mercedes blue-print
and the object like your brand new Mercedes.
12
Object is an instance of a class.
An object is a self-contained
component with methods or
behaviour and properties or state.
Objects are the real world
manifestation of a class like your
house is the manifestation of the
architect’s blue-print. Or your car is a
real object of type car.
Objects occupy memory location at
run-time.
Spotle.ai Study Material
Spotle.ai/Learn
Creating An Object In Java
13
Cat myKitty = new Cat()
Cat myKitty is the declaration of the
object myKitty of class Cat.
Objects are created by using the
operator New which allocates memory
for the object.
The Cat() command invokes the no-arg
constructor we defined earlier (In Slide
11).
So when Cat myKitty = new Cat()
is run, the following gets printed:
Meow! I am a new Cat.
Spotle.ai Study Material
Spotle.ai/Learn
Class Object
A class is a data type.
It defines a template
or blueprint for an
object.
Object is an instance
of a class.
Does not occupy
memory location.
Occupies memory
location at run time.
Does not really exist
as it only provides a
template. You can
therefore not perform
operations on a class.
You perform
operations on objects.
Class Vs Object
14
Think of the class like the Mercedes blue-print
and the object like your brand new Mercedes.

More Related Content

What's hot

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
Elizabeth Thomas
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
Nilesh Dalvi
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
harsh kothari
 
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
Vinod Kumar
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Pavith Gunasekara
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
VINOTH R
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Java swing
Java swingJava swing
Java swing
Apurbo Datta
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
mahir jain
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 

What's hot (20)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Java package
Java packageJava package
Java package
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Java Streams
Java StreamsJava Streams
Java Streams
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Java swing
Java swingJava swing
Java swing
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 

Similar to Class and Objects in Java

03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
mha4
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
mha4
 
Classes_python.pptx
Classes_python.pptxClasses_python.pptx
Classes_python.pptx
RabiyaZhexembayeva
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
talha ijaz
 
Java is an Object-Oriented Language
Java is an Object-Oriented LanguageJava is an Object-Oriented Language
Java is an Object-Oriented Language
ale8819
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
NuurAxmed2
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
ssuser8347a1
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)dannygriff1
 
python note.pdf
python note.pdfpython note.pdf
python note.pdf
Nagendra504676
 
Ground Gurus - Python Code Camp - Day 3 - Classes
Ground Gurus - Python Code Camp - Day 3 - ClassesGround Gurus - Python Code Camp - Day 3 - Classes
Ground Gurus - Python Code Camp - Day 3 - Classes
Chariza Pladin
 
Unidad o informatica en ingles
Unidad o informatica en inglesUnidad o informatica en ingles
Unidad o informatica en ingles
Marisa Torrecillas
 
S12.s01 - Material TP.pdf
S12.s01 - Material TP.pdfS12.s01 - Material TP.pdf
S12.s01 - Material TP.pdf
julioamericoramirezs
 
JS-02-JavaScript-Objects.ppt
JS-02-JavaScript-Objects.pptJS-02-JavaScript-Objects.ppt
JS-02-JavaScript-Objects.ppt
MadhukarReddy74
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
BG Java EE Course
 
IPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptxIPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptx
DhavalaShreeBJain
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
Epsiba1
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ Comparator
Sean McElrath
 

Similar to Class and Objects in Java (20)

Lecture 4
Lecture 4Lecture 4
Lecture 4
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
Classes_python.pptx
Classes_python.pptxClasses_python.pptx
Classes_python.pptx
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
java
javajava
java
 
Java is an Object-Oriented Language
Java is an Object-Oriented LanguageJava is an Object-Oriented Language
Java is an Object-Oriented Language
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)
 
python note.pdf
python note.pdfpython note.pdf
python note.pdf
 
Ground Gurus - Python Code Camp - Day 3 - Classes
Ground Gurus - Python Code Camp - Day 3 - ClassesGround Gurus - Python Code Camp - Day 3 - Classes
Ground Gurus - Python Code Camp - Day 3 - Classes
 
Unidad o informatica en ingles
Unidad o informatica en inglesUnidad o informatica en ingles
Unidad o informatica en ingles
 
S12.s01 - Material TP.pdf
S12.s01 - Material TP.pdfS12.s01 - Material TP.pdf
S12.s01 - Material TP.pdf
 
Unit - 3.pptx
Unit - 3.pptxUnit - 3.pptx
Unit - 3.pptx
 
JS-02-JavaScript-Objects.ppt
JS-02-JavaScript-Objects.pptJS-02-JavaScript-Objects.ppt
JS-02-JavaScript-Objects.ppt
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
IPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptxIPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptx
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ Comparator
 

More from Spotle.ai

Spotle AI-thon - AI For Good Business Plan Showcase - Team IIM Indore - AI Ro...
Spotle AI-thon - AI For Good Business Plan Showcase - Team IIM Indore - AI Ro...Spotle AI-thon - AI For Good Business Plan Showcase - Team IIM Indore - AI Ro...
Spotle AI-thon - AI For Good Business Plan Showcase - Team IIM Indore - AI Ro...
Spotle.ai
 
Spotle AI-thon - AI For Good Business Plan Showcase - Cummins College
Spotle AI-thon - AI For Good Business Plan Showcase - Cummins CollegeSpotle AI-thon - AI For Good Business Plan Showcase - Cummins College
Spotle AI-thon - AI For Good Business Plan Showcase - Cummins College
Spotle.ai
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Elit...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Elit...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Elit...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Elit...
Spotle.ai
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India- Ankur chat...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India- Ankur chat...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India- Ankur chat...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India- Ankur chat...
Spotle.ai
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team La c...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team La c...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team La c...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team La c...
Spotle.ai
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Temp...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Temp...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Temp...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Temp...
Spotle.ai
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Zer...
 Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Zer... Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Zer...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Zer...
Spotle.ai
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Shivam Gi...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Shivam Gi...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Shivam Gi...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Shivam Gi...
Spotle.ai
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Cyber Pun...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Cyber Pun...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Cyber Pun...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Cyber Pun...
Spotle.ai
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Tech Owls...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Tech Owls...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Tech Owls...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Tech Owls...
Spotle.ai
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Jar...
 Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Jar... Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Jar...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Jar...
Spotle.ai
 
Artificial intelligence in fintech
Artificial intelligence in fintechArtificial intelligence in fintech
Artificial intelligence in fintech
Spotle.ai
 
Semi-supervised Machine Learning
Semi-supervised Machine LearningSemi-supervised Machine Learning
Semi-supervised Machine Learning
Spotle.ai
 
Basics of Reinforcement Learning
Basics of Reinforcement LearningBasics of Reinforcement Learning
Basics of Reinforcement Learning
Spotle.ai
 
Tableau And Data Visualization - Get Started
Tableau And Data Visualization - Get StartedTableau And Data Visualization - Get Started
Tableau And Data Visualization - Get Started
Spotle.ai
 
Artificial Intelligence in FinTech
Artificial Intelligence in FinTechArtificial Intelligence in FinTech
Artificial Intelligence in FinTech
Spotle.ai
 
Supervised and Unsupervised Machine Learning
Supervised and Unsupervised Machine LearningSupervised and Unsupervised Machine Learning
Supervised and Unsupervised Machine Learning
Spotle.ai
 
Growing-up With AI
Growing-up With AIGrowing-up With AI
Growing-up With AI
Spotle.ai
 
AI And Cyber-security Threats
AI And Cyber-security ThreatsAI And Cyber-security Threats
AI And Cyber-security Threats
Spotle.ai
 
Robotic Process Automation With Blue Prism
Robotic Process Automation With Blue PrismRobotic Process Automation With Blue Prism
Robotic Process Automation With Blue Prism
Spotle.ai
 

More from Spotle.ai (20)

Spotle AI-thon - AI For Good Business Plan Showcase - Team IIM Indore - AI Ro...
Spotle AI-thon - AI For Good Business Plan Showcase - Team IIM Indore - AI Ro...Spotle AI-thon - AI For Good Business Plan Showcase - Team IIM Indore - AI Ro...
Spotle AI-thon - AI For Good Business Plan Showcase - Team IIM Indore - AI Ro...
 
Spotle AI-thon - AI For Good Business Plan Showcase - Cummins College
Spotle AI-thon - AI For Good Business Plan Showcase - Cummins CollegeSpotle AI-thon - AI For Good Business Plan Showcase - Cummins College
Spotle AI-thon - AI For Good Business Plan Showcase - Cummins College
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Elit...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Elit...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Elit...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Elit...
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India- Ankur chat...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India- Ankur chat...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India- Ankur chat...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India- Ankur chat...
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team La c...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team La c...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team La c...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team La c...
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Temp...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Temp...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Temp...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Temp...
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Zer...
 Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Zer... Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Zer...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Zer...
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Shivam Gi...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Shivam Gi...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Shivam Gi...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Shivam Gi...
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Cyber Pun...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Cyber Pun...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Cyber Pun...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Cyber Pun...
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Tech Owls...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Tech Owls...Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Tech Owls...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Tech Owls...
 
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Jar...
 Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Jar... Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Jar...
Spotle AI-thon Top 10 Showcase - Analysing Mental Health Of India - Team Jar...
 
Artificial intelligence in fintech
Artificial intelligence in fintechArtificial intelligence in fintech
Artificial intelligence in fintech
 
Semi-supervised Machine Learning
Semi-supervised Machine LearningSemi-supervised Machine Learning
Semi-supervised Machine Learning
 
Basics of Reinforcement Learning
Basics of Reinforcement LearningBasics of Reinforcement Learning
Basics of Reinforcement Learning
 
Tableau And Data Visualization - Get Started
Tableau And Data Visualization - Get StartedTableau And Data Visualization - Get Started
Tableau And Data Visualization - Get Started
 
Artificial Intelligence in FinTech
Artificial Intelligence in FinTechArtificial Intelligence in FinTech
Artificial Intelligence in FinTech
 
Supervised and Unsupervised Machine Learning
Supervised and Unsupervised Machine LearningSupervised and Unsupervised Machine Learning
Supervised and Unsupervised Machine Learning
 
Growing-up With AI
Growing-up With AIGrowing-up With AI
Growing-up With AI
 
AI And Cyber-security Threats
AI And Cyber-security ThreatsAI And Cyber-security Threats
AI And Cyber-security Threats
 
Robotic Process Automation With Blue Prism
Robotic Process Automation With Blue PrismRobotic Process Automation With Blue Prism
Robotic Process Automation With Blue Prism
 

Recently uploaded

A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 

Recently uploaded (20)

A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 

Class and Objects in Java

  • 2. Spotle.ai Study Material Spotle.ai/Learn A class is a data type in Java that defines a template or blueprint for an object. In other words a class refers to the category or type of objects. So your cat Kitty is of type cat, your red Mercedes is of type car and your bank account is of type savings account. A class has variables defining properties and methods defining behaviour of its objects. Class Image Source: Wikipedia 2
  • 3. Spotle.ai Study Material Spotle.ai/Learn Class Syntax 3 Public Class Cat { colour; breed; getBreed() meow() eat() } Variables Methods Name of the class
  • 4. Spotle.ai Study Material Spotle.ai/Learn A variable is a named field containing information associated with the class or object. For example the colour variable of Class Cat indicates the colour of the specific cat. A variable has a data type indicating what type of variable (number, text, array, custom, etc) it is. What Are Variables? 4 Colour = Black Colour = White
  • 5. Spotle.ai Study Material Spotle.ai/Learn Types Of Variables 5 Local Variables • A variable declared inside a class method/ constructor is called a local variable. • Other methods in the class are not aware of these variables. • For example, consider the drink method of class Cat: drink() {float milk_qty = 10} milk_qty is a local variable of method drink(). Instance Variables • Are variables declared inside a class but outside of any method or constructor. • These are called instance variables because their values are instance specific and are not shared among instances. Eg. the colour variable of the Class Cat. Class Variables • Are variables declared inside a class with the keyword static. • A single copy of a static variable is shared among all instances of a class. • Static variables are used to declare common properties – for example the number of legs of a cat or the mileage of a brand of cars.
  • 6. Spotle.ai Study Material Spotle.ai/Learn What Is A Class? 6 What is your colour? But you cannothide your no_of_legs. Thatis a static variablein Class Cat! Instance And Static Variables My colour is my colour. None of your colour!
  • 7. Spotle.ai Study Material Spotle.ai/Learn Methods are used to describe behaviour of the objects of a class. A method is a set of statements which is referred to by name and can be invoked at any point in a program. It performs a logical unit of work. For example get_mileage() method in class Car is used to return a specific car’s mileage. In our cat example, meow() and drink_milk are methods of the cat objects. What Are Methods? 7 Meow() Meow()
  • 8. Spotle.ai Study Material Spotle.ai/Learn Public int getMileage() { return mileage; } Public void refuel(float fuel) { total_fuel = total_fuel + fuel; } Syntax Of A Method 8 Return type indicates the data type of the variable returned by a method. This indicates the parameter with which the method is invoked from within a program. This is the method name. The body of the method describes the functionality.
  • 9. Spotle.ai Study Material Spotle.ai/Learn What Are Constructors? 9 Constructor is a block of code defined in a class that initializes the newly created object. A constructor is structurally very similar to an instance method in Java but it is not a method as it doesn’t have a return type. A constructor is automatically called when the instance of a class is created. Public class Cat { Cat() { System.out.println(“Meow !I am a new Cat.”) } } Definition Example
  • 10. Spotle.ai Study Material Spotle.ai/Learn Types Of Constructors 10 If a class does not have any constructor, Java compiler inserts a default constructor into the code. A default constructor, for class Cat, looks like this. Note the body is empty: Cat() { } The default constructor is not inserted if you implement a constructor for your class. A no-argument constructor is one that takes no arguments or parameters. For example: Cat() { System.out.println(“Meow !I am a new Cat.”) } } Default Constructors Parameterized Constructors No Argument Constructors A constructor with arguments or parameters is known as a Parameterized constructor. For example: Cat( String msg) { System.out.println(“Meow !I am a new Cat with a special message” + msg) } }
  • 11. Spotle.ai Study Material Spotle.ai/Learn Class Syntax - Revisited 11 public class Cat { string colour; string breed; static no_of_legs = 4 Cat() { System.out.println(“Meow !I I am a new Cat.”) } public void meow() { System.out.println(“Meow on demand!”); } } Variables Methods Name of the class Constructors
  • 12. Spotle.ai Study Material Spotle.ai/Learn What Is An Object? Think of the class like the Mercedes blue-print and the object like your brand new Mercedes. 12 Object is an instance of a class. An object is a self-contained component with methods or behaviour and properties or state. Objects are the real world manifestation of a class like your house is the manifestation of the architect’s blue-print. Or your car is a real object of type car. Objects occupy memory location at run-time.
  • 13. Spotle.ai Study Material Spotle.ai/Learn Creating An Object In Java 13 Cat myKitty = new Cat() Cat myKitty is the declaration of the object myKitty of class Cat. Objects are created by using the operator New which allocates memory for the object. The Cat() command invokes the no-arg constructor we defined earlier (In Slide 11). So when Cat myKitty = new Cat() is run, the following gets printed: Meow! I am a new Cat.
  • 14. Spotle.ai Study Material Spotle.ai/Learn Class Object A class is a data type. It defines a template or blueprint for an object. Object is an instance of a class. Does not occupy memory location. Occupies memory location at run time. Does not really exist as it only provides a template. You can therefore not perform operations on a class. You perform operations on objects. Class Vs Object 14 Think of the class like the Mercedes blue-print and the object like your brand new Mercedes.