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

Android Build a Simple Android App Improving Our Code Simple Refactoring: Using a New Class

Faisal Julaidan
Faisal Julaidan
13,944 Points

What is the 'm' at the beginning of every field name?

I see that every time the lecturer declare a new filed, he put the 'm' letter at the beginning of the field name

Why?

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Faisal! There are different kinds of variables including member variables defined in a class (also called fields), variables definied in a method or code block, and variables declared in the method declarations.

The instructors here teach the convention of naming member variables as starting with the lower case "m".

Here is some documentation from Oracle about variable declaration. But note that the "m" style of naming member variables is not just a convention in Java, but other languages as well.

Hope this helps! :sparkles:

Faisal Julaidan
Faisal Julaidan
13,944 Points

are variables private by default ?

Kourosh Raeen
Kourosh Raeen
23,733 Points

It's a coding convention to start non-public, non-static field names with m to distinguish them from local variables. See more here: http://source.android.com/source/code-style.html#follow-field-naming-conventions