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 trialMarina Alenskaja
9,320 PointsJava types: why the difference between strings and integers when naming?
Hi guys I was watching the video and it annoyed be a bit that the string variables are defined with capital S but the integer wasn't. Why the difference, and how do you remember it?
2 Answers
Marc Schultz
23,356 PointsIn Java all types with a capital character at the beginning are classes.
All lowercase types are primitives.
ninaddeshpande
6,158 PointsYou can write Integer ('I' capital, same as String) while declaring variable. Integer is a class (java.lang.Integer), it wraps a value of the primitive type int in an object. So, when we write 'int', it is a primitive type which is nothing but the instance of Integer class.
Marina Alenskaja
9,320 PointsMarina Alenskaja
9,320 PointsOkay thanks. He just didn't explain that, so it was confusing.. I thought both where just datatypes and the same thing - like in Swift.
Marc Schultz
23,356 PointsMarc Schultz
23,356 PointsThey are both datatypes. But datatypes can differ from another. Where primitives are the lowest form of datatypes, classes contain a lot of information and in most cases they also contain primitives.
In Swift you differentiate between structs and classes. There are no real primitives as I know.
A X
12,842 PointsA X
12,842 PointsMarc can you explain what a primitive is?
Marc Schultz
23,356 PointsMarc Schultz
23,356 PointsYou can think of a Primitive as the lowest level data type a programming language can have.
But if you want to dive into it more deeply then I recommend reading the wikipedia article.