From the course: Java 8 Essential Training

Unlock the full course today

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

Creating reusable code with methods

Creating reusable code with methods - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Creating reusable code with methods

- Most programming languages support the ability to create reusable code, code blocks that you can call from multiple places in an application. These are sometimes called functions or subroutines. But in Java they're called methods, and they're always declared as members of a class. The main method is one example. This is the signature of a method that you have to have to start up an application from the console. But not all Java applications use this main method. For example, an Android application or a Java EE application, have different requirements. Regardless, you can create your own custom methods and then call them from anywhere in your application. I'll declare a new method, and I'll place it outside of the existing main method but still within the class declaration. In order to call this method from my main method, I must declare it initially as static. Then I have to declare what kind of data the method is going to return. I'll say void which means it's not going to return…

Contents