This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running Java Program