无法在Windows上运行Hello World Java程序

时间:2019-06-02 21:20:23

标签: java windows

public class Main {
    public static void main(String[] args) {
        //Set your print into the console
        System.out.println("Hello World");
    }
}

我曾尝试通过命令提示符(cmd.exe)执行该程序,但它一直在输出错误。

我希望与世界打招呼,但我得到:

Error: could not find or load main class MyClass.java

1 个答案:

答案 0 :(得分:0)

由于您几乎没有提供任何信息,所以很难说出错误在哪里。

这是将打印“ Hello World”的代码

public class Main {
    //Class name is irrelevent, but it must be the same as the filename

    //Define a main method, it HAS to be public, static and called 'main' and should     
    //receive a String array and return void (just copy the next row)
    public static void main(String[] args) {
        //Set your print into the console
        System.out.println("Hello World");
    }

}

现在通过在终端中输入来编译文件:

javac <the path to your .java file>

然后:

java <classname (here Main)>