Java 代码的正确执行顺序是什么
What is the Correct Order Of Execution of a Java Code
我们在关于 java 代码执行的测试中遇到了这个问题:-
Select java 代码执行的正确顺序
a) Class 装载机
b) 解释
c) 编译
d) 字节码验证
e) Java 源代码
f) 执行
选项:-
- e-a-c-b-d-f
- e-a-b-c-d-f
- e-b-a-c-b-f
- e-c-a-d-b-f
我将选项 4 标记为我的选择。我不知道确切的原因,但我觉得那个最好。
结果说我回答错了。 T_T
谁能告诉我正确答案是什么以及为什么。
(大学声称的正确答案是选项 3)
(并且在给这个 post link 之后,大学更正了选项 4 的解决方案)
(看完大家的评论和解决方案,对执行过程有了更深入的了解,而不是仅仅解决一个愚蠢的故障MCQ......伟大的社区)。
正确顺序是 e-c-a-d-b-f,所以正确答案是 4.
其他三个答案可以证明是错误的,因为这三个答案在 c) 之前都有 a),但你根本不可能有 a) Class Loader 在 c) Compilation 步骤之前生成 Class Loader 应该加载的字节码.
┌──────────────────────────────────┐
│ e) Java Source Code (.java file) │ Obvious starting point
└──────────────────────────────────┘
↓
┌────────────────────────────────┐
│ c) Compilation (javac command) │
└────────────────────────────────┘ Then we compile the source code
↓ to byte code.
┌────────────────────────┐
│ Bytecode (.class file) │
└────────────────────────┘
↓
┌─────────────────┐ The classloader is responsible for
┌──────┤ a) Class Loader ├─ JVM ┐ locating the byte code and making it
│ └─────────────────┘ │ available to the JVM as a byte array
│ ↓ │
│ ┌───────────────────────────┐ │ In the linking phase of preparing a
│ │ d) Byte Code Verification │ │ class for use, the byte code is
│ └───────────────────────────┘ │ verified by the JVM.
│ ↓ │
│ ┌───────────────────┐ │
│ │ b) Interpretation │ │ This one is a bit iffy, but you can
│ └───────────────────┘ │ argue that the byte code is interpreted
│ ↓ │ before it is executed, but the JVM
│ ┌──────────────┐ │ could easily JIT-compile to native
│ │ f) Execution │ │ code without ever executing the code
│ └──────────────┘ │ in interpretation mode.
└───────────────────────────────┘
请注意,稍后还会再次使用 ClassLoader
按需加载 资源 。
我们在关于 java 代码执行的测试中遇到了这个问题:-
Select java 代码执行的正确顺序
a) Class 装载机
b) 解释
c) 编译
d) 字节码验证
e) Java 源代码
f) 执行
选项:-
- e-a-c-b-d-f
- e-a-b-c-d-f
- e-b-a-c-b-f
- e-c-a-d-b-f
我将选项 4 标记为我的选择。我不知道确切的原因,但我觉得那个最好。
结果说我回答错了。 T_T
谁能告诉我正确答案是什么以及为什么。
(大学声称的正确答案是选项 3) (并且在给这个 post link 之后,大学更正了选项 4 的解决方案)
(看完大家的评论和解决方案,对执行过程有了更深入的了解,而不是仅仅解决一个愚蠢的故障MCQ......伟大的社区)。
正确顺序是 e-c-a-d-b-f,所以正确答案是 4.
其他三个答案可以证明是错误的,因为这三个答案在 c) 之前都有 a),但你根本不可能有 a) Class Loader 在 c) Compilation 步骤之前生成 Class Loader 应该加载的字节码.
┌──────────────────────────────────┐
│ e) Java Source Code (.java file) │ Obvious starting point
└──────────────────────────────────┘
↓
┌────────────────────────────────┐
│ c) Compilation (javac command) │
└────────────────────────────────┘ Then we compile the source code
↓ to byte code.
┌────────────────────────┐
│ Bytecode (.class file) │
└────────────────────────┘
↓
┌─────────────────┐ The classloader is responsible for
┌──────┤ a) Class Loader ├─ JVM ┐ locating the byte code and making it
│ └─────────────────┘ │ available to the JVM as a byte array
│ ↓ │
│ ┌───────────────────────────┐ │ In the linking phase of preparing a
│ │ d) Byte Code Verification │ │ class for use, the byte code is
│ └───────────────────────────┘ │ verified by the JVM.
│ ↓ │
│ ┌───────────────────┐ │
│ │ b) Interpretation │ │ This one is a bit iffy, but you can
│ └───────────────────┘ │ argue that the byte code is interpreted
│ ↓ │ before it is executed, but the JVM
│ ┌──────────────┐ │ could easily JIT-compile to native
│ │ f) Execution │ │ code without ever executing the code
│ └──────────────┘ │ in interpretation mode.
└───────────────────────────────┘
请注意,稍后还会再次使用 ClassLoader
按需加载 资源 。