Internal Details of Hello Java Program

Internal Details of Hello Java Program

In the previous section, we have created Java Hello World program and learn how to compile and run a Java program. In this section, we are going to learn, what happens while we compile and run the Java program. Moreover, we will see some questions based on the first program.

What happens at compile time?

At compile time, the Java file is compiled by Java Compiler (It does not interact with OS) and converts the Java code into bytecode.

compilation of simple java program

What happens at runtime?

At runtime, the following steps are performed:

Java Runtime Processing

Classloader: It is the subsystem of JVM that is used to load class files.

Bytecode Verifier: Checks the code fragments for illegal code that can violate access rights to objects.

Interpreter: Read bytecode stream then execute the instructions.

Q) Can you save a Java source file by another name than the class name?

Yes, if the class is not public. It is explained in the figure given below:

how to save simple java program by another name

To compile: javac Hard.java
To execute: java Simple

Observe that, we have compiled the code with file name but running the program with class name. Therefore, we can save a Java program other than class name.

Q) Can you have multiple classes in a java source file?

Yes, like the figure given below illustrates:

how to contain multiple class in simple java program


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263863.html

(0)
上一篇 2022年6月1日
下一篇 2022年6月1日

相关推荐

发表回复

登录后才能评论