Problem description:
Compile a simple Hello. java program and use the javac Hello. java command in the cmd command line to compile the program. The Hello. class file can be generated. However, after you enter the java Hello command (the file directory is the same as the command directory), the error message "cannot be found or the main class cannot be loaded" is displayed ". Solution: Find the cause and solution from the Internet, and refer to the Environment Variable classpath setting problem, but the problem still persists after multiple attempts. Run java-cp % classpath; Hello. The result is correct. Use echo % classpath % or set classpath to view the classpath environment variable value. It is found that only the classpath value in the current user variable is displayed, rather than the classpath value in the system variable. Solution 1: add the classpath value in the system variable to the user variable and execute java Hello! Use java-cp % classpath; Hello to execute, still correct! Solution 2: add the classpath value in the system variable to display the current path strength, for example, the difference between searching for user variables and system variables online. The user variables are used by the current user, if you log on with another user, this environment variable does not work (private ). System variables are available to all users (public ). But I still don't know why?