Do I need to set classpath when configuring the Java environment variable?

do I need to set classpath when configuring the Java environment variable?


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