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

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
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
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
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
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
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

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
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
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
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
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
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
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)
 
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
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 

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