ProLesson 2.6Beginner3 min readUpdated 30 October 2026
Methods, parameters and return values
Split code into small reusable methods, pass values in, get results back, overload methods, and understand why Java is always pass-by-value.
A method is a named block of code that does one job. Instead of repeating the same lines, you write them once and call the method whenever you need it. Good methods are small, have clear names and do one thing.
01Writing and calling a method
Bill.java
public class Bill {
static double addGst(double amount) { // return type, name, parameter
return amount * 1.18;
}
static void printLine(String label, double value) { // void: returns nothing
System.out.println(label + ": " + value);
}
public static void main(String[] args) {
double total = addGst(1000);
printLine("Total with GST", total);
}
}Total with GST: 1180.0
The parts of a method: return type (double, or void for nothing), name, parameters in brackets, and a body. return sends a value back and ends the method.
We use static here so main can call these methods directly. Module 04 explains static properly.
Loading the rest of the lesson…