Step 1: Create a Java source file
There are actually quite a few caveats to this step alone because Java as some requirements that make it more restrictive than any other language in this blog. In Java, there everything is an "Object" and thus extends from java.lang.Object. Therefore, you will have to create a full class definition even though we will not be instantiating any classes. The source file for Hello World thus looks like the following:
__________________________________________________________________________________
public class HelloWorld extends java.lang.Object { public static void main(String args[]){ System.out.println("Hello World in Java from ecocrypt.blogspot.com"); } }__________________________________________________________________________________
There is another caveat in Java the class HelloWord must be stored in a file called HelloWorld.java. Picking another name will cause a compiler error.
Step 2: Compile the Java Source
At a command prompt, type the java compiler command:
prompt % javac HelloWorld.java
The result of this will be to produce an output file called HelloWorld.class, this class file is a byte code version of the HelloWorld.java source file. Unlike golang, where the output of the linker can be directly executed, the java class file is not executable. However, a java executable program and load the HelloWorld.class file, and execute the instructions.
Step 3: Running HelloWorld
At the command prompt, type:
prompt % java HelloWorld
Hello World in Java from ecocrypt.blogspot.com
Congratulate yourself! You have successfully installed the JDK, created a simple java source file compiled it to byte code, and run it inside of the Java Virtual Machine.
No comments:
Post a Comment
All comments are greatly appreciated! Comments will be moderated, and usually appear within 1 day. If you like a post, instead of saying you like it, vote for it or digg it (links provided). If there is any ERROR, PLEASE Comment I strive for good quality complete content.