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 Basics Perfecting the Prototype Reviewing Our Feedback

Marina Alenskaja
Marina Alenskaja
9,320 Points

Java 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
Marc Schultz
23,356 Points

In Java all types with a capital character at the beginning are classes.

All lowercase types are primitives.

Marina Alenskaja
Marina Alenskaja
9,320 Points

Okay 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
Marc Schultz
23,356 Points

They 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.

Marc can you explain what a primitive is?

Marc Schultz
Marc Schultz
23,356 Points

You 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.

ninaddeshpande
ninaddeshpande
6,158 Points

You 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.