Java Reference
In-Depth Information
6. Write a class named TestProgram that contains main(). The first
command-line argument (args[0]) is going to be the String to be
tested, and the second command-line argument (args[1]) is going to
be the double to be tested. Use the Double.parseDouble() method to
parse the second command-line argument into a double.
7. Within main(), assign the maxStringLength field of FormatTest to 12
and the minSize field to 100.00.
8. Invoke the testStringLength() and testDouble() methods, passing in
the corresponding command-line argument. Display the result.
9. Save, compile, and run the TestProgram class several times, making
sure that everything is working correctly.
If you enter a String for args[0] that is longer than 12 characters, the
result of testStringLength() should be false. If args[1] is a double that is
smaller than 100.00, the result of testDouble() should be false.
Summary
Every class belongs to a package. The package keyword is used to
declare a class within a package, and the package declaration must be
the first statement in a .java source file. If a class is not declared within
a package, then the class appears in the default package.
■■
A package creates a namespace. The package name becomes a part of
the class name.
■■
The import keyword is used to import a package into a source file.
Importing a package allows you to use a class from that package with-
out prefixing the package name to the class name. The java.lang pack-
age is implicitly imported into each source file.
■■
The .class file for a class must appear in a directory structure that
matches the package name that the class is declared in. You can use the
-d flag of the javac tool to have the compiler generate these folders for
you automatically.
■■
The compiler and JVM use the CLASSPATH environment variable to
determine where to look for bytecode.
■■
There are four levels of access in Java that can be applied to the fields
and methods of a class: public, protected, private, and default.
■■
Search WWH ::




Custom Search