Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Harnessing the Power of Objects Methods and Constants

Kevin Faust
Kevin Faust
15,353 Points

pre-java requisites

ive completed the java basics but after that things are getting too hard and i dont get what's going on. this track is not for beginners at all. are there some other easier to understand object oriented programming tracks?

Bobby Hook
Bobby Hook
744 Points

I agree with you. The basics was nice and easy this has jumped in pace and i'm struggling too.

Chaz Hall
Chaz Hall
1,970 Points

I think the constant use of jargon is what is throwing me off. The assumption that everything is understand annoys me as the class continues. The beginning java course used videos and such to explain difficult concepts. Now that the difficult concepts are here it seems that those little flash (?) videos in the middle of the lecture just disappeared. I'm getting it but it's a struggle because of the repetitive jargon use.

5 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hi Kevin!

What exactly does 'static' do?

Static is a keyword that allows the class, or blueprint, to have exposed properties. There are a couple of reasons why you might want to do this. Some classes are utility only classes, meaning you would never create an instance. You know like calling new on it. One reason it is often used is for defining constants that will be true of every type of that instance. Like we did with MAX_PEZ. They are called class level variables or class constants. It's helpful to remember that your class might live amongst many other classes, and you just want a little bit of information about the class, and would not want/need to create an instance. I introduced this now as an attempt to demystify some of the boilerplate code. At the end of the course we will see that the main method is static, so you it can be called directly from the Example.class like so:

Example.main(args);

Why do we use the lower case 'm' before the instance variables? is it just to make the code easier to read?

The m prefix is a coding style that is used by the Android development team. The m stands for member, and initially it is used to show that that it is private member variable that should not be exposed outside of the instance. To expose it you write getters and setters, but only if you want to actually expose it. This is definitely not required. You can actually clear things up using a keyword named this, which we will explore but here is an example:

// Using Android Style
public class Dog {
    private String mName;

   public Dog(String name) {
      mName = name;
   }

  public String getName() {
     return mName;
  }
}

// Using this approach
public class Dog {
    private String name;

   public Dog(String name) {
      // See this might be confusing how many names there are at use
      this.name = name;
   }

  public String getName() {
     // No need to use this, because there isn't one in local scope, so name is assumed to be the private field.
     return name;
  }
}

Thank you for your awesome questions!

Does that help? Let me know if you are still feeling blocked!

Hi Craig,

That's helpful, but I'd like to chime in that it'd be great to see a visual on screen when you're talking. Not all learners are visual in that way but I am. It helped for me to turn on CC also, but a visual relationship diagram would be great.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hi Kevin!

Sorry to hear things aren't clicking. I usually recommend hitting up the Java SE tutorials for those who would like to learn more.

Is there something I can help with specifically, I'm sure another one of your classmates might be struggling with the same thing, so asking your question probably will actually help someone else learn!

Let me know if I can help, I'd love to try!

Kevin Faust
Kevin Faust
15,353 Points

Hey Craig,

How are you doing? What exactly does 'static' do? When we used repl, it looked like it is just so we can call instance variables directly by the class? Why would we need to do this? Why do we use the lower case 'm' before the instance variables? is it just to make the code easier to read?

Thanks

Hi Craig,

I'm confused why you sent students to the Java site when we're paying to learn it here. Is there any Treehouse content that can help those struggling? I'm having to do as much work for a site I pay $50 a month for as I did when I was struggling on the free sites...

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

I added some Teacher's notes to this video. I'd love your feedback Kevin P !

Gabriel Bogo
Gabriel Bogo
416 Points

Hey Kevin, I'm having the same struggle, did you learn Java afterwards? What was your path?

Kevin Faust
Kevin Faust
15,353 Points

Hey Gabriel, I persisted through the java track while also spending a lot of time on it. just keep trying to break down the code and watching youtube vids on certain topics if you really have to. im not a fan of watching others youtube vids as i cant trust them and so i usually just tried to read around or ask on the forums. I completed the java track in around 1.5 months and then headed over to android for roughly 2.5 months. I didnt really use too much of the advanced topics covered in java but moreso with just the basic concepts. my main goal was android after all and so the java track definetely gave me a good sort of preparation on it. Right now im learning python and resumed doing web development. i thought it was only java that was hard but if i started python without my knowledge of java, i wouldve been having the exact same struggle. once you understand this object oriented programming stuff, you'll be able to apply it anywhere. python was much less of a hassle due to java knowledge. just keep at it and the logic will start to develop. Good luck!!

Gabriel Bogo
Gabriel Bogo
416 Points

Thank you very much Kevin, I'll definetely persist on it!