Explore the English language on a new scale using AI-powered English language navigator.
Hello world program line by lineSummaryIn this tutorial we will discuss Hello world program line by line and familiarize reader with the very basic principles of Java. Code analysisLet's recall source code for the Hello world program first: HelloWorld.javapublic class HelloWorld {
/** * @param args */ public static void main(String[] args) { System.out.println("Hello World! I am new to Java."); }
}
First of all, Java is an object-oriented programming language. Thus, Java program necessarily consists of classes. There are no global variables and functions, as you may see in C++. We called the class HelloWorld:
public class HelloWorld {
}
Draw attention to the fact, that filename of the file is <class name>.java. It is obligatory in Java. Entry pointEach application in Java has an entry point to start from. It is a public static method called main. Arguments to application are passed through args parameter.
public static void main(String[] args) {
} Print commandSystem.out.println("Hello World! I am new to Java.");
The command above prints "Hello World! I am new to Java." to the console. We won't expect this line in depth here. At present just memorize it as a tool to output something to the console. CommentsAbove the main method declaration you see comments block:
/** * @param args */
It is special comments, called Javadoc. Using this system, one may automatically generate documentation for properly commented source. Build and runNow you know all about Hello world program. In previous article we built and ran it with the click in Eclipse, but it is also useful to know, how to build applications manually. BuildingEnter the directory with your source file and run the following command: javac HelloWorld.java After it is executed you will see a new file HelloWorld.class. This file is a compiled HelloWorld class. RunningNow you can run it using following command: java HelloWorld If you done everything right, "Hello World! I am new to Java." should appear in the console: |