SlideShare a Scribd company logo
OOP - JAVA
Variables in Java
4/6/2022 1
Department of Computer
PRO – GRADE 5
Lecturer. OMEED M. M
Table of contents
 What is Variable?
 Allocating memory
 Types of variables
 Constructor
4/6/2022 2
Variable in Java
Variables used to store in our computer’s memory
Why called it variable?
Because the values inside the variables are changeable.
 Attributes - things that the object stores data in, generally
variables.
 Methods - Functions and Procedures attached to an Object and
allowing the object to perform actions
4/6/2022 3
Allocating memory
In order to store some data in our computer memory we have to
allocate some space so how we can do that? we will go through
allocating memory,
4/6/2022 4
Allocating memory
For this purpose we have to declare variables.
How we can declare variable we are going to using assignment
We can assign a value to a variable by using (Equal =) operator.
Ex.
String ANY_NAME = “ANY_NAME”
4/6/2022 5
Variable in Java
• Re-difine variable
4/6/2022 6
Variable in Java
• Println
4/6/2022 7
Types of variables
There are Three type of variables:-
1. Instance variables
2. Local variables
3. Class variables (Static variables)
4/6/2022 8
Instance variables
Instance variables Declared inside class but not inside method.
Ex.
Class test{
Int data=15; //instance variable
Float pi=3.114f; //instance variable
}
Cannot be reinitialized directly within class
Ex.
Class test{
Int data=15; //instance variable
data =20; //Error for correction we have to put it into a method
void testMethod(){
data=20 // correct;
} }
4/6/2022 9
Local variables
Local variables – Declared inside method or method parameters.
Ex.
Int areatest (int radius){
Int total = radius * radius;
Return total;
}
-These are not accessible outside method.
-They did not get default values.
4/6/2022 10
Class / Static variables
Class variables − are variables declared within a class, outside any
method, with the static keyword
-Static variable is shared between all objects because it belong to
the class. It does not belong to the object
-A static variable can be accessed without creating an instance of the
class.
4/6/2022 11
Constructor
A constructor in Java is similar to a method that is invoked when an
object of the class is created.
Unlike Java methods, a constructor has the same name as that of the
class and does not have any return type. For example,
class Test {
Test() {
// constructor body
}
}
4/6/2022 12
Types of variables
class A{
int date=50; //_________ variable
static int m=100; //_________ variable
void method(){
int n=90; //________ variable
}
} //end of class
4/6/2022 13
Any Questions ?
4/6/2022 14

More Related Content

Similar to OOP using java (Variable in java) (20)

Computer programming 2 Lesson 6
Computer programming 2  Lesson 6Computer programming 2  Lesson 6
Computer programming 2 Lesson 6
MLG College of Learning, Inc
 
Data types ^J variables and arrays in Java.pptx
Data types ^J variables and arrays in Java.pptxData types ^J variables and arrays in Java.pptx
Data types ^J variables and arrays in Java.pptx
sksumayasumaya5
 
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
Indu32
 
7. VARIABLEs presentation in java programming. Pdf
7. VARIABLEs presentation in java programming. Pdf7. VARIABLEs presentation in java programming. Pdf
7. VARIABLEs presentation in java programming. Pdf
simukondasankananji8
 
Object Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for studentsObject Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for students
ASHASITTeaching
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
Module 4_Chapter One - Java Methods.pptx
Module 4_Chapter One - Java Methods.pptxModule 4_Chapter One - Java Methods.pptx
Module 4_Chapter One - Java Methods.pptx
jhesorleylaid2
 
Learning Java 2 - Variables, Data Types and Operators
Learning Java 2 - Variables, Data Types and OperatorsLearning Java 2 - Variables, Data Types and Operators
Learning Java 2 - Variables, Data Types and Operators
MinhNguyen1493
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
Lakshmi Sarvani Videla
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
Shipra Swati
 
Java-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.pptJava-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.ppt
JyothiAmpally
 
javaClasses.pptx
javaClasses.pptxjavaClasses.pptx
javaClasses.pptx
MattMarino13
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
Indu65
 
Ppt chapter05
Ppt chapter05Ppt chapter05
Ppt chapter05
Richard Styner
 
Constant a,variables and data types
Constant a,variables and data typesConstant a,variables and data types
Constant a,variables and data types
mithilesh kumar
 
