Default values for primitives and references : Data Type Introduction « Data Type « Java Tutorial






TypeDefault Value
booleanfalse
byte0
short0
int0
long0L
char\u0000
float0.0f
double0.0d
object referencenull


public class ClassInitializer1 {
  static boolean bool;
  static byte by;
  static char ch;
  static double d;
  static float f;
  static int i;
  static long l;
  static short sh;
  static String str;

  public static void main(String[] args) {
    System.out.println("bool = " + bool);
    System.out.println("by = " + by);
    System.out.println("ch = " + ch);
    System.out.println("d = " + d);
    System.out.println("f = " + f);
    System.out.println("i = " + i);
    System.out.println("l = " + l);
    System.out.println("sh = " + sh);
    System.out.println("str = " + str);
  }
}








2.1.Data Type Introduction
2.1.1.The Primitive Types
2.1.2.Size for Java's Primitive Types
2.1.3.Default values for primitives and references
2.1.4.Literals
2.1.5.Surprise! Java lets you overflow
2.1.6.Wrapping a Primitive Type in a Wrapper Object: boolean, byte, char, short, int, long, float, double
2.1.7.Print the limits of primitive types (e.g. byte, short, int ...) in Java
2.1.8.Get the minimum and maximum value of a primitive data types
2.1.9.Shows default initial values
2.1.10.Primitive utilities
2.1.11.Return primitive type the passed in wrapper type corresponds to