Sign in to follow this  
Razorpro

Java problem!!!!

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
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
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
Quote:
Original post by Aldacron
Look, printf prints to standard out. System.out.println prints to standard out. Therefore, they are equivalent.


There final outcome may be the same but they are not equivalent perhaps you don't understand printf because println & printf are not same, printf does formatted out-put with a format string.

Quote:
Original post by Aldacron
The new method in 1.5 is the same, but takes advantage of the variable args support added to the language.


like i said before there not the same, printf does formatting and can take advantage of locales, println doesn't do anything like that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this