A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Types of Java

Boolean (True or False, 1 Byte)
Boolean (True or False, 1 Byte)

Java, unlike languages like C and C++, treats boolean as a completely separate data type which has 2 distinct values: true and false. The values 1 and 0 are of type int and are not implicitly convertible to boolean.

Char (a Character, 2 Bytes)
Char (a Character, 2 Bytes)

Why is the size of "char" in Java 2 bytes? In old languages like C and C++ we can use only ASCII characters and to represent all ASCII characters 8-bits are enough. Hence char size is 1 byte.

source: quora.com
Double (Float Number, 8 Bytes)
Double (Float Number, 8 Bytes)

A float gives you approx. 6-7 decimal digits precision while a double gives you approx. 15-16. Also the range of numbers is larger for double. A double needs 8 bytes of storage space while a float needs just 4 bytes.

Float (Float Number, 4 Bytes)
Float (Float Number, 4 Bytes)

How to convert from a float to 4 bytes in Java? ... possible duplicate of Java: Bytes to floats / ints – Brian Roach Jan 13 '13 at 22:24. The exact values don't matter.

int (Number, 4 Bytes)
int (Number, 4 Bytes)

Trailing Buffer: the end of the input may be an uneven number of bytes (not a multiple of 4 specifically) depending on the source. ... Java Convert 4 bytes to int. 8.

Short (Number, 2 Bytes)
Short (Number, 2 Bytes)

ByteBuffer bb = ByteBuffer.allocate(2); bb.order(ByteOrder.LITTLE_ENDIAN); bb.put(firstByte); bb.put(secondByte); short shortVal = bb.getShort(0); And vice versa, you can put a short, then pull out bytes. By the way, bitwise operations automatically promote the operands to at least the width of an int.