.class 与 .java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1015340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.class vs .java
提问by Devoted
What's the difference between a .class file and a .java file? I am trying to get my applet to work but currently I can only run it in Eclipse, I can't yet embed in HTML. Thanks
.class 文件和 .java 文件有什么区别?我试图让我的小程序工作,但目前我只能在 Eclipse 中运行它,我还不能嵌入 HTML。谢谢
**Edit: How to compile with JVM then?
**编辑:那么如何用 JVM 编译?
采纳答案by Brian
A .class file is a compiled .java file.
.class 文件是编译后的 .java 文件。
.java is all text and is human readable.
.class is binary (usually).
.java 都是文本,是人类可读的。
.class 是二进制的(通常)。
You compile a java file into a class file by going to the command line, navigating to the .java file, and running
通过转到命令行,导航到 .java 文件,然后运行,将 java 文件编译为类文件
javac "c:\the\path\to\your\file\yourFileName.java"
You must have a java SDK installed on your computer (get it from Oracle), and make sure the javac.exe file is locatable in your computer's PATH environment variable.
您的计算机上必须安装了 java SDK(从Oracle获取),并确保 javac.exe 文件可在计算机的 PATH 环境变量中找到。
Also, check out Java's Lesson 1: Compiling & Running a Simple Program
另外,请查看 Java 的第 1 课:编译和运行简单程序
If any of this is unclear, please comment on this response and I can help out :)
如果有任何不清楚的地方,请对此回复发表评论,我可以提供帮助:)
回答by dfa
- .class -> compiled (for JVM)
- .java -> source (for humans)
- .class -> 已编译(用于 JVM)
- .java -> 源代码(用于人类)
回答by Malcolm
.java files are source files, while .class files are compiled (bytecode) classes.
.java 文件是源文件,而 .class 文件是编译(字节码)类。
Use javac (http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html) to compile source into bytocode.
使用 javac ( http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html) 将源代码编译为 bytocode。
回答by Mark
A .java file contains your Java source code while a .class file contains the Java bytecode produced by the Java compiler. It is your .class files that run on the JVM to execute a Java application.
.java 文件包含 Java 源代码,而 .class 文件包含 Java 编译器生成的 Java 字节码。您的 .class 文件在 JVM 上运行以执行 Java 应用程序。
It is the .class files you will use when you deploy your applet.
它是您在部署小程序时将使用的 .class 文件。
回答by Eric
.java usually holds your code in clear text
.java 通常以明文形式保存您的代码
.class contains the byte code of your .java. Think of it as a compiled version of the .java file
.class 包含你的 .java 的字节码。将其视为 .java 文件的编译版本
回答by Soufiane Barakat
person can be defined as a class Person. This class should reside in a Java source code file (Person.java). Using this Java source code file, the Java compiler (javac.exe on Windows or javac on Mac OS X/Linux/UNIX) generates bytecode (compiled code for the Java Virtual Machine) and stores it in Person.class.
人可以定义为类人。此类应驻留在 Java 源代码文件 (Person.java) 中。使用此 Java 源代码文件,Java 编译器(Windows 上的 javac.exe 或 Mac OS X/Linux/UNIX 上的 javac)生成字节码(Java 虚拟机的编译代码)并将其存储在 Person.class 中。
回答by Dattatreyo Paul
Java files is an human readable language (for example, the code we write in Eclipse/any other IDE).
Java 文件是一种人类可读的语言(例如,我们在 Eclipse/任何其他 IDE 中编写的代码)。
Class files are in byte-code compiled for Java Virtual Machine (JVM).
类文件是为 Java 虚拟机 (JVM) 编译的字节码。