From the course: Learning Java 11

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Defining functions in Java

Defining functions in Java - Java Tutorial

From the course: Learning Java 11

Start my 1-month free trial

Defining functions in Java

- To use a function in Java, we must first define the function. We've already seen this a little bit with the functions we mapped out in the last lesson. For the Make PB&J Sandwich function, we had to define the steps needed to accomplish the given tasks. Make a peanut butter and jelly sandwich. For Announce Developer Tea Time, we had to define the steps to announce tea time. It's important to remember that just because we are defining a function, does not mean we are using it. Just because I have given you the instructions on how to make a PB&J, does not mean you've made a PB&J. This means, the way we write this code will be a little different than the things we've written in the past. Let's try implementing our Announced Developer Tea Time function in Java. To define this function, we are going to write code outside the main function for the first time. Everything we've done so far has been about executing code. Not defining new functionality that could potentially be used. To…

Contents