• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Are my notes correct

 
andrew dale
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are notes I'm making from Head To Java book....

They are focusing on teaching how arrays and objects work

They give a line or two of code and then explain them, but I don't understand their explanations completely so I am going through the code and making sure I understand everything that is going on... I am hope you can look over the notes I am making (I have no background in programming so everything is new to me and I don't want to be learning things I think are right but are really wrong.)

Also the very last part of the code I don't understand at all, if you can explain it to me it would be appreciated.

I will continue trying to figure it out and if I do I will edit the post with what I think is happening



p.s. sorry if my notes are very sloppy written, I try to write them as I am thinking of whats going on because... I have no idea whats going on.
 
Jon Avadis
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


that is declaing that the dog will have arrays and pets being the variable


Not exactly. You are declaring an Array of the type dog, and call it pets.
Thats like saying, all my pets are gonna be dogs and they are gonna be arranged as an array.
Later you can refer to your pets as pets[0], pets[1], etc, and every pet is a dog.



The 7 is new objects with is the dogs and pets being the variable of them.


No. Your initializing your pets Array now, after you declared it in the first line.
Your pets Array is created with enough space to hold 7 dogs, but there are no actual dog-objects in it yet.
You basically saying: give me a place for my pets, and that place needs to have room for 7 dogs.
 
Jon Avadis
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


creating a new objects for every variable which is a new dog object for each pet


Yes, you are actually creating new dogs now, and assigning them to your "group" of pets.


fido being the variable given the object of new dog


This is a declaration and initzialization in one line.
If you pick it apart it says:
first: fido is gonna be a dog.
second: assign a new dog-object to fido.




name is a class variable of the class dog. It means that every dog has a name.
The name may be blank when the dog is "born", but with that line you give him one


telling fido to bark using method applied in another line of code


Yes.



Applying the dog array to myDogs variable? Don't understand the part after equals


Your doing the same thing you did with pets here, but in a single line
Your declaring a new array called myDogs, thats supposed to hold dogs and then after the equals-sign, you initialize
that array, preparing room to hold 3 dogs. The capital 'D' of "Dog" there is an error if im not mistaking.

 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good answers, but a few little points:
Jon Avadis wrote: . . .
name is a class variable of the class dog. . . .
More likely an instance variable.
Initialising variables like that is actually poor design. It would be better like thisThat way you never have a "blank" (actually null) name to deal with. Beware: nulls can cause all sorts of problems.
The capital 'D' of "Dog" there is an error if im not mistaking.
Although the compiler will complain about the D, it should be D. The convention is that class names begin with a capital letter. Obviously you have to be consistent: Dog or dog, and don't mix the two.
 
andrew dale
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone for helping and correcting my mistakes, all of your explanations helped me a lot and I understand it now... It is greatly appreciated.

Thanks again! This forum and members are awesome.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome Jon Avadis was particularly helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic