O'Reilly logo

Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) by Marcus Green, Bill Brogden

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting and Casting Primitives

Every Java expression—whether arithmetic, a literal, or a method call—has a type. When the result of an expression has to be assigned to a variable or used in another expression, a different type may be required. The Java compiler is allowed to perform some type conversions automatically but rejects others unless the programmer provides a specific cast. This section discusses the rules the compiler uses.

Widening Conversions

Generally speaking, the Java compiler is allowed to perform primitive conversions that do not lose information about the magnitude of the value. It is also allowed to perform some conversions of integers to floating-point values that lose some precision due to the impossibility of representing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required