简体   繁体   English

从Java开始的问题

[英]Issue starting out with java

I got a problem starting out with java. 我从Java开始遇到问题。

I set my path as 我将路径设置为

C:\\Program Files\\Java\\jdk1.8.0_102\\bin C:\\ Program Files \\ Java \\ jdk1.8.0_102 \\ bin

and made the basic Hello.java notepad file. 并制作了基本的Hello.java记事本文件。 The problem is when I try to compile using: 问题是当我尝试使用以下命令进行编译时:

C:\>javac

I get an error: 我收到一个错误:

C:\\ is not recognized as an internal or external command, operable program or batch file. C:\\无法识别为内部或外部命令,可操作程序或批处理文件。

What did I do wrong/What may be the cause of this? 我做错了什么/可能是什么原因造成的?

The reason CMD gives that error is because you wrote C:> in the command, and that is unnecessary. CMD给出该错误的原因是因为您在命令中编写了C:> ,这是不必要的。

You simply need to write 您只需要写

javac Hello.java

And that compiles the file. 然后编译文件。 When your CMD directory is that of the file. 当您的CMD目录是文件的目录时。 After compiling, run 编译后,运行

java Hello

To run it 运行它

To start with, please, check, that java has been installed properly by typing in cmd: 首先,请输入cmd来检查Java是否已正确安装:

java -version

Then, to compile some source file you need to provide this file as a parameter to java compiler. 然后,要编译某些源文件,您需要将此文件作为参数提供给java编译器。 Like this: 像这样:

javac Hello.java  

After that, you should get your code compiled and Hello.class file should appear. 之后,您应该编译代码并出现Hello.class文件。

At first try to set java home from your command prompt like this - 首先,尝试从命令提示符设置Java主目录,如下所示:

set CLASSPATH=C:\Program Files\Java\jdk1.8.0_102\bin

Then from terminal try to check whether it is installed properly, using - 然后从终端尝试使用-检查它是否正确安装。

java -version 

If everything is correct then you would see message like this - 如果一切正确,那么您会看到以下消息-

java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

Then you should set JAVA_HOME and PATH at your computer using this link 然后,您应该使用此链接在计算机上设置JAVA_HOME和PATH

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

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