Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java

Can someone explain the significance of the m in private String mAnswer;

Why not call the private String Answer and reference it from that point on throughout the code?

2 Answers

Jacob Bergdahl
Jacob Bergdahl
29,118 Points

Two reasons. First, when you see the variable in the code, it lets you know immediately that it's a member variable, without having to check. The second reason is that when you press "m" in your code, all your member variables show up, so you can easily see them that way. It's a naming convention that every Java developer use (different programming languages use different prefixes).

Seth Kroger
Seth Kroger
56,403 Points

I wouldn't say every Java developer uses that convention but it is a very common one. I've seen plenty of tutorials and code not use that convention too. But it is also official in some big coding style standards, like Google's for Android OS https://source.android.com/source/code-style.html#follow-field-naming-conventions. It depends on who you are and what you're doing.

Kevin Faust
Kevin Faust
15,353 Points

alot of the code i see in stackoverflow doesnt use the m prefix

Great. That adds another layer of clarity on the significance of member variables. Thanks for your help Jacob, my Java jiu-jitsu sensei!