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 Local Development Environments How it Works The Java Virtual Machine

Kevin Faust
Kevin Faust
15,353 Points

some lingering questions regarding the property methods and uses

(updated)

hi

clear && javac com/teamtreehouse/Systemizer.java && java com.teamtreehouse.Systemizer

i dont get why we we couldnt just use clear && javac Systemizer.java && java Systemizer like we always did. whats the difference between the two? we never used the first one before

im wondering why System.getProperty("java.class.path") returns a period? I believe that java.class.path is where all your java files are located on your system (was able to see this after analyzing the code some more on the ide). so therefore since we are just using a workspace, there really isnt a path where the java jdk is installed and thats why it's just a period. correct me if im wrong.

so getProperties() returns all the properties of the current system and has a key and value like a map. both the keys and values are strings. however they're something called a Property object. can someone explain on that some more?

stringPropertyName() basically takes the key values and puts them into a set as strings. is this usually used in conjunction with System.getProperties()?

and in the video we did a bit of changing directories. we used cd/tmp to switch but again, whats a reason for switching out of our default directory. do we often do this?

also how come we didnt need to import java.util.Properties?

im still wondering what the point is of doing all this. Its cool to see how we can see all the properties of our system, but im just not sure how this would be incorporated in a project of some sort. what can we actually do and achieve with these properties?

thanks

1 Answer

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Ok so I will try to answer as many as I can. I am trying to go through the workspace at the same time to see what you are seeing.

1) i dont get why we we couldnt just use clear && javac Systemizer.java && java Systemizer like we always did. whats the difference between the two? we never used the first one before

when the workspace is started, it puts you outside the folder for Systemizer.java. We will call this the ROOT workspace folder then the sub folders in it would be com followed by teamtreehouse where Systemizer.java lives. To call commands on a file the console has to know where its looking, so if there are sub folders you have to put them unless you are in the current directory which you would get to by using a cd command.

2) im wondering why System.getProperty("java.class.path") returns a period?

A period being returned should indicate that it is in the current directory. There are more commands you can play with here

3) so getProperties() returns all the properties of the current system and has a key and value like a map. both the keys and values are strings. however they're something called a Property object. can someone explain on that some more?

So if you rewatch the video of Craig going through the docs on System.getProperties() and the other methods, if you pause it or go to the same URL he is at and take a few minutes to read what he is scrolling through. I know it is a lot but it will help the next time you find yourself there. System.getProperties() will return a Properties object, now just returning the object by itself doesn't have a whole lot you can do unless you use the methods(functions) that are built-in to a Properties object like the method called stringPropertyNames() which returns "a set of keys in this property list where the key and its corresponding value are strings". Because he "chained" together System.getProperties().stringPropertyNames() and stored it in a variable named propNames which he casted as Set<String>. This works out. Because the description of stringPropertyNames() states that it is going to return "a set of keys.... that are strings" so he knows that this variable will need to be casted as a Set<String> because that is the return type. Make sense?

4) also how come we didnt need to import java.util.Properties?

You would need to if you wanted to specifically create and instantiate your own variable as a Properties object. But he was able to get by this because you dont need to import System. System.getProperties() returns a Properties object but he chained it to a function called stringPropertyNames() which turned it into a Set of strings instead of a Properties object. To cast his variable as Set he did import Set. Had it needed to be a Properties object, he would of then had to import Properties object to cast his variable as such. So you have the right idea.

I tried to break this up best I could. I dont know if this helped at all or confused you more. Let us know, maybe someone could explain it better than I.

Kevin Faust
Kevin Faust
15,353 Points

thanks chris. i did some further research and understand it better however i cant really see the use of this. in all honesty how often have you needed to know the properties of your system using this method

Craig Dennis
Craig Dennis
Treehouse Teacher

Kevin it's more about needing to know what system your code is running on, remember you can write code for Windows/Mac/Linux, so you might use an if statement to only run certain types of specific code. Most commonly I use it to get the proper version of the file separator or new line. It's handy, and I wanted to show them, cuz we'll get more into them as we go further into web frameworks.

Hope that helps!