Lesson 2- Java Data Types
Lesson 2- Java Data Types
int A = 16;
char x = ‘B’ ;
Session Agenda
3 Type Casting
4 Hands-on-Skills
What is Data Type?
Data type specifies the size and type of values that can be stored in an identifier
Primitive Non-Primitive
Data Types
Primitive Non-Primitive
Character Integral
Floating
Byte (1 byte) -128 to 127
Boolean -9,223,372,036,854,775,808
Long (8 bytes) to
9,223,372,036,854,775,807
The Analogy of Data Type Sizes in Java: Visualizing with Glasses
-9,223,372,036,854,775,808
to
9,223,372,036,854,775,807
-2147483648
to
2147483647
-32768 to 32767
-128 to 127
-2147483648
to
2147483647
-128 to 127
The float or double data type should never be used for precise values,
Boolean such as currency.
The default value of float is 0.0F
The default value of double is 0.0d
Data Types Range
✓ Character data types are used to store character values.
Integral ✓ Char data type is a single 16-bit unicode character
Floating
Char (2 bytes) 0 to 65,535
Character
Boolean
Data Types & Range
✓ Boolean data types are used to store boolean values.
✓ This data type is used for simple flag that track true or false
Integral conditions
Floating
boolean True / False
Character
Boolean
Hands-on-Skills
Primitive Data Type Demo Java Code
Different Data type
OUTPUT
Instance variable
How to find the size of a primitive data type in Java?
OUTPUT
K.K Type Casting
Assigning a value of one type to a variable of another type is known as Type Casting.
Widening
[email protected]
Hands-on-Skills
K.K Type Casting Demo Java Code
Narrowing type casting
OUTPUT
Thank You