codegurukool.com · Free coding tutorials & online compiler

Home › Java Tutorial › Java data types

Java data types

Primitive types and their sizes.

Java has eight primitive types: byte, short, int, long, float, double, char and boolean. A long literal ends with L and a float literal with f. Underscores make big numbers readable. Everything else, such as String, is a reference type.

Example code

public class Main {
  public static void main(String[] args) {
    byte b = 100;
    int i = 2_000_000;
    long big = 9_000_000_000L;
    float f = 1.5f;
    double d = 2.25;
    System.out.println(b);
    System.out.println(i);
    System.out.println(big);
    System.out.println(f);
    System.out.println(d);
    System.out.println(Integer.MAX_VALUE);
  }
}

Run this code in the online editor

← Java variablesJava type casting →