Java for Linux

Downloading: First of all download JDK for the Linux (Fedora Core 3) Operating System. To download the latest version of
jdk, click on the link http:/www.java.sun.com.
and download the latest version for Linux Operating System. I have downloaded
jdk-1_5_0_01-linux-i586.bin for this tutorial.
Installing: Now install the downloaded version at
your
machine. To install change the directory where you have downloaded the SDK ( I
have downloaded it in my home directory /home/deepak) and execute self-extracting
binary file by using the following command:
| chmod +x jdk-1_5_0_01-linux-i586.bin |
On running, the self-extracting binary file displays the
License agreement text asking you for the acceptance to the agreement:
| ./jdk-1_5_0_01-linux-i586.bin |
Above command should create a directory called
jdk1.5.0_01 in the /home/deepak directory. Move the SDK directory to /usr/java/.
Create /usr/java if doesn't exist. Here is the command used:
Set the JAVA_HOME environment variable, by modifying
/etc/profile so it includes the following:
JAVA_HOME="/usr/java/jdk1.5.0_01"
export JAVA_HOME |
/etc/profile is run at startup and when a user logs
into the system, so you will need to log out and log back in for JAVA_HOME to be
defined.
Make sure that JAVA_HOME is defined correctly by using
the command below. You can find the to your Java SDK by using the following
command:
Output should be
Now you have successfully download and install JDK at
your machine. Now its time to develop and run a simple Hello World java program.
Lets create a simple Hello World java program:
HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
} |
Compile the above program by using the following
command:
or you may compile the program by going inside the bin
directory because we have save the program in the bin directory.
(or /usr/java/j2sdk1.4.0/bin/javac Test.java)
But note here that the file name and the class name must be same. The results
into creating the HelloWorld.class file.
Now we have to execute the compiled program, for this
we have execute the following command that shows the output of the given
program.
[prompt]$ java Test
Hello world |
or you may execute your program by going inside the bin
directory because we are creating the HelloWorld.class file in the bin
directory. the class file exists like the below one:
/usr/java/j2sdk1.4.0/bin/java Test
The Java SDK includes the following commands:
- javac:
Linux Java compiler (i.e. javac program-name.java)
- java:
Byte code interpreter / Java program launcher. (i.e. java program-name
Do not include ".class" extension.)
Test version: java -version
- appletviewer:
Views Java applet embedded in html file. (appletviewer myfile.html)
- javaws:
Java Web Start application manager. Java application handler for browser.
(Also see YoLinux
Mozilla configuration tutorial)
- javadoc:
Generate API documentation from tagged comments.
- javah:
Creates C header and stub files for Java class.
- javap:
Java file disassembler
- jdb:
Java debugger
- jar:
JAR archive file generation tool.

|