SlideShare a Scribd company logo
Java – Variable Type
Organized By: Vinay Arora
Assistant Professor
CSED, Thapar University
www.slideshare.net/aroravinay
Vinay Arora
CSED
Variable
 A variable provides us with named storage that our programs can
manipulate.
 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; and the set of operations that
can be applied to the variable.
Vinay Arora
CSED
Types of variable/s
 There are three kind of variables in Java:
 Local variables
 Instance variables
 Class/static variables
Vinay Arora
CSED
Local Variable
 Local variables are declared in methods, constructors, or blocks.
 Local variables are created when the method, constructor or block is
entered and the variable will be destroyed once it exits the method,
constructor or block.
 Access modifiers cannot be used for local variables.
 Local variables are visible only within the declared method, constructor or
block.
 Local variables are implemented at stack level internally.
 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.
Vinay Arora
CSED
Local Variable (Conti…)
Vinay Arora
CSED
Local Variable (Conti…)
Vinay Arora
CSED
Instance Variable/s
 Instance variables are declared in a class, but outside a method,
constructor or any block.
 When a space is allocated for an object in the heap, a slot for each
instance variable value is created.
 Instance variables are created when an object is created with the use of
the keyword 'new' and destroyed when the object is destroyed.
 Instance variables hold values that must be referenced by more than one
method, constructor or block, or essential parts of an object's state that
must be present throughout the class.
 Instance variables can be declared in class level before or after use.
 Access modifiers can be given for instance variables.
Vinay Arora
CSED
Instance Variable/s (Conti…)
 The instance variables are visible for all methods, constructors
and block in the class. Normally, it is recommended to make
these variables private (access level). However visibility for
subclasses can be given for these variables with the use of
access modifiers.
 Instance variables have default values. For numbers the default
value is 0, for Booleans it is false and for object references it is
null. Values can be assigned during the declaration or within the
constructor.
 Instance variables can be accessed directly by calling the
variable name inside the class. However within static methods
and different class ( when instance variables are given
accessibility) should be called using the fully qualified
name . ObjectReference.VariableName.
Vinay Arora
CSED
Instance Variable/s (Conti…)
Vinay Arora
CSED
Class/static variables
 Class variables (also known as static variables) are declared with
the static keyword in a class, but outside a method, constructor or a
block.
 There would only be one (copy of each) class variable per class,
regardless of how many objects are created from it.
 Static variables are rarely used other than being declared as constants.
Constants are variables that are declared as public/private, final and
static. Constant variables never change from their initial value.
 Static variables are stored in static memory. It is rare to use static
variables other than declared final and used as either public or private
constants.
 Static variables are created when the program starts, and destroyed
when the program stops.
Vinay Arora
CSED
Class/static variables (Conti…)
 Visibility is similar to instance variables. However, most static variables
are declared public since they must be available for users of the class.
 Default values are same as instance variables. For numbers, the default
value is 0; for Booleans, it is false; and for object references, it is null.
Values can be assigned during the declaration or within the constructor.
Additionally values can be assigned in special static initializer blocks.
 Static variables can be accessed by calling with the class
name . ClassName.VariableName.
 When declaring class variables as public static final, then variables
names (constants) are all in upper case. If the static variables are not
public and final the naming syntax is the same as instance and local
variables.
Vinay Arora
CSED
Class/static variables (Conti…)
Vinay Arora
CSED
Thnx…
Ad

More Related Content

What's hot (20)

Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
Kurapati Vishwak
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
Vinod Kumar
 
Inheritance
InheritanceInheritance
Inheritance
Sapna Sharma
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Java swing
Java swingJava swing
Java swing
Apurbo Datta
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Data types in java
Data types in javaData types in java
Data types in java
HarshitaAshwani
 
Java variable types
Java variable typesJava variable types
Java variable types
Soba Arjun
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
Spotle.ai
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptx
NITHISG1
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Java modules
Java modulesJava modules
Java modules
Rory Preddy
 
Java interface
Java interfaceJava interface
Java interface
BHUVIJAYAVELU
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
Abid Kohistani
 
