aspose file tools*
The moose likes Cattle Drive and the fly likes trouble with my first assignment - Head First Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "trouble with my first assignment - Head First Java" Watch "trouble with my first assignment - Head First Java" New topic
Author

trouble with my first assignment - Head First Java

Daniel Morrison
Greenhorn

Joined: Mar 26, 2007
Posts: 11
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 ]

The recipe for perpetual ignorance is: be satisfied with your opinions and content with your knowledge. <br />Elbert Hubbard (1856 - 1915)
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1362
    
  17
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

Joined: Mar 26, 2007
Posts: 11
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

Joined: Nov 03, 2006
Posts: 1362
    
  17
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

Joined: Mar 26, 2007
Posts: 11
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

Joined: Nov 03, 2006
Posts: 1362
    
  17
The problem is in this line:



Can you see what is happening?
Daniel Morrison
Greenhorn

Joined: Mar 26, 2007
Posts: 11
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

Joined: Nov 03, 2006
Posts: 1362
    
  17
Good on you

Yepp - it does *exactly* what you ask it to!
Daniel Morrison
Greenhorn

Joined: Mar 26, 2007
Posts: 11
Yes, and thanks. I also found the other flaw put there by the author:

should come after...


Thanks again
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
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

Joined: Oct 06, 2006
Posts: 1
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.


"Egotism is the anesthetic which soothes the pain of stupidity."- unknown
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1195
I need a beer...........
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: trouble with my first assignment - Head First Java