Advanced Java functions
In this section, I'd like you to take a deeper look into Java methods and also learn some really valuable things about how programming languages think about and manipulate information. To help us do this, I'd like to run an experiment of sorts, and to start that experiment off, I've written a really basic Java program:
package advancedmethods; public class AdvancedMethods { public static void main(String[] args) { int x = 5; magic(x); System.out.println("main: " + x); } public static void magic(int input) { input += 10; } }
At the core of this Java program is the magic
method, which is user-defined following the main
method. When we come across a new Java method, there's three real things we should notice about it:
- First, we should ask, "what are its input values?". In the case of our
magic
method, it expects only a single integer as input. - Then, we probably want to ask, "what does this method return?...