SlideShare a Scribd company logo
1 of 14
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)

packages and interfaces
packages and interfacespackages and interfaces
packages and interfacesmadhavi patil
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesSakkaravarthiS1
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in javaElizabeth alexander
 
Classes, objects, methods, constructors, this keyword in java
Classes, objects, methods, constructors, this keyword  in javaClasses, objects, methods, constructors, this keyword  in java
Classes, objects, methods, constructors, this keyword in javaTharuniDiddekunta
 
Core Java Introduction | Basics
Core Java Introduction  | BasicsCore Java Introduction  | Basics
Core Java Introduction | BasicsHùng Nguyễn Huy
 
Unit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfUnit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfArpana Awasthi
 
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.pptxIndu65
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxDrYogeshDeshmukh1
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Sagar Verma
 
Introduction to Classes and Objects in Java - Edufect
Introduction to Classes and Objects in Java - EdufectIntroduction to Classes and Objects in Java - Edufect
Introduction to Classes and Objects in Java - EdufectEdufect
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptxEpsiba1
 

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

packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
CHAPTER 3 part1.pdf
CHAPTER 3 part1.pdfCHAPTER 3 part1.pdf
CHAPTER 3 part1.pdf
 
BIT211_3.pdf
BIT211_3.pdfBIT211_3.pdf
BIT211_3.pdf
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
 
Classes, objects, methods, constructors, this keyword in java
Classes, objects, methods, constructors, this keyword  in javaClasses, objects, methods, constructors, this keyword  in java
Classes, objects, methods, constructors, this keyword in java
 
Core Java Introduction | Basics
Core Java Introduction  | BasicsCore Java Introduction  | Basics
Core Java Introduction | Basics
 
Java defining classes
Java defining classes Java defining classes
Java defining classes
 
Unit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfUnit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdf
 
Java chapter 4
Java chapter 4Java chapter 4
Java chapter 4
 
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
 
Ppt chapter05
Ppt chapter05Ppt chapter05
Ppt chapter05
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 
Reflection
ReflectionReflection
Reflection
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
 
Introduction to Classes and Objects in Java - Edufect
Introduction to Classes and Objects in Java - EdufectIntroduction to Classes and Objects in Java - Edufect
Introduction to Classes and Objects in Java - Edufect
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 

More from 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 controlsomeed
 
Asp.net CheckBoxList control
Asp.net CheckBoxList controlAsp.net CheckBoxList control
Asp.net CheckBoxList controlomeed
 
Asp.net CheckBox control
Asp.net CheckBox controlAsp.net CheckBox control
Asp.net CheckBox controlomeed
 
Asp.net RadiobuttonList control
Asp.net RadiobuttonList controlAsp.net RadiobuttonList control
Asp.net RadiobuttonList controlomeed
 
Asp.net Radiobutton control
Asp.net Radiobutton controlAsp.net Radiobutton control
Asp.net Radiobutton controlomeed
 
Asp.net textbox control
Asp.net textbox controlAsp.net textbox control
Asp.net textbox controlomeed
 
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 languageomeed
 
analog clock C#
analog clock C#analog clock C#
analog clock C#omeed
 
graphic Design
graphic Design graphic Design
graphic Design omeed
 

More from omeed (15)

understanding of java basics
understanding of java basics understanding of java basics
understanding of java basics
 
Introduction to oop using java
Introduction  to oop using java Introduction  to oop using java
Introduction to oop using java
 
Asp.net LinkButton & imageButton controls
Asp.net LinkButton & imageButton controlsAsp.net LinkButton & imageButton controls
Asp.net LinkButton & imageButton controls
 
Asp.net CheckBoxList control
Asp.net CheckBoxList controlAsp.net CheckBoxList control
Asp.net CheckBoxList control
 
Asp.net CheckBox control
Asp.net CheckBox controlAsp.net CheckBox control
Asp.net CheckBox control
 
Asp.net RadiobuttonList control
Asp.net RadiobuttonList controlAsp.net RadiobuttonList control
Asp.net RadiobuttonList control
 
Asp.net Radiobutton control
Asp.net Radiobutton controlAsp.net Radiobutton control
Asp.net Radiobutton control
 
Asp.net textbox control
Asp.net textbox controlAsp.net textbox control
Asp.net textbox control
 
Understanding of Asp.net & page lifecycle
Understanding of Asp.net & page lifecycle Understanding of Asp.net & page lifecycle
Understanding of Asp.net & page lifecycle
 
Asp.net introduction to web development
Asp.net introduction to web development Asp.net introduction to web development
Asp.net introduction to web development
 
WEB DEVELOPMENT Using Python programming language
WEB DEVELOPMENT Using Python programming language WEB DEVELOPMENT Using Python programming language
WEB DEVELOPMENT Using Python programming language
 
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
 
Third and fourth generation programming language
Third and fourth generation programming languageThird and fourth generation programming language
Third and fourth generation programming language
 
analog clock C#
analog clock C#analog clock C#
analog clock C#
 
graphic Design
graphic Design graphic Design
graphic Design
 

Recently uploaded

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Recently uploaded (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

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