compile and run of java program
If you are new to Java programming and wish to learn it right now by doing some hands-on practice, you have come to the right place. This tutorial will help you writing your first Java program, typically a “hello world” one - your first step of the adventure into Java programming world. Throughout this tutorial, you will learn fundamental concepts and steps which are necessary for every Java fresher.1. Downloading and installing JDK software
In order to write and run a Java program, you need to install a software program called Java SE Development Kit (or JDK for short, and SE means Standard Edition). Basically, a JDK contains:- JRE(Java Runtime Environment): is the core of the Java platform that enables running Java programs on your computer. The JRE includes JVM(Java Virtual Machine) that runs Java programs by translating from bytecode to platform-dependent code and executes them (Java programs are compiled into an intermediate form called bytecode), and other core libraries such as collections, File I/O, networking, etc.
- Tools and libraries that support Java development.
- javac.exe: is Java compiler that translates programs written in Java code into bytecode form.
- java.exe: is the Java Virtual Machine launcher that executes bytecode.
Check the option “Accept License Agreement”, and choose an appropriate version for your computer from the list. Here we choose the version for Windows x64:
After downloading the program, run it to install the JDK on your computer (just following the steps, leave the defaults and click Next, Next…):
You would see the JDK is installed in the following directory, for example: C:\Program Files\Java\jdk1.7.0_21. The following screenshot describes the JDK’s directory structure:
Now let’s test if Java runtime is installed correctly. Open a command prompt window and type:
java -version
You would see the following result:
That shows version of the JRE, e.g. “1.7.0_21” - Congratulations! Your computer is now capable of running Java programs.
Now try to type the following command:
javac -version
You would see the following error:
That’s because Windows could not find the javac.exe program, so we need to set some environment variables which tell the location of javac.exe.
2. Setting up environment variables
Now we’re going to set environment variables so that the javac.exe program can be accessed anywhere from command line. On Windows 7, go to My Computer and click System Properties:
Then click Advanced system settings:
The System Properties dialog appears, select Advanced tab and click Environment Variables...:
The Environment Variable dialog appears, click on the New… button under the System variables section.
That opens up the New System Variable dialog. Type the following information:
The field Variable name must be JAVA_HOME, and the field Variable value must point to JDK’s installation directory on your computer. Here it is set to c:\Program Files\Java\jdk1.7.0_21. Click OK to close this dialog.
Now back to the Environment Variables dialog, look for a variable called Path under the System Variables list, and clickEdit…:
In the Edit System Variable dialog, append the following to the end of the field Variable value:
;%JAVA_HOME%\bin
Note that there is a semicolon at the beginning to separate this value from other ones. Click OK three times to close all the dialogs.
Now we have to quit the current command prompt and open a new one to see the changes takes effect. Type the following command again in the re-opened command prompt window:
javac -version
You would see the following output:
Congratulations! You have completed the setup for essential Java development environment on your computer. It’s now ready to write your first Java program.








This is helpfull for fresher..........
ReplyDelete