| Author |
Very simple program from Head First is showing no output on print
|
vazu rahan
Greenhorn
Joined: May 10, 2011
Posts: 5
|
|
Hi to all.
I would like to ask for help for this very simple program from the Head First book. I get no output from the XP Command prompt.
Nothing shows up when I run it through javac MyFirstApp.java. But if I create errors on the code, it shows it.
My path on Environmental variables is installed properly since it shows errors like a missing semicolon etc.
C:\Program Files\Java\jdk1.6.0_25\bin
|
 |
Jesus Angeles
Ranch Hand
Joined: Feb 26, 2005
Posts: 2036
|
|
Javac compiles it.
Java will run it.
Try read carefully the instructions in the book again.
|
 |
vazu rahan
Greenhorn
Joined: May 10, 2011
Posts: 5
|
|
Yes, it creates a .class file on the folder where the .java is.
But after fixing all the errors, command prompt doesn't show output. After typing javac MyFirstApp.java, it just goes to another prompt like this.
---------------------------------------------------------------------------------------------------
C:\Program Files\Java\jdk1.6.0_25\bin>javac myfirstapp.java
C:\Program Files\Java\jdk1.6.0_25\bin>
---------------------------------------------------------------------------------------------------
If I intentionally place errors on it. Here's the output
---------------------------------------------------------------------------------------------------
C:\Program Files\Java\jdk1.6.0_25\bin>javac myfirstapp.java
myfirstapp.java:5: ';' expected
System.out.print("I Rule!")
^
1 error
C:\Program Files\Java\jdk1.6.0_25\bin>
---------------------------------------------------------------------------------------------------
It's supposed to print I Rule!
BTW, I'm using Windows XP command prompt.
Thanks for the reply though.
|
 |
Jesus Angeles
Ranch Hand
Joined: Feb 26, 2005
Posts: 2036
|
|
No, it is not supposed to print 'I rule'.
It did what javac is supposed to do. That is, to compile your class.
To run, you will use 'java'.
It is a 2 step process: compile using 'javac', then run using 'java'.
Carefully re-read that part of the book. I am assuming, there is an instruction there. If not, then just google for how to compile and run java program.
|
 |
vazu rahan
Greenhorn
Joined: May 10, 2011
Posts: 5
|
|
No, it doesn't show how to use java.
It doesn't even show how to setup the Environmental Variables thing.
Okay but now I was able to run the program by typing
java MyFirstApp
but it requires the file to be on the bin folder. I'll now search the internet how to make the files on a folder on my desktop to run.
|
 |
Jesus Angeles
Ranch Hand
Joined: Feb 26, 2005
Posts: 2036
|
|
At page xxviii 'intro', you see some instructions.
You must read all sections not just jump, if you want to be careful to not miss instructions.
|
 |
john price
Ranch Hand
Joined: Feb 24, 2011
Posts: 495
|
|
Save the program as "MyFirstApp.java".
Open the CLI (Command Line Interface aka Command Prompt).
Change the directory to the directory of the file (If you saved the file in C:\Users\cc11rocks\JavaStuff), then type:
Then, type in (to compile the program):
If nothing seems to happen, it made the byte file properly.
Then, to run the program, type in (to run the program):
You should see "I Rule" on the next line and then back to command line with a blinking cursor. Congrats, you have compiled and ran a Java program!
,
cc11rocks aka John Price
|
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
|
 |
vazu rahan
Greenhorn
Joined: May 10, 2011
Posts: 5
|
|
|
Okay, I think the reason it doesn't work is because java is case sensitive. Is that correct?
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
vazu rahan wrote:Okay, I think the reason it doesn't work is because java is case sensitive. Is that correct?
Java is case sensitive, Yes. But looking at your previous reply actual problem was perhaps a PATH issue.
but it requires the file to be on the bin folder...
While you read the book you may also read the Java Beginners Faq as well
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
vazu rahan
Greenhorn
Joined: May 10, 2011
Posts: 5
|
|
Thank you very much. I'll read on the link you gave.
Thanks.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Welcome to the Ranch
I can't remember whether this is stated explicitly, but a successful run of the javac tool produces no output
myprompt > javac MyFile.java
myprompt >
If nothing happens, you must assume it was successful. If anything went wrong, there would be an error message. Then you try
java MyFile
|
 |
jake dickens
Ranch Hand
Joined: Mar 23, 2011
Posts: 30
|
|
Campbell Ritchie wrote:Welcome to the Ranch
I can't remember whether this is stated explicitly, but a successful run of the javac tool produces no output
myprompt > javac MyFile.java
myprompt >
If nothing happens, you must assume it was successful. If anything went wrong, there would be an error message. Then you try
java MyFile
If you are still having trouble with it what i do is make a folder on my desktop and name is whatever then when you got done making a code file and save it to C:\user\your name\desktop\whatever file then save as myfile.java then go to cmd put in cd\ enter then type c:\user\desktop\whatever\ then you go javac myfile.java will complie and make a myfile.class then java myfile then will show what you did.
|
 |
 |
|
|
subject: Very simple program from Head First is showing no output on print
|
|
|