Methods & Parameters
Methods are blocks of reusable code that perform specific tasks. They can accept input parameters and return output values, making your code modular and organized. This is a foundational concept in enterprise application development that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world Java experience. Take your time with each section and practice the examples
40 min•By Priygop Team•Last updated: Feb 2026
Methods in Java
Example
public class MethodsDemo {
// Method with no parameters, no return
static void greet() {
System.out.println("Hello from Java!");
}
// Method with parameters
static void greetPerson(String name) {
System.out.println("Hello, " + name + "!");
}
// Method with return value
static int add(int a, int b) {
return a + b;
}
// Method with multiple parameters
static double calculateBMI(double weight, double height) {
return weight / (height * height);
}
// Method overloading (same name, different parameters)
static int multiply(int a, int b) {
return a * b;
}
static double multiply(double a, double b) {
return a * b;
}
static int multiply(int a, int b, int c) {
return a * b * c;
}
public static void main(String[] args) {
// Calling methods
greet();
greetPerson("Alice");
int sum = add(15, 25);
System.out.println("Sum: " + sum);
double bmi = calculateBMI(70, 1.75);
System.out.println("BMI: " + String.format("%.1f", bmi));
// Method overloading in action
System.out.println("2 x 3 = " + multiply(2, 3));
System.out.println("2.5 x 3.5 = " + multiply(2.5, 3.5));
System.out.println("2 x 3 x 4 = " + multiply(2, 3, 4));
}
}Try It Yourself: Utility Methods
Try It Yourself: Utility MethodsJava
Java Editor
✓ ValidTab = 2 spaces
Java|43 lines|1290 chars|✓ Valid syntax
UTF-8