![]() |
![]() |
Java if statement | |
Java if-else statement | |
Java nested if-else | |
Java else-if ladder | |
Java Switch case statement | |
Java Nested Switch Case | |
Java Ternary/Conditional operator |
Java while loop | |
Java do-while loop | |
Java for loop | |
Java Enhanced loop/for each loop | |
Java Labelled for loop | |
Java Nesting of loops | |
Java Break and Continue |
Java Programs | |
Java Keywords Dictionary | |
Java Interview Questions | |
The datatype specifies the size and type
of data than can be stored in the memory for later use.
Integer types can hold whole numbers
like 45672, -789. Java doesn’t support the concept of unsigned
data types therefore all values in java are signed
.
Java supports 4 types of integer data types as shown below.
Type | Memory required to store value | Minimum storage | Maximum storage |
---|---|---|---|
byte | 1 byte | -128 | 127 |
short | 2 bytes | -32,768 | 32,767 |
int | 4 bytes | -2,147,483,648 | 2,147,483,647 |
long | 8 bytes | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
byte byteValue = 78; short shortValue = 22360; int intValue = 987654321; int long = 922337203685477590;
If you declare a variable without assigning or with assigning a value then automatically the memory space
is reserved to the respective variable
Floating types can hold numbers containing fractional part
such as 89.2, -12.03.
There are two types of floating point numbers in java.
The float types are single precision number. Floating point numbers are treated as double precision
quantities. That why append f or F to the numbers is used like – 3.14f, 9.81f
These are used when greater precision
in storage is required. All mathematical functions, such as sin,cos and sqrt returns double type value.
Type | Memory required to store value | Minimum storage value | Maximum storage value |
---|---|---|---|
float | 4 bytes | -3.4E-038 | 3.4E+038 |
double | 8 bytes | -1.7E-308 | 1.7E+308 |
By default the value is considered as double
if you declared as like 83.90
Java provides the character data type called char
to store single character constant in memory
Boolean holds only two values either true
or false
following table shows the size required for storing the single values of char and boolean datatypes
Type | Size | Example |
---|---|---|
char | 2 bytes | char a = 's' |
boolean | 1 bit | boolean b = true; |