java methods

Methods in Java

Depending on the programming language, different names are used for functions. In some programming languages a distinction is made between functions that return a value as the result of a calculation and routines that only execute code. The latter are also known as procedures. However, methods are used in the java programming language.

A method is a block of code that performs some operation. A method can optionally define input parameters that allow callers to pass arguments into the method. A method can optionally return a value as output. Methods are useful for encapsulating common operations in a single reusable block, ideally using a name that clearly describes what the method does.

The method is a component of a class and can also be declared and implemented only in a class. They can be called at any number of places in the program. The values passed to the method are the arguments, whose types must be compatible with the parameter types in the method definition.