Java Tutorials - My First Java Program Tutorial (Lesson Two)
Ok now let's have a quick look at our code
//OUR FIRST PROGRAM.
The use of // denote a comment - it is good practice to add comments.
public class HelloWorld {
}
The keyword class specifies that we are defining a class, all java program must contain a class and in Java all code must be contained in a class.
public static void main(String[] args) {
}
All java programs begin execution with the method named main(),
Notice that the main entry point must be marked as both public and static (otherwise the Java Virtual Machine cannot invoke it).
Finally:
System.out.println("Hello World");
System.out is a standard method provided by Java Rutime System that allows you print to the console.
Important Steps to Remember
Steps for Saving, compiling and Running a Java
Step 1:Save your java program With .java Extension.
Step 2:Compile the file from DOS prompt by typing javac
Step 3:Successful Compilation, results in creation of .class containing byte code.
Step 4:Execute the file by typing java
Step 5 :Congratulation you should now see your output.
