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 variable case

Why is it that when I declare a variable of type String I type it out with a capital S. But when I do Int I have to do it with lower case? Is there any specific reason?

String name = console.readLine("Enter your name:  ");
int age = Integer.parseInt(ageAsString);
Simon Coates
Simon Coates
28,694 Points

unsure if it's a convention or a rule, but primitive types are lower case, while object types are Upper case. At the very least, it's a visual clue. I assume you understand pass by value/reference, so can appreciate why being able to see at a glance the object/primitive distinction is a useful when writing code.

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! Essentially, it's because the int is a primitive data type. Java provides support for strings through the use of the java.lang.String class. And because this is all case sensitive you have to use the capitalization specified. Here's some documentation on the primitive data types including information about the String class.


Hope this helps! :sparkles: