简体   繁体   English

从命令提示符编译 java 及其问题

[英]compiling java from command prompt and its issues

i'm very new to java and only started working two days ago... i decided to work it through command line rather than IDE.. and it gave issues they are我对 Java 很陌生,两天前才开始工作......我决定通过命令行而不是 IDE 来工作......它给了他们一些问题

while setting up path variable...在设置路径变量时...

1)what exactly is PATH variable i got away from it by command "set path=%path%;C:\\Program Files\\Java\\jdk1.8.0_45\\bin" and i don't know what i did could u explain it in layman terms 1)PATH变量究竟是什么我通过命令“set path=%path%;C:\\Program Files\\Java\\jdk1.8.0_45\\bin”摆脱了它,我不知道我做了什么你能解释一下通俗地说

mean while ,in searching solution for PATH variable i found there is another variable called CLASSPATH variable..意思是,在搜索 PATH 变量的解决方案时,我发现还有一个名为 CLASSPATH 变量的变量..

2)so what is CLASSPATH variable do need to find solution for that too.. 2)那么什么是 CLASSPATH 变量也需要为此找到解决方案..

after setting up just PATH variable i compiled program and it got following errors..仅设置 PATH 变量后,我编译程序并出现以下错误..

3)could explain what are the following errors and correct me 3)可以解释以下错误并纠正我

meanwhile my encounter with files in 'java' i found out there are jdk and jre and my question is与此同时,我遇到了“java”中的文件,我发现有jdkjre ,我的问题是

4)why do we choose only 'jdk' while setting up path variable 4)为什么我们在设置路径变量时只选择'jdk'

i have read differences between jdk and jre but i didn't understand it clearly they said that我已经阅读了 jdk 和 jre 之间的差异,但我没有清楚地理解他们说的

" jre doesn't have compiler " and even though we can run our programs and i didn't get it.. explain me that too.. “ jre 没有编译器”,即使我们可以运行我们的程序,但我没有得到它.. 也向我解释一下..

thanks in advance....提前致谢....

在此处输入图片说明

1)what exactly is PATH variable 1)到底什么是PATH变量

The PATH variable is a Windows system variable that tells Windows where to look when you enter a command without path information. PATH变量是 Windows 系统变量,当您输入没有路径信息的命令时,它会告诉 Windows 在哪里查看。 So entering "java.exe" can work from anywhere when you enter it at a command prompt if you have the full path to it in the PATH variable.因此,如果您在PATH变量中有完整路径,那么当您在命令提示符下输入“java.exe”时,它可以在任何地方工作。 Read the following page about how the PATH and CLASSPATH are used in Java.阅读以下页面,了解如何在 Java 中使用PATHCLASSPATH

2)so what is CLASSPATH variable 2)什么是CLASSPATH变量

I'm not sure since you don't give any context, but I think you are referring to the Java Virtual Machine's (JVM) variable that tells the JVM where to look for classes and resources.我不确定,因为您没有提供任何上下文,但我认为您指的是 Java 虚拟机 (JVM) 变量,它告诉 JVM 在哪里查找类和资源。

3)could explain what are the following errors and correct me 3)可以解释以下错误并纠正我

If you mean the compile error in the screen shot, the error is because you did not use the proper name System .如果您的意思是屏幕截图中的编译错误,则错误是因为您没有使用正确的名称System Java is case sensitive. Java 区分大小写。 There is no object called system .没有名为system对象。

4)why do we choose only 'jdk' while setting up path variable 4)为什么我们在设置路径变量时只选择'jdk'

Some definitions:一些定义:

  • JRE = Java Runtime Environment. JRE = Java 运行时环境。 Bare minimum binaries and libraries for running the core Java classes.用于运行核心 Java 类的最少二进制文件和库。
  • JDK = Java Development Kit. JDK = Java 开发工具包。 It contains all core binaries and libraries needed to do basic developement (javac, jar, etc).它包含进行基本开发所需的所有核心二进制文件和库(javac、jar 等)。 A JDK includes a JRE. JDK 包括 JRE。
  • JVM = Java Virtual Machine. JVM = Java 虚拟机。 The runtime (java.exe) that executes Java code.执行 Java 代码的运行时 (java.exe)。

在字符串中 S 必须是大写,在 System.out.println 中 S 必须是大写

1)what exactly is PATH variable 1)到底什么是PATH变量

PATH is an environment variable specifying a set of directories where executable programs are located, so if you sent a command that is the name of a executable, your OS will search those dirs for the program to run PATH 是一个环境变量,指定了一组可执行程序所在的目录,因此如果您发送了一个可执行文件名称的命令,您的操作系统将搜索这些目录以运行程序

2)so what is CLASSPATH variable do need to find solution for that too.. 2)那么什么是 CLASSPATH 变量也需要为此找到解决方案..

This is where java looks for the class files.这是java查找类文件的地方。 Usually specified by .cp cmd line argument通常由 .cp cmd 行参数指定

3)could explain what are the following errors and correct me 3)可以解释以下错误并纠正我

My guess is "system.out.println()" should be "System.out.println()"我的猜测是“system.out.println()”应该是“System.out.println()”

4)why do we choose only 'jdk' while setting up path variable 4)为什么我们在设置路径变量时只选择'jdk'

JDK has a compiler. JDK 有一个编译器。 Compiler turns your source code .java into .class files which the computer (running the JVM) can actually understand.编译器将您的源代码 .java 转换为计算机(运行 JVM)可以实际理解的 .class 文件。 JRE is good enough if you only want to run the programs, but you need a JDK to compile them from source code.如果您只想运行程序,JRE 就足够了,但是您需要一个 JDK 来从源代码编译它们。

1) PATH is the environment variable that says where to look for commands that you enter on the command line. 1) PATH 是环境变量,表示在哪里查找您在命令行中输入的命令。 If you type the command "java" at the command prompt, the OS will search in each directory listed in PATH, in order, until it finds an executable named "java" (for example, java.exe or java.cmd).如果在命令提示符下键入命令“java”,操作系统将在 PATH 中列出的每个目录中依次搜索,直到找到名为“java”的可执行文件(例如,java.exe 或 java.cmd)。 If PATH were empty, the OS would only look in the current directory.如果 PATH 为空,操作系统将只在当前目录中查找。

2) CLASSPATH is where the JVM will search for Java library files (.jar files) at both compile time and at run time. 2) CLASSPATH 是 JVM 在编译时和运行时搜索 Java 库文件(.jar 文件)的地方。 It should be set to something like c:\\jdk\\lib (where "jdk" is where you installed the JDK).它应该设置为类似于 c:\\jdk\\lib(其中“jdk”是您安装 JDK 的位置)。

3) In your screenshot, it looks like your code is lowercase where it should be uppercase: change string --> String and system --> System 3)在您的屏幕截图中,您的代码似乎是小写的,而应该是大写的:更改字符串--> 字符串和系统--> 系统

4) The JDK is the Java Developer's kit, used when you are developing Java programs. 4) JDK 是Java Developer's kit,在开发Java 程序时使用。 JRE is the runtime environment, needed by anyone who will run Java programs. JRE 是任何运行 Java 程序的人都需要的运行时环境。 The JDK usually contains the JRE, but if someone who is not developing can just use the JRE. JDK 通常包含 JRE,但如果不是开发人员可以直接使用 JRE。

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

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