CHAPTER 6

FUNCTIONS

Every programming language supports functions in two categories: (1) user-defined functions, and (2) language-supplied functions (also known as library functions). To begin with, let us start with user-defined functions.

6.1 Functions in Java

In most object-oriented languages, either functions belong to a class or they do not belong to any particular class (free or global). In Java, every function must be a part of some class. There is no concept of free or global function.

Functions are small pieces of code doing a particular task. Functions are called methods in Java. Hence, the name of the topic should have been “methods in Java”.

So far, we have not introduced objects. Hence, you may not appreciate the significance of ...

Get Programming with Java 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.