Java types range

Learn with this article how to calculate range of Java integer types. You will never have to Google for the Jave type range table anymore!Calculating range of Java integer types is a very easy and simple process. Here is the process:

  1. Get storage amount of desired type, you can get it from the list below (it’s good (and simple) to memorize it)
    long  –  8 bytes
    int  –  4 bytes
    short  –  2 bytes
      –  1 byte
  2. Multiply amount of bytes 8 times, ie. for int it is 4×8 = 32
  3. Use the value from Step 2 as exponent for power with base 2:  2³² = 4,294,967,296
  4. Divide the value from Step 3 by two to get negative range of your type:  4,294,967,296÷2 = 2,147,483,648
  5. Subtract 1 from the value from Step 4 to get the positive range of your type: 2,147,483,648 – 1 = 2,147,483,647
  6. You have calculated the type range! For int from example, it is -2,147,483,648 to 2,147,483,647

Do you know any simpler method? Leave it in the comments!

Learn more about Java