Java HelloWorld Program
In this page, you will learn how to write a Java program
hello world java program :- Java code to print "Hello World".
Open Notepad and type as below:
Java source code
Save this file as HelloWorld.java
To compile: javac HelloWorld.java
To execute: java HelloWorld
Output:
Hello World
What happens at Compile Time?
To commence with Java programming, we must know the significance of Java Compiler. When we write any program in a text editor like Notepad, we use Java compiler to compile it. A Java Compiler javac is a computer program or set of programs which translates java source code into java byte code.
The output from a Java compiler comes in the form of Java class files (with .class extension). The java source code contained in files end with the .java extension. The file name must be the same as the class name, as classname.java. When the javac compiles the source file defined in a .java files, it generates bytecode for the java source file and saves in a class file with a .class extension.
Following figure shows the working of the Java compiler:
Once the byte code is generated it can be run on any platform using Java Interpreter (JVM). It interprets byte code (.class file) and converts into machine specific binary code. Then JVM runs the binary code on the host machine.
At Compile Time, Java file is compiled by Java Compiler (it does not interact with OS) and converts the Java code into Byte code (Which is nothing but .class file)
.
What happens at Run time?
At Run time, following steps are performed
Classloader: is the Sub system of JVM that is used to load class files.
Bytecode Verifier: Checks the code fragments for illegal code
Interpreter: read bytecode stream then execute the instructions
0 comments:
Post a Comment