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 Java Objects (Retired) Harnessing the Power of Objects Method Signatures

Aditya Puri
Aditya Puri
1,080 Points

2 questions

SO I have 2 questions?-

1) Is including the keyword "get" in front of getter methods a naming convention or is it an essential part of the syntax?

2)How can a java tell the difference between a class field variable and a method? Both of them start in the same way which is- (public/private) (output datatype) (name) .

2 Answers

Hi

1) Is including the keyword "get" in front of getter methods a naming convention or is it an essential part of the syntax? Generally speaking, Yes ... it is a convention, that you should stick with it.

There is nothing stop you from creating a method called "GrabIt" and writing your own code to deal with it ... then you loose all IDE support and users of your code would have no idea what you are doing ... again I advise stick with the convention.

2)How can a java tell the difference between a class field variable and a method? Both of them start in the same way which is- (public/private) (output datatype) (name) .

public/private defines who can access the targeted item.
A field can be private or public and A method can be private or public

java is not going to get confused because where as a field is defined as in: private String myString; or public String myString;

a method would have a different syntax private String myMethod(){ } or public String myMethod(){ }

hope this helps. If this answers your question, please mark the post answered.

Thanks

Why do you post that everywhere??