Anonymous

How Do You Execute A Java File From The Cmd Of Windows?

3

3 Answers

Anonymous Profile
Anonymous answered
First check whether JDK is being installed in your system.
   C:\> java -version

The output will look something like:

Java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

This means jdk 1.6 is installed and windows knows its path.
Just to ensure set the environment variable PATH to point to java\bin
(For XP)
Right Click My Computer from desktop -> Click Properties -> Click Advanced -> Click
Environment Variables.
In the list you will see a variable PATH being set.
Prepend the jdk path to the variable.
Click on the variable -> click edit -> in the value text box prepend the path
for example, 'C:\program files\java\jdk1.6.0.3\bin;'

Then compile your program as below,
C:\> javac mypgm.java
Finally run the program correcting compilation errors,
C:\> java mypgm
Anonymous Profile
Anonymous answered
You must compile the file before executing
To compile type:
javac filename
it will display errors, if any. Then type java filename
and your file will be executed

sridher yamsani Profile
sridher yamsani answered
To execute Java file from command use the following syntax
c:/>java filename without extension

Answer Question

Anonymous