954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Window closes too quickly

hi,
i just wrote my first java program, it compiles and runs and all, but the console window closes too quickly u can hardly see the output.
how can i rectify that?

NewToJava
Newbie Poster
3 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

Which OS are you in?

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

Windows, and i'm using JBuilder

NewToJava
Newbie Poster
3 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

Not sure what the problem is, but you could try sending the output to a text file to view it in Notepad. Normally to run a java class file you would type something like

java myProgram


Try

java myProgram > output.txt


That will create a file, output.txt, that you can open and view the console output of your program.

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

Thanks, i'll try the .text u mentioned

NewToJava
Newbie Poster
3 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

first better way... is try to run programs in command prompt thats is the best way to start a learning step for java

install jdk 1.5 or latest 1.6

then set your class path

compile it

javac programname.java


and run

java programname

you will get the output in the command prompt console itself

vinod_javas
Practically a Posting Shark
871 posts since Feb 2007
Reputation Points: 119
Solved Threads: 7
 

use the following at the end of your code

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
in.readLine();

it will pause your command prompt and wait for an input.

Fungus1487
Posting Pro in Training
459 posts since Apr 2007
Reputation Points: 66
Solved Threads: 56
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You