What commands are you executing at the command prompt which give that result? It sounds like you forgot to compile before running, but that is just one possibility.
The HelloWorldApp class implements an application that
simply prints “Hello World!” to standard output. /
import java.lang.;
class HelloWorldApp {
public static void main(String args) {
System.out.println(“Hello World!”); // Display the string.
}
}
I have created to 2 paths in an environment variable
System
CLASS_PATH = C:\Program Files\Java\jdk-19\lib*.jar
JAVA_HOME = C:\Program Files\Java\jdk-19
User and System
PATH = C:\Program Files\Java\jdk-19\bin
I don’t know how to target to a current working file
/*
The HelloWorldApp class implements an application that
simply prints “Hello World!” to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println(“Hello World!”); // Display the string.
}
}
I think the error in your code comes from the comment at the top, the comment does not close correctly
After removing the comments, I run the code java HelloWorld.java I got the result, but if I compile the code and run the code java HelloWorld or java HelloWorld.class it gives me the error. Below is the command line
Z:\COMP501\application>java HelloWorldApp.class
Error: Could not find or load main class HelloWorldApp.class
Caused by: java.lang.ClassNotFoundException: HelloWorldApp.class
Z:\COMP501\application>java HelloWorldApp
Error: Could not find or load main class HelloWorldApp
Caused by: java.lang.ClassNotFoundException: HelloWorldApp
This sequence of events has got me scratching my head. The first one looks correct for compiling the class (and should produce the HelloWorldApp.class file with the Java bytecode). The second one in that sequence should not work, but does for some strange reason. The third one is not supposed to work (and does not, so that is working as intended). The last one is what should work for running the code in the class file and the fact that it does not is very surprising and confusing.
Z:\COMP501\application>java HelloWorldApp
Error: Could not find or load main class HelloWorldApp
Caused by: java.lang.ClassNotFoundException: HelloWorldApp