undcemcs02> # Create the file.
undcemcs02> emacs MyPackageClass.java
undcemcs02> # List the file contents.
undcemcs02> cat MyPackageClass.java
package mypack;
class MyPackageClass {
public static void main( String[ ] args ) {
System.out.println( "This is my package!" );
}
}
undcemcs02> # Compile the file.
undcemcs02> javac MyPackageClass.java
undcemcs02> # Compile the packages.
undcemcs02> javac -d . MyPackageClass.java
undcemcs02> # This forces the compiler to create the "mypack" package.
undcemcs02> # The -d keyword specifies the destination for where to
undcemcs02> # save the class file.
undcemcs02> # You can use any directory name, like c:/user (windows), or
undcemcs02> # if you want to keep the package within the same directory,
undcemcs02> # you can use the dot sign ".", like in the example above.
undcemcs02> # Note: The package name should be written in lower case to
undcemcs02> # avoid conflict with class names.
undcemcs02> ls
mypack/ MyPackageClass.class MyPackageClass.java
undcemcs02> ls mypack/
MyPackageClass.class
undcemcs02> # When we compiled the package in the example above, a new
undcemcs02> # folder was created, called "mypack".
undcemcs02> # To run the MyPackageClass.java file, write the following:
undcemcs02> java mypack/MyPackageClass
This is my package!
|