SlideShare a Scribd company logo
1 of 10
Download to read offline
Variable Types
• Each variable in Java has a specific type, which determines the size and layout of
the variable's memory.
• the range of values that can be stored within that memory.
• Variable Declaration:
datatype variable = value ;
datatype variable = value , variable = value,…;
Variable Types
• Example
int a, b, c; // Declares three int’s, a, b, and c.
int a = 10, b = 10; // Example of initialization
byte B = 22; // initializes a byte type variable B.
double pi = 3.14159; // declares and assigns a value of PI.
char a = 'a'; // the char variable a is initialized with value 'a'
Variable Types
• Variable Types
• Local Variable
• Instance Variable
• Class / Static Variable
Variable Type – Local Variable
• It declared inside of methods, constructors, or blocks.
• Access modifier cannot be used for local variable.
• Local variables are visible only within the methods.
• Variable can be accessed when the method is called.
Class
{
method
{
declare variable
}
}
Variable Type – Local Variable
public class Dog
{
public void dogAge()
{
int age = 0;
age = age + 7;
System.out.println(“Dog age is : “ + age);
}
public static void main(String args[])
{
Dog dog = new Dog();
dog.pupAge();
}
}
Variable Type – Instance Variable
• It declare inside of a class but outside of methods.
• This variable can be access by any methods.
• By creating object for a class, we can access this
variable from main methods.
Class
{
declare variable
method
{
//can use var
}
}
Variable Type – Instance Variable
public class Dog {
int age;
public void Dog(int i) {
age = i;
}
public void display() {
System.out.println(“Dog age is : “ + age);
}
public static void main(String args[]) {
Dog dog = new Dog(30);
dog.display();
}
}
Variable Type – Class / Static Variable
• Variable declared inside of class but outside
of methods with static keyword.
• Static variables are stored in the static
memory.
• Static variables can be accessed by static
methods or constructors.
Class
{
declare static variable
constructor
{
//can use var
}
static method
{
//can use var
}
}
Variable Type – Class / Static Variable
public class Dog {
static int age;
public void Dog(int i) {
age = i;
System.out.println(age); //30
}
public static void main(String args[]) {
Dog dog = new Dog(30);
dog.display();
age= 40;
System.out.println(age); //40
}
}

More Related Content

What's hot

Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 
Constants, Variables and Data Types in Java
Constants, Variables and Data Types in JavaConstants, Variables and Data Types in Java
Constants, Variables and Data Types in Java
Abhilash Nair
 

What's hot (20)

java Features
java Featuresjava Features
java Features
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Java-java virtual machine
Java-java virtual machineJava-java virtual machine
Java-java virtual machine
 
Data types in java
Data types in javaData types in java
Data types in java
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Java exception
Java exception Java exception
Java exception
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Method overriding
Method overridingMethod overriding
Method overriding
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Constants, Variables and Data Types in Java
Constants, Variables and Data Types in JavaConstants, Variables and Data Types in Java
Constants, Variables and Data Types in Java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Object and class
Object and classObject and class
Object and class
 
Java operators
Java operatorsJava operators
Java operators
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
 

Similar to Java variable types

Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
Rakesh Madugula
 
demo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptdemo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.ppt
FerdieBalang
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
Sunil Kumar Gunasekaran
 

Similar to Java variable types (20)

class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
Explain Classes and methods in java (ch04).ppt
Explain Classes and methods in java (ch04).pptExplain Classes and methods in java (ch04).ppt
Explain Classes and methods in java (ch04).ppt
 
javaClasses.pptx
javaClasses.pptxjavaClasses.pptx
javaClasses.pptx
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritance
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
Lec4
Lec4Lec4
Lec4
 
unit 2 java.pptx
unit 2 java.pptxunit 2 java.pptx
unit 2 java.pptx
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
demo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptdemo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.ppt
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
Core java
Core javaCore java
Core java
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Java session4
Java session4Java session4
Java session4
 
03 classes interfaces_principlesofoop
03 classes interfaces_principlesofoop03 classes interfaces_principlesofoop
03 classes interfaces_principlesofoop
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritance
 
Best Core Java Training In Bangalore
Best Core Java Training In BangaloreBest Core Java Training In Bangalore
Best Core Java Training In Bangalore
 

More from Soba Arjun

More from Soba Arjun (20)

Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Java modifiers
Java modifiersJava modifiers
Java modifiers
 
Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypes
 
Dbms interview questions
Dbms interview questionsDbms interview questions
Dbms interview questions
 
C interview questions
C interview questionsC interview questions
C interview questions
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questions
 
Php interview questions with answer
Php interview questions with answerPhp interview questions with answer
Php interview questions with answer
 
Computer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary MemoryComputer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary Memory
 
Birds sanctuaries
Birds sanctuariesBirds sanctuaries
Birds sanctuaries
 
Important operating systems
Important operating systemsImportant operating systems
Important operating systems
 
Important branches of science
Important branches of scienceImportant branches of science
Important branches of science
 
Important file extensions
Important file extensionsImportant file extensions
Important file extensions
 
Java Abstraction
Java AbstractionJava Abstraction
Java Abstraction
 
Java Polymorphism
Java PolymorphismJava Polymorphism
Java Polymorphism
 
Java Overriding
Java OverridingJava Overriding
Java Overriding
 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
 
java Exception
java Exceptionjava Exception
java Exception
 
Java Methods
Java MethodsJava Methods
Java Methods
 
java Inheritance
java Inheritancejava Inheritance
java Inheritance
 
Major tribes of india
Major tribes of indiaMajor tribes of india
Major tribes of india
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

Java variable types

  • 1.
  • 2. Variable Types • Each variable in Java has a specific type, which determines the size and layout of the variable's memory. • the range of values that can be stored within that memory. • Variable Declaration: datatype variable = value ; datatype variable = value , variable = value,…;
  • 3. Variable Types • Example int a, b, c; // Declares three int’s, a, b, and c. int a = 10, b = 10; // Example of initialization byte B = 22; // initializes a byte type variable B. double pi = 3.14159; // declares and assigns a value of PI. char a = 'a'; // the char variable a is initialized with value 'a'
  • 4. Variable Types • Variable Types • Local Variable • Instance Variable • Class / Static Variable
  • 5. Variable Type – Local Variable • It declared inside of methods, constructors, or blocks. • Access modifier cannot be used for local variable. • Local variables are visible only within the methods. • Variable can be accessed when the method is called. Class { method { declare variable } }
  • 6. Variable Type – Local Variable public class Dog { public void dogAge() { int age = 0; age = age + 7; System.out.println(“Dog age is : “ + age); } public static void main(String args[]) { Dog dog = new Dog(); dog.pupAge(); } }
  • 7. Variable Type – Instance Variable • It declare inside of a class but outside of methods. • This variable can be access by any methods. • By creating object for a class, we can access this variable from main methods. Class { declare variable method { //can use var } }
  • 8. Variable Type – Instance Variable public class Dog { int age; public void Dog(int i) { age = i; } public void display() { System.out.println(“Dog age is : “ + age); } public static void main(String args[]) { Dog dog = new Dog(30); dog.display(); } }
  • 9. Variable Type – Class / Static Variable • Variable declared inside of class but outside of methods with static keyword. • Static variables are stored in the static memory. • Static variables can be accessed by static methods or constructors. Class { declare static variable constructor { //can use var } static method { //can use var } }
  • 10. Variable Type – Class / Static Variable public class Dog { static int age; public void Dog(int i) { age = i; System.out.println(age); //30 } public static void main(String args[]) { Dog dog = new Dog(30); dog.display(); age= 40; System.out.println(age); //40 } }