+91 81900 98289

Java Data Types

Primitive types hold the value itself: int, long, double, boolean, and char are the ones you will use first. int is a 32-bit whole number. double is a fractional number. boolean is only true or false.

String is not a primitive. A String variable holds a reference to a text object. The same is true for arrays and for every class you write. null means the reference does not point at an object yet.

Example

true prints as the word true. A double may print without a trailing zero.

public class Types { public static void main(String[] args) { int marks = 86; double fee = 14999.50; boolean paid = true; System.out.println(marks + " " + fee + " " + paid); } }
Use int for counts and ids that fit. Use long when the number can grow past about two billion. Use BigDecimal, not double, when the value is money that must match to the paisa.