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

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,413 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!