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

Methods in Java

From what I understand there are two types of Methods:

1.Built in (comes with the compiler)

2.User Defined.

Are there some tips to always spot a method ?

Is there something you can see in the syntax to always find the method ?

Could you say anything after a . is a method ? e.g. system.out.println() ?

Sorry for the question I am just trying to build my findamental knowlege so I dont get lost later.

I will be making other posts with questionns about class , objects, constructers...

If I am asking this at the point I'm at , others are also probably a little confused as well.

Thanks !

1 Answer

A dot or . doesn't always indicate a method, but one common characteristic of a method is that they are usually followed by parenthesis. So in your example, System.out.println() , println would be the method be used. The reason methods have parenthesis is because methods are able to take input for example println takes a string to be displayed. Not all methods take input but they will still have parenthesis after the name when they are used. For example .length(). Not everything that has parenthesis is a method, for example things like if statements or while loops have them but it's generally easy to distinguish an if statement from a method call. Lastly, calls to a constructor will also have parenthesis but constructors could be considered a specific type of method, also constructors will always have the same name of the class making them easy to distinguish from other methods.

Hope this answered your question, let me know if you need any clarification.