6 Functions in Java

6.1 INTRODUCTION

A function is a self-contained block of code written once for a particular purpose, but can be used again and again. It is a basic entity for Java programming language. Even the execution of the program starts from the main function. It is the basic building block for modular programming.

Depending on the parameters and return type (discussed later on), functions are classified into four categories:

1.   No return type and no arguments/parameters.

2.   No return type but arguments/parameters.

3.   Return type but no argument/parameters.

4.   Return type with argument/parameters.

All the above categories except the third one are discussed in this chapter. The third category is discussed in the chapter titled ...

Get Java Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.