Wednesday, August 6, 2008

installing java and running a simple program

Hello all! I downloaded the jdk package from SUN's site and installed it offline. It's just simple.

offline istallation

If you download the .bin file from Sun's site, then you can install it by:
sudo ./j2sdk-1_4_2_16-linux-i586.bin

online istallation
sudo aptitude install sun-java6-jdk

Now, you have to set the path variables for JAVA:
export JAVA_HOME=/mnt/F/ubuntu/j2sdk1.4.2_16
export PATH=$JAVA_HOME/bin:$PATH

Now, switch to the directory /usr/bin :
cd /usr/bin

Now execute these commands sequentially:
sudo rm ./java
sudo rm ./java_vm
sudo rm ./javaws

sudo ln -s /mnt/F/ubuntu/j2sdk1.4.2_16/bin/java ./java
sudo ln -s /mnt/F/ubuntu/j2sdk1.4.2_16/bin/java_vm ./java_vm
sudo ln -s /mnt/F/ubuntu/j2sdk1.4.2_16/bin/javaws ./javaws
sudo ln -s /mnt/F/ubuntu/j2sdk1.4.2_16/bin/javac ./

You are done! Now you can run any java program from any directory you like.

Compiling your first java program


You may write a sample code like this:
//First Java Program
class Main
public static void main (String[] args)
System.out.println ("Hello Ubuntu!");

Compile it:

Run it:
java Main

you should get the output "Hello Ubuntu!"


lotto 649 said...

Yugs, daw nabasahan ko naman ni sa iban nga blog?

Shahan said...

Sorry man, i cant understand that.please use english.