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 - Java Tutorial
From the course: Java 8 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Programming conditional logic3m 45s
-
(Locked)
Using the switch statement4m 51s
-
(Locked)
Creating looping code blocks5m 23s
-
(Locked)
Creating reusable code with methods4m 15s
-
(Locked)
Overloading methods with different signatures4m 51s
-
(Locked)
Passing arguments by reference or by value4m 47s
-
(Locked)
Challenge: Creating a more complex calculator application1m 53s
-
(Locked)
Solution: Creating a more complex calculator application3m 23s
-
(Locked)
-
-
-
-
-
-