SCJP Sun Certified Programmer for Java 5 Study Guide (Exam 310-055) (Certification Press)

Here are the key points from this chapter.

Using javac and java (Objective 7.2)

q  

Use -d to change the destination of a class file when it's first generated by the javac command.

q  

The -d option can build package-dependent destination classes on-the-fly if the root package directory already exists.

q  

Use the -D option in conjunction with the java command when you want to set a system property.

q  

System properties consist of name=value pairs that must be appended directly behind the -D, for example, Java -Dmyproperty=myvalue.

q  

Command-line arguments are always treated as Strings.

q  

The java command-line argument 1 is put into array element 0, argument 2 is put into element 1, and so on.

Searching with java and javac (Objective 7.5)

q  

Both java and javac use the same algorithms to search for classes.

q  

Searching begins in the locations that contain the classes that come standard with J2SE.

q  

Users can define secondary search locations using classpaths.

q  

Default classpaths can be defined by using OS environment variables.

q  

A classpath can be declared at the command line, and it overrides the default classpath.

q  

A single classpath can define many different search locations.

q  

In Unix classpaths, forward slashes (/) are used to separate the directories that make up a path. In Windows, backslashes (\) are used.

q  

In Unix, colons (:) are used to separate the paths within a classpath. In Windows, semicolons (;) are used.

q  

In a classpath, to specify the current directory as a search location, use a dot (.)

q  

In a classpath, once a class is found, searching stops, so the order of locations to search is important.

Packages and Searching (Objective 7.5)

q  

When a class is put into a package, its fully qualified name must be used.

q  

An import statement provides an alias to a class's fully qualified name.

q  

In order for a class to be located, its fully qualified name must have a tight relationship with the directory structure in which it resides.

q  

A classpath can contain both relative and absolute paths.

q  

An absolute path starts with a / or a \.

q  

Only the final directory in a given path will be searched.

JAR Files (Objective 7.5)

q  

An entire directory tree structure can be archived in a single JAR file.

q  

JAR files can be searched by java and javac.

q  

When you include a JAR file in a classpath, you must include not only the directory in which the JAR file is located, but the name of the JAR file too.

q  

For testing purposes, you can put JAR files into .../jre/lib/ext, which is somewhere inside the Java directory tree on your machine.

Static Imports (Objective 7.1)

q  

You must start a static import statement like this: import static

q  

You can use static imports to create shortcuts for static members (static variables, constants, and methods) of any class.

Категории