简体   繁体   English

如何运行一个简单的Java程序

[英]How to Run a Simple Java Program

I dad left Java since so long as a result now it happens that sometimes I forget the simple things and used to behave like a Stupid. 我父亲离开了Java,因为直到现在这样的结果是,有时我忘记了简单的事情并且过去表现得像个笨蛋。

To run a Simple Java program say "Hello World" written in Notepad what do I have to Do? 要运行简单Java程序,请说用记事本编写的“ Hello World”,我该怎么办?

I know the commands javac "Filename.java" and java "Filename" respectively to run it from the Command prompt. 我知道分别从命令提示符下运行命令javac“ Filename.java”和java“ Filename”的命令。

But When I try to do that I got this message: 但是当我尝试这样做时,我收到了以下消息:

"javac is not recognized as an internal or external command, operable program or batch file." “ javac不被识别为内部或外部命令,可操作程序或批处理文件。”

and I could not Complie the file. 而且我无法编译文件。

I hava little idea that we need to do some stuffs like setting the classpath or perhaps the path evnironment variables but it was exactly that I don't remember. 我几乎不知道我们需要做一些事情,例如设置类路径或可能是路径环境变量,但这确实是我不记得了。

Can anybody please help me? 有人可以帮我吗?

Thanks, david 谢谢大卫

  1. Add a JAVA_HOME env variable to point to the jdk installation directory 添加一个JAVA_HOME env变量以指向jdk安装目录
  2. To your PATH env variable, add %JAVA_HOME%\\bin 在您的PATH env变量中,添加%JAVA_HOME%\\bin
  3. Add a CLASSPATH env variable to point to %JAVA_HOME%\\lib . 添加CLASSPATH env变量以指向%JAVA_HOME%\\lib
  4. remember to open a new console window and try running javac and java - everything should be fine now. 记住要打开一个新的控制台窗口并尝试运行javacjava现在一切都很好。

1) create JAVA_HOME environmental variable set value to java home directory 1)创建JAVA_HOME环境变量设置值到java主目录

eg c:\\program files\\java\\jdk1.5; 例如c:\\program files\\java\\jdk1.5;

1) set PATH in environmental variable to your java bin directory 1)将环境变量中的PATH设置为您的Java bin目录

eg %JAVA_HOME%\\bin 例如%JAVA_HOME%\\bin

and to check classpath is set correctly run javac command on cmd 并检查是否正确设置了classpath在cmd上运行javac命令

and this link will help to create and run simple java application java tutorial 并且此链接将有助于创建和运行简单的Java应用程序Java教程

您需要JDK才能运行javac。

I suggest you first start coding in eclipse, it provides all the environment set up for you. 我建议您首先在eclipse中开始编码,它为您提供了所有设置的环境。 Once you get good with coding, you can try command prompt compiling and running. 一旦熟悉了编码,就可以尝试命令提示符进行编译和运行。 That way, you will be confident with language first and then go into the nitty-gritties of the environment and set up. 这样,您将首先对语言充满信心,然后进入环境的精妙环境并进行设置。

Its better to use any java IDE either eclipse or netBeans Download Link But in case if you like to go through Command prompt method, then u need to set the paths. 最好使用任何Java IDE eclipse或netBeans 下载链接。但是,如果您希望通过Command提示方法,则需要设置路径。 (These are the variables for your OS, that used to know where your commands eg java or javac etc are located). (这些是您的OS的变量,用于了解您的命令(例如java或javac等)的位置)。 Hope from other answers you set the paths. 希望从其他答案中您能设定路径。

Good luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM