Java is multi platform programming language.It uses JDK(includes jre) to create a class file from the source code and then the generated class file can be run on any computer by using Java Virtual Machine(JVM).So to write and execute java programs Java Development Kit(JDK) must be installed on the computer.

Installing JRE /JDK on Ubuntu 10.04 for java programming
If you have not installed the JDK yet, then first install jdk on ubuntu 10.04 and then return to this page.
When you have installed JDK successfully on ubuntu ,then you will be able to write and execute jav programs.Follow these simple steps to write and execute your first java program on ubuntu 10.04 –

How to compile and run java program on Ubuntu 10.04

1. Open Gedit OR Write click on Desktop and select Create Documents->Empty File.

2. Write this simple java code to test..

// A program to print some text.
public class Welcome
{
// main method begins execution of Java application
public static void main( String[] args )
{
System.out.println("Hello World!");
System.out.println("Welcome to Java Programming! on Ubuntu 10.04");

} // method main ends here
} // end of the class Welcome

3. Save it as “Welcome.java” on your Desktop(or in any other directory).
4. Now compile this java program to create the class file by using this command on terminal(CTRL+ALT+T).

$ javac Welcome.java

5. Now you will notice a class file “Welcome.class” on your Desktop.Now JVM will execute this code through the command given below –

$ java Welcome

6. Then the java Program will be execute by jvm and you will see the following output.
Hello World!
Welcome to Java Programming! on Ubuntu 10.04

how to program in java on ubuntu 10.04

Join the Conversation

15 Comments

  1. Thanks, I just started with the book “Head First Java” and I couldn’t figure out a way to open my first code.
    I just knew I wouldn’t have to manually download Sun’s (or Oracle’s) Java from the internet 🙂

  2. thanks
    its very helpful for me because i am new to linux world, its my first time using linux based os.

  3. i hv installed jdk 1.6 from ubuntu software center n then compiled the program on desktop but it didn’t work.
    the error was……….
    The program ‘javac’ can be found in the following packages: * openjdk-6-jdk * ecj * gcj-4.4-jdk * gcj-4.3Try: sudo apt-get install
    ………………………..
    does anybody hv any solution to this problem, also i hv not set any class path in ubuntu 10.04 as we do in windows.

    thanx in advance………….

Leave a comment

Leave a Reply to Saumya Cancel reply

Your email address will not be published. Required fields are marked *