I/O Streams
I/O StreamsI/O Streams
I/O Streams
Ravi Chythanya
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
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
Tushar B Kute
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
kamal kotecha
 
Super and final in java
Super and final in javaSuper and final in java
Super and final in java
anshu_atri
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
Kurapati Vishwak
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
Vinod Kumar
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Java variable types
Java variable typesJava variable types
Java variable types
Soba Arjun
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
Spotle.ai
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptx
NITHISG1
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
Abid Kohistani
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
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
Tushar B Kute
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
kamal kotecha
 
Super and final in java
Super and final in javaSuper and final in java
Super and final in java
anshu_atri
 

Viewers also liked (16)

Variable
VariableVariable
Variable
ND Arisanti
 
Types of variables in statistics
Types of variables in statisticsTypes of variables in statistics
Types of variables in statistics
Zakaria Hossain
 
Introduction to Limited Dependent variable
Introduction to Limited Dependent variableIntroduction to Limited Dependent variable
Introduction to Limited Dependent variable
Ashok Dsouza
 
6 java - loop
6  java - loop6  java - loop
6 java - loop
vinay arora
 
Daily Reports "PPL IAIN Salatiga" 2017
Daily Reports "PPL IAIN Salatiga" 2017Daily Reports "PPL IAIN Salatiga" 2017
Daily Reports "PPL IAIN Salatiga" 2017
ND Arisanti
 
Importance of null and alternate hypothesis in a scientific research study
Importance of null and alternate hypothesis in a scientific research study Importance of null and alternate hypothesis in a scientific research study
Importance of null and alternate hypothesis in a scientific research study
Charm Rammandala
 
Kinds Of Variable
Kinds Of VariableKinds Of Variable
Kinds Of Variable
Dr. Cupid Lucid
 
Variables And Measurement Scales
Variables And Measurement ScalesVariables And Measurement Scales
Variables And Measurement Scales
guesta861fa
 
Research hypothesis....ppt
Research hypothesis....pptResearch hypothesis....ppt
Research hypothesis....ppt
Rahul Dhaker
 
Basic variables ppt
Basic variables pptBasic variables ppt
Basic variables ppt
Shaker Middle School
 
Research methodology
Research methodologyResearch methodology
Research methodology
Rolling Plans Pvt. Ltd.
 
research-methodology-ppt
 research-methodology-ppt research-methodology-ppt
research-methodology-ppt
sheetal321
 
Variables
 Variables Variables
Variables
shoffma5
 
Research methodology notes
Research methodology notesResearch methodology notes
Research methodology notes
City Union Bank Ltd
 
Types of Variables
Types of VariablesTypes of Variables
Types of Variables
Ali Mustafa
 
Research Methodology
Research MethodologyResearch Methodology
Research Methodology
sh_neha252
 
Types of variables in statistics
Types of variables in statisticsTypes of variables in statistics
Types of variables in statistics
Zakaria Hossain
 
Introduction to Limited Dependent variable
Introduction to Limited Dependent variableIntroduction to Limited Dependent variable
Introduction to Limited Dependent variable
Ashok Dsouza
 
Daily Reports "PPL IAIN Salatiga" 2017
Daily Reports "PPL IAIN Salatiga" 2017Daily Reports "PPL IAIN Salatiga" 2017
Daily Reports "PPL IAIN Salatiga" 2017
ND Arisanti
 
Importance of null and alternate hypothesis in a scientific research study
Importance of null and alternate hypothesis in a scientific research study Importance of null and alternate hypothesis in a scientific research study
Importance of null and alternate hypothesis in a scientific research study
Charm Rammandala
 
Variables And Measurement Scales
Variables And Measurement ScalesVariables And Measurement Scales
Variables And Measurement Scales
guesta861fa
 
Research hypothesis....ppt
Research hypothesis....pptResearch hypothesis....ppt
Research hypothesis....ppt
Rahul Dhaker
 
research-methodology-ppt
 research-methodology-ppt research-methodology-ppt
research-methodology-ppt
sheetal321
 
Variables
 Variables Variables
Variables
shoffma5
 
