Troubleshooting

   

Floating-Point Literal Loss of Precision Error

The compiler reports as error stating that your assignment of a floating-point literal to a variable of type float might result in a loss of precision.

When you assign a floating-point literal to a float variable, you must explicitly specify the type suffix. When you omit the suffix, the compiler assumes that the literal is of type double , which cannot be assigned to a float without an explicit cast. The following two statements illustrate a correct and an incorrect assignment statement:

 float myFirstFloat = 1.0;   // compiler error float mySecondFloat = 2.0F; // correct 

ArrayIndexOutOfBoundsException

An ArrayIndexOutOfBoundsException occurs at runtime when you attempt to access an array's elements.

Remember that the first index in a Java array is 0 and the last valid index is one less than the length of the array. For example:

 // create an array to hold two integer values int[] dataArray = new int[2]; // several correct data assignment statements dataArray[0] = 23;  // valid assignment to first index dataArray[1] = 43;  // valid assignment to last index dataArray[dataArray.length-1] = 50;  // valid assignment to last index // runtime errors dataArray[2] = 55;                 // ArrayIndexOutOfBoundsException dataArray[dataArray.length] = 55;  // ArrayIndexOutOfBoundsException 
   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net