Friday, August 15, 2014

Installing Java

Java is a programming language which is most popular because of its operating system independence. The platform independence of Java is provided because of the runtime provided by different operating systems. Java comes in two flavour:
  • JRE (Java Runtime Environment) - This is required if you want to run Java programs only.
  • JDK (Java Development KIT) - This includes JRE also. It is required when you want to develop Java programs also.

Current Java version is 8.0. However the older versions are still prevalent in many Production environments.

Downloading and installing Java

This contains download for Windows and various Linux/Unix flavor. For Linux system you can use their respective utilities to install also. They may install some other flavor of java like openJDK but generally that should not matter in terms of doing development. For example in OpenSuse you can use the yum and in ubuntu you can use apt-get. After Oracle takeover of Sun, one has to accept the agreement before downloading the Java SDK.

After Java is downloaded define the variables as follows:

Windows -
  • Define JAVA_HOME=<Path where Java is installed>. For example if Java is installed at C:\ProgramFiles\Java\ than JAVA_HOME is set to "C:\ProgramFiles\Java\".
  • Append the following at the beginning of your path variable C:\ProgramFiles\Java\bin;C:\ProgramFiles\Java\jre\bin;
  • Similarly in unix and Linux based systems, set the JAVA_HOME and path to the location.

If you intend to write many java classes using plain editors, atleast set the present directory to your class path. e.g in Windows 


Running Java

Open your text editor and write a java file. A java file ends with extension .java. Let's give the file name as Everything in Java is a class so we will need to write the class. Also note that the file name is the same as class name.

public class HelloOyeJava {
    public static void main(String[] args) {
        System.out.println("Hello Oye Java");

Now open a command prompt/terminal and go to the directory where you have saved the above Java file. run the following command


javac is the compiler which compiles the java file and makes a class file out of it.If the program is successful than you will see one more file HelloOyeJava.class. To run the file put the following command

java HelloOyeJava

It should show the output "Hello Oye Java" in console.

For better development use one of the IDE.

More on Java

No comments:

Post a Comment