Wondering what will be the default classpath when not specifying classpath option?
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 .
.
cd
'ed into. If your Windows shell says C:\dir\subdir>
then the current working directory is C:\dir\subdir
(or on *nix, if your prompt says something like user@machine:/usr/bin$
then the current working directory is /usr/bin
). –
Huggermugger I think people are answering this person's question too literally. Yes, CLASSPATH defaults to ".", but there are a bunch of classes that automatically get loaded even when you don't set CLASSPATH or use the -classpath command line argument.
The following is a good place to learn about this process:
http://docs.oracle.com/javase/8/docs/technotes/tools/findingclasses.html
It is the current Working directory "."
You can check it out your self too
class CheckClassPath{
public static void main(String args[]){
System.out.println(System.getProperty("java.class.path"));
}
}
The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings. official manual
© 2022 - 2024 — McMap. All rights reserved.
-classpath
flag. – Punic