Thursday, December 26, 2013

Java Compiler, interpreter and configuring.

Hi Guys in this post we learn, what is java compiler, interpreter and how to configure java.

All the programming languages require compiler and a interpreter so that the instructions written the high level language can be easily understood by the system. Same is the case with the JAVA only difference between JAVA and other languages is java compiler will not convert the code into executable code rather it converts it in to byte code. The advantage of this byte code is, it can be executed on any platform if one has java interpreter of JVM[Java Virtual Machine] as explained in the below image.
Source: Head.First.Java.2nd.Edition

How To configure:

Before configuring let me explain the difference JDK and JRE. 

JDK: Java Development Kit which consists of both compiler(javac) and JVM(java). javac is a command to compile the java program and java is a command to interpret the byte code. We will learn how to use these commands shortly. Downloading and installing the JDK will enable your system to perform both compiling and interpreting the java code using javac and java commands from command line respectively.

In case you are only interpreting but not compiling any java code then you can just install JRE.

JRE: Java Run time Environment consists of only JVM(java) which enables one's system to run the java byte code irrespective platform where the byte code has been compiled. As said above we need java command to run the byte code. To run this command compiler is not mandatory.

One can download the JDK and JRE from:
http://www.oracle.com/technetwork/java/javase/downloads/index.html

Windows Configuring:

After downloading JDK or JRE as per requirement[either 32 or 64 bit based on system] you can install the executable by double clicking on it and follow the steps.
Once it is done you need to include javac and jre in your path variables, to do it please follow the steps below.

Windows 7-configuration:

1: Click on Windows button.
2. Right click on  computer and click on properties.
3. Click on Advanced system settings.
4. Click on Environment variables button and select a 'path' variable from 'system variables section as shown in the below image and click on edit button.
5. In the window pop up add the path “C:\Program Files (x86)\Java\jdk\bin” if you have downloaded JDK or “C:\Program Files (x86)\Java\jre\bin” if you have downloaded only JRE. 
The folder structure may differ based on the system type you have chosen 32 or 64. If you have chosen 32 bit then the folder structure will be as mentioned otherwise it will something like "C:\Program Files\Java\jdk\bin".
Note: Be careful while editing the path variables. All the values in the path variable are separated by colon(;) so, add the above path with out editing any values to the end of it separated by colon(;).


Once you are done with the above steps open command window and type javac -version and java -version
This commands should give you the version info of the java you installed in your machine as shown in the below image.
Note:Close all the open command windows before running the above commands

This ensures that we have successfully installed the java in our machine.
If one has installed JDK both the commands will give version info, in case of JRE only java -version will give info as compiler is not available.

Windows-8 Configuration:

To configure java in windows-8 please follow the below stpes.

1. Run Control Panel in Windows 8's Metro UI.
2. Click More Settings in Control Panel  on the left.
3. Search "Environment Variables" in Control Panel, and click "Edit the system environment variables".
4. Click on "Environment Variables"
5. Repeat steps 4 and 5 from the windows-7 configurations.
6. Once it is done you can verify the java installation by running the javac and java commands as told in  windows-7 configurations.

Hope this helps everyone..



No comments:

Post a Comment