-------------------------------------- Java Sag is under construction: Hello World example in Java
Please inform us if you find a non good advertisement : info.enim dot gmail.com

Best Web Hosting

dimanche 6 mai 2012

Hello World example in Java

Hello World is a classic sample to start when we learn a new programming language. Below is the Java version of Hello World program, it simple enough to start.

package org.kodejava.example.intro;

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

The code contains one class called HelloWorld, a main(String[] args) method which is the execution entry point of every Java application and a single line of code that write a Hello World string to the console.
The HelloWorld class must be saved in a file named HelloWorld.java, the class file name is case sensitive. In the example we also define a package name for the class. In this case the HelloWorld.java must be placed in a org\kodejava\example\intro directory.
To run the application we need to compile it first. I assume that you have your Java in your path. To compile it type
-------------------------------------------------------------------------
javac -cp . org\kodejava\example\intro\HelloWorld.java
-------------------------------------------------------- 
The compilation process will result a file called HelloWorld.class, this is the binary version of our program. As you can see that the file ends with .class extension because Java is everyting about class.
To run it type the command bellow, class name is written without it extension.
------------------------------------------------------------------
java -cp . org.kodejava.example.intro.HelloWorld
------------------------------------------------------------------

Aucun commentaire:

Enregistrer un commentaire

Best Web Hosting