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
Let me know if I understood this basic class!
OKAY, let see, I want to know if I understood the basic of this class. String is a data type, we can compare String similar to a room where we create variables like sections where we put the different kind of brand shoes? the brands shoes would be the values ? like this way. String sections = "nike"; did I understand that part? as the class progress we discover console, System, int, are these objects that have their methods? for example console has .printf, also have the .readLine? System has the .exit method? and int is primitive and primitive objects has do special work? am I right? int work with numbers ? and with int being a primitive also let you create variables right??. and last thing to understand the user or keyboard in the age warm we use the normal concept String ageAsString = console.readLine("How old are you? "); to convert this we the int age = Integer.parseInt(ageAsString); my question on this last example is: is Integer an object that has a method that help us to abstract whatever the String ageAsString has to say? sorry guys I just want to know if I understood.
I'll try to clear things up:
- primitives are not objects, there are differences between the two that will become more obvious as you keep learning more java
- int, double, boolean, are primitives. There are 8 in total, look them up.
- The console is an object, yeah, strings too are objects
- Objects have methods, yep (Primitives don't! Primitives are just a value.)
- Variables can be primitive variables or reference variables and they don't work the same, you'll find out more later. Primitive variables are for all the primitive data types. Reference variables are for objects.
- This is getting way complicated for where you are now, but: Integer and int aren't exactly the same. Like I said int is a primitive. Integer is an object, like String. You can put an int primitive into an Integer object, and an Integer object back into an int primitive. But here is the difference: int is just a number, it doesn't have any methods (because it's not an object). That's why this Integer object exists. The Integer object is basically an int upgraded into an object to add some handy features (like the parseInt() method). All primitive data types have their own "object with extras" and you can recognize them because they're capitalized. So you have boolean (primitive) and Boolean (object), float (primitive) and Float (object), etc.
- So I hope I helped and didn't confuse you. Don't worry if you don't get it right away. There are some subtleties in the code you're seeing that are actually a bit complicated to explain, but keep following the java track and you'll understand more and more of those subtleties as you go.
And I forgot to answer your actual question: the parseInt() method is a method that reads a string and tries to turn it into an int. So Integer is a special object for int values, and it has this parseInt() method that will read a String, and convert it into an int if possible. (If it's not possible, for example the string contains a word instead of a number, the program will complain about it when you try to run it).