Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Very simple program from Head First is showing no output on print

 
vazu rahan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Javac compiles it.

Java will run it.

Try read carefully the instructions in the book again.
 
vazu rahan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
vazu rahan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I think the reason it doesn't work is because java is case sensitive. Is that correct?
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
vazu rahan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much. I'll read on the link you gave.

Thanks.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50258
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic