Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Running Java Program  RSS feed

 
Greenhorn
Posts: 28
  • 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
 
Ranch Hand
Posts: 732
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops.
java HelloWorld
 
Rajesh Kumar
Greenhorn
Posts: 28
  • 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
  • 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
 
Greenhorn
Posts: 24
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!