Notes / Java / Functions

Functions (Methods) in Java — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Functions In Java, functions are called methods because they always live inside a class.

Syntax

syntax
returnType methodName(type param) {
    return value;
}

Example

java
public class Main {
    static int add(int a, int b) {
        return a + b;
    }

    public static void main(String[] args) {
        int result = add(4, 7);
        System.out.println("Sum: " + result);
    }
}

Output

outputSum: 11

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Be ready to explain Java's "pass by value" rule precisely: for objects, it's the reference itself that's copied, not the object's contents.
Back to notes Read full lesson →