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

how does camel casing work and what is its use

i failed to capture how camel casing works in java

2 Answers

Noah Schill
Noah Schill
10,020 Points

All camel casing is, is formatting a chain of words as follows:

The first word is lower-case, then any words following would begin with an uppercase letter. This is because, in Java, we cannot use spaces for method names or for variables, as this would separate them into separate commands. If we leave them all lowercase, we cannot distinguish the words between them. for example:
```myonvariable``` could be read as my own variable, myon variable myonv ariable, etc. By doing camel casing, we have an efficient and simple way to separate words without introducing any extra characters or leaving whitespace.

thanx Noah

Naphtali Matione,

the camel case in Java has no function at all. It is just convention for better readabilty of your code. If you wanted you could write your variables in lowercase only or put underscores between the words (without whitespace) and your code would still work the same. However, you should definitely use the camel case since it is an unwritten rule.

Also Java is case sensitive. So testVariable and testvariable would be two different variables.

thanx mario

You are welcome Naphtali.