• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why won't it stay on screen?  RSS feed

 
J Flanagan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an intermediate level of experience in programming with C++ and I decided I wanted to learn how to program in Java, of which I know nothing. So, at the recommendation of several of my geek friends (it's not insulting... we're all geeks here...) I bought a copy of Headfirst Java and it directed me to this site. Good thing! I need some help! Please? Pretty Please? With graphics and mice and everything nice? :roll:

When I compiled and ran (is that even the proper terminology?) my very first app, "HELLO WORLD!" (what else?), it flashed across the screen rapidly and then closed the window. I didn't even get a chance to read the text that was displayed it moved so quickly. I'm simply curious if this is the intended effect or if there's something wrong somewhere, be it with my programming - even though I copied it exactly from the text - or elsewhere, as I'm still unsure where it all goes in the whole parade of data.

Perhaps, as I'm on the topic, someone could explain how that works as well - the path my code follows from text file (without the .txt extension) to
an executed program. Where does it go? What does it do? Is it ALIVE?! Who out there knows where the code goes? And can you explain it to me (and the rest of us)?

Lotsa Lub!

~JF

jasondflanagan@gmail.com
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm simply curious if this is the intended effect or if there's something wrong somewhere, be it with my programming

Nothing wrong, this was your first "Goodbye World"

If you could post your program too, we may help you to find out what is wrong.
And please keep your next post simple too
 
Craig Tyler
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you ran it by typing "java MyClass" in the Run dialog under the Start menu (assuming you're using Windows), then that behavior is perfectly natural. So manually open up a command prompt and run it from there instead. The window won't close automatically and you can see the glory of yet another Hello World program gone right.

Of course, my assumption about what you did might be wrong.

Edit: The same can happen under certain IDEs when you try to run programs from them. They run the program, finish it, assume that that's what you wanted, and close the window on you.
[ February 07, 2006: Message edited by: Craig Tyler ]
 
J Flanagan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your responses!

I tried your suggestion of opening the command prompt... That didn't work either, but in the mean time I was writing the loop sample code in the book....

Then I tried running the sample for looping in the book using the same process of running it from the start menu -> run. Same flash of command prompt shell and nothing after. And then I tried from the command prompt. Neither worked, but this time the following error message was displayed:

"%javac is not recognized as an internal or external command operable program or batch file"

Below is the code.....


public class Loopy {
public static void main (String[] args)
{
int x = 1;
System.out.println("Before the Loop");
while (x < 4)
{
System.out.println("In the Loop");
System.out.println("The value of X is " + x);
x = x + 1;}
System.out.println("This is after the loop!");}}


What the duce?! I thought java was supposed to be easy to use!

~J Flanagan
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your java setup is incomplete. You will need to set the path of the classes and the .jar files that are needed by your compiler and JVM to run your .java and .class files. This setup is dependent on your OS.

Go through this link for more info:

http://java.sun.com/developer/onlineTraining/new2java/gettingstartedjava.html
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for windows XP

control panel/System/Advanced/Environment Variables (at the bottom)

highlight 'Path' in System variables section, click 'Edit' and add to the end of the line
;C:\Program Files\Java\jdk1.5.0_05\bin

where the opening ; is a separater
and the rest of it is the path to javac.exe
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!