Java Reference
In-Depth Information
NoClassDefFoundError
A
NoClassDefFoundError
is thrown by the JVM or class loader when the defi nition of a
class cannot be found. You might have seen this error before when attempting to run a Java
program and the JVM cannot fi nd your class:
java NotThere
If there is no class named
NotThere
in the classpath, the following output displays:
Exception in thread “main” java.lang.NoClassDefFoundError: NotThere
Caused by: java.lang.ClassNotFoundException: NotThere
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Summary
This chapter covered the “Flow Control” objectives of the SCJP exam. The goal of this
chapter was to discuss the details of various entities in Java that alter the fl ow of control.
The decision-making control structures in Java are the
if
and
switch
statements. An
if
statement is the most basic of decision-making control structures in Java, and the
switch
statement is useful when comparing an integer value to a fi xed number of cases.
The repetition control structures in Java are the
for
, enhanced
for
,
while
, and
do
loops.
The
for
loop is useful for repeating something a fi xed number of times. The enhanced
for
is designed for iterating through arrays and collections. The
while
and
do-while
loops are
used when repeating a task an indeterminate number of times; the difference is that a
do-
while
loop executes at least once. We also discussed the effect of the
break
and
continue
keywords on a loop.
This chapter discussed assertions in detail. An assertion is a
boolean
expression placed
at particular points in your code where you think something should always be true. A
failed assertion throws an
AssertionError
, and we explored how to enable assertions at
runtime.
We also explained the details of exceptions in Java, including the differences between
errors, runtime exceptions, and checked exceptions. We saw the effect the Handle or
Declare Rule has on your code and the use of the
try
,
catch
,
finally
,
throw
, and
throws
keywords.
Search WWH ::
Custom Search