I write a simple program using java language, then try to compile and run it on Windows console, the compile is ok, but when I try to run it with command line '>java HelloWorld', the console reports 'Error: Could not find or load main class', this is my code(c:\Sample\HelloWorld.java) as below:
package com.sample.test;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
If I comment out the line "package com.sample.test", try the compile and run command lines again, everything is ok, I can't understand why. Here is the environment variables in my computer:
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
Path=%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
CLASSPATH=.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar
My question is if I still want to reserve the package declaration, how can I run my program?