In the preceding part, we have developed a Java program that displays "Hello World" and grasped the process of compiling and executing a Java program. This section will delve into the intricacies of compiling and running a Java program. Additionally, we will explore some inquiries related to the initial program.
What happens at compile time?
During compilation, the Java compiler processes the Java file without interacting with the operating system. The Java compiler translates the Java code into bytecode.
What happens at runtime?
At runtime, the following steps are performed:
Classloader is a crucial component of the Java Virtual Machine (JVM) responsible for loading class files.
The Bytecode Verifier is responsible for inspecting code snippets to identify any unauthorized code that may breach object access permissions.
Interpreter: The interpreter is responsible for reading the bytecode stream and then executing the instructions provided within it.
Q) Can you save a Java source file by another name than the class name?
Yes, the class being non-public is clarified in the provided diagram below:
| 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: