• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!