Skip to main content
GameDev.net gamedev.net
🔒 Locked

Java problem!!!!

Started by Razorpro Sep 3, 2004 at 9:36 AM 11 replies 1.1k views
Original Post
Razorpro
Razorpro
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
Evil Steve
Evil Steve
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.
benryves
benryves
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 +++]
cgoat
cgoat
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)
Aldacron
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.
snk_kid
snk_kid
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).
MrPoopypants
MrPoopypants
is the file called practice.java ?
(0110101101000110)The Murphy Philosophy: Smile . . . tomorrow will be worse.
Razorpro
Razorpro
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.
drkpriest
drkpriest
you don't need to

import java.lang.*

i guess it wouldn't compile without it. :S
Aldacron
Aldacron
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.
kapru
kapru
complie it first using javac then run using java
snk_kid
snk_kid
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.
Sneftel
Sneftel
Guys, both of your points are abundantly clear.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.