Back to Lessons

Methods and Functions in Java

April 5, 2026

Java Methods

Reusable blocks of code performing specific tasks.

Method Examples

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

public static void printMessage(String msg) {
    System.out.println(msg);
}

public static void main(String[] args) {
    int result = add(5, 3);
    printMessage("Hello");
}

Key Points

  • Syntax: [access] [static] returnType methodName(parameters).
  • static methods called without object.
  • Method overloading: same name, different parameters.
  • void methods don't return value.