Q. What is Java bytecode?
A. A low-level version of your program that runs on the Java virtual machine. This level
of abstraction makes it easier for the developers of Java to ensure that our programs run
on a broad variety of devices.
Q. It seems wrong that Java should just let ints overflow and give bad values. Shouldn’t
Java automatically check for overflow?
A. This issue is a contentious one among programmers. The short answer is that the
lack of such checking is one reason such types are called primitive data types. A little
knowledge can go a long way in avoiding such problems. We use the int type for small
numbers (less than ten decimal digits), and the long type when values run into the billions
or more.
Q. What is the value of Math.abs(-2147483648)?
A. -2147483648. This strange (but true) result is a typical example of the effects of
integer overflow.
Q. How can I initialize a double variable to infinity?
A. Java has built-in constants available for this purpose: Double.POSITIVE_INFINITY
and Double.NEGATIVE_INFINITY.
Q. Can you compare a double to an int?
A. Not without doing a type conversion, but remember that Java usually does the requisite
type conversion automatically. For example, if x is an int with the value 3, then
the expression (x < 3.1) is true—Java converts x to double (because 3.1 is a double
literal) before performing the comparison.
Q. What happens if I use a variable before initializing it to a value?
A. Java will report a compile-time error if there is any path through your code that
would lead to use of an uninitialized variable.
Q. What are the values of 1/0 and 1.0/0.0 as Java expressions?
A. The first generates a runtime exception for division by zero (which stops your program
because the value is undefined); the second has the value Infinity.