Jump to content
  • Advertisement
Sign in to follow this  
Razorpro

Java problem!!!!

This topic is 5214 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a problem with a simple Java Hello World program. Everything compiles fine with no errors, but when I run the app, it comes up and then goes away. But right before it goes away it prints something up, which is not Hello World. I think the first word is Exception. Anyways here is the code that I compiled: public class Practice { public static void main(String[] args) { System.out.println("Hello World!"); } } I have no idea what's going on. I get no errors and yet it doesn't run. Well I mean a DOS prompt quickly flashes on and off. Can anyone help me? Thanks, Taylor GI Student

Share this post


Link to post
Share on other sites
Advertisement
Run it from the command prompt, so you can read the error. Goto start -> run and type "cmd". The goto the directory the Java program is in (cd blah) and do "java blah" where 'blah' is the name if your Java file.

Share this post


Link to post
Share on other sites
System.out.println("Hello World!"); <- this is not a command to print text as such.
System.out.println is more for debugging purposes.

Share this post


Link to post
Share on other sites
The only way I could see that failing is if you got a "ClassNotFoundException". That would mean your classpath is messed up and it can't locate the Practice class.

Open a command prompt, cd to the directory where you compiled it and run the following:

java -cp . Practice

(Assuming your program is Practice.java, and the resulting Practice.class is in the same location)

Share this post


Link to post
Share on other sites
Quote:
Original post by benryves
System.out.println("Hello World!"); <- this is not a command to print text as such.
System.out.println is more for debugging purposes.


No, System.out.println is for printing text to standard out. If you only use it for debugging that's your business, but not why it exists. It's the equivalent of printf in C.

Share this post


Link to post
Share on other sites
Quote:
Original post by Aldacron
Quote:
Original post by benryves
System.out.println("Hello World!"); <- this is not a command to print text as such.
System.out.println is more for debugging purposes.


No, System.out.println is for printing text to standard out. If you only use it for debugging that's your business, but not why it exists. It's the equivalent of printf in C.


negative (sorry i've beening listening to Arnie prank calls to much), the equivalent to printf in java is printf method of PrintStream type (only in 1.5).

Share this post


Link to post
Share on other sites
Quote:
Original post by MrPoopypants
is the file called practice.java ?


Yeah, I have Practice.java and Practice.class in the same directory. And since it compiles with no errors, I know it's got to be something wrong with finding the files, but I don't see how it can get it wrong.

Share this post


Link to post
Share on other sites
Quote:
Original post by snk_kid
negative (sorry i've beening listening to Arnie prank calls to much), the equivalent to printf in java is printf method of PrintStream type (only in 1.5).


Look, printf prints to standard out. System.out.println prints to standard out. Therefore, they are equivalent. Neither has any purpose beyond printing to standard out. My point was that it is not intended for debugging only. The new method in 1.5 is the same, but takes advantage of the variable args support added to the language.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!