SlideShare a Scribd company logo
1 of 13
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…

More Related Content

What's hot

Java variable types
Java variable typesJava variable types
Java variable typesSoba Arjun
 
Constructors in java
Constructors in javaConstructors in java
Constructors in javachauhankapil
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Sandeep Rawat
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#Adeel Rasheed
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Conceptsthinkphp
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVAAnkita Totala
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
Strings in Java
Strings in Java Strings in Java
Strings in Java Hitesh-Java
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaRahul Jain
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Java. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsJava. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsМарія Русин
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in javaNilesh Dalvi
 
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...Edureka!
 

What's hot (20)

Java variable types
Java variable typesJava variable types
Java variable types
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
 
C# Constructors
C# ConstructorsC# Constructors
C# Constructors
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
JAVA FEATURES
JAVA FEATURESJAVA FEATURES
JAVA FEATURES
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Constructors
ConstructorsConstructors
Constructors
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Java. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsJava. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax Applications
 
Core Java
Core JavaCore Java
Core Java
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
 
Java features
Java  features Java  features
Java features
 

Viewers also liked

Types of variables in statistics
Types of variables in statisticsTypes of variables in statistics
Types of variables in statisticsZakaria Hossain
 
Introduction to Limited Dependent variable
Introduction to Limited Dependent variableIntroduction to Limited Dependent variable
Introduction to Limited Dependent variableAshok Dsouza
 
Daily Reports "PPL IAIN Salatiga" 2017
Daily Reports "PPL IAIN Salatiga" 2017Daily Reports "PPL IAIN Salatiga" 2017
Daily Reports "PPL IAIN Salatiga" 2017ND 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 Scalesguesta861fa
 
Research hypothesis....ppt
Research hypothesis....pptResearch hypothesis....ppt
Research hypothesis....pptRahul Dhaker
 
research-methodology-ppt
 research-methodology-ppt research-methodology-ppt
research-methodology-pptsheetal321
 
Variables
 Variables Variables
Variablesshoffma5
 
Types of Variables
Types of VariablesTypes of Variables
Types of VariablesAli Mustafa
 
Research Methodology
Research MethodologyResearch Methodology
Research Methodologysh_neha252
 

Viewers also liked (16)

Variable
VariableVariable
Variable
 
Types of variables in statistics
Types of variables in statisticsTypes of variables in statistics
Types of variables in statistics
 
Introduction to Limited Dependent variable
Introduction to Limited Dependent variableIntroduction to Limited Dependent variable
Introduction to Limited Dependent variable
 
6 java - loop
6  java - loop6  java - loop
6 java - loop
 
Daily Reports "PPL IAIN Salatiga" 2017
Daily Reports "PPL IAIN Salatiga" 2017Daily Reports "PPL IAIN Salatiga" 2017
Daily Reports "PPL IAIN Salatiga" 2017
 
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
 
Kinds Of Variable
Kinds Of VariableKinds Of Variable
Kinds Of Variable
 
Variables And Measurement Scales
Variables And Measurement ScalesVariables And Measurement Scales
Variables And Measurement Scales
 
Research hypothesis....ppt
Research hypothesis....pptResearch hypothesis....ppt
Research hypothesis....ppt
 
Basic variables ppt
Basic variables pptBasic variables ppt
Basic variables ppt
 
Research methodology
Research methodologyResearch methodology
Research methodology
 
research-methodology-ppt
 research-methodology-ppt research-methodology-ppt
research-methodology-ppt
 
Variables
 Variables Variables
Variables
 
Research methodology notes
Research methodology notesResearch methodology notes
Research methodology notes
 
Types of Variables
Types of VariablesTypes of Variables
Types of Variables
 
Research Methodology
Research MethodologyResearch Methodology
Research Methodology
 

Similar to 3 java - variable type

Chapter4-var.pdf
Chapter4-var.pdfChapter4-var.pdf
Chapter4-var.pdfkumari36
 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics PresentationOmid 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.pptxgomathikalai
 
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&j2eeShiva 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 3Sagar Verma
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal 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 CardHari kiran G
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)Khaled Anaqwa
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 eehomeworkping9
 

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
 
Chapter4-var.pdf
Chapter4-var.pdfChapter4-var.pdf
Chapter4-var.pdf
 
Java Variable Types
Java Variable TypesJava Variable Types
Java Variable Types
 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics Presentation
 
Class Members Access/Visibility Guide (Checklist)
Class Members Access/Visibility Guide (Checklist)Class Members Access/Visibility Guide (Checklist)
Class Members Access/Visibility Guide (Checklist)
 
Variables in java.pptx
Variables in java.pptxVariables in java.pptx
Variables in java.pptx
 
Abap Objects for BW
Abap Objects for BWAbap Objects for BW
Abap Objects for BW
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
 
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
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java
JavaJava
Java
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2ee
 
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
 
Java basics
Java basicsJava basics
Java basics
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
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
 
Java defining classes
Java defining classes Java defining classes
Java defining classes
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
 

More from vinay arora

Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawlervinay 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 diagramvinay 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 - decisionvinay arora
 
2 java - operators
2  java - operators2  java - operators
2 java - operatorsvinay arora
 
1 java - data type
1  java - data type1  java - data type
1 java - data typevinay arora
 
Security & Protection
Security & ProtectionSecurity & Protection
Security & Protectionvinay arora
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronizationvinay arora
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitivesvinay arora
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devicesvinay arora
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devicesvinay arora
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphicsvinay 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. - Structuresvinay arora
 

More from vinay arora (20)

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

Recently uploaded

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

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.