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

Derick Brown
Derick Brown
7,361 Points

Need a deeper understanding of Java

I'm still a little confused about Java...or I may be overthinking these challenges and videos lol.

So far I completed the Java Basics course and I have about an hour left until I completed Java Objects course. There are a few things I'm still not understanding about Java and the videos I'm watching:

  1. We bounce back and forth between multiple Java files in our Workspaces. Craig will put a method in one Java file then put another method in a different Java file. How does he know which file to put each method?

  2. I often see Craig add methods between other methods. Does the order of where you place methods matter?

  3. I'm watching these videos and I realized Craig will explain what he's doing but I"m not 100% sure WHY. I can read through and understand what he's typing but not sure how he came to that conclusion. How does he know what he's typing is the right direction and right way to go?

  4. What's the difference between using "private" on a variable and using "public" on a variable but ONLY using that variable within that class? Wouldn't they both achieve the same thing? Which is a variable only being accessed by that class only.

  5. If you declare a variable in one method, can that variable be accessed in another method? Example:

public String thisTest() {
     String test = "now!";
}

public String thisTestTwo() {
     String test2 = "Get over here " + test;
}

Sorry for the long post. It's just when I do my challenges, I understand what's being asked of me and I generate a conclusion but it's hard for me to even know where to begin, if I'm thinking right about the situation, what methods and variables I need, etc. I guess you can say I have a confidence issue lol.

If someone can help me out then that'll be great!

Thanks!

Ronald Goodwin
Ronald Goodwin
2,357 Points

Bro this is the exact issue I am having. Like I know how to do all the things I understand how to do them but I do not completely understand why, or when to use certain things. and there is things very similiar to each other and I dont know how to choose the correct one to use.

Ronald,

If you can articulate your questions, point-to-point, I'll try to help.

Steve.

7 Answers

Hey Derick! Great questions; you're clearly understanding lots and just need a few details covering off. Let's try to do that ...

  1. He knows 'cos he's Craig. Be like Craig. ;-) No, seriously, that just comes with time & exposure to similar things - let's not worry about this right now.
  2. No. The order of methods doesn't matter. There's a sensible order sometimes but that's just for the sake of clarity. Don't worry about that either.
  3. The design aspect of the applications Craig is generating is left as out-of-scope for now. By the time you finish the courses, you'll have a better idea of how that works. You'll get a feel for it.
  4. The difference with private & public. There's a long list of that stuff! If you only use it within an instance of the class then, no, there's no real difference. BUT leaving a member variable public allows external access - this might not be just your code; we could be running a web app with database connections and some dodgy geezer tries to access your member variables without going via the getters/setters - bad man. So, there's a security issue beyond your own code that needs to be considered.
  5. No. If you declare a variable within a confined scope that variable is only accessible within that scope. That works for examples like your method; loops too. Anything that has a set of code that can run independently of the rest of the code has its own scope variables declared inside that scope are only available within that scope.

I hope that helps a little. Feel free to ask more Q's! I can be reached on here or on Twitter @OnlySteveH - I'm on Facebook, Skype etc too ...

Steve.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hi Derick Brown (and nekilof )

Thanks so much for the feedback! (And thanks for the ping and all your hard work Steve Hunter )

I'm assuming you are both talking about the Java Objects course. I have definitely gotten similar feedback that students are understanding the HOW but at the same time not necessarily knowing the WHY of what I'm doing what I'm doing. And that's my bad. Sorry bout that, there is so much to cover and so little time! I shaved too much off of this course, trying to make it digestible, while still relatively light.

I'm currently wrapping up a few remaining workshops to complete the Techdegree at the moment, but I plan to refresh this course, and the one following it, Java Data Structures very soon after that.

One way I've thought about tackling that feedback is by introducing white-boarding before we go and code each step. I think this will help visualize the problem and allow us to talk about why and how we are going to attack the portion. Do you think that would help in this specific situation?

The other thing that I feel I did poorly in this course, was that I forgot to enforce a crucial piece of knowledge that is important when you are just starting to code. Other people will use your code. Even if it doesn't seem like it in the beginning. That is one of the main drivers in understanding what this access level stuff (private/public) is really getting at, and I skipped over it...blargh :( . By specifying these levels you are intentionally communicating what your class is capable of doing. By only exposing things that others can rely on, you are able to hide how other things are implemented. So as your codebase (and skills) grow, you can come back and change the private bits of your application, and the people relying on your code won't know the difference, because you can keep the public methods, or API, the same.

There is quite a bit of detail involved in designing an application with sound OO principles and I have a course on the Java Content Roadmap, which as popularity has declared, I plan to get to soon after the refreshes.

As these courses in the Learn Java track progress, you'll find the answers to most of your questions through hands-on practice, and I do so appreciate your want to know it all right now. Curiosity is the sign of a great developer.

Again thanks for your feedback and I do plan on incorporating it in refreshes and new content, so keep it coming!

:+1:

Ronald Goodwin
Ronald Goodwin
2,357 Points

Dont be to hard on yourself Craig. You do amazing at teaching us the "how " to do it though.;

Hey Craig, I wasn't expecting a reply from yourself, but I appreciate it! I was referring to your Java Objects course. I look forward to your new content. ~Abby

Derick Brown
Derick Brown
7,361 Points

Hey Craig, I didn't know you were an actual member of the site lol. But now that I know you're also a member, I'll definitely contact you if I have any questions or concerns. You're doing a great job teaching Java and you're trying your best to consolidate so much material into only a few hours. What you're teaching is pretty much a college course that goes on for months let alone you only have 4 hours to teach everything front o back lol. So you're doing a really good job and I appreciate your help!

Thanks for the reply and explanation on everything. I'm definitely looking forward to the new course you're undergoing.

If I could add something to that; I'd say work through more object-oriented languages. Try some Objective-C, C++, Swift - the concepts are the same across these languages. Whilst some elements of HTML or front-end web languages contain OOP principles, they're not as strict as true OOP languages. (I'm an old fart who used to code in the brilliant Smalltalk language, so excuse me!).

The things you raised as mis-or-non-understandings were mainly OOP things. So, write more code in OOP languages; learn how classes/objects/instances/constructors etc work in different languages. You'll get so familiar with the concepts, you'll be dead clear on the Java stuff! Just expose yourself to as many different examples of the concepts that confuse you; ask questions in the forum/Twitter (whatever!) as you need to when you deal with these concepts. Repeating these concepts will add them to the foundation of your knowledge. That foundation will just grow and grow.

Oh, and don't feel shy of asking Craig Dennis for a helpful reply; he just liked one of my tweets, for example! ;-) Craig's accessible, if a little busy.

Shout me if you need help; happy to lend assistance.

Steve.

Ronald Goodwin
Ronald Goodwin
2,357 Points

Wouldn't him trying to use other languages only confuse him at this point? I know Java is based off C++ but there is enough minor differences where I assume it could get hectic for someone who doesn't have a strong base in either? like me for instance lol

I feel that visiting and addressing the same concepts in different contexts aids learning.

That's not the same for everyone and nor is discounting that approach.

I think seeing the same thing presented or articulated slightly differently helps cement the foundation of that concept.

Steve.

Derick Brown
Derick Brown
7,361 Points

Steve Hunter nekilof

Thank you so much for your guys' replies! Very helpful indeed. So I guess the best thing for me to do is keep trying and diversifying my studies a bit until I get more comfortable with the language. I'm a bit familiar with other languages so I try to learn Java as if I'm dealing with HTML, CSS or something. Like in terms of accessing properties from different files, passing in values, manipulating these values, etc. But I'll get it sooner or later.

Thanks for everything!

Hi Derick, I share many of your frustrations with Craig's Java class. I want to know why Craig does everything that he does in his videos, and I'm taking a break from that series because I could feel my frustration level rising when he doesn't explain fully what he's doing and why. I can at least take a stab at #4 on your questions by saying that public variables are applied globally so they're used sparingly. If something is declared public within a variable it's "globally" applied within that variable. I suppose an analogy would be that I apply a pesticide to a lawn on just the weeds (a private variable: spray weeds). If I instead accidentally apply a local but public variable spray the pesticide, I'd spray the whole lawn and kill the flowers and the veggies that were growing....but I'm not killing all the flowers in the neighborhood like I would if this was just a public declaration. I might be wrong, but I think I understand that much :-)

Otherwise, I know it's super old fashioned, but I've found the Head First series by O' Reilley to be a great supplement to most of the Treehouse courses in terms of it also breaks things down into little chunks and does go into the history and the reasons behind why we do the things we do in a given language. I also appreciate the simplistic language and the pictures...not gonna lie ;) So my answer to this problem was to diversify my learning and seek supplements. I'll be curious what others advise.

Ronald Goodwin
Ronald Goodwin
2,357 Points

Steve Hunter My issue is

I know about inheritance and using different methods, and variables and global and local. my issue is I do not know when or why to use things like the constructor I get how to use it but knowing why or when confuses me. inheritance is a huge thing I understand how to write syntax wise but not in a way that I understand when to use something. like all the syntax is understanding to me but the logic of when or why to use one aspect as apposed to another is what is getting me.

OK - that's an insight into what you don't think you understand.

Now articulate a question to answer a small part of that perceived dark area. Just one question for one piece of the puzzle.

We can go from there.

Steve.

Ronald Goodwin
Ronald Goodwin
2,357 Points

1.How do I tell what to include in a super class or an inherited class ?as of now the only things I can think of to put in a super class is variables

  1. Getters/setters or constructors which one to use and why?

  2. Packages< how do I know when to create a new package?

  3. interfaces,abstract, and regular classes, how do I know which one of these to use at specific times?

I can create all the things I asked questions about, I just cant figure out when and what should be used.