Java Reference
In-Depth Information
public static
throws IOException {
String [] names = getPackageContent ( "" );
static void
void main ( String [] args ) throws
for ( String name : names ) {
System . out . println ( name );
System . out . println ( "Done" );
Note that if you run this application in the “javasrc” project, it will list the members of the
demonstration package ( ) twice, because it will find them both in the
build directory and in the JAR file. If this is an issue, change the List to a Set (see The Col-
lections Framework ) .
Using and Defining Annotations
You need to know how to use annotations in code or to define your own annotations.
Apply annotations in your code using @ AnnotationName before a class, method, field, etc.
Define annotations with @interface at the same level as class , interface , etc.
Annotations are a way of adding additional information beyond what the source code con-
veys. Annotations may be directed at the compiler or at runtime examination. Their syntax
was somewhat patterned after javadoc annotations (such as @author , @version inside “doc
comments”). Annotations are what I call class-like things (so they have initial-cap names),
but are prefixed by @ sign where used (e.g., @Override ). You can place them on classes,
methods, fields, and a few other places; they must appear immediately before what they an-
notate (ignoring space and comments). A given annotation may only appear once in a given
position (this is relaxed in Java 8 or 9).
Search WWH ::

Custom Search