Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Meet Objects Creating Classes

Simon Johnson
Simon Johnson
1,277 Points

List and explanations of keywords for reference

I was following up until this point, but the level (like so many times I have tried to learn programming languages in the past) has ramped up significantly from the previous course.

I am sure I am not the only one but I feel like I am being lost a little bit with the number of "new" keywords banded around in each subsequent video.

I know I can refer to the Oracle Java documentation, but most of that, at least at the moment, just adds more confusion.

Can anybody point me to, or can I suggest an addition to the Teacher's notes on each video; a summary of the "new" keywords, and their definition and significance within the video or current module.

I am making plenty of notes as I go along and even stopping at the end of each video and downloading the srt file to read the transcript, but still feeling a little lost.

Thanks in advance.

2 Answers

OK - now, I'll confess to having never come across a Pez before doing this course; it is still something I've never used so it isn't real-world example to me. Craig pointed me in the right direction when I asked him!

PezDispenser is the class (the template). PezDispenser() is the constructor and dispenser is the variable the instance of the class is assigned to.

So, dispenser holds the instance of PezDispenser that is created by using the new PezDispenser() line.

The GoKart thing is similar. The keyword GoKart is the class itself which is created/instantiated by using new GoKart() (the constructor) but this constructor wants a parameter (something that you give the constructor to construct the GoKart you want. In this instance, you want to create a coloured kart; let's say we want a green one ... GoKart simonKart = new GoKart("green");

That creates a variable called simonKart that is waiting to hold a GoKart sized object (that's the left hand side of the equals sign done). We then create a GoKart using the constructor that takes a colour. The new keyword then uses the constructor with a string GoKart("green") that creates the object. The equals sign puts the object created to the right of it into the space generated to its left.

I hope that helps!

Steve.

Simon Johnson
Simon Johnson
1,277 Points

yes that makes it much clearer. weirdly you simply using simonKart instead of color made it click.

Thank you

Yes. It is much easier when you realise that you can call your variables anything. That name is totally up to you; not part of any functionality at all.

There are naming conventions that are used to create meaningful variable names but, when you're learning, it is useful to understand that the allocated name is just that; a name; a label that holds no functionality at all. You can call them what you like (but you'll regret that in the real programming world!!).

One thing at a time.

Steve.

Hi Simon,

Don't be alarmed; many students get confused at these new concepts. Keeping at it and gaining familiarity of them is the key to really understanding them.

I don't have a list (but I'm happy to put one together if you let know what's causing you trouble) but I did write a post on various keywords that you've just come across. Please have a read of this post to see if that either helps or allows you to articulate further questions that I hope to be able to help with!

Keep me posted.

Steve.

Simon Johnson
Simon Johnson
1,277 Points

Thanks Steve.

lots of the words are familiar to me, but their context is what I am finding difficult, and what is what etc.

I have had a look at your linked post and I think it will be of great use. I am going to print it out and have it as a reference.

Thanks for the quick response.

I think my biggest difficulty is getting my head around the concept of the model/s used in Pez Dispenser and GoKart, if someone could possible give another "real world" example of the use case of this that might give me a little better understanding. The reusing of phrases is confusing me, i.e. PezDispenser, PezDispenser(), dispenser,