What are the primitive data types in Java?
| Type | Size | Default value | Range or values |
|---|---|---|---|
| byte | 8 bit | 0 | -128 to 127 |
| short | 16 bit | 0 | -32,768 to 32,767 |
| int | 32 bit | 0 | about -2.1 billion to 2.1 billion |
| long | 64 bit | 0L | very big whole numbers |
| float | 32 bit | 0.0f | decimal, about 7 digits |
| double | 64 bit | 0.0 | decimal, about 15 digits |
| char | 16 bit | ‘\u0000’ | one Unicode character |
| boolean | not defined | false | true or false |
public class Main {
public static void main(String[] args) {
System.out.println(Integer.MAX_VALUE);
System.out.println(Long.MAX_VALUE);
System.out.println((int) Character.MAX_VALUE);
}
}
Output
2147483647
9223372036854775807
65535
Every other type is a reference type. See Java Data Types.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |