Java Language Mapping classnames to pathnames


Example

The standard Java toolchain (and 3rd-party tools designed to interoperate with them) have specific rules for mapping the names of classes to the pathnames of files and other resources that represent them.

The mappings are as follows

  • For classes in the default package, the pathnames are simple filenames.
  • For classes in a named package, the package name components map to directories.
  • For named nested and inner classes, the filename component is formed by joining the class names with a $ character.
  • For anonymous inner classes, numbers are used in place of names.

This is illustrated in the following table:

ClassnameSource pathnameClassfile pathname
SomeClassSomeClass.javaSomeClass.class
com.example.SomeClasscom/example/SomeClass.javacom/example/SomeClass.class
SomeClass.Inner(in SomeClass.java )SomeClass$Inner.class
SomeClass anon inner classes(in SomeClass.java )SomeClass$1.class, SomeClass$2.class, etc