Types of Variables
Types of VariablesTypes of Variables
Types of Variables
Ali Mustafa
 
Research Methodology
Research MethodologyResearch Methodology
Research Methodology
sh_neha252
 
Ad

Similar to 3 java - variable type (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
 
Chapter4-var.pdf
Chapter4-var.pdfChapter4-var.pdf
Chapter4-var.pdf
kumari36
 
Java Variable Types
Java Variable TypesJava Variable Types
Java Variable Types
Shahid Rasheed
 
Java-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.pptJava-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.ppt
JyothiAmpally
 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics Presentation
Omid Sohrabi
 
Class Members Access/Visibility Guide (Checklist)
Class Members Access/Visibility Guide (Checklist)Class Members Access/Visibility Guide (Checklist)
Class Members Access/Visibility Guide (Checklist)
Jayasree Perilakkalam
 
Variables in java.pptx
Variables in java.pptxVariables in java.pptx
Variables in java.pptx
gomathikalai
 
Abap Objects for BW
Abap Objects for BWAbap Objects for BW
Abap Objects for BW
Luc Vanrobays
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
Ahmad sohail Kakar
 
OCA Java SE 8 Exam Chapter 4 Methods Encapsulation
OCA Java SE 8 Exam Chapter 4 Methods EncapsulationOCA Java SE 8 Exam Chapter 4 Methods Encapsulation
OCA Java SE 8 Exam Chapter 4 Methods Encapsulation
İbrahim Kürce
 
Java Basics
Java BasicsJava Basics
Java Basics
Emprovise
 
Java
JavaJava
Java
Griffinder VinHai
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2ee
Shiva Cse
 
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
Sagar Verma
 
Java basics
Java basicsJava basics
Java basics
Shivanshu Purwar
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
Kuntal Bhowmick
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
 
Java defining classes
Java defining classes Java defining classes
Java defining classes
Mehdi Ali Soltani
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
Ahmed Shawky El-faky
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Chapter4-var.pdf
Chapter4-var.pdfChapter4-var.pdf
Chapter4-var.pdf
kumari36
 
Java-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.pptJava-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.ppt
JyothiAmpally
 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics Presentation
Omid Sohrabi
 
Class Members Access/Visibility Guide (Checklist)
Class Members Access/Visibility Guide (Checklist)Class Members Access/Visibility Guide (Checklist)
Class Members Access/Visibility Guide (Checklist)
Jayasree Perilakkalam
 
Variables in java.pptx
Variables in java.pptxVariables in java.pptx
Variables in java.pptx
gomathikalai
 
OCA Java SE 8 Exam Chapter 4 Methods Encapsulation
OCA Java SE 8 Exam Chapter 4 Methods EncapsulationOCA Java SE 8 Exam Chapter 4 Methods Encapsulation
OCA Java SE 8 Exam Chapter 4 Methods Encapsulation
İbrahim Kürce
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2ee
Shiva Cse
 
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
Sagar Verma
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
Kuntal Bhowmick
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Ad

More from vinay arora (20)

Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawler
vinay arora
 
Use case diagram (airport)
Use case diagram (airport)Use case diagram (airport)
Use case diagram (airport)
vinay arora
 
Use case diagram
Use case diagramUse case diagram
Use case diagram
vinay arora
 
Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)
vinay arora
 
SEM - UML (1st case study)
SEM - UML (1st case study)SEM - UML (1st case study)
SEM - UML (1st case study)
vinay arora
 
4 java - decision
4  java - decision4  java - decision
4 java - decision
vinay arora
 
2 java - operators
2  java - operators2  java - operators
2 java - operators
vinay arora
 
1 java - data type
1  java - data type1  java - data type
1 java - data type
vinay arora
 
Uta005 lecture3
Uta005 lecture3Uta005 lecture3
Uta005 lecture3
vinay arora
 
Uta005 lecture1
Uta005 lecture1Uta005 lecture1
Uta005 lecture1
vinay arora
 
Uta005 lecture2
Uta005 lecture2Uta005 lecture2
Uta005 lecture2
vinay arora
 
