Data Type in Java
Data Type in Java
By Kamal
Apr28
INTRODUCTION
Java Data Types
Lets us discuss and implement each one of the following data types that are as follows:
1.Boolean Data Type
Boolean data type represents only one bit of information either True or False which is
intended to represent the two truth values of logic and Boolean algebra, but the size of the
Boolean data type is virtual machine-dependent.
Syntax:
Boolean BooleanVar;
222.Byte Data Type. Byte Data Type
The byte data type is an 8-bit signed two’s complement integer. The byte data type is
useful for saving memory in large arrays.
Syntax:
Byte bytevar;
size: 1 byte(8 bits)
PRIMITIVE DATA TYPES
3.Short Data Type
The short data type is a 16-bit signed two’s complement integer. Similar
to byte, use a short to save memory in large arrays, in situations where
the memory saving actually matters.
Syntax:
Short shortVar;
Size:2 bytes(16 bits)
4.Integer Data Type
It is a 32-bit signed two’s complement integer.
Syntax:
Int intVar;
Size:4 bytes(32 bits)
Example: How to Print an
Integer entered by an user
OUTPUT
5.Long Data Type
The range of a long is quite large. The long data types is a 64-bit two’s
complement integer and is useful for those occasions where an int type is not
Large enough to hold the desired value. The size of the long datatype
is 8 bytes(64 bits).
Syntax:
Long longVar;