Literals : Data Type Introduction « Data Type « Java Tutorial






public class MainClass {
  char c = 0xffff; // max char hex value

  byte b = 0x7f; // max byte hex value

  short s = 0x7fff; // max short hex value

  int i1 = 0x2f; // Hexadecimal (lowercase)

  int i2 = 0X2F; // Hexadecimal (uppercase)

  int i3 = 0177; // Octal (leading zero)

  // Hex and Oct also work with long.
  long n1 = 200L; // long suffix

  long n2 = 200l; // long suffix (but can be confusing)

  long n3 = 200;

  // ! long l6(200); // not allowed
  float f1 = 1;

  float f2 = 1F; // float suffix

  float f3 = 1f; // float suffix

  float f4 = 1e-45f; // 10 to the power

  float f5 = 1e+9f; // float suffix

  double d1 = 1d; // double suffix

  double d2 = 1D; // double suffix

  double d3 = 47e47d; // 10 to the power
}








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