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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.