This week's book giveaway is in the Big Data forum. We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line! See this thread for details.

when u run the code, from the 16 loop onwards, number takes a constant value. why is that? using long a limiting value is also reached. why is that? is it only a DOS thing? if u make a GUI window and display number in that will it go on displaying the numbers?

The largest value an int can represent is 2^31-1; the largest value a long can represent is 2^63-1. They are stored in a finite number of machine bits, so there's a finite magnitude they can represent.

The float and double data types have much larger ranges, but lower precision.

Before we get into this: note that none of this is unique to Java. Many computer languages -- especially those related to FORTRAN and C -- behave this way.

Integers "wrap around". If you add one to the largest possible integer, you don't get what you expect. This is called "overflow". If you add one to the largest positive int in Java, you actually get the largest possible negative int -- i.e., (2^31-1) + 1 -> -2^31 . This is a result of something called "two's complement" notation -- the way that negative numbers are represented.

ints and longs are exact, while floating-point numbers (float and double) are not. Remember that between any two real numbers, there are an infinity of intermediate values. As a result, no finite computer representation can represent an arbitrary real number exactly. The "exactness" of a floating-point representation is called its precision. floats have 20-something bits of precision, and doubles have 50-something. Because a long is 64 bits, that means that there isn't a unique double value for each possible long value -- i.e., some adjacent long values correspond to the same double value.

Here's an overview article at Wikipedia which explains all of these concepts.