O'Reilly logo

Sams Teach Yourself Java™ in 24 Hours, Sixth Edition by Rogers Cadenhead

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

Exceptions

Although you are just learning about them now, you have probably become well-acquainted with exceptions during the last 17 previous hours. These errors turn up when you write a Java program that compiles successfully but encounters a problem as it runs.

For example, a common programming mistake is to refer to an element of an array that doesn’t exist, as in the following statements:

String[] greek = { "Alpha", "Beta", "Gamma" };System.out.println(greek[3]);

The String array greek has three elements. Because the first element of an array is numbered 0 rather than 1, the first element is greek[0], the second greek[1], and the third greek[2]. So the statement attempting to display greek[3] is erroneous. The preceding statements compile ...

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