aspose file tools*
The moose likes Beginning Java and the fly likes Running Java Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Running Java Program" Watch "Running Java Program" New topic
Author

Running Java Program

Rajesh Kumar
Greenhorn

Joined: Nov 16, 2001
Posts: 28
Dear Friends
I am new to Java
A Strange Doubt.
Can I run my java program like this...
java HelloWorld.class
My HelloWorld program is like this
class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello World ");
}
};
After Compiling ...Can i Run the program as like
java HelloWorld.class ?
If anyone having idea...Please participate in this discussion.
Thanks in advance
Yours
Rajesh
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
ofcourse you can.
just without the .class
use:
java Hello
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
oops.
java HelloWorld
Rajesh Kumar
Greenhorn

Joined: Nov 16, 2001
Posts: 28
Dear Roy Ben Ami,
Can I run like this ?
java HelloWorld.class ?
Originally posted by Roy Ben Ami:
oops.
java HelloWorld
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
nope. you need to drop the .class
when you run the java.exe file it expects to find .class files so you cant specify the .class at the end.
why do u want to use .class at the end?
just run like this:
java HelloWorld
Sals Hamid
Greenhorn

Joined: Jan 04, 2002
Posts: 24
This is the right code
public class Salman
{
public static void main(String args[])
{
System.out.println("Hello World");
}
}
First save as this program Salman.java
Then compile it using javac Salman.java
and then run by using java Salman


No Path of Flowers lead to glory
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Running Java Program