SlideShare a Scribd company logo
1 of 14
Download to read offline
Basic Datatypes
• Datatypes: int, String, float, short, byte, long,
double, Boolean.
• Datatypes used to create a variables.
• Variables are reserved memory location to store
values.
• When we create variables, we receive some
space in memory.
96.6
200
P1713
Moon
name
regno
amountpercentage
Basic Datatypes
• By assigning different values to variables, we
can store different datatypes.
• 2 datatypes: Primitive, Reference/Object
96.6
200
P1713
Moon
name
regno
amountpercentage
datatype variable_name = value;
datatype variable_name;
variable_name = value;
Basic Datatypes – Primitive Data Types
• Primitive datatypes are predefined by the language and named by a
keywords.
• There are 8 primitive datatypes supported by java.
1. byte
2. short
3. int
4. long
5. float
6. double
7. boolean
8. char
Primitive Data Types ( byte)
• 8 bit signed 2’s complement integer.
(-128)
(0)
• Used to save space in large array.
• 4 times smaller than int.
byte a = 68;
(127)
byte a = -128;
Primitive Data Types ( short)
• 16 bit signed 2’s complement integer.
(-32,768)
(0)
(32,767)
• Used to save space in large array.
• 2 times smaller than int.
short a = 1000;short a = -1000;
Primitive Data Types ( int)
• 32 bit signed 2’s complement integer.
(-2,147,483,648)
(0)
(2,147,483,647)
• Default datatypes for integral values.
• There is a concern about memory.
int a = 1236542;int a = -123648;
Primitive Data Types ( long)
• 64 bit signed 2’s complement integer.
• This type is used when a wider range than int is need
long a = 10486L;long a = -100L;
L is maximum duration of 32
10486L =
-9,223,372,036,854,775,808 to 0L to -9,223,372,036,854,775,807
Primitive Data Types ( float)
• single-precision 32-bit IEEE 754 floating point.
• Used to save memory in large arrays of floating point values.
• Never used for precise values such as currency.
float a = 234.5f;0.0f
Primitive Data Types ( double)
• double-precision 32-bit IEEE 754 floating point.
• generally used as the default data type for decimal values.
• Never used for precise values such as currency.
double a = 234.5;0.0d
Primitive Data Types ( boolean)
• It represents one bit of information.
• 2 possible values: true and false.
• This data type is used for simple flags that
track true/false conditions.
• Default value: false.
boolean a = true;
asign a=10
asign b=20
a=b //false
asign b=b-a
a=b //true
Primitive Data Types ( char)
• 16 bit Unicode character.
• Char data type is used to store any character.
char a = ‘A’;‘u0000’
(0)
‘uffff’
(65,535 inclusive)
Basic Datatypes – Reference Data Types
• Reference variables are created using defined constructors of the classes.
• They are used to access objects.
• Class objects and various type of array variables come under reference datatype
• Default value is null.
Animal a=new Animal();
Animal a=new Animal(0,’asdf’);
Basic Datatypes Notation Character represented
n Newline (0x0a)
r Carriage return (0x0d)
f Formfeed (0x0c)
b Backspace (0x08)
s Space (0x20)
t tab
" Double quote
' Single quote
 backslash
ddd Octal character (ddd)
uxxxx Hexadecimal UNICODE
character (xxxx)
• Few special escape
sequences for String
and char literals

More Related Content

What's hot (13)

Loops and arrays
Loops and arraysLoops and arrays
Loops and arrays
 
Presentation of array
Presentation of arrayPresentation of array
Presentation of array
 
Files and data storage
Files and data storageFiles and data storage
Files and data storage
 
concept of data structure
concept of data structureconcept of data structure
concept of data structure
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Unit 1 array based implementation
Unit 1  array based implementationUnit 1  array based implementation
Unit 1 array based implementation
 
Dsa unit 1
Dsa unit 1Dsa unit 1
Dsa unit 1
 
Array
ArrayArray
Array
 
Matlab Organizing Data
Matlab Organizing DataMatlab Organizing Data
Matlab Organizing Data
 
National 5 Data Types
National 5 Data TypesNational 5 Data Types
National 5 Data Types
 
Arrays
ArraysArrays
Arrays
 
Chapter 6 java
Chapter 6 javaChapter 6 java
Chapter 6 java
 
Introduction to arrays
Introduction to arraysIntroduction to arrays
Introduction to arrays
 

Similar to Java basic datatypes

java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
jyoti_lakhani
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
 

Similar to Java basic datatypes (20)

Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypes
 
Variable
VariableVariable
Variable
 
5. variables & data types
5. variables & data types5. variables & data types
5. variables & data types
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
 
Data type
Data typeData type
Data type
 
Java session3
Java session3Java session3
Java session3
 
Lect5
Lect5Lect5
Lect5
 
Java Tutorial Lab 2
Java Tutorial Lab 2Java Tutorial Lab 2
Java Tutorial Lab 2
 
Java - Basic Datatypes.pptx
Java - Basic Datatypes.pptxJava - Basic Datatypes.pptx
Java - Basic Datatypes.pptx
 
