SlideShare a Scribd company logo
Java basic datatypes
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)

PPTX
Loops and arrays
abha aggarwal
 
PPT
Presentation of array
Shamim Hossain
 
PDF
Files and data storage
Zaid Shabbir
 
PPTX
concept of data structure
varagilavanya
 
PDF
Arrays in C++
Maliha Mehr
 
PPTX
Unit 1 array based implementation
LavanyaJ28
 
PPTX
Dsa unit 1
ColorfullMedia
 
PPT
Array
Tejas Patel
 
PPTX
Matlab Organizing Data
DataminingTools Inc
 
PPT
National 5 Data Types
Forrester High School
 
PPTX
Arrays
kuldeep94
 
PPTX
Chapter 6 java
Ahmad sohail Kakar
 
PPTX
Introduction to arrays
RWEKA
 
Loops and arrays
abha aggarwal
 
Presentation of array
Shamim Hossain
 
Files and data storage
Zaid Shabbir
 
concept of data structure
varagilavanya
 
Arrays in C++
Maliha Mehr
 
Unit 1 array based implementation
LavanyaJ28
 
Dsa unit 1
ColorfullMedia
 
Matlab Organizing Data
DataminingTools Inc
 
National 5 Data Types
Forrester High School
 
Arrays
kuldeep94
 
Chapter 6 java
Ahmad sohail Kakar
 
Introduction to arrays
RWEKA
 

Similar to Java basic datatypes (20)

PDF
Java basic datatypes
Soba Arjun
 
PPTX
5. variables & data types
M H Buddhika Ariyaratne
 
PPTX
Java - Basic Datatypes.pptx
Nagaraju Pamarthi
 
PPTX
Computer programming 2 Lesson 5
MLG College of Learning, Inc
 
PPTX
Topic-5_-Programming-Fundamentals-Part-2.pptx
HaroldOmega1
 
PPTX
Datatype introduction- JAVA
Hamna_sheikh
 
PPTX
Computer Programming Java Data Types.pptx
MarianneIsid
 
PPTX
DATATYPES IN JAVA primitive and nonprimitive.pptx
mustaq4
 
PPTX
a variable in Java must be a specified data type
Kavitha S
 
PPSX
Java session3
Jigarthacker
 
PPTX
Data types
nehajhala4
 
PPTX
DATA TYPES in Python done by Sanajai of MCA
JPrince9
 
PPTX
Data types IN JAVA
garishma bhatia
 
PPTX
Lect5
Jamsher bhanbhro
 
PPTX
Java Data Types
Spotle.ai
 
PPTX
JAVA LESSON-01.pptx
StephenOczon1
 
PPTX
Java data types
AbhishekMondal42
 
PPT
Data types
myrajendra
 
PPTX
L2 datatypes and variables
teach4uin
 
Java basic datatypes
Soba Arjun
 
5. variables & data types
M H Buddhika Ariyaratne
 
Java - Basic Datatypes.pptx
Nagaraju Pamarthi
 
Computer programming 2 Lesson 5
MLG College of Learning, Inc
 
Topic-5_-Programming-Fundamentals-Part-2.pptx
HaroldOmega1
 
Datatype introduction- JAVA
Hamna_sheikh
 
Computer Programming Java Data Types.pptx
MarianneIsid
 
DATATYPES IN JAVA primitive and nonprimitive.pptx
mustaq4
 
a variable in Java must be a specified data type
Kavitha S
 
Java session3
Jigarthacker
 
Data types
nehajhala4
 
DATA TYPES in Python done by Sanajai of MCA
JPrince9
 
Data types IN JAVA
garishma bhatia
 
Java Data Types
Spotle.ai
 
JAVA LESSON-01.pptx
StephenOczon1
 
Java data types
AbhishekMondal42
 
Data types
myrajendra
 
L2 datatypes and variables
teach4uin
 
Ad

More from Soba Arjun (20)

PDF
Java interview questions
Soba Arjun
 
PDF
Java modifiers
Soba Arjun
 
PDF
Java variable types
Soba Arjun
 
PDF
Dbms interview questions
Soba Arjun
 
PDF
C interview questions
Soba Arjun
 
PDF
Technical interview questions
Soba Arjun
 
PDF
Php interview questions with answer
Soba Arjun
 
PDF
Computer Memory Types - Primary Memory - Secondary Memory
Soba Arjun
 
PDF
Birds sanctuaries
Soba Arjun
 
PDF
Important operating systems
Soba Arjun
 
PDF
Important branches of science
Soba Arjun
 
PDF
Important file extensions
Soba Arjun
 
PDF
Java Abstraction
Soba Arjun
 
PDF
Java Polymorphism
Soba Arjun
 
PDF
Java Overriding
Soba Arjun
 
PDF
Java Inner Classes
Soba Arjun
 
PDF
java Exception
Soba Arjun
 
PDF
Java Methods
Soba Arjun
 
PDF
java Inheritance
Soba Arjun
 
PDF
Major tribes of india
Soba Arjun
 
Java interview questions
Soba Arjun
 
Java modifiers
Soba Arjun
 
Java variable types
Soba Arjun
 
Dbms interview questions
Soba Arjun
 
C interview questions
Soba Arjun
 
Technical interview questions
Soba Arjun
 
Php interview questions with answer
Soba Arjun
 
Computer Memory Types - Primary Memory - Secondary Memory
Soba Arjun
 
Birds sanctuaries
Soba Arjun
 
Important operating systems
Soba Arjun
 
Important branches of science
Soba Arjun
 
Important file extensions
Soba Arjun
 
Java Abstraction
Soba Arjun
 
Java Polymorphism
Soba Arjun
 
Java Overriding
Soba Arjun
 
Java Inner Classes
Soba Arjun
 
java Exception
Soba Arjun
 
Java Methods
Soba Arjun
 
java Inheritance
Soba Arjun
 
Major tribes of india
Soba Arjun
 
Ad

Recently uploaded (20)

PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Dimensions of Societal Planning in Commonism
StefanMz
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
community health nursing question paper 2.pdf
Prince kumar
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 

Java basic datatypes

  • 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