[英]Running a java program on command prompt
I have recently started learning the basics of Java programming language. 我最近开始学习Java编程语言的基础知识。 To run my program at the command prompt, I downloaded the java development kit also known as JDK, and I set my windows 10 system path to: 为了在命令提示符下运行我的程序,我下载了Java开发工具包,也称为JDK,并将我的windows 10系统路径设置为:
C:\\Program Files\\Java\\jdk-9.0.1\\bin;C:\\Program Files\\Java\\jre-9.0.1\\bin C:\\ Program Files \\ Java \\ jdk-9.0.1 \\ bin; C:\\ Program Files \\ Java \\ jre-9.0.1 \\ bin
After writing a simple Hello World program with the following format: 用以下格式编写简单的Hello World程序之后:
class test{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
and running it on command prompt using 并使用命令提示符运行它
javac test.java javac test.java
, and then writing ,然后写
java test java测试
the output says: 输出说:
Error: Main method is not static in class test, please define the main method as: 错误:主类方法在类测试中不是静态的,请将主方法定义为:
public static void main(String[] args) public static void main(String [] args)
I have tried compiling my simple program on an online Java compiler and everything works fine. 我试过在在线Java编译器上编译我的简单程序,一切正常。
As suggested using a Java decompiler. 正如使用Java反编译器所建议的那样。 I used http://www.javadecompilers.com/result and the output was: 我使用了http://www.javadecompilers.com/result ,输出结果如下:
import java.io.PrintStream;
public class test {
public test() {} public void main(String[] paramArrayOfString) {
System.out.println("Hello World!");
}
}
Where is the problem coming from? 问题来自哪里? How can I fix it? 我该如何解决?
I was using "Sublime Text 3" when writing and saving my test.java program. 在编写和保存我的test.java程序时,我使用的是“Sublime Text 3”。 @Silvio Mayolo suggested using a java decompiler to find out the problem, and I noticed that when saving my program in Sublime, the static gets deleted in test.java file for some reason. @Silvio Mayolo建议使用java反编译器找出问题,我注意到在Sublime中保存我的程序时,由于某种原因,静态会在test.java文件中被删除。 Then I did the following steps: 然后我做了以下步骤:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.