Does windows10 need to set classpath when configuring the Java environment variable?

some of the tutorials I saw online set classpath, but did not set classpath in the actual configuration. Will not setting classpath affect the use of Java?

Jan.19,2022

what you are looking at are all old and outdated materials, one by one without verification at all. In fact, the CLASSPATH environment variable has not been set for eight lifetimes, and it is not officially recommended. Incorrect environment variables can lead to unexpected error results.

refer to the description of this environment variable in the official documentation: https://docs.oracle.com/javas.

pay special attention to this:

The preferred way to specify the class path is by using the -cp command line switch. This allows the CLASSPATH to be set individually for each application without affecting other applications. Setting the CLASSPATH can be tricky and should be performed with care.

win10 do not need


1. Why configure classpath? By default, when you run (with the java command) a bytecode file (.class), look for it in the current directory, and execute it if you find the running bytecode file, otherwise an error will be reported. In order to run this bytecode file in any directory, you need to configure classpath.
2. Why is it not recommended to configure classpath? When you configure classpath, you run the java command in a directory, and the computer looks for a bytecode file (.class) that matches the name in the directory you set when you configure classpath, and runs it (otherwise an error is reported). However, if you compile a bytecode file with a duplicate name in another directory, the computer will still look for the bytecode file with the same name from the directory you set when you configured classpath. At this time, you will run the bytecode file in the directory you originally set up instead of the bytecode file with the same name you compiled last.
3. Video description: ideo/av33686176/?p=21" rel=" nofollow noreferrer "> https://www.bilibili.com/vide.

Menu