SlideShare a Scribd company logo
Data types and Literals




                          1
Objectives

On completion of this period, you would be able to
 know

•   Data types in Java
•   Literals in Java




                                                     2
Recap


In the previous class we have discussed
   •   White spaces, separators, literals and keywords
   •   Comments in Java




                                                         3
Data types in Java
• Data types in Java are classified into
   • Primitive types
   • Non-primitive types
• Primitive types are also known as simple data
  types
• A primitive type is predefined by the language
• Primitive types are further classified into
   • Numeric types
   • Non-numeric types



                                               4
Data types in Java
• Non-primitive types are also known as reference
  types
• Non-primitive types are
  • Classes
  • Interfaces
  • Arrays




                                                5
The classification of data types in Java
                             Data types in Java



             Primitive                         Non-primitive

 Numeric         Non-numeric
                                            classe            Arrays
                                            s
 integer
                      char                        Interface

Floating point             Boolea
                           n
                         Fig. 6.1 Data types in Java
                                                                  6
Data types

•   Primitive Java data types can be grouped into
    •   integers
    •   floating point numbers
    •   characters
    •   boolean




                                                    7
Integer types

•   Java defines four integer types: byte, short, int and
    long
•   All these are signed, positive and negative values
•   Java does not support unsigned types
•   byte is 8 bit width , short is 16 bit width int is 32
    bit width and long is 64 bit width



                                                            8
byte type

•   The smallest type is byte
•   Range from -128 to +128
•   Byte variables are declared by use of keyword
    ‘byte ‘
     eg.
         byte x, y;




                                                    9
short type

•  short is a signed 16 bit type.
• Its range is from -32,768 to +32,767

• It is probably the least used data type in Java

• Keyword used is ‘short’

eg.
  short x;




                                                    10
int type

•     The most commonly used integer data type is int
•     It has a range of -2,147,483,648 to 2,147,483,647
•     Keyword used is ‘int’
eg.
    int x;




                                                     11
long type
•   long is a signed 64 bit type
•   Useful where an int type is not large enough to hold
    the desired value
•   The range of large is quite large
•   This makes it useful when large, whole numbers are
    needed
•   Keyword used is ‘long’
eg. :
    long seconds;
                                                      12
floating point types

•   floating point numbers are also known as real
    numbers
•   Are used when fractional components are required
•   float and double are two kinds of floating point
    types
•   Keywords used are ‘float’ and ‘double’


                                                       13
Float type

•   float specify a single precision value that uses 32
    bits of storage
•   float type is useful when you require fractional
    component, but does not require a large degree of
    precision
eg.
    float area;

                                                          14
double type

•   double uses 64 bits of storage
•   When you need to maintain accuracy over many
    iterative calculations or manipulating large valued
    numbers double is the best choice
eg. :
    double area;


                                                      15
character type

•   In Java the data type used to store character is char
•   char in Java is different from char in C and C++
•   Java used Unicode to represent characters
•   Unicode was selected because it would help in
    internationalization of Java as a programming
    language
•   Java character is 16 bit type. The range of the
    characters is 0 to 65,536


                                                       16
boolean type

•   boolean data type is used to represent logical
    values that can be either true or false
•   All relational, conditional and logical operators
    return boolean values
•   It used only one bit of storage
•   Keyword used is ‘boolean’
•   eg;.
    •   boolean flag;



                                                        17
The simple data types in Java
•   In summary Java defines eight simple types of
    data. They are
    •   byte
    •   short
    •   int
    •   long
    •   char
    •   float
    •   double
    •   boolean

                                                    18
Summary
•   In this class we have discussed
    •   Data types in Java
    •   Literals in Java




                                      19
Quiz
1.Which of the following data type can store only
   two values
a)   int
b)   float
c)   boolean
d)   All of the above


                                                    20
Quiz

2.String Literal Enclosed with

a)   ‘‘
b)   ““
c)   **
d)   All the Above



                                 21
Frequently Asked Questions

1.   List the different data types available in Java

2.   Explain the various data types available in Java

3.   List the Literal in Java

4.   Explain the Literals in Java



                                                       22

More Related Content

What's hot

Java program structure
Java program structureJava program structure
Java program structure
shalinikarunakaran1
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
garishma bhatia
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Lovely Professional University
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
CharthaGaglani
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
Arzath Areeff
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
harsh kothari
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Java Tokens
Java  TokensJava  Tokens
Datatypes in c
Datatypes in cDatatypes in c
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
sasi saseenthiran
 
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
 

What's hot (20)

Java program structure
Java program structureJava program structure
Java program structure
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
 
Java string handling
Java string handlingJava string handling
Java string handling
 

Similar to Data types

Data types IN JAVA
Data types IN JAVAData types IN JAVA
Data types IN JAVA
garishma bhatia
 
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
 
Variable
VariableVariable
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
 
332 ch07
332 ch07332 ch07
332 ch07YaQ10
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ayshwarya Baburam
 
ITFT - Java
ITFT - JavaITFT - Java
ITFT - Java
Blossom Sood
 
Java basic-data-types
Java basic-data-typesJava basic-data-types
Java basic-data-types
Shahid Rasheed
 
Java basic data types
Java basic data typesJava basic data types
Java basic data types
javaicon
 
Java basic data types
Java basic data typesJava basic data types
Java basic data types
3trg
 
demo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptdemo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.ppt
FerdieBalang
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
One97 Communications Limited
 
Datatype
DatatypeDatatype
Datatype
baran19901990
 
Data types in Java
Data types in JavaData types in Java
Data types in Java
Play Store
 
Java Datatypes
Java DatatypesJava Datatypes
Java Datatypes
Mayank Aggarwal
 
basics dart.pdf
basics dart.pdfbasics dart.pdf
basics dart.pdf
ssuser0ca68e
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
eShikshak
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
Madishetty Prathibha
 

Similar to Data types (20)

Data types IN JAVA
Data types IN JAVAData types IN JAVA
Data types IN JAVA
 
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
 
Variable
VariableVariable
Variable
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
332 ch07
332 ch07332 ch07
332 ch07
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
ITFT - Java
ITFT - JavaITFT - Java
ITFT - Java
 
Java basic-data-types
Java basic-data-typesJava basic-data-types
Java basic-data-types
 
Java basic data types
Java basic data typesJava basic data types
Java basic data types
 
Java basic data types
Java basic data typesJava basic data types
Java basic data types
 
demo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptdemo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.ppt
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Datatype
DatatypeDatatype
Datatype
 
Data types in Java
Data types in JavaData types in Java
Data types in Java
 
Java Datatypes
Java DatatypesJava Datatypes
Java Datatypes
 
Java session3
Java session3Java session3
Java session3
 
basics dart.pdf
basics dart.pdfbasics dart.pdf
basics dart.pdf
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
Datatyps in posgresql
Datatyps in posgresqlDatatyps in posgresql
Datatyps in posgresql
 

More from myrajendra

Fundamentals
FundamentalsFundamentals
Fundamentals
myrajendra
 
Data type
Data typeData type
Data type
myrajendra
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
myrajendra
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
myrajendra
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
myrajendra
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
myrajendra
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
myrajendra
 
Dao example
Dao exampleDao example
Dao example
myrajendra
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
myrajendra
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to htmlmyrajendra
 
Views
ViewsViews
Views
myrajendra
 

More from myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

Recently uploaded

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 

Recently uploaded (20)

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 

Data types

  • 1. Data types and Literals 1
  • 2. Objectives On completion of this period, you would be able to know • Data types in Java • Literals in Java 2
  • 3. Recap In the previous class we have discussed • White spaces, separators, literals and keywords • Comments in Java 3
  • 4. Data types in Java • Data types in Java are classified into • Primitive types • Non-primitive types • Primitive types are also known as simple data types • A primitive type is predefined by the language • Primitive types are further classified into • Numeric types • Non-numeric types 4
  • 5. Data types in Java • Non-primitive types are also known as reference types • Non-primitive types are • Classes • Interfaces • Arrays 5
  • 6. The classification of data types in Java Data types in Java Primitive Non-primitive Numeric Non-numeric classe Arrays s integer char Interface Floating point Boolea n Fig. 6.1 Data types in Java 6
  • 7. Data types • Primitive Java data types can be grouped into • integers • floating point numbers • characters • boolean 7
  • 8. Integer types • Java defines four integer types: byte, short, int and long • All these are signed, positive and negative values • Java does not support unsigned types • byte is 8 bit width , short is 16 bit width int is 32 bit width and long is 64 bit width 8
  • 9. byte type • The smallest type is byte • Range from -128 to +128 • Byte variables are declared by use of keyword ‘byte ‘ eg. byte x, y; 9
  • 10. short type • short is a signed 16 bit type. • Its range is from -32,768 to +32,767 • It is probably the least used data type in Java • Keyword used is ‘short’ eg. short x; 10
  • 11. int type • The most commonly used integer data type is int • It has a range of -2,147,483,648 to 2,147,483,647 • Keyword used is ‘int’ eg. int x; 11
  • 12. long type • long is a signed 64 bit type • Useful where an int type is not large enough to hold the desired value • The range of large is quite large • This makes it useful when large, whole numbers are needed • Keyword used is ‘long’ eg. : long seconds; 12
  • 13. floating point types • floating point numbers are also known as real numbers • Are used when fractional components are required • float and double are two kinds of floating point types • Keywords used are ‘float’ and ‘double’ 13
  • 14. Float type • float specify a single precision value that uses 32 bits of storage • float type is useful when you require fractional component, but does not require a large degree of precision eg. float area; 14
  • 15. double type • double uses 64 bits of storage • When you need to maintain accuracy over many iterative calculations or manipulating large valued numbers double is the best choice eg. : double area; 15
  • 16. character type • In Java the data type used to store character is char • char in Java is different from char in C and C++ • Java used Unicode to represent characters • Unicode was selected because it would help in internationalization of Java as a programming language • Java character is 16 bit type. The range of the characters is 0 to 65,536 16
  • 17. boolean type • boolean data type is used to represent logical values that can be either true or false • All relational, conditional and logical operators return boolean values • It used only one bit of storage • Keyword used is ‘boolean’ • eg;. • boolean flag; 17
  • 18. The simple data types in Java • In summary Java defines eight simple types of data. They are • byte • short • int • long • char • float • double • boolean 18
  • 19. Summary • In this class we have discussed • Data types in Java • Literals in Java 19
  • 20. Quiz 1.Which of the following data type can store only two values a) int b) float c) boolean d) All of the above 20
  • 21. Quiz 2.String Literal Enclosed with a) ‘‘ b) ““ c) ** d) All the Above 21
  • 22. Frequently Asked Questions 1. List the different data types available in Java 2. Explain the various data types available in Java 3. List the Literal in Java 4. Explain the Literals in Java 22