SlideShare a Scribd company logo
In Java, all variables must be declared before they can be used.
Few examples
Instance variables
Technically speaking, objects store their individual states in
“non-static fields”, that is, fields declared without the static keyword.
Non-static fields are also known as instance variables because
their values are unique to each instance of a class
(to each object, in other words);
the currentSpeed of one bicycle is independent
fromthe currentSpeed of another.
Instance variables are declared in a class,
but outside a method, constructor or any block.
Instance variables are created when an object is created
and destroyed when the object is destroyed.
Instance variables hold object's state, available to all methods,
constructors or blocks of a class, and accessible by using references or
objects out the class.
Instance variables have default values
● numbers : 0
● Booleans : false
● Object references : null
Values can be assigned during the declaration
or within the constructor.
Identify Instance variables
Class Variables (Static Fields)
A class variable is any field declared with the static modifier;
there is exactly one copy of this variable in existence,
regardless of how many times the class has been instantiated.
Example :
A field defining the number of gears for a particular kind of bicycle could
be marked as static since conceptually the same number of gears will
apply to all instances.
static int numGears =6
Local variables
Similar to how an object stores its state in fields, a method will often store
its temporary state in local variables.
The syntax for declaring a local variable is similar to declaring a field
There is no special keyword designating a variable as local;
that determination comes entirely from the location in which the
variable is declared
— which is between the opening and closing braces of a method.
Access modifiers cannot be used for local variables.
Local variables are visible only
within the declared method, constructor or block.
There is no default value for local variables so local variables should be
declared and an initial value should be assigned before the first use.
Identify Local variable
How we can fix this error?
Error: variable mmight not have been initialized
m++;
1 error
Parameters
args variable is the parameter to main method.
public static void main ( String[ ] args )
Parameters are always classified as “variables”not “fields”.
This applies to parameter-accepting constructs as well.

More Related Content

PPT
3 java - variable type
PPTX
Java basics and java variables
PPTX
Local variables Instance variables Class/static variables
PPTX
Static keyword ppt
PDF
Chapter 01 Introduction to Java by Tushar B Kute
PPTX
Pi j3.2 polymorphism
PPT
Classes&objects
PDF
Java essentials for hadoop
3 java - variable type
Java basics and java variables
Local variables Instance variables Class/static variables
Static keyword ppt
Chapter 01 Introduction to Java by Tushar B Kute
Pi j3.2 polymorphism
Classes&objects
Java essentials for hadoop

What's hot (19)

PPTX
Object oriented programming in java
PPTX
Week9 Intro to classes and objects in Java
PDF
CLASS & OBJECT IN JAVA
PPTX
6. static keyword
PDF
Java Basics Presentation
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
PPTX
Learning core java
PPTX
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
PDF
Java data types, variables and jvm
PPT
Final keyword in java
PPTX
Classes objects in java
PPTX
Logic and Coding of Java Interfaces & Swing Applications
PPTX
Java static keyword
PPTX
PCSTt11 overview of java
PPT
Java static keyword
PPTX
Android webinar class_java_review
PPTX
oops concept in java | object oriented programming in java
PPT
Lect 1-class and object
PPTX
Classes, objects in JAVA
Object oriented programming in java
Week9 Intro to classes and objects in Java
CLASS & OBJECT IN JAVA
6. static keyword
Java Basics Presentation
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Learning core java
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Java data types, variables and jvm
Final keyword in java
Classes objects in java
Logic and Coding of Java Interfaces & Swing Applications
Java static keyword
PCSTt11 overview of java
Java static keyword
Android webinar class_java_review
oops concept in java | object oriented programming in java
Lect 1-class and object
Classes, objects in JAVA
Ad

Viewers also liked (7)

PPTX
Java arrays
PPT
Array in Java
PPT
Java Arrays
PPTX
Arrays in java
PPT
Java: Introduction to Arrays
PPTX
Arrays in Java
PPTX
Arrays in java
Java arrays
Array in Java
Java Arrays
Arrays in java
Java: Introduction to Arrays
Arrays in Java
Arrays in java
Ad

Similar to Java Variable Types (20)

PPTX
Computer programming 2 Lesson 6
PDF
7. VARIABLEs presentation in java programming. Pdf
PPT
Java-Variables_about_different_Scope.ppt
PPTX
Variables
PPTX
class as the basis.pptx
DOCX
Class notes(week 3) on class objects and methods
PPTX
classes-objects in oops java-201023154255.pptx
PPTX
Classes-and-Object.pptx
PDF
Class notes(week 3) on class objects and methods
PPT
3. Data types and Variables
PPTX
3.Classes&Objects.pptx
PPTX
Chapter 5:Understanding Variable Scope and Class Construction
PPTX
This and Static Keyword
PPTX
Java Tokens in java program . pptx
PPTX
Variables in java.pptx
PPTX
Lecture 6.pptx
PPTX
Lecture_4_Static_variables_and_Methods.pptx
PPT
Ap Power Point Chpt5
PPT
Java findamentals2
PPT
Java findamentals2
Computer programming 2 Lesson 6
7. VARIABLEs presentation in java programming. Pdf
Java-Variables_about_different_Scope.ppt
Variables
class as the basis.pptx
Class notes(week 3) on class objects and methods
classes-objects in oops java-201023154255.pptx
Classes-and-Object.pptx
Class notes(week 3) on class objects and methods
3. Data types and Variables
3.Classes&Objects.pptx
Chapter 5:Understanding Variable Scope and Class Construction
This and Static Keyword
Java Tokens in java program . pptx
Variables in java.pptx
Lecture 6.pptx
Lecture_4_Static_variables_and_Methods.pptx
Ap Power Point Chpt5
Java findamentals2
Java findamentals2

More from Shahid Rasheed (7)

PDF
Java Variable Storage
PDF
Java Instantiation
PDF
Variable Naming Best Practices
PDF
Java Basic Operators
PDF
Java basic-data-types
PDF
Java basic-syntax
PDF
What is-java
Java Variable Storage
Java Instantiation
Variable Naming Best Practices
Java Basic Operators
Java basic-data-types
Java basic-syntax
What is-java

Recently uploaded (20)

PPTX
Institutional Correction lecture only . . .
PDF
Pre independence Education in Inndia.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
master seminar digital applications in india
Institutional Correction lecture only . . .
Pre independence Education in Inndia.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
human mycosis Human fungal infections are called human mycosis..pptx
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Microbial diseases, their pathogenesis and prophylaxis
PPH.pptx obstetrics and gynecology in nursing
01-Introduction-to-Information-Management.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial disease of the cardiovascular and lymphatic systems
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Week 4 Term 3 Study Techniques revisited.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
TR - Agricultural Crops Production NC III.pdf
Pharma ospi slides which help in ospi learning
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O7-L3 Supply Chain Operations - ICLT Program
Module 4: Burden of Disease Tutorial Slides S2 2025
master seminar digital applications in india

Java Variable Types

  • 1. In Java, all variables must be declared before they can be used.
  • 3. Instance variables Technically speaking, objects store their individual states in “non-static fields”, that is, fields declared without the static keyword.
  • 4. Non-static fields are also known as instance variables because their values are unique to each instance of a class (to each object, in other words); the currentSpeed of one bicycle is independent fromthe currentSpeed of another.
  • 5. Instance variables are declared in a class, but outside a method, constructor or any block.
  • 6. Instance variables are created when an object is created and destroyed when the object is destroyed.
  • 7. Instance variables hold object's state, available to all methods, constructors or blocks of a class, and accessible by using references or objects out the class.
  • 8. Instance variables have default values ● numbers : 0 ● Booleans : false ● Object references : null Values can be assigned during the declaration or within the constructor.
  • 10. Class Variables (Static Fields) A class variable is any field declared with the static modifier;
  • 11. there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated.
  • 12. Example : A field defining the number of gears for a particular kind of bicycle could be marked as static since conceptually the same number of gears will apply to all instances. static int numGears =6
  • 13. Local variables Similar to how an object stores its state in fields, a method will often store its temporary state in local variables.
  • 14. The syntax for declaring a local variable is similar to declaring a field
  • 15. There is no special keyword designating a variable as local; that determination comes entirely from the location in which the variable is declared — which is between the opening and closing braces of a method.
  • 16. Access modifiers cannot be used for local variables.
  • 17. Local variables are visible only within the declared method, constructor or block.
  • 18. There is no default value for local variables so local variables should be declared and an initial value should be assigned before the first use.
  • 20. How we can fix this error? Error: variable mmight not have been initialized m++; 1 error
  • 21. Parameters args variable is the parameter to main method. public static void main ( String[ ] args )
  • 22. Parameters are always classified as “variables”not “fields”. This applies to parameter-accepting constructs as well.