Topic Overview and Actualization

Greetings! Today, we will venture into the universe of functions and procedures in Java, which are vital tools in the programmer's toolbox - they introduce reusable components that can be defined once and used everywhere. Functions execute tasks and return a value, whereas procedures perform tasks without returning anything. This lesson will guide you through writing Java functions and procedures.

Understanding Java Syntax for Functions and Procedures

Functions and procedures are similar to recipes. They consolidate instructions to carry out specific tasks. Imagine baking a cake — a procedure — and sharing it — a function. Baking doesn't yield anything, so it's a procedure. However, sharing returns the remaining cakes, making it a function.

The structure of functions and procedures in Java is as follows:

At first, this structure may seem strange, but think of it as a recipe. static is just a keyword you have to remember for now. returnType is the type of dish you'll get after cooking. functionName is the title of the recipe. The parameters are the ingredients, with the {} brackets containing the cooking method - the recipe itself.

Writing Our Own Java Function

With those explanations in mind, let's craft some functions and procedures.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal