Introduction to Programming in Java

5. "Hello World"

5.2. Inside the Magic

The "Hello World" program has become a de-facto standard with computer programmers for a first program in any language. The main advantage is that it is as simple as a program can get - when considering what it does. Depending upon the language and/or environment though, it may be necessary for some set-up code and/or syntactic glue.

In the program shown above, there are two pieces of syntactic glue.

The first part, public class HelloWorld, and the accompanying matched pair of curly braces, declare a Class construct. At this point, we could try and explain what a class is, but for someone who is genuinely new to programming, the explanation would probably be more of a distraction than a help. For now, we will settle for a simple universal truth - all Java code must be contained inside a Class construct.

The second part, public static void main(String[] args) and the accompanying matched pair of curly braces declare a Method construct. In particular, they declare a special type of method that Java can use as the entry point for a program. A method is a somewhat simpler construct than a class, but for now we will just describe it as a group of runnable code. A main method is required for each and every Java program. (Methods are also known as 'functions' in some other programming languages such as C++).