package keyword in java

The "package" keyword specifies the Java package in which the classes declared in a Java source file reside.

  1. package;
  3. public class MyCompanyService {
  4. }
public class MyCompanyService {

In the above example, the source file must be placed under the package /com/mycompany/services

Rules regarding the package statement

A source file can be placed under a specific package or default package.

The package statement (if specified) must be the first line in the source file.

Package name must follow the pattern: level1.leve2.level3….leveln
level1.leve2.level3….leveln are the sub packages in the same order.

If a Java source file does not contain a package statement, the classes defined in the file are in the default package.

Note that classes in the default package can not be referenced from classes in non−default packages.

In the example above, the fully−qualified class name of the MyCompanyService class is

About the Author

Karibasappa G C (KB)
Founder of
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to

Connect with me on Facebook for more updates

Share this article on