SlideShare uma empresa Scribd logo
1 de 18
Computer
Programming 2
Lesson 5 – JAVA DATATYPES
Prepared by: Analyn G. Regaton
DATATYPES
Variables are nothing but reserved memory
locations to store values. This means that
when you create a variable you reserve some
space in the memory.
Based on the data type of a variable, the
operating system allocates memory and
decides what can be stored in the reserved
memory. Therefore, by assigning different
data types to variables, you can store
integers, decimals, or characters in these
variables.
TWO DATA
TYPES
 Primitive Data Types
 Reference/Object Data Types
PRIMITIVE
DATATYPES
Primitive datatypes are predefined
by the language and named by a
keyword. Let us now look into the
eight primitive data types in detail.
EIGHT
PRIMITIVE
DATATYPES
 Byte
 Short
 Int
 Long
 Float
 Double
 Boolean
 Char
BYTE
 Byte data type is an 8-bit signed two's complement
integer
 Minimum value is -128 (-2^7)
 Maximum value is 127 (inclusive)(2^7 -1)
 Default value is 0
 Byte data type is used to save space in large arrays,
mainly in place of integers, since a byte is four times
smaller than an integer.
 Example: byte a = 100, byte b = -50
SHORT
 Short data type is a 16-bit signed two's
complement integer
 Minimum value is -32,768 (-2^15)
 Maximum value is 32,767 (inclusive) (2^15
-1)
 Short data type can also be used to save
memory as byte data type. A short is 2
times smaller than an integer
 Default value is 0.
 Example: short s = 10000, short r = -20000
INT
 Int data type is a 32-bit signed two's complement
integer.
 Minimum value is - 2,147,483,648 (-2^31)
 Maximum value is 2,147,483,647(inclusive) (2^31 -1)
 Integer 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
LONG
 Long data type is a 64-bit signed two's
complement integer
 Minimum value is -
9,223,372,036,854,775,808(-2^63)
 Maximum value is 9,223,372,036,854,775,807
(inclusive)(2^63 -1)
 This type is used when a wider range than int
is needed
 Default value is 0L
 Example: long a = 100000L, long b = -200000L
FLOAT
 Float data type is 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
 Float data type is never used for precise values
such as currency
 Example: float f1 = 234.5f
DOUBLE
 double data type is a double-precision 64-bit
IEEE 754 floating point
 This data type is generally used as the default
data type for decimal values, generally the
default choice
 Double data type should never be used for
precise values such as currency
 Default value is 0.0d
 Example: double d1 = 123.4
BOOLEAN
 boolean data type 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
CHAR
 char data type is 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
DATATYPES
 Reference variables are created using defined
constructors of the classes. They are used to access
objects. These variables are declared to be of a
specific type that cannot be changed. For example,
Employee, Puppy, etc.
 Class objects and various type of array variables come
under reference datatype.
 Default value of any reference variable is null.
 A reference variable can be used to refer any object of
the declared type or any compatible type.
 Example: Animal animal = new Animal("giraffe");
JAVA
LATERALS
 A literal is a source code representation of a fixed value.
They are represented directly in the code without any
computation.
 Literals can be assigned to any primitive type variable. For
example −
 byte, int, long, and short can be expressed in decimal(base
10), hexadecimal(base 16) or octal(base 8) number systems
as well.
JAVA
LATERALS
 Prefix 0 is used to indicate octal, and prefix 0x indicates
hexadecimal when using these number systems for literals. For
example −
 String literals in Java are specified like they are in most other
languages by enclosing a sequence of characters between a pair of
double quotes. Examples of string literals are –
 String and char types of literals can contain any Unicode
characters. For example −
ESCAPE
SEQUENCE
Computer programming 2  Lesson 5

Mais conteúdo relacionado

Mais procurados (20)

Arrays in c_language
Arrays in c_language Arrays in c_language
Arrays in c_language
 
Lect5
Lect5Lect5
Lect5
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Python - variable types
Python - variable typesPython - variable types
Python - variable types
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Data types in python lecture (2)
Data types in python lecture (2)Data types in python lecture (2)
Data types in python lecture (2)
 
Data types in c++
Data types in c++Data types 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
 
Data types
Data typesData types
Data types
 
Data types
Data typesData types
Data types
 
Java session3
Java session3Java session3
Java session3
 
Data type
Data typeData type
Data type
 
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++
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-c
 
Data types
Data typesData types
Data types
 

Semelhante a Computer programming 2 Lesson 5

Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6REHAN IJAZ
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsatifmugheesv
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in pythonsunilchute1
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersTanishq Soni
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGEPRASANYA K
 
009 Data Handling .pptx
009 Data Handling .pptx009 Data Handling .pptx
009 Data Handling .pptxssuser6c66f3
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming NeedsRaja Sekhar
 
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.pptpubgnewstate1620
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfYRABHI
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netJaya Kumari
 

Semelhante a Computer programming 2 Lesson 5 (20)

Java - Basic Datatypes.pptx
Java - Basic Datatypes.pptxJava - Basic Datatypes.pptx
Java - Basic Datatypes.pptx
 
5. variables & data types
5. variables & data types5. variables & data types
5. variables & data types
 
Data Handling
Data HandlingData Handling
Data Handling
 
Data types ,variables,array
Data types ,variables,arrayData types ,variables,array
Data types ,variables,array
 
Data types
Data typesData types
Data types
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type results
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiers
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
 
009 Data Handling .pptx
009 Data Handling .pptx009 Data Handling .pptx
009 Data Handling .pptx
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
Python slide.1
Python slide.1Python slide.1
Python slide.1
 
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
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
 
Chapter - 2.pptx
Chapter - 2.pptxChapter - 2.pptx
Chapter - 2.pptx
 
Data types in C
Data types in CData types in C
Data types in C
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
 
Datatypes
DatatypesDatatypes
Datatypes
 

Mais de MLG College of Learning, Inc (20)

PC111.Lesson2
PC111.Lesson2PC111.Lesson2
PC111.Lesson2
 
PC111.Lesson1
PC111.Lesson1PC111.Lesson1
PC111.Lesson1
 
PC111-lesson1.pptx
PC111-lesson1.pptxPC111-lesson1.pptx
PC111-lesson1.pptx
 
PC LEESOON 6.pptx
PC LEESOON 6.pptxPC LEESOON 6.pptx
PC LEESOON 6.pptx
 
PC 106 PPT-09.pptx
PC 106 PPT-09.pptxPC 106 PPT-09.pptx
PC 106 PPT-09.pptx
 
PC 106 PPT-07
PC 106 PPT-07PC 106 PPT-07
PC 106 PPT-07
 
PC 106 PPT-01
PC 106 PPT-01PC 106 PPT-01
PC 106 PPT-01
 
PC 106 PPT-06
PC 106 PPT-06PC 106 PPT-06
PC 106 PPT-06
 
PC 106 PPT-05
PC 106 PPT-05PC 106 PPT-05
PC 106 PPT-05
 
PC 106 Slide 04
PC 106 Slide 04PC 106 Slide 04
PC 106 Slide 04
 
PC 106 Slide no.02
PC 106 Slide no.02PC 106 Slide no.02
PC 106 Slide no.02
 
pc-106-slide-3
pc-106-slide-3pc-106-slide-3
pc-106-slide-3
 
PC 106 Slide 2
PC 106 Slide 2PC 106 Slide 2
PC 106 Slide 2
 
PC 106 Slide 1.pptx
PC 106 Slide 1.pptxPC 106 Slide 1.pptx
PC 106 Slide 1.pptx
 
Db2 characteristics of db ms
Db2 characteristics of db msDb2 characteristics of db ms
Db2 characteristics of db ms
 
Db1 introduction
Db1 introductionDb1 introduction
Db1 introduction
 
Lesson 3.2
Lesson 3.2Lesson 3.2
Lesson 3.2
 
Lesson 3.1
Lesson 3.1Lesson 3.1
Lesson 3.1
 
Lesson 1.6
Lesson 1.6Lesson 1.6
Lesson 1.6
 
Lesson 3.2
Lesson 3.2Lesson 3.2
Lesson 3.2
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
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
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
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
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
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
 
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
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 

Último (20)

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
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Ữ Â...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
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...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
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
 
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
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 

Computer programming 2 Lesson 5

  • 1. Computer Programming 2 Lesson 5 – JAVA DATATYPES Prepared by: Analyn G. Regaton
  • 2. DATATYPES Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables.
  • 3. TWO DATA TYPES  Primitive Data Types  Reference/Object Data Types
  • 4. PRIMITIVE DATATYPES Primitive datatypes are predefined by the language and named by a keyword. Let us now look into the eight primitive data types in detail.
  • 5. EIGHT PRIMITIVE DATATYPES  Byte  Short  Int  Long  Float  Double  Boolean  Char
  • 6. BYTE  Byte data type is an 8-bit signed two's complement integer  Minimum value is -128 (-2^7)  Maximum value is 127 (inclusive)(2^7 -1)  Default value is 0  Byte data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an integer.  Example: byte a = 100, byte b = -50
  • 7. SHORT  Short data type is a 16-bit signed two's complement integer  Minimum value is -32,768 (-2^15)  Maximum value is 32,767 (inclusive) (2^15 -1)  Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an integer  Default value is 0.  Example: short s = 10000, short r = -20000
  • 8. INT  Int data type is a 32-bit signed two's complement integer.  Minimum value is - 2,147,483,648 (-2^31)  Maximum value is 2,147,483,647(inclusive) (2^31 -1)  Integer 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. LONG  Long data type is a 64-bit signed two's complement integer  Minimum value is - 9,223,372,036,854,775,808(-2^63)  Maximum value is 9,223,372,036,854,775,807 (inclusive)(2^63 -1)  This type is used when a wider range than int is needed  Default value is 0L  Example: long a = 100000L, long b = -200000L
  • 10. FLOAT  Float data type is 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  Float data type is never used for precise values such as currency  Example: float f1 = 234.5f
  • 11. DOUBLE  double data type is a double-precision 64-bit IEEE 754 floating point  This data type is generally used as the default data type for decimal values, generally the default choice  Double data type should never be used for precise values such as currency  Default value is 0.0d  Example: double d1 = 123.4
  • 12. BOOLEAN  boolean data type 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. CHAR  char data type is 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 DATATYPES  Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed. For example, Employee, Puppy, etc.  Class objects and various type of array variables come under reference datatype.  Default value of any reference variable is null.  A reference variable can be used to refer any object of the declared type or any compatible type.  Example: Animal animal = new Animal("giraffe");
  • 15. JAVA LATERALS  A literal is a source code representation of a fixed value. They are represented directly in the code without any computation.  Literals can be assigned to any primitive type variable. For example −  byte, int, long, and short can be expressed in decimal(base 10), hexadecimal(base 16) or octal(base 8) number systems as well.
  • 16. JAVA LATERALS  Prefix 0 is used to indicate octal, and prefix 0x indicates hexadecimal when using these number systems for literals. For example −  String literals in Java are specified like they are in most other languages by enclosing a sequence of characters between a pair of double quotes. Examples of string literals are –  String and char types of literals can contain any Unicode characters. For example −