java Java程序执行背后的内部过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11414421/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 05:00:35  来源:igfitidea点击:

Internal proccess behind execution of Java program

jvmjava

提问by asura

I wanted to know the step-by-step internal process that happens on execution of a java program.

我想知道在执行 java 程序时发生的分步内部过程。

Example if we giv java testin command prompt.
What all process got invoked?
How JVM is instantiated ? till it prints the output..

例如,如果我们在命令提示符下给出java 测试
什么所有进程都被调用了?
JVM 是如何实例化的?直到它打印输出..

采纳答案by Vamsi

Go through the Java Executionpage.You will find the answer to the above question.

浏览Java Execution页面。您将找到上述问题的答案。

回答by Nishant Sharma

Java program execution follows 5 majors steps:

Java 程序执行遵循 5 个主要步骤:

Edit Compile Load Verify and Execute

编辑编译加载验证并执行

  1. Edit - Here the programmer uses a simple editor or a notepad application to write the java program and in the end give it a .java extension

  2. Compile - In this step the programmer gives the javac command and the .java files are converted into bytecode which is the language understood by the java virtual machine (and this is what makes java platform independent language). Any compile time errors are raised at this step

  3. Load - The program is then loaded into memory. This is done by the class loader which takes the .class files containing the bytecode and stores it in the memory. The .class file can be loaded from your hard disk or from the network as well

  4. Verify - the bytecode verifier checks if the bytecode loaded are valid and do not breach java's security restrictions

  5. Execute - The JIT (Just-in-Time) compiler compiles the program one bytecode at a time and runs the program

  1. 编辑 - 这里程序员使用一个简单的编辑器或记事本应用程序来编写 java 程序,最后给它一个 .java 扩展名

  2. 编译 - 在这一步中,程序员给出 javac 命令,.java 文件被转换成字节码,这是 java 虚拟机可以理解的语言(这就是 java 平台独立语言的原因)。在此步骤中引发任何编译时错误

  3. 加载 - 然后将程序加载到内存中。这是由类加载器完成的,它获取包含字节码的 .class 文件并将其存储在内存中。.class 文件可以从硬盘或网络加载

  4. 验证 - 字节码验证器检查加载的字节码是否有效并且不违反 java 的安全限制

  5. Execute - JIT(Just-in-Time)编译器一次编译一个字节码并运行程序

回答by Jayghosh Wankar

The execution of java code internally will be in the following steps:-

内部java代码的执行将分为以下几个步骤:-

Execution Command -->java Test
   1.Start JVM
   2.Create and Start Main Thread
   3.Look at Test.class File-->Main Thread is responsible for checking if not found Runtime Exception will occur saying Exception in Thread Main
   4.Load Test.class file
   5.Execute Main method
   6.Unload Test.class
   7.Terminate Main Thread
   8.Shut down JVM

回答by Krishan

Have a look at this article, it clearly explains all steps one by one: Java Program Execution Steps.

看看这篇文章,它一一清楚地解释了所有步骤: Java Program Execution Steps。

回答by csandreas1

1)The JVMexecutes the program's bytecodes.
2)JVMs typically execute bytecodesusing a combination of interpretation and so-called just-in-time (JIT) compilation.
3)Analyzes the bytecodes as they're interpreted
4) A just-in-time (JIT) compiler—such as Oracle's Java HotSpot compiler—translates the bytecodes into the underlying computer's machine language.

1) JVM执行程序的字节码。
2)JVM 通常使用解释和所谓的即时 (JIT) 编译的组合来执行字节码
3) 在解释字节码时对其进行分析
4) 即时 (JIT) 编译器(例如 Oracle 的 Java HotSpot 编译器)将字节码转换为底层计算机的机器语言。

回答by ShankarSalunkhe

I dont know but however, the concept that i have understood , I will explain you the same....

我不知道,但是,我已经理解的概念,我将向您解释相同的....

Initially, the very first when you enter the command java abc(filename is abc.java) to run the program....the program will search for Java Runtime Environment as you have entered command (JAVA in cmd)....it means the path that you have set in Environment Variable....

最初,当您输入命令java abc(文件名是 abc.java)来运行程序时....当您输入命令时,程序将搜索 Java Runtime Environment(cmd 中的 JAVA)....它表示您在环境变量中设置的路径....

Then the JVM is activated........JVM will give a call to the class loader.......then the class loader will go to the operating system to take a permission for the program execution.....once OS allows.....class loader will check the file name and the program name........(As you know the class name and file name should be same)........If everything goes fine........program is loaded in the Memory.....:)

然后JVM被激活......JVM会调用类加载器......然后类加载器会去操作系统获取程序执行的权限...... ..一旦操作系统允许.....类加载器将检查文件名和程序名........(如您所知,类名和文件名应该相同)...... .如果一切顺利......程序已加载到内存中.......:)

Cheers :)

干杯:)

Shankar Salunkhe

尚卡尔·萨伦赫