File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Reading Head First Java - confused Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading Head First Java - confused" Watch "Reading Head First Java - confused" New topic

Reading Head First Java - confused

Mark Ly

Joined: Jul 31, 2011
Posts: 2
Hi guys. I've been reading Head First Java to get into Java. I'm at the beginning of the second chapter where things get more Object Oriented... oriented?

Anyways, pg61 (if you have the book) and it has me writing the following code:

When I execute this, all that comes out is the "Playing the movie." Am I missing the point, or isn't it supposed to do more than that? I have that all in one file and I'm thinking maybe I need to have the second class in another file or something. I'd really appreciate some insight on this.

I know this is a really dumb question and I probably have a few people laughing at me, but I'm really determined to learn Java so be prepared for a few more of my stupid questions. :P
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
I don't think I or anyone I know about has ever had an urge to laugh at anyone trying to learn complicated things like programming language

As for your code, lets look at the class Movie:
It has 3 member variables that indicates that it holds 3 kinds of information namely: Title, genre and rating
It has 1 member function which has one purpose: printing out the string "Playing the movie"

The main method goes through the trouble of creating two instances of that class, giving it names, genres and ratings but those attributes are never seen because the playIt() function doesn't include them in the output string.
I would assume that at some point you should be able to get the movie title, genre and rating, so what we are looking at is an incomplete class. I bet your assignment is to add new functions to it like getTitle(), getGenre() and getRating().
You could also modify the playIt() function to include the name of the movie: Playing the movie: Gone with the Stock
Mark Ly

Joined: Jul 31, 2011
Posts: 2
That makes sense now. So it was storing the info, just not printing it I assume.

I changed up the code a bit and made it actually display all the info for each of the movies.

Thanks for the help Unnar!
Benjamin Thvedt
Ranch Hand

Joined: Jul 29, 2011
Posts: 31
Reading the same book, just did that one myself! Yeah, it seems like there is a lot of extra stuff for something that just outputs "Playing the movie!"
I agree. Here's the link:
subject: Reading Head First Java - confused
jQuery in Action, 3rd edition