This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trouble with my first assignment - Head First Java

 
Daniel Morrison
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm new here and to java; done SOME programming. Using some very lightly here. So my question is that I can't seem to run a java .class file that I created. I'm using the book Head First Java and was able to create and compile the Hello World app, but when I double-click it to run it... nothing. I'm doing all of this in OS X.4.8 and the book says that I don't need to install anything else to do java on the OS X platform. The code is:

public class hello {
public static void main (String[] args) {
System.out.println("Hello World");
}
}

All help will be appreciated

[edited subject - pmc]
[ March 27, 2007: Message edited by: Pauline McNamara ]
 
Katrina Owen
Sheriff
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's see if I understood correctly.

You have written your code:



and saved this as



Then you typed


and it compiled without any error messages.

Then you have typed


but nothing happened.

Does this sum it up correctly?

If not, what error messages are you seeing?
 
Daniel Morrison
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is why I posted that I was a new user of Java; I've found my mistake. I wasn't typing java hello to see it run. I was instead double-clicking the hello.class file from the finder.
However, I do have another problem with running a different file that I created. I created another, longer file that has both a loop, if/else statements that compiles, but won't run. In the book that I'm using, Head First Java, it's the program for the beer song; displays the 99 bottles of beer counting down as it goes through the loop.
I've checked the spelling of everything, but no go.
:roll:
 
Katrina Owen
Sheriff
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why I spelled it out - it is difficult to know exactly what could be happening.

How about you post your code (remember to use [ CODE ] tags!), and we can have a look-see?

I should probably mention that you should post in the Java Beginners forum if you haven't signed up for the cattle drive (the bartenders will most likely move your post, anyway). But since I am around, I am happy to help.
 
Daniel Morrison
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, thought I was in the right place. The code is as follows:

Hope I did that code thingy right
I was able to get this to compile, but not run using java beersong from the terminal.

I appreciate your help, Thanks from a Greenhorn
 
Katrina Owen
Sheriff
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is in this line:



Can you see what is happening?
 
Daniel Morrison
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it should be

It never got a chance to start.
That's the thing about code; it doesn't like ANY errors.
 
Katrina Owen
Sheriff
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good on you

Yepp - it does *exactly* what you ask it to!
 
Daniel Morrison
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, and thanks. I also found the other flaw put there by the author:

should come after...


Thanks again
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does indeed hurt me to have to move this thread, it's such a wonderful discussion.

The Java in General Beginners forum is its real home though, so I'll close it here and let any further discussion happen over there.

Welcome to javaranch Daniel!

And Katrina, I sure hope you'll be hanging out 'round the ranch for a good spell thar, pardner.
 
Dave Evans
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pauline McNamara wrote:It does indeed hurt me to have to move this thread, it's such a wonderful discussion.

The Java in General Beginners forum is its real home though, so I'll close it here and let any further discussion happen over there.

Welcome to javaranch Daniel!

And Katrina, I sure hope you'll be hanging out 'round the ranch for a good spell thar, pardner.


you could also add a last line to end the song..



after the while loop, but before the end of the main method. this way the song comes to a proper end.
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need a beer...........
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic