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 Getting Started with Java Strings and Variables

filibonio hernandez
filibonio hernandez
2,826 Points

Hey there do you have to use Camel Casing on Variables too?

So I am wondering about this question because when the teacher is creating the code he puts a capital N in name in the variable like this:

String firstName = "etc";

how come the variable is put in that way the capital n in name and no capital f in first. What I am really asking does it really matter to do it that way in Java.?

2 Answers

Gyorgy Andorka
Gyorgy Andorka
13,811 Points

The Java convention is that class (type) names should be in camel case (ThisIsAType), while variable and method names in lower camel case (or "mixed case"), where the very first letter is lowercased (thisIsAnObjectOrAMethod).

filibonio hernandez
filibonio hernandez
2,826 Points

ahh okay that makes sense. but I'm wondering is it a necessity though in java why not have both lower case? or is it just how the java system works to put it that way.?

Gyorgy Andorka
Gyorgy Andorka
13,811 Points

The aim of these conventions is just to make the code more readable - you can visually separate e.g. a type from an instance immediately by looking at the case which is used. They're not "enforced" in any way by the Java compiler though, if that's what you mean.

He actually mentions in the video that while not required, it is standard practice to use Camel Case when naming variables.