File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running Java Program

 
Rajesh Kumar
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 732
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ofcourse you can.
just without the .class
use:
java Hello
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops.
java HelloWorld
 
Rajesh Kumar
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 732
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic