Sunday, 25 September 2011

Steps to compile and Run a java program in Ubuntu Linux

Steps to run JAVA program in Ubuntu:
1. Go to Applications > Accessories > Terminal, to open terminal window.
2. Type the following in command line
gedit Welcome.java
3. Enter the code bellow in the editor.
 class Welcome
{
    public static void main (String []args)
    {
    System.out.println("Welcome to UBUNTU");
    }
}

4. Save the file and close to return to terminal window.
5. Firstly compile the code using the following command
javac Welcome.java
That would produce an class file you may need to run the program.
7. Now run this executable using the following command
java Welcome
8. Output should show as follows:
Welcome to UBUNTU

Install Java in Ubuntu Linux

How to download and install prebuilt OpenJDK packages

JDK 6
Debian, Ubuntu, etc.

On the command line(Applications-> Accessories->Terminal), type:

    $ sudo apt-get install openjdk-6-jre
    $ sudo apt-get install openjdk-6-jdk

The openjdk-6-jre package contains just the Java Runtime Environment. If you want to develop Java programs then install the openjdk-6-jdk package.