Computer programming 2 Lesson 5
Computer programming 2  Lesson 5Computer programming 2  Lesson 5
Computer programming 2 Lesson 5
 
java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
 
DATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.netDATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.net
 
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury SechetDConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
 
Data Types in C language
Data Types in C languageData Types in C language
Data Types in C language
 
Fundamentals of Information Encryption
Fundamentals of Information EncryptionFundamentals of Information Encryption
Fundamentals of Information Encryption
 
Data types
Data typesData types
Data types
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
 

More from Soba Arjun

More from Soba Arjun (20)

Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Java modifiers
Java modifiersJava modifiers
Java modifiers
 
Java variable types
Java variable typesJava variable types
Java variable types
 
Dbms interview questions
Dbms interview questionsDbms interview questions
Dbms interview questions
 
C interview questions
C interview questionsC interview questions
C interview questions
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questions
 
Php interview questions with answer
Php interview questions with answerPhp interview questions with answer
Php interview questions with answer
 
Computer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary MemoryComputer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary Memory
 
Birds sanctuaries
Birds sanctuariesBirds sanctuaries
Birds sanctuaries
 
Important operating systems
Important operating systemsImportant operating systems
Important operating systems
 
Important branches of science
Important branches of scienceImportant branches of science
Important branches of science
 
Important file extensions
Important file extensionsImportant file extensions
Important file extensions
 
Java Abstraction
Java AbstractionJava Abstraction
Java Abstraction
 
Java Polymorphism
Java PolymorphismJava Polymorphism
Java Polymorphism
 
Java Overriding
Java OverridingJava Overriding
Java Overriding
 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
 
java Exception
java Exceptionjava Exception
java Exception
 
Java Methods
Java MethodsJava Methods
Java Methods
 
java Inheritance
java Inheritancejava Inheritance
java Inheritance
 
Major tribes of india
Major tribes of indiaMajor tribes of india
Major tribes of india
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Java basic datatypes

  • 1.
  • 2. Basic Datatypes • Datatypes: int, String, float, short, byte, long, double, Boolean. • Datatypes used to create a variables. • Variables are reserved memory location to store values. • When we create variables, we receive some space in memory. 96.6 200 P1713 Moon name regno amountpercentage
  • 3. Basic Datatypes • By assigning different values to variables, we can store different datatypes. • 2 datatypes: Primitive, Reference/Object 96.6 200 P1713 Moon name regno amountpercentage datatype variable_name = value; datatype variable_name; variable_name = value;
  • 4. Basic Datatypes – Primitive Data Types • Primitive datatypes are predefined by the language and named by a keywords. • There are 8 primitive datatypes supported by java. 1. byte 2. short 3. int 4. long 5. float 6. double 7. boolean 8. char
  • 5. Primitive Data Types ( byte) • 8 bit signed 2’s complement integer. (-128) (0) • Used to save space in large array. • 4 times smaller than int. byte a = 68; (127) byte a = -128;
  • 6. Primitive Data Types ( short) • 16 bit signed 2’s complement integer. (-32,768) (0) (32,767) • Used to save space in large array. • 2 times smaller than int. short a = 1000;short a = -1000;
  • 7. Primitive Data Types ( int) • 32 bit signed 2’s complement integer. (-2,147,483,648) (0) (2,147,483,647) • Default datatypes for integral values. • There is a concern about memory. int a = 1236542;int a = -123648;
  • 8. Primitive Data Types ( long) • 64 bit signed 2’s complement integer. • This type is used when a wider range than int is need long a = 10486L;long a = -100L; L is maximum duration of 32 10486L = -9,223,372,036,854,775,808 to 0L to -9,223,372,036,854,775,807
  • 9. Primitive Data Types ( float) • single-precision 32-bit IEEE 754 floating point. • Used to save memory in large arrays of floating point values. • Never used for precise values such as currency. float a = 234.5f;0.0f
  • 10. Primitive Data Types ( double) • double-precision 32-bit IEEE 754 floating point. • generally used as the default data type for decimal values. • Never used for precise values such as currency. double a = 234.5;0.0d
  • 11. Primitive Data Types ( boolean) • It represents one bit of information. • 2 possible values: true and false. • This data type is used for simple flags that track true/false conditions. • Default value: false. boolean a = true; asign a=10 asign b=20 a=b //false asign b=b-a a=b //true
  • 12. Primitive Data Types ( char) • 16 bit Unicode character. • Char data type is used to store any character. char a = ‘A’;‘u0000’ (0) ‘uffff’ (65,535 inclusive)
  • 13. Basic Datatypes – Reference Data Types • Reference variables are created using defined constructors of the classes. • They are used to access objects. • Class objects and various type of array variables come under reference datatype • Default value is null. Animal a=new Animal(); Animal a=new Animal(0,’asdf’);
  • 14. Basic Datatypes Notation Character represented n Newline (0x0a) r Carriage return (0x0d) f Formfeed (0x0c) b Backspace (0x08) s Space (0x20) t tab " Double quote ' Single quote backslash ddd Octal character (ddd) uxxxx Hexadecimal UNICODE character (xxxx) • Few special escape sequences for String and char literals