Sunday, October 31, 2010

Java - Hello world

The most common and basic lesson in programming is the "Hello World" tutorial. The purpose of this tutorial is to write the most basic program which displays the text "Hello World". Here is an example of this in Java:

public class HelloWorld {
 public static void main (String[] args){
  
  // Print "Hello World" to the console
  System.out.println("Hello World");
 }

}


In Java and other programming languages, all code is contained in either a class or multiple classes. The class in this example is HelloWorld. In Java the execution of the program begins in the main method. In order to make your code easier to understand, it is best practice to add comments to it. Comments in Java are preceded by // and aren't read by the compiler. If you have multiple lines of comments, use /* at the beginning and */ at the end.

The last line of code here displays the text between the brackets in the Java console. This is the simplest way to print out information in Java.


No comments:

Post a Comment