Tsallaka zuwa abun ciki
Justice Tech School

Data Types

Primitive types hold simple values: byte, short, int, long (whole numbers), float, double (decimals), char and boolean. Everything else, such as String and arrays, is a reference type. Use int for most whole numbers and double for decimals, and add L to a long literal.

Example
int big = Integer.MAX_VALUE;
long huge = 9_000_000_000L;
double d = 5 / 2;
double e = 5 / 2.0;
System.out.println(big);
System.out.println(huge);
System.out.println(d + " " + e);
System.out.println((char) 66);
System.out.println(0.1 + 0.2);

Result

2147483647
9000000000
2.0 2.5
B
0.30000000000000004

Exercise

Which type holds true or false?

 ok = true;

Quiz Test

What is 5 / 2 with two ints?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.