Saturday, 2 March 2013

How to run a java program?

How to install JDK

Step 1: Open your web browser and go to Type “jdk” in the search box. Select the first result which would be named “Java SE Downloads”.
  • Install JDK
  • Create java file
  • Compile that java file with Javac command on Dos.
  • Run the generated class file with java command on Dos.
Step 2: Click on the Java icon for Java Platform (JDK)7u10.
Step 3: Accept the License Agreement and select the java installation as per your system configuration.
Step 4: The JDK installer will be saved in the location that you have selected. Double click on the downloaded JDK installer or right click on JDK installer and click on run as administrator.
Step 5: Follow the instructions on your screen to install JDK on your system.

The JDK has now been installed on the system. You need to set the path of the JDK in the Environment Variables of the System. Follow the procedure given below to set the path permanently.
Start computer then right click properties–advance system setting–environmental variable–System variable–path–edit
Then type ; and paste the path of the bin folder of JDK in which it is installed, then type then click on ok and close all windows.
Now you are ready to execute java programs in your system.
First you have to write code in any editor like Notepad in Windows OS. Then, save the file with .java extension.
A simple program in java—
class Apple {
public static void main (String []a) {
String name=a[0];
System.out.println(“Welcome  “+name);
Name of the file is
When above line of code executes then it will print “Welcome” on MS-dos
Executing the program—
Open MS-Dos
Directory of the file and MS-Dos must be the same for executing the java program.
Now type in MS-Dos javac and press Enter.
The java compiler will compile the .java file and create apple.class file.
When Apple.class is generated, type java Apple ayyaz in MS-Dos and press Enter
Then u will see the following Output in MS-Dos.

No comments:

Post a Comment