There are two main types of data types in Java: primitive and non-primitive. The eight primitive data types are boolean, char, byte, short, int, long, float, and double. These include four integral types of different sizes to store whole numbers, two floating point types to store decimal numbers, a character type to store single characters using Unicode, and a boolean type to store true/false values. The non-primitive types are classes, interfaces, and arrays which can store more complex data.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
265 views
Data Types in Java
There are two main types of data types in Java: primitive and non-primitive. The eight primitive data types are boolean, char, byte, short, int, long, float, and double. These include four integral types of different sizes to store whole numbers, two floating point types to store decimal numbers, a character type to store single characters using Unicode, and a boolean type to store true/false values. The non-primitive types are classes, interfaces, and arrays which can store more complex data.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6
Data types in Java
• Why data types are required in any programming language?
• C is a statically typed language, Python is dynamically typed language
and java is strongly typed language. • Data types specify the different sizes and values that can be stored in the variable. • There are two types of data types in Java: • Primitive data types: Boolean, char, byte, short, int, long, float and double. • Non-primitive data types: Classes, Interfaces, and Arrays. Integral Data Types Integral Data Types
4 types based on integral values: byte, short, int, long
All numeric types are signed. There are NO unsigned types in
Java. Integrals are stored as 2's compliment.
Type Size Range
byte 8 bits -128 through +127 short 16 bits -32768 through +32767 int 32 bits -2147483648 through +2147483647 long 64 bits -9223372036854775808 through +9223372036854775807 Floating point Data Types
2 types based on floating point values: float and double
Storage conforms to IEEE 754 standard Floating point numbers are not accurate. They are an approximation floats store 7 significant digits. doubles store 15.
Type Size Range
38 38 float 32 bits -3.4 * 10 through +3.4 * 10 double 64 bits -1.7 * 10308 through +1.7 * 10 308 Character data type
The char type defines a single character
In many other programming languages, character types are
8-bits (they store ASCII values). In Java, character types are 16-bits.
Java characters store characters in unicode format.
Unicode is an international character set which defines
characters and symbols from several different world languages. Unicode includes ASCII at its low range (0-255)
Characters can be converted to integers to perform
mathematical functions on them. Boolean data type
The boolean type defines a truth value: true or false.
Booleans are often used in control structures to represent a condition
or state.
Java characters store characters in unicode format.
Unicode is an international character set which defines characters
and symbols from several different world languages. Unicode includes ASCII at its low range (0-255)