Defining and Calling Methods in Java
A method is a named, reusable block of code. Its signature declares an access modifier, a return type, a name, and a parameter list in parentheses, and its body, in braces, holds the actual statements that run each time it's called. Defining a method doesn't run it — calling it by name, with matching arguments, is what actually executes its body, and control returns to wherever it was called from once the method finishes.
Static methods belong to the class itself and can be called without creating an object first (main is the most obvious example, called automatically by the JVM), while instance methods belong to a specific object and need one to exist before they can be called — a distinction covered more fully once objects and classes are introduced properly.
The method signature
Access modifier, return type, name, and parameter list together describe what a method needs and returns.
The method body
The actual statements inside the braces, which only run when the method is called.
Calling a method
Writing its name with parentheses, and any required arguments, transfers control into its body.
Returning to the caller
Once a method's body finishes, or hits a return, execution resumes right after wherever it was called from.
static versus instance
A static method belongs to the class and needs no object to call; an instance method belongs to a specific object and needs one to exist first.
public class MethodDemo { static void greet(String name) { System.out.println("Hello, " + name + "!"); } public static void main(String[] args) { greet("Ada"); greet("Bo"); }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.