Table of Contents

Java - (Method|Functions)

About

A function that belong to an object is called a methods. A static method is then a sort of function.

Methods:

Hiding internal state and requiring all interaction to be performed through an object's methods is known as data encapsulation — a fundamental principle of object-oriented programming.

In the Java programming language, every application must contain a main method. it's the entry point for your application and will subsequently invoke all the other methods required by your program.

Syntax

Standard

public double calculateAnswer(double wingSpan, int numberOfEngines, double length, double grossTons) {
	//do the calculation here
}

The only required elements of a method declaration are the method's:

More generally, method declarations have six components, in order:

The Java programming language doesn't let you pass methods into methods. But you can pass an object into a method and then invoke the object's methods.

Generic

Generic

public static <GenetricParameters> returnType methodeName(Class<GenetricParameters> p1, Class<GenetricParameters> p2) {
        return ;
}

Example:

public static <K, V> boolean compare(Pair<K, V> p1, Pair<K, V> p2) {
        return p1.getKey().equals(p2.getKey()) &&
               p1.getValue().equals(p2.getValue());
}

Signature

Function - Signature

Modifier

You specify a type method by using a modifier in the member's declaration.

Return

A method returns to the code that invoked it when it

whichever occurs first.

A method can return:

You also can use as return types an interface names.

Documentation / Reference