Java Reference
In-Depth Information
System.err.println("Class
not
found:
"+cn-
fe.getMessage());
}
catch (IllegalAccessException iae)
{
System.err.println("Illegal
access:
"+i-
ae.getMessage());
}
catch (InstantiationException ie)
{
System.err.println("Unable to instantiate loaded
class");
}
}
}
Assumingthatyou'vecompiledallsourcefiles( javac *.java ,forexample),ex-
ecute java ViewerDemo EXE . You should observe the following output:
outputting EXE content in hexadecimal
If you were to execute java ViewerDemo PNG , you should see similar output.
Suppose you attempted to load and instantiate the abstract Viewer class via java
ViewerDemo "" . Although this class would load, newInstance() would throw
aninstanceofthe InstantiationException class,andyouwouldseethefollow-
ing output:
Unable to instantiate loaded class
Table 4-3 ' s descriptions of the getAnnotations() and getDeclaredAn-
notations() methods reveal that each method returns an array of Annotation ,
aninterfacethatislocatedinthe java.lang.annotation package. Annotation
is the superinterface of Override , SuppressWarnings , and all other annotation
types.
Table4-3 'smethoddescriptionsalsoreferto Constructor , Field ,and Method .
Instances oftheseclasses represent aclass's constructors andaclass's oraninterface's
fields and methods.
Constructor represents a constructor and is generically declared as Con-
structor<T> , where T identifies the class in which the constructor represented by
Search WWH ::




Custom Search