Wednesday, November 23, 2011

Understand Hello World example

A Java class is like the design you draw on a blueprint, you want to define details, functionality for an object before you actually create and use it.

The Hello World example does not have much going on yet, but it consists of the most fundamental lines. Here is the line-by-line explanation.
1. public class HelloWorld - declare a class and name it HelloWorld
2. public static void main(String[] args) - the start point of the program. In some programming languages, usually it's the "main" to start the whole process.
3. System.out.println("Hello World") - this is the line that actually does the job to print out "Hello World" on the screen". You can play it around little bit by changing "Hello World" to something else like "Hello Galaxy", re-compile the code (command javac HelloWorld.java), and run it again (command java HelloWorld). You will see "Hello Galaxy" on the screen.

No comments:

Post a Comment