The java <class-name> command syntax is one of the ways in which the problem of programs failing to run with the error message can be rectified. At the start, you need to understand the right way to launch a program using a Java command and the normal syntax used is shown below:-
java [ <options> ] <class-name> [<arg> ...]
In which, the <option> is a command line option which starts with a "-" character, following which <class-name> is a fully qualified Java class name, and <arg> is a given command line argument that gets passed to your application.
The fully qualified name or FQN for the class is written as you would in your Java source code in a conventional manner. For e.g:-
However, some versions of the java command allow you to use slashes instead of periods. For e.g:-
This will initially confuse you and look like a file pathname, but that is not the case here. Please Note that the term fully qualified name is a basic standard in the Java terminology.
Here is a given example of what a java command should look like:
java -Xmx100m com.acme.example.ListUsers fred joe bert
The above Java command will browse for the compiled version of the com.acme.example.ListUsers class. After the class is loaded, check and search if there is any method starting with a signature, return type and modifiers which are given by public static void main(String). One must also keep in mind that the name of the method’s argument is NOT part of the signature. The method must be passed to the command line arguments ("fred", "joe", "bert") as mentioned in the above line of code as a String.