top of page

Java Built-in Functions

In Java, a methods is the same as a function. All the functions must be defined within a class. By that, it can be summarized by defining a Java method as a function belonging to a class. A function is a named unit of code that can be invoked anywhere in the class.

Structure of a Function

  • Access specifier – This shows the scope of availability of a function. ‘Public’ means that the function can be called from anywhere in the program. We have other access specifiers such as private and protected. Protected, the method can only be called within the class and its subclasses. Private can only be called inside the class.

​

  • Modifier – ‘Static’ is optional in a function definition. In this case static means  the function is a not an object of the main class but a method that belongs to the main class.

​

  • Return type – This is a function that returns a value and functions that do not return anything. Void, means that the function does not have a return value. If the function was to return a value, replace void with the data type of the returned value.

​

  • Function name – This the name of the function.

​

  • Parameter list – This informs the compiler about the data type it will receive and the value to be returned.

apply() Method

The apply() method of the Function interface can take any object type as an argument and can return any object type.

​

andThen() Method

The andThen() method of the Function interface, the input function will be executed first, and on the result the second function (andThen) will be executed.

​

​

compose() Method

The compose() method is just the reverse of the andThen() method. The second functional interface will be executed first and followed by the first functional interface.

bottom of page