Security & Protection
Security & ProtectionSecurity & Protection
Security & Protection
vinay arora
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
vinay arora
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitives
vinay arora
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devices
vinay arora
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devices
vinay arora
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphics
vinay arora
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
vinay arora
 
A&D - UML
A&D - UMLA&D - UML
A&D - UML
vinay arora
 
Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawler
vinay arora
 
Use case diagram (airport)
Use case diagram (airport)Use case diagram (airport)
Use case diagram (airport)
vinay arora
 
Use case diagram
Use case diagramUse case diagram
Use case diagram
vinay arora
 
Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)
vinay arora
 
SEM - UML (1st case study)
SEM - UML (1st case study)SEM - UML (1st case study)
SEM - UML (1st case study)
vinay arora
 
4 java - decision
4  java - decision4  java - decision
4 java - decision
vinay arora
 
2 java - operators
2  java - operators2  java - operators
2 java - operators
vinay arora
 
1 java - data type
1  java - data type1  java - data type
1 java - data type
vinay arora
 
Security & Protection
Security & ProtectionSecurity & Protection
Security & Protection
vinay arora
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
vinay arora
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitives
vinay arora
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devices
vinay arora
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devices
vinay arora
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphics
vinay arora
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
vinay arora
 

Recently uploaded (20)

Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 

3 java - variable type

  • 1. Java – Variable Type Organized By: Vinay Arora Assistant Professor CSED, Thapar University www.slideshare.net/aroravinay
  • 2. Vinay Arora CSED Variable  A variable provides us with named storage that our programs can manipulate.  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; and the set of operations that can be applied to the variable.
  • 3. Vinay Arora CSED Types of variable/s  There are three kind of variables in Java:  Local variables  Instance variables  Class/static variables
  • 4. Vinay Arora CSED Local Variable  Local variables are declared in methods, constructors, or blocks.  Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor or block.  Access modifiers cannot be used for local variables.  Local variables are visible only within the declared method, constructor or block.  Local variables are implemented at stack level internally.  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.
  • 7. Vinay Arora CSED Instance Variable/s  Instance variables are declared in a class, but outside a method, constructor or any block.  When a space is allocated for an object in the heap, a slot for each instance variable value is created.  Instance variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed.  Instance variables hold values that must be referenced by more than one method, constructor or block, or essential parts of an object's state that must be present throughout the class.  Instance variables can be declared in class level before or after use.  Access modifiers can be given for instance variables.
  • 8. Vinay Arora CSED Instance Variable/s (Conti…)  The instance variables are visible for all methods, constructors and block in the class. Normally, it is recommended to make these variables private (access level). However visibility for subclasses can be given for these variables with the use of access modifiers.  Instance variables have default values. For numbers the default value is 0, for Booleans it is false and for object references it is null. Values can be assigned during the declaration or within the constructor.  Instance variables can be accessed directly by calling the variable name inside the class. However within static methods and different class ( when instance variables are given accessibility) should be called using the fully qualified name . ObjectReference.VariableName.
  • 10. Vinay Arora CSED Class/static variables  Class variables (also known as static variables) are declared with the static keyword in a class, but outside a method, constructor or a block.  There would only be one (copy of each) class variable per class, regardless of how many objects are created from it.  Static variables are rarely used other than being declared as constants. Constants are variables that are declared as public/private, final and static. Constant variables never change from their initial value.  Static variables are stored in static memory. It is rare to use static variables other than declared final and used as either public or private constants.  Static variables are created when the program starts, and destroyed when the program stops.
  • 11. Vinay Arora CSED Class/static variables (Conti…)  Visibility is similar to instance variables. However, most static variables are declared public since they must be available for users of the class.  Default values are same as instance variables. For numbers, the default value is 0; for Booleans, it is false; and for object references, it is null. Values can be assigned during the declaration or within the constructor. Additionally values can be assigned in special static initializer blocks.  Static variables can be accessed by calling with the class name . ClassName.VariableName.  When declaring class variables as public static final, then variables names (constants) are all in upper case. If the static variables are not public and final the naming syntax is the same as instance and local variables.
  翻译: