File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Easy Way to remember Ranges of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Easy Way to remember Ranges of " Watch "Easy Way to remember Ranges of " New topic

Easy Way to remember Ranges of

Steve Bartholomew

Joined: Jul 18, 2005
Posts: 1
...Primitive values - any good tips

(eg - byte 8 bits, short 16 bits etc....)

any good websites / refreshers to help with converting bin to hex and so on?

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Well always remember that the signed primitives have one less positive value than negative.

For SCJP 5.0 you don't need to worry as much about this than say the 1.4 exam.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
K Bala

Joined: Jul 14, 2005
Posts: 28

Here is a formula to calculate the value range for primitive data types - byte to long.

Value Range = (-2^n-1) to (2^n-1)-1 where n is the size in bits.

So this is how it works.

Variable Type Size(in bits) Value
byte 8 (-2^7) - 2^7-1 (-128 to 127)
short 16 (-2^15) - 2^15-1(-32768 to 32767)
int 32 (-2^31) - 2^31-1
long 64 (-2^63) - 2^63-1

Quitters never win; Winners NEVER QUIT!!!
I agree. Here's the link:
subject: Easy Way to remember Ranges of
It's not a secret anymore!