Understand primitive data types in Java
- Details
- Written by Nam Ha Minh
- Last Updated on 18 August 2019   |   Print Email
Data types are cornerstones of a programming language. The Java language has 8 primitive types: boolean, byte, char, double, float, int, long, and short.
A boolean type represents either true or false value.
A char type represents a single character, such as 'a', 'B', 'c', ...Actually char type is 16-bit integer number (un-signed).
The others are numeric types. The following section lists the primitive types which represent numbers in the Java language (the char type is also included because it is actually a number type):
Integer numbers:
- byte: 8 bit (1 byte)
minimum value: -128 (-27)
maximum value: 127 (27-1)
- char: 16 bit (2 bytes)
minimum value: 0
maximum value: 65,535
- short: 16 bit (2 bytes)
minimum value: -32,768 (-215)
maximum value: 32,767 (215-1)
- int: 32 bit (4 bytes)
minimum value: -2,147,483,648 (-231)
maximum value: 2,147,483,647 (231-1)
- long: 64 bit (8 bytes)
minimum value: approx. -9,2 billions of billion (-263)
maximum value: approx. 9,2 billions of billion (-263-1)
Floating-point numbers:
- float: 32 bit (4 bytes):
- double: 64 bit (8 bytes):
There are 4 integer types: byte, short, int, and long.
There are 2 floating point number types: float and double.
Related Tutorials:
- Summary of all keywords in Java
- Some notes about arrays in Java
- Some notes about numeric literals in Java
Other Recommended Tutorials:
- 9 Rules about Constructors in Java
- 12 Rules and Examples About Inheritance in Java
- 12 Rules of Overriding in Java You Should Know
- 10 Java Core Best Practices Every Java Programmer Should Know
- Understand Interfaces in Java
- Understand how variables are passed in Java
Comments
I would like to report you a but, in primitives types section, in long is maximum value: approx. 9,2 billions of billion (-2^63-1), shouldn't be (2^63-1)?