How to write methods

Define a static method

A static method belongs to the class and can be called from main without creating an object.

static void greet() {
    System.out.println("Hello!");
}

Call the method

A method body runs only when the method is called.

public static void main(String[] args) {
    greet();
    greet();
}

Name methods clearly

Use verbs and lowerCamelCase, such as printReceipt or calculateTotal. Each method should have one focused purpose.

Understand the signature

A declaration includes modifiers, a return type, a method name, and parentheses containing any parameters.

private static void printDivider() {
    System.out.println("--------");
}