SlideShare a Scribd company logo
Variables & Data Types
Dr. M H B Ariyaratne
https://goo.gl/ytyvLS
Variables
● Reserved memory locations to store values
● When we create a variable we reserve some space in
memory.
● Based on the datatype of a variable, the operating
system allocates memory and decides what can be
stored in the reserved memory.
● By assigning different data types to variables, we can
store integers, decimals, or characters in these variables
Types of Variables
Primitive Data Types
Reference/Object Data Types
Primitive Data Types
Predefined by the language
Named by a keyword
Java - eight primitive data types
Naming variables in JAVA
● Variable names are case-sensitive
● An unlimited-length sequence of Unicode letters and digits
● Beginning with a letter, the dollar sign "$", or the underscore character "_"
● White space is not permitted
● Subsequent characters may be letters, digits, dollar signs, or underscore
characters.
● Use full words instead of cryptic abbreviations.
● Must not be a keyword or reserved word.
● If only one word, spell that word in all lowercase letters
● If more than one word, capitalize the first letter of each subsequent word.
● If your variable stores a constant value capitalizing every letter and
Primitive Data Types - byte
● Byte data type is an 8-bit signed two's complement
integer
● Minimum value is -128 (-27)
● Maximum value is 127 (inclusive)(27 -1)
● Default value is 0
● Byte data type is used to save space in large arrays,
mainly in place of integers
● Example: byte a = 100 , byte b = -50
Primitive Data Types - short
● 16-bit signed two's complement integer.
● Minimum value is -32,768 (-215)
● Maximum value is 32,767 (inclusive) (215 -1)
● Short data type can also be used to save memory as byte
data type. A short is 2 times smaller than an int
● Default value is 0.
● Example: short s = 10000, short r = -20000
Primitive Data Type - int
● A 32-bit signed two's complement integer.
● Minimum value is - 2,147,483,648.(-231)
● Maximum value is 2,147,483,647(inclusive).(231 -1)
● int is generally used as the default data type for integral
values unless there is a concern about memory
● The default value is 0.
● Example: int a = 100000, int b = -200000
Primitive Data Type - long
● A 64-bit signed two's complement integer.
● Minimum value is -9,223,372,036,854,775,808.(-263)
● Maximum value is 9,223,372,036,854,775,807 (inclusive).
(263 -1)
● This type is used when a wider range than int is needed.
● Default value is 0L.
● Example: long a = 100000L, int b = -200000L
Primitive Data Types - float
● A single-precision 32-bit IEEE 754 floating point.
● Float is mainly used to save memory in large arrays of
floating point numbers.
● Default value is 0.0f.
● Example: float f1 = 234.5f
Primitive Data Types - double
● A double-precision 64-bit IEEE 754 floating point.
● Generally used as the default data type for decimal
values
● Default value is 0.0d.
● Example: double d1 = 123.4
Primitive Data Types - boolean
● Represents one bit of information.
● There are only two possible values: true and false.
● This data type is used for simple flags that track
true/false conditions.
● Default value is false.
● Example: boolean one = true
Primitive Data Types - char
● A single 16-bit Unicode character.
● Minimum value is 'u0000' (or 0).
● Maximum value is 'uffff' (or 65,535 inclusive).
● Char data type is used to store any character.
● Example: char letterA ='A'
Reference Data Types
We will discuss them under as a separate presentation on Objects and Strings.
Thank you

More Related Content

What's hot

Lect5
Lect5Lect5
Data types in C
Data types in CData types in C
Data types in C
Satveer Mann
 
Primitive data types
Primitive data typesPrimitive data types
Primitive data types
Student
 
Data type
Data typeData type
Data type
Frijo Francis
 
Datatypes in c
Datatypes in cDatatypes in c
Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
k v
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
arnold 7490
 
Data types in Java
Data types in JavaData types in Java
Data types in Java
Play Store
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
Neeru Mittal
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
Lect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer AbbasLect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer Abbas
Information Technology Center
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Smit Shah
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
REHAN IJAZ
 
04 data types & variables
04   data types & variables04   data types & variables
04 data types & variables
dhrubo kayal
 
Data types
Data typesData types
Data types
Syed Umair
 
Structure in c
Structure in cStructure in c
Structure in c
Prabhu Govind
 
Data types
Data typesData types
Data types
Nokesh Prabhakar
 
HPEC 2021 sparse binary format
HPEC 2021 sparse binary formatHPEC 2021 sparse binary format
HPEC 2021 sparse binary format
ErikWelch2
 
Welcome to our_presentation in c
Welcome to our_presentation in cWelcome to our_presentation in c
Welcome to our_presentation in c
imran hasan
 
XPath XQuery Training by Wishtree in India Pune Bangalore Bengaluru Gurgaon ...
XPath  XQuery Training by Wishtree in India Pune Bangalore Bengaluru Gurgaon ...XPath  XQuery Training by Wishtree in India Pune Bangalore Bengaluru Gurgaon ...
XPath XQuery Training by Wishtree in India Pune Bangalore Bengaluru Gurgaon ...
Wishtree Technologies
 

What's hot (20)

Lect5
Lect5Lect5
Lect5
 
Data types in C
Data types in CData types in C
Data types in C
 
Primitive data types
Primitive data typesPrimitive data types
Primitive data types
 
Data type
Data typeData type
Data type
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
Data types in Java
Data types in JavaData types in Java
Data types in Java
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Lect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer AbbasLect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer Abbas
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
 
04 data types & variables
04   data types & variables04   data types & variables
04 data types & variables
 
Data types
Data typesData types
Data types
 
Structure in c
Structure in cStructure in c
Structure in c
 
Data types
Data typesData types
Data types
 
HPEC 2021 sparse binary format
HPEC 2021 sparse binary formatHPEC 2021 sparse binary format
HPEC 2021 sparse binary format
 
Welcome to our_presentation in c
Welcome to our_presentation in cWelcome to our_presentation in c
Welcome to our_presentation in c
 
XPath XQuery Training by Wishtree in India Pune Bangalore Bengaluru Gurgaon ...
XPath  XQuery Training by Wishtree in India Pune Bangalore Bengaluru Gurgaon ...XPath  XQuery Training by Wishtree in India Pune Bangalore Bengaluru Gurgaon ...
XPath XQuery Training by Wishtree in India Pune Bangalore Bengaluru Gurgaon ...
 

Similar to 5. variables & data types

java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
jyoti_lakhani
 
Variable
VariableVariable
Data types
Data typesData types
Data types
nehajhala4
 
Java - Basic Datatypes.pptx
Java - Basic Datatypes.pptxJava - Basic Datatypes.pptx
Java - Basic Datatypes.pptx
Nagaraju Pamarthi
 
Data types
Data typesData types
Data types
Dr. Rupinder Singh
 
Unit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.pptUnit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.ppt
pubgnewstate1620
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
StephenOczon1
 
Java Tutorial Lab 2
Java Tutorial Lab 2Java Tutorial Lab 2
Java Tutorial Lab 2
Berk Soysal
 
Python Essentials - PICT.pdf
Python Essentials - PICT.pdfPython Essentials - PICT.pdf
Python Essentials - PICT.pdf
Prashant Jamkhande
 
Data Types and variables in C++.pptx
Data Types and variables in C++.pptxData Types and variables in C++.pptx
Data Types and variables in C++.pptx
jamilmalik19
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
nikshaikh786
 
C language basics
C language basicsC language basics
C language basics
Nikshithas R
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
Jayfee Ramos
 
Data types ,variables,array
Data types ,variables,arrayData types ,variables,array
Data types ,variables,array
Gujarat Technological University
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART I
Hari Christian
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
lemonchoos
 
introduction to python
 introduction to python introduction to python
introduction to python
Jincy Nelson
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
Samiksha Pun
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
Pratik Devmurari
 
2._Java_Syntax_and_Data_Type.pptx.pdf
2._Java_Syntax_and_Data_Type.pptx.pdf2._Java_Syntax_and_Data_Type.pptx.pdf
2._Java_Syntax_and_Data_Type.pptx.pdf
luxasuhi
 

Similar to 5. variables & data types (20)

java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
 
Variable
VariableVariable
Variable
 
Data types
Data typesData types
Data types
 
Java - Basic Datatypes.pptx
Java - Basic Datatypes.pptxJava - Basic Datatypes.pptx
Java - Basic Datatypes.pptx
 
Data types
Data typesData types
Data types
 
Unit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.pptUnit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.ppt
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
 
Java Tutorial Lab 2
Java Tutorial Lab 2Java Tutorial Lab 2
Java Tutorial Lab 2
 
Python Essentials - PICT.pdf
Python Essentials - PICT.pdfPython Essentials - PICT.pdf
Python Essentials - PICT.pdf
 
Data Types and variables in C++.pptx
Data Types and variables in C++.pptxData Types and variables in C++.pptx
Data Types and variables in C++.pptx
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
C language basics
C language basicsC language basics
C language basics
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Data types ,variables,array
Data types ,variables,arrayData types ,variables,array
Data types ,variables,array
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART I
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
 
introduction to python
 introduction to python introduction to python
introduction to python
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
 
2._Java_Syntax_and_Data_Type.pptx.pdf
2._Java_Syntax_and_Data_Type.pptx.pdf2._Java_Syntax_and_Data_Type.pptx.pdf
2._Java_Syntax_and_Data_Type.pptx.pdf
 

More from M H Buddhika Ariyaratne

14. collections
14. collections14. collections
14. collections
M H Buddhika Ariyaratne
 
13. interfaces
13. interfaces13. interfaces
13. interfaces
M H Buddhika Ariyaratne
 
12. arrays
12. arrays12. arrays
11. java methods
11. java methods11. java methods
11. java methods
M H Buddhika Ariyaratne
 
10. inheritance
10. inheritance10. inheritance
10. inheritance
M H Buddhika Ariyaratne
 
9. strings
9. strings9. strings
8. objects & classes
8. objects & classes8. objects & classes
8. objects & classes
M H Buddhika Ariyaratne
 
7. flowcharts and pseudocode
7. flowcharts and pseudocode7. flowcharts and pseudocode
7. flowcharts and pseudocode
M H Buddhika Ariyaratne
 
6. java operators
6. java operators6. java operators
6. java operators
M H Buddhika Ariyaratne
 
4. mathematics for computing
4. mathematics for computing4. mathematics for computing
4. mathematics for computing
M H Buddhika Ariyaratne
 
3. introduction to java
3. introduction to java3. introduction to java
3. introduction to java
M H Buddhika Ariyaratne
 
2. data structures & algorithms
2. data structures & algorithms2. data structures & algorithms
2. data structures & algorithms
M H Buddhika Ariyaratne
 
1. introduction mathematics for computing and object oriented programming
1. introduction   mathematics for computing  and  object oriented programming1. introduction   mathematics for computing  and  object oriented programming
1. introduction mathematics for computing and object oriented programming
M H Buddhika Ariyaratne
 
Gis for healthcare introduction
Gis for healthcare   introductionGis for healthcare   introduction
Gis for healthcare introduction
M H Buddhika Ariyaratne
 
Open hospital management information system
Open hospital management information systemOpen hospital management information system
Open hospital management information system
M H Buddhika Ariyaratne
 
Who am i and what i have done
Who am i and what i have doneWho am i and what i have done
Who am i and what i have done
M H Buddhika Ariyaratne
 
Electronic health record system for sri lankan general practitioners
Electronic health record system for sri lankan general practitionersElectronic health record system for sri lankan general practitioners
Electronic health record system for sri lankan general practitioners
M H Buddhika Ariyaratne
 

More from M H Buddhika Ariyaratne (17)

14. collections
14. collections14. collections
14. collections
 
13. interfaces
13. interfaces13. interfaces
13. interfaces
 
12. arrays
12. arrays12. arrays
12. arrays
 
11. java methods
11. java methods11. java methods
11. java methods
 
10. inheritance
10. inheritance10. inheritance
10. inheritance
 
9. strings
9. strings9. strings
9. strings
 
8. objects & classes
8. objects & classes8. objects & classes
8. objects & classes
 
7. flowcharts and pseudocode
7. flowcharts and pseudocode7. flowcharts and pseudocode
7. flowcharts and pseudocode
 
6. java operators
6. java operators6. java operators
6. java operators
 
4. mathematics for computing
4. mathematics for computing4. mathematics for computing
4. mathematics for computing
 
3. introduction to java
3. introduction to java3. introduction to java
3. introduction to java
 
2. data structures & algorithms
2. data structures & algorithms2. data structures & algorithms
2. data structures & algorithms
 
1. introduction mathematics for computing and object oriented programming
1. introduction   mathematics for computing  and  object oriented programming1. introduction   mathematics for computing  and  object oriented programming
1. introduction mathematics for computing and object oriented programming
 
Gis for healthcare introduction
Gis for healthcare   introductionGis for healthcare   introduction
Gis for healthcare introduction
 
Open hospital management information system
Open hospital management information systemOpen hospital management information system
Open hospital management information system
 
Who am i and what i have done
Who am i and what i have doneWho am i and what i have done
Who am i and what i have done
 
Electronic health record system for sri lankan general practitioners
Electronic health record system for sri lankan general practitionersElectronic health record system for sri lankan general practitioners
Electronic health record system for sri lankan general practitioners
 

Recently uploaded

Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 

Recently uploaded (20)

Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 

5. variables & data types

  • 1. Variables & Data Types Dr. M H B Ariyaratne https://goo.gl/ytyvLS
  • 2. Variables ● Reserved memory locations to store values ● When we create a variable we reserve some space in memory. ● Based on the datatype of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. ● By assigning different data types to variables, we can store integers, decimals, or characters in these variables
  • 3. Types of Variables Primitive Data Types Reference/Object Data Types
  • 4. Primitive Data Types Predefined by the language Named by a keyword Java - eight primitive data types
  • 5. Naming variables in JAVA ● Variable names are case-sensitive ● An unlimited-length sequence of Unicode letters and digits ● Beginning with a letter, the dollar sign "$", or the underscore character "_" ● White space is not permitted ● Subsequent characters may be letters, digits, dollar signs, or underscore characters. ● Use full words instead of cryptic abbreviations. ● Must not be a keyword or reserved word. ● If only one word, spell that word in all lowercase letters ● If more than one word, capitalize the first letter of each subsequent word. ● If your variable stores a constant value capitalizing every letter and
  • 6. Primitive Data Types - byte ● Byte data type is an 8-bit signed two's complement integer ● Minimum value is -128 (-27) ● Maximum value is 127 (inclusive)(27 -1) ● Default value is 0 ● Byte data type is used to save space in large arrays, mainly in place of integers ● Example: byte a = 100 , byte b = -50
  • 7. Primitive Data Types - short ● 16-bit signed two's complement integer. ● Minimum value is -32,768 (-215) ● Maximum value is 32,767 (inclusive) (215 -1) ● Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an int ● Default value is 0. ● Example: short s = 10000, short r = -20000
  • 8. Primitive Data Type - int ● A 32-bit signed two's complement integer. ● Minimum value is - 2,147,483,648.(-231) ● Maximum value is 2,147,483,647(inclusive).(231 -1) ● int is generally used as the default data type for integral values unless there is a concern about memory ● The default value is 0. ● Example: int a = 100000, int b = -200000
  • 9. Primitive Data Type - long ● A 64-bit signed two's complement integer. ● Minimum value is -9,223,372,036,854,775,808.(-263) ● Maximum value is 9,223,372,036,854,775,807 (inclusive). (263 -1) ● This type is used when a wider range than int is needed. ● Default value is 0L. ● Example: long a = 100000L, int b = -200000L
  • 10. Primitive Data Types - float ● A single-precision 32-bit IEEE 754 floating point. ● Float is mainly used to save memory in large arrays of floating point numbers. ● Default value is 0.0f. ● Example: float f1 = 234.5f
  • 11. Primitive Data Types - double ● A double-precision 64-bit IEEE 754 floating point. ● Generally used as the default data type for decimal values ● Default value is 0.0d. ● Example: double d1 = 123.4
  • 12. Primitive Data Types - boolean ● Represents one bit of information. ● There are only two possible values: true and false. ● This data type is used for simple flags that track true/false conditions. ● Default value is false. ● Example: boolean one = true
  • 13. Primitive Data Types - char ● A single 16-bit Unicode character. ● Minimum value is 'u0000' (or 0). ● Maximum value is 'uffff' (or 65,535 inclusive). ● Char data type is used to store any character. ● Example: char letterA ='A'
  • 14. Reference Data Types We will discuss them under as a separate presentation on Objects and Strings.