Find out byte's max value, min value and size

The following code use constants defined from Byte class to find out the max and min value of a byte type variable.


public class Main {

  public static void main(String args[]) {
    System.out.println("Max value from Byte class:"+Byte.MAX_VALUE);
    System.out.println("Min value from Byte class:"+Byte.MIN_VALUE);
  }
}

The code above outputs:


Max value from Byte class:127
Min value from Byte class:-128

To get the size of a byte value, just call its static constant SIZE as the follows:


public class Main {

  public static void main(String args[]) {
    System.out.println("Size of a Byte:"+Byte.SIZE);
  }
}

The output:


Size of a Byte:8
Home 
  Java Book 
    Essential Classes  

Byte:
  1. Byte
  2. Find out byte's max value, min value and size
  3. Create Byte object with its constructor
  4. Convert Byte to byte, double, float, int, long and short
  5. Decode a string to a byte
  6. Byte class defines static methods to convert string value to byte value
  7. Convert byte value to string value
  8. Compare two byte values