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 started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment