Course Content
Core Java
About Lesson

The Java compiler relies on a specific naming convention to locate and compile classes correctly.

For a source file containing a public class, the filename must match the name of the public class exactly, including case sensitivity. This convention is crucial for the Java compiler to locate and compile the class correctly.

So a Java source file can contain at most one public class, and the name of that class must match the filename exactly.

In addition to the public class, a Java source file can contain any number of non-public classes. These non-public classes can be non-public top level classes, inner classes, or nested classes. They do not have any specific naming requirements and can have any valid Java identifier as their name.

Scroll to Top