java - Java代码的正确执行顺序是什么
问题描述
我们在有关 java 代码执行的测试中遇到了这个问题:-
选择正确的java代码执行顺序
a) 类加载器
b) 解释
c) 编译
d) 字节码验证
e) Java 源代码
f) 执行
选项 :-
- eacbdf
- eabcdf
- ebacbf
- ecadbf
我将选项 4 标记为我的选择。我不知道确切的原因,但那个听起来对我来说最好。
结果,它说我的答案是错误的。T_T
有人能说出正确答案是什么以及为什么。
(大学声称的正确答案是选项 3)(在给出此帖子的链接后,大学更正了选项 4 的解决方案)
(看了大家的评论和解决方案后,对执行过程有了更深入的了解,而不是仅仅解决一个愚蠢的错误MCQ...... GREAT COMMUNITY)。
解决方案
正确的顺序是ecadbf,所以正确的答案是4。
其他三个答案可能是错误的,因为这三个答案都在c) 之前有 a) ,但你根本不能在c) 编译步骤之前有a) 类加载器,该步骤生成类加载器应该加载的字节码。
┌──────────────────────────────────┐
│ 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
稍后还会再次使用 来按需加载资源。
推荐阅读
- mongodb - 通过karatedsl使用mongodb、redis和rabbit mq的最佳方式?
- macos - Mac 在启动时继续重启
- excel - 单元格更改后,如何使某个范围内的单元格进行硬编码?
- java - javafx fxml方法如何给当前界面添加活动可见事件?
- html - 哪个具有优先级,输入所在的表单标签或输入的表单属性?
- r - 使用 data.table 自定义函数创建自定义 R 包
- php - 使用 PHP 从数据库中填充 Bootstrap 下拉菜单
- c# - 在项目自己的控制台上使用 SetParent,在 winforms 面板中
- java - 我不明白这个错误。(android构建错误科尔多瓦)
- python - 如何在不每次都重新运行函数的情况下重用 Python 类中的返回值?