File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A little help for a total beginner?

 
Pierre Bungle
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello hello,

Hope you're all well. This is my first post on this forum, but it was recommended by this textbook I stumbled upon (Head First Java). I find myself not understanding some really basic stuff, and have unfortunately run out of time to get it on my own. A little help would be immensely appreciated! Be patient, I'm a real doofus when it comes to coding... ;)

Here's the crux:



There are two things I don't understand:
1) is the first statement in the while loop creating a second array, in our hq array?
2) what is the statement hq[x].id = x actually doing (specifically the .id part)? I thought the . operator meant you were calling a method?

Thanks for your time!
 
Brian Legg
Ranch Hand
Posts: 488
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags next time

1) is the first statement in the while loop creating a second array, in our hq array?


Nope, it is creating a new HeapQuiz object and assigning it to the first slot of your "hq" array which is declared to hold HeapQuiz objects. The "hq[x]" part of the statement is just accessing the "x" index (in this case 0) of your hq array while the "= new HeapQuiz();" part of your statement is creating a new object of type HeapQuiz and is returning a refernence to this object into your array.

2) what is the statement hq[x].id = x actually doing (specifically the .id part)? I thought the . operator meant you were calling a method?


Yes, the .id is accessing the member variable named "id" that belongs to the HeapQuiz object. While it is true you can use the dot operator to access methods, you can also access member variables as long as they are visible in your program. What I mean by visible is you could not access "id" using the dot operator if "id" was declared private.

Hope that helps, and welcome to the JavaRanch!
 
Brian Legg
Ranch Hand
Posts: 488
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good practice exercise would be to figure out what your hq array would look like after the while loop is finished (don't peek at the book).

 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

I have added CODE tags so you can see how much better the post looks. But please use thread titles which tell us what the thread is about.
 
Pierre Bungle
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the help, much appreciated!

I'll use quotes next time
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CODE in that case, not QUOTE, please
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic