SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Arrays in c_language
Arrays in c_language Arrays in c_language
Arrays in c_language
Infinity Tech Solutions
 
Lect5
Lect5Lect5
Lect5
Jamsher bhanbhro
 
C++ data types
C++ data typesC++ data types
C++ data types
pratikborsadiya
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
Mohd Sajjad
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
CGC Technical campus,Mohali
 
Python - variable types
Python - variable typesPython - variable types
Python - variable types
Learnbay Datascience
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
Hridoy Bepari
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Data types in python lecture (2)
Data types in python lecture (2)Data types in python lecture (2)
Data types in python lecture (2)
Ali ٍSattar
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
Venkata.Manish Reddy
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
Data types
Data typesData types
Data types
nehajhala4
 
Data types
Data typesData types
Data types
Syed Umair
 
Java session3
Java session3Java session3
Java session3
Jigarthacker
 
Data type
Data typeData type
Data type
Frijo Francis
 
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
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
Saad Sheikh
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-c
teach4uin
 
Data types
Data typesData types
Data types
Nokesh Prabhakar
 

Similar to Computer programming 2 Lesson 5 (20)

Java - Basic Datatypes.pptx
Java - Basic Datatypes.pptxJava - Basic Datatypes.pptx
Java - Basic Datatypes.pptx
Nagaraju Pamarthi
 
5. variables & data types
5. variables & data types5. variables & data types
5. variables & data types
M H Buddhika Ariyaratne
 
Data Handling
Data HandlingData Handling
Data Handling
Praveen M Jigajinni
 
Data types ,variables,array
Data types ,variables,arrayData types ,variables,array
Data types ,variables,array
Gujarat Technological University
 
Data types
Data typesData types
Data types
Sachin Satwaskar
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
REHAN IJAZ
 
4. Data Handling computer shcience pdf s
4. Data Handling computer shcience pdf s4. Data Handling computer shcience pdf s
4. Data Handling computer shcience pdf s
TonyTech2
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type results
atifmugheesv
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
sunilchute1
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiers
Tanishq Soni
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
PRASANYA K
 
009 Data Handling .pptx
009 Data Handling .pptx009 Data Handling .pptx
009 Data Handling .pptx
ssuser6c66f3
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 
Python slide.1
Python slide.1Python slide.1
Python slide.1
Aswin Krishnamoorthy
 
DATATYPES IN JAVA primitive and nonprimitive.pptx
DATATYPES IN JAVA primitive and nonprimitive.pptxDATATYPES IN JAVA primitive and nonprimitive.pptx
DATATYPES IN JAVA primitive and nonprimitive.pptx
mustaq4
 
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
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
YRABHI
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
StephenOczon1
 
Chapter - 2.pptx
Chapter - 2.pptxChapter - 2.pptx
Chapter - 2.pptx
MikialeTesfamariam
 
data types in c programming language in detail
data types in c programming language in detaildata types in c programming language in detail
data types in c programming language in detail
atulk4360
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
REHAN IJAZ
 
4. Data Handling computer shcience pdf s
4. Data Handling computer shcience pdf s4. Data Handling computer shcience pdf s
4. Data Handling computer shcience pdf s
TonyTech2
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type results
atifmugheesv
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
sunilchute1
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiers
Tanishq Soni
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
PRASANYA K
 
009 Data Handling .pptx
009 Data Handling .pptx009 Data Handling .pptx
009 Data Handling .pptx
ssuser6c66f3
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 
DATATYPES IN JAVA primitive and nonprimitive.pptx
DATATYPES IN JAVA primitive and nonprimitive.pptxDATATYPES IN JAVA primitive and nonprimitive.pptx
DATATYPES IN JAVA primitive and nonprimitive.pptx
mustaq4
 
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
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
YRABHI
 
data types in c programming language in detail
data types in c programming language in detaildata types in c programming language in detail
data types in c programming language in detail
atulk4360
 
Ad

More from MLG College of Learning, Inc (20)

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

Recently uploaded (20)

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
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
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
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
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
 
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
 
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
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
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
 
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
 
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
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
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
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
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
 
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
 
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
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
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
 
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
 

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 −
  翻译: