What’s the default classpath when not specifying classpath?

The current working directory (.).

From The Java™ tutorials: PATH and CLASSPATH:

The default value of the class path is “.”, meaning that only the current directory is searched. Specifying either the CLASSPATH variable or the -cp command line switch overrides this value.

Does this include subdirectories?

No, no entry in the classpath is “recursive”. You have to list each subdirectory (or jar) explicitly. However, if you have an Example.class file representing class pkg.subpkg.Example, and the default classpath is used, then this file should live in ./pkg/subpkg/Example.class.

If java attempts to resolve pkg.subpkg.Example it will look in /pkg/subpkg of each classpath entry. I.e. you do not have to list ., pkg, and pkg/subpkg in the classpath, only ..

Leave a Comment