Java problem!!!!

Started by
11 comments, last by Sneftel 19 years, 7 months ago
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
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.
System.out.println("Hello World!"); <- this is not a command to print text as such.
System.out.println is more for debugging purposes.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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)
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.
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).
is the file called practice.java ?
(0110101101000110)The Murphy Philosophy: Smile . . . tomorrow will be worse.
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.
you don't need to

import java.lang.*

i guess it wouldn't compile without it. :S
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.

This topic is closed to new replies.

Advertisement