In Java, the package keyword is used to specify a directory structure to which the current source file must belong. For example:

package com.mycompany.code;

public class MyClass {
}

In the above example, the source file MyClass.java must be placed under the directory /com/mycompany/code

Here are some rules regarding the package statement:

    • a source file can be put under a package or not.
    • the package statement (if specified) must be the first line in the source file.
    • package name must follow the pattern: level1.leve2.level3....leveln

 

Related keyword: import. See all keywords in Java.

 

Related Topics:

 

Other Recommended Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment