As @JonSkeet pointed out, and as I checked myself as well, your code should work fine.
Perhaps it is something wrong with your classpath; as indicated by @StephenC and @g00se in their comments, you can try running your program by explicitly including the current directory as your class path by providing the -cp
flag:
F:\DMP>java -cp . test.HelloWorld
As an alternative, you can try a different approach and try defining your file structure according to your java package - it's always good practice to do so and it can help you avoid some mistakes.
I mean, if you placed your class in the test
package:
package test;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Your folder structure can look like:
test/
HelloWorld.java
Equivalently:
F:\DMP\test\HelloWorld.java
Then, compile your code like this:
F:\DMP>javac test\HelloWorld.java
You should be able to run your program like this:
F:\DMP>java test.HelloWorld