Unit-1 Data Types and Operators.pptx to computers
Unit-1 Data Types and Operators.pptx to computersUnit-1 Data Types and Operators.pptx to computers
Unit-1 Data Types and Operators.pptx to computers
csangani1
 
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyjChapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
berihun18
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
Padma Kannan
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
Epsiba1
 
Data types ^J variables and arrays in Java.pptx
Data types ^J variables and arrays in Java.pptxData types ^J variables and arrays in Java.pptx
Data types ^J variables and arrays in Java.pptx
sksumayasumaya5
 
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
Indu32
 
7. VARIABLEs presentation in java programming. Pdf
7. VARIABLEs presentation in java programming. Pdf7. VARIABLEs presentation in java programming. Pdf
7. VARIABLEs presentation in java programming. Pdf
simukondasankananji8
 
Object Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for studentsObject Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for students
ASHASITTeaching
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
Module 4_Chapter One - Java Methods.pptx
Module 4_Chapter One - Java Methods.pptxModule 4_Chapter One - Java Methods.pptx
Module 4_Chapter One - Java Methods.pptx
jhesorleylaid2
 
Learning Java 2 - Variables, Data Types and Operators
Learning Java 2 - Variables, Data Types and OperatorsLearning Java 2 - Variables, Data Types and Operators
Learning Java 2 - Variables, Data Types and Operators
MinhNguyen1493
 
Java-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.pptJava-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.ppt
JyothiAmpally
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
Indu65
 
Constant a,variables and data types
Constant a,variables and data typesConstant a,variables and data types
Constant a,variables and data types
mithilesh kumar
 
Unit-1 Data Types and Operators.pptx to computers
Unit-1 Data Types and Operators.pptx to computersUnit-1 Data Types and Operators.pptx to computers
Unit-1 Data Types and Operators.pptx to computers
csangani1
 
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyjChapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
berihun18
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
Padma Kannan
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
Epsiba1
 

More from omeed (15)

understanding of java basics
understanding of java basics understanding of java basics
understanding of java basics
omeed
 
Introduction to oop using java
Introduction  to oop using java Introduction  to oop using java
Introduction to oop using java
omeed
 
Asp.net LinkButton & imageButton controls
Asp.net LinkButton & imageButton controlsAsp.net LinkButton & imageButton controls
Asp.net LinkButton & imageButton controls
omeed
 
Asp.net CheckBoxList control
Asp.net CheckBoxList controlAsp.net CheckBoxList control
Asp.net CheckBoxList control
omeed
 
Asp.net CheckBox control
Asp.net CheckBox controlAsp.net CheckBox control
Asp.net CheckBox control
omeed
 
Asp.net RadiobuttonList control
Asp.net RadiobuttonList controlAsp.net RadiobuttonList control
Asp.net RadiobuttonList control
omeed
 
Asp.net Radiobutton control
Asp.net Radiobutton controlAsp.net Radiobutton control
Asp.net Radiobutton control
omeed
 
Asp.net textbox control
Asp.net textbox controlAsp.net textbox control
Asp.net textbox control
omeed
 
Understanding of Asp.net & page lifecycle
Understanding of Asp.net & page lifecycle Understanding of Asp.net & page lifecycle
Understanding of Asp.net & page lifecycle
omeed
 
Asp.net introduction to web development
Asp.net introduction to web development Asp.net introduction to web development
Asp.net introduction to web development
omeed
 
WEB DEVELOPMENT Using Python programming language
WEB DEVELOPMENT Using Python programming language WEB DEVELOPMENT Using Python programming language
WEB DEVELOPMENT Using Python programming language
omeed
 
Apple’s AI-Powered Personal Assistant Uses DNN - siri
Apple’s AI-Powered Personal Assistant Uses DNN - siri  Apple’s AI-Powered Personal Assistant Uses DNN - siri
Apple’s AI-Powered Personal Assistant Uses DNN - siri
omeed
 
Third and fourth generation programming language
Third and fourth generation programming languageThird and fourth generation programming language
Third and fourth generation programming language
omeed
 
analog clock C#
analog clock C#analog clock C#
analog clock C#
omeed
 
graphic Design
graphic Design graphic Design
graphic Design
omeed
 
understanding of java basics
understanding of java basics understanding of java basics
understanding of java basics
omeed
 
Introduction to oop using java
Introduction  to oop using java Introduction  to oop using java
Introduction to oop using java
omeed
 
Asp.net LinkButton & imageButton controls
Asp.net LinkButton & imageButton controlsAsp.net LinkButton & imageButton controls
Asp.net LinkButton & imageButton controls
omeed
 
Asp.net CheckBoxList control
Asp.net CheckBoxList controlAsp.net CheckBoxList control
Asp.net CheckBoxList control
omeed
 
Asp.net CheckBox control
Asp.net CheckBox controlAsp.net CheckBox control
Asp.net CheckBox control
omeed
 
Asp.net RadiobuttonList control
Asp.net RadiobuttonList controlAsp.net RadiobuttonList control
Asp.net RadiobuttonList control
omeed
 
Asp.net Radiobutton control
Asp.net Radiobutton controlAsp.net Radiobutton control
Asp.net Radiobutton control
omeed
 
Asp.net textbox control
Asp.net textbox controlAsp.net textbox control
Asp.net textbox control
omeed
 
Understanding of Asp.net & page lifecycle
Understanding of Asp.net & page lifecycle Understanding of Asp.net & page lifecycle
Understanding of Asp.net & page lifecycle
omeed
 
Asp.net introduction to web development
Asp.net introduction to web development Asp.net introduction to web development
Asp.net introduction to web development
omeed
 
WEB DEVELOPMENT Using Python programming language
WEB DEVELOPMENT Using Python programming language WEB DEVELOPMENT Using Python programming language
WEB DEVELOPMENT Using Python programming language
omeed
 
Apple’s AI-Powered Personal Assistant Uses DNN - siri
Apple’s AI-Powered Personal Assistant Uses DNN - siri  Apple’s AI-Powered Personal Assistant Uses DNN - siri
Apple’s AI-Powered Personal Assistant Uses DNN - siri
omeed
 
Third and fourth generation programming language
Third and fourth generation programming languageThird and fourth generation programming language
Third and fourth generation programming language
omeed
 
analog clock C#
analog clock C#analog clock C#
analog clock C#
omeed
 
graphic Design
graphic Design graphic Design
graphic Design
omeed
 
Ad

Recently uploaded (20)

Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptxWhat is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptxWhat is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Ad

OOP using java (Variable in java)

  • 1. OOP - JAVA Variables in Java 4/6/2022 1 Department of Computer PRO – GRADE 5 Lecturer. OMEED M. M
  • 2. Table of contents  What is Variable?  Allocating memory  Types of variables  Constructor 4/6/2022 2
  • 3. Variable in Java Variables used to store in our computer’s memory Why called it variable? Because the values inside the variables are changeable.  Attributes - things that the object stores data in, generally variables.  Methods - Functions and Procedures attached to an Object and allowing the object to perform actions 4/6/2022 3
  • 4. Allocating memory In order to store some data in our computer memory we have to allocate some space so how we can do that? we will go through allocating memory, 4/6/2022 4
  • 5. Allocating memory For this purpose we have to declare variables. How we can declare variable we are going to using assignment We can assign a value to a variable by using (Equal =) operator. Ex. String ANY_NAME = “ANY_NAME” 4/6/2022 5
  • 6. Variable in Java • Re-difine variable 4/6/2022 6
  • 7. Variable in Java • Println 4/6/2022 7
  • 8. Types of variables There are Three type of variables:- 1. Instance variables 2. Local variables 3. Class variables (Static variables) 4/6/2022 8
  • 9. Instance variables Instance variables Declared inside class but not inside method. Ex. Class test{ Int data=15; //instance variable Float pi=3.114f; //instance variable } Cannot be reinitialized directly within class Ex. Class test{ Int data=15; //instance variable data =20; //Error for correction we have to put it into a method void testMethod(){ data=20 // correct; } } 4/6/2022 9
  • 10. Local variables Local variables – Declared inside method or method parameters. Ex. Int areatest (int radius){ Int total = radius * radius; Return total; } -These are not accessible outside method. -They did not get default values. 4/6/2022 10
  • 11. Class / Static variables Class variables − are variables declared within a class, outside any method, with the static keyword -Static variable is shared between all objects because it belong to the class. It does not belong to the object -A static variable can be accessed without creating an instance of the class. 4/6/2022 11
  • 12. Constructor A constructor in Java is similar to a method that is invoked when an object of the class is created. Unlike Java methods, a constructor has the same name as that of the class and does not have any return type. For example, class Test { Test() { // constructor body } } 4/6/2022 12
  • 13. Types of variables class A{ int date=50; //_________ variable static int m=100; //_________ variable void method(){ int n=90; //________ variable } } //end of class 4/6/2022 13