aspose file tools*
The moose likes Beginning Java and the fly likes Head First Java - ARGH! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java - ARGH!" Watch "Head First Java - ARGH!" New topic
Author

Head First Java - ARGH!

Mike Klein
Greenhorn

Joined: Jun 22, 2009
Posts: 2
I've been working through the Head First Java book (2nd edition), and things were going pretty well until chapter 6. Now I'm totally lost and frustrated. I apologize in advance, but this is going to be a bit long and rant-ish. But I REALLY want to learn java and now I'm very discouraged.

It seems like there are two main things that should be accomplished in CH6: learning to use some java pre-built classes, and fixing the DotCom game. I pretty much follow everything up through page 133, then things start going horribly wrong.

On page 134 they want me to compare ArrayLists to regular arrays in a "Sharpen Your Pencil" exercise. Like "how would you get the size of a regular array"? I have no idea, and the index in the book is awful.

On page 139 there is a class. Cool. I want to type in the class and see it work. But it doesn't work. Something about setLocationCells being passed an int, but expecting a String. Or is that a <String>? Is there a difference? I have no idea. I thought strings were declared with [].

Now on page 140 it looks like they're going to introduce multi-dimensional arrays, but then they don't. But on page 141 they're talking about 3 classes - and they proceed to print multiple versions of some of the classes, but not all the classes you'd need to actually have a running program, and with tons of junk scribbled amongst it. And then on pages 146 and 147 there's an exercise to match up code to annotations, but then they never give you the answers, so I don't know if I'm right or not. Now there's some stuff about booleans, then more "ready-bake" code, then to a really well written few pages about "Using the Library (the java API).

ARGH!

This chapter seems to present things in the most illogical, random, and confusing way possible. I'm not even sure what I was supposed to have learned in this chapter, and since there's really nothing except a "code magnet" exercise, I have no way to check that I really understand this stuff before proceeding to the next chapter. I also thought I was going to be writing some code, or at least typing in some code..?
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Mike:

To be honest, the Head First series isn't for everyone. Personally, I didn't particularly care for the format, and in general, I tend to prefer the 'standard' technical format.

On page 134 they want me to compare ArrayLists to regular arrays in a "Sharpen Your Pencil" exercise. Like "how would you get the size of a regular array"? I have no idea, and the index in the book is awful.


See here for ArrayLists, and here for information on arrays.

John.
David Sharpe
Ranch Hand

Joined: Jun 15, 2009
Posts: 32
I can sympathize with your trouble, but I'm not really sure what your question is. I do see a few question marks in that self-described rant though , so I'll try to address one of them:

Mike Klein wrote:Or is that a <String>? Is there a difference? I have no idea. I thought strings were declared with [].


A more experienced Java programmer might correct me, but I'm unaware of anything the [ ] symbol applies to except arrays. A string is declared simply String apple = "Apple";. I'm a bit concerned that you've reached CH6/page 133 without being comfortable with that. You may want to slow down a bit.

p.s. A C "string" is declared: char greeting[]="Hello";. If you're a C programmer and you think that's going to give you a head start on Java, then you're absolutely right, but you'd still better slow down enough to grasp the syntax before you start reading about objects.

p.p.s. If you want to try another book, maybe try The Java Tutorial: A Short Course on the Basics, 4th Edition. It comes right from Sun, and every section ends with questions, answers included.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38902
    
  23
You can find the Java Tutorial free of charge on the net.

I would disagree that knowing C gives one a head start in Java. The differences are many and subtle, and I have seen people get problems because they thought C/C++ and Java mean the same thing when they have similar syntax.
David Sharpe
Ranch Hand

Joined: Jun 15, 2009
Posts: 32
I actually meant it more broadly then that: i.e. if you already know one programming language, it tends to make learning another easier.
Campbell Ritchie wrote:I have seen people get problems because they thought C/C++ and Java mean the same thing when they have similar syntax.

That's true too.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Mike, it's all part of the journey, all resources have their weaknesses and issues. Even the java Tutorial will have you ripping your hair out from time to time, though it's pretty good in most ways. I have three or four different sites I turn to regularly.

Don't rule out Google as a resource. There's all kinds of resources on the net. If one doesn't do it for you, a well turned google search phrase will turn up all sorts of good stuff.

edited to correct spelling.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38902
    
  23
Take your point, Dave Sharpe
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2851
    
  11

Well, I disagree with everyone. The Heads First books are a great way to learn a new topic like Java, and also knowing C/C++ totally helps you learn Java. Java is what C++ should have been, or looking it at it another way, knowing C++ makes you appreciate the differences between it and Java. When I think back to the days of multiple inheritance, global variables, code split among C and h files, and overloaded operators, I'm so happy I learned Java.

OK, I looked at page 139 thanks to Amazon's free previews. I noticed a couple of things. Firs setLocationLIst() doesn't expect a String, but an ArrayList<String>. That is, an ArrayList that can only hold Strings. It used to be back in the day that an ArrayList could hold any kind of Object, and there was no way to make it more specific except by checking everything as you put it in (are you a String?) and checking again when you took it out (are you a String?). It was tedious. We also had to walk 10 miles through the snow to get to work. (Confused? Talk to my father. 10 miles through the snow to school in Los Angeles, and uphill both ways.) Anyway the ArrayList<String> syntax might look ugly at first, but believe me, it's worth it.

The second thing I noticed is there are no calls to setLocationList() anywhere in the code on page 139. That means there is some other code calling it, probably code left over from when you were using arrays. You want to enhance that code with something like this:



Then pass "list" as the parameter to setLocationList(). Right now you're passing an integer array, aren't you? And the compiler is complaining that you are passing int [] not int, and it expects ArrayList<String> not String.

Anyway, good luck with it! Everybody gets frustrated with programing at some point.
 
wood burning stoves
 
subject: Head First Java - ARGH!