Monday, December 26, 2011

How to run Java program using command prompt in Windows 7

How to run Java program using command prompt in Windows 7?

Step 1: Install JDK (Java Development Kit) version 1.6.0_24 will work properly to my knowledge, if u have any other version working good then no issues. This is a link to get JDK

Java Platform, Standard Edition Development Kit (JDK 6 Update 23).

Now the java will be installed in C:\ drive program files, u will get path say example C:\Program Files\Java\jdk1.6.0_23\bin

Step 2:

Now we have to add the Java interpreter and compiler to system environment variables by following procedure Select Start -> Computer -> System Properties -> Advanced system settings -> Environment Variables -> System variables -> PATH. Edit the path and prepend C:\Program Files\Java\jdk1.6.0_23\bin; to the beginning of the PATH variable and click OK for 3 times. You may also need to reboot for the environment variable change to take effect.

YUP!!!!!!!!! Ur system is ready to run java programs.

Step 3: Create a folder lie myjava, mywork, javaprog etc.., then write a short program like HelloWorld in a notepad and save as HelloWorld.java but not as *.txt file save it as Any file.

Example : public class HelloWorld

{

public static void main(String[] args)

{

System.out.println("Hello, World!");

}

}

Save the note pad with the same name of the public class. [ above program cannot be saved as helloworld, it will not run because java is case sensitive]

Step 4: open command prompt check for java version

C:\Users\Username>java –version {it will show version of java installed eg: java 1.6.0_24 and some stuff}

C:\Users\Username>javac –version {it will show version of java installed eg: javac 1.6.0_24}

Now change directory to folder u created and saved java file in it.

C:\Users\Username>cd\

C:\>

C:\cd myjava

C:\myjava>

C:\myjava>javac HelloWorld.java {compile the program)

If there r no errors then u won else read, think and resolve errors.

C:\myjava>java Helloworld {run the program}

Hello !!! World.

Note:

check and install exact version.

Edit environment variable path and restart the system to take effect.

Save program with class name bcoz it is case sensitive.

No comments:

Post a Comment