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 Conditional ints

1,949 Points

For var types, why do we write "int" instead of "Int"? Don't we capitalize "String"?

Wondering why "int" is correct, but "Int" is not. In a previous exercise, String had to be capitalized, didn't it?

String firstName = "X";

int numberOfPeople = 3;

2 Answers

Rob Bridges
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey Annette,

So it comes down to how things are defined in java, java has primitive data types that are built into it.

These include

  • byte
  • short
  • int
  • float
  • double
  • long
  • char
  • boolean

we don't need to capitalize these because java syntax is always to have the primitive types uncapitalized.

The reason that we capitalize String is because it's not a natural data type that is built into java, it's actually a class that is predefined in java with it's own methods to call on it. Due to Java naming conventions we always capitalize a class, so we call it String.

This is why we can also call methods on any string, like String.parseInt(); or String.length(); because these methods are part of the class String.

It's the same as the class Character. though char is a primitive type we cannot type things such char.isUpperCase(); because char is only a primitive type, and not a Class. Where as Character is the defined class that contains chars.

Let me know if there's anything I need to further clear up.


1,949 Points

Wow, this is super helpful. Thank you for the detailed answer! I totally understand now.