Error: the main class usertest could not be found or loaded

This class has a specified package

An error occurred when running java test from the command line: the main class usertest could not be found or loaded

    first of all, the user test needs to compile
    the command, such as the folder where the user test.java is located, executes javac user test.java to compile. After compiling, the user test.class file appears in the directory where the user test.java is located, and then it can be run on the command line<

    runs the usertest.class file through the Java command
    first, let’s see what the package name written after the package of the class usertest.java is. My name is com.bean

    when I run Java usertest in the bean directory, I report an error: can't find or load the main class usertest

    later, I see that someone says Java com.bean.usertest can run, and it really can run after a try. But Java usertest can’t run. Later, it is found that this class has a specified package

This class does not specify a package

1. Use javac usertest. Java to compile our. Java file

2. If the java file does not specify a package, just use the Java command to run our class file (Java usertest)

Read More: