I have this simple code:
public class HelloWorld{
public static void main(String[] args){
System.out.println(\"HelloWorld\");
}
}
try:
java -cp "C:\WhatEverDirectoryYourFileIsIn" HelloWorld
You could get this behaviour if you have an incorrect / inappropriate setting of the CLASSPATH environment variable; e.g. the current directory isn't on the classpath. (It is by default ... )
Try this:
java -classpath . HelloWorld
Assuming that works ... the problem is your understanding of the concept of the "classpath". This is explained well by the Oracle documentation:
In CMD, instead of typing:
java HelloWorld
Try typing:
java HelloWorld.class