Coding/Learn/java/method parameters
Java Foundational Course
01.Introduction to Java
02.Your First Java Program
03.Syntax & Code Structure
04.Comments in Java
05.Variables & Declaration
06.Primitive Data Types
07.Numbers & Arithmetic Operators
08.Strings in Java
09.Booleans & Relational Operators
10.Type Casting & Conversion
11.Scanner & Interactive Input
12.Logical Operators (&&, ||, !)
13.If Statements
14.If-Else Statements
15.If-Else-If Ladders
16.Switch Statements
17.While Loops
18.Do-While Loops
19.Standard For Loops
20.Break & Continue Statements
21.Arrays in Java
22.Array Indexing & Traversal
23.Enhanced For-Each Loop
24.Essential String Methods
25.Methods in Java
26.Method Parameters & Arguments
27.Method Overloading
28.Classes & Objects in Java
29.Constructors in Java
30.Exception Handling (try-catch-finally)
31.Capstone Mini Projects
Course Certificate0%

Complete all lessons to earn

LearnMethod Parameters & Arguments
26 / 31 0%
Lesson 26 of 31
6 mins read

Method Parameters & Arguments

PreviousNext Lesson
In Plain English

Parameters act as variables inside the method definition. When you call a method, you supply values (arguments) that get copied into those parameters. Java is strictly Pass-by-Value: primitive argument values are copied into method parameters without affecting the caller's original variables.

The Mental Model

"Passing by value is like photocopying a document and handing the copy to an assistant. If the assistant writes notes or crosses out a paragraph on their copy, your original master document remains pristine."

Deep Dive: How It Works

Parameters are listed in parentheses separated by commas: `(String name, int age)`.

Argument types and order must match the parameter list exactly.

Pass-by-value: modifying a primitive parameter inside the method has ZERO effect outside the method.

Syntax Blueprint

public static void greetUser(String name, int visits) {
    System.out.println("Welcome " + name + ", visit #" + visits);
}

Specify type and name for each parameter in the method signature.

PointCore Rules to Remember

Point star
Multiple Parameters: Separate each parameter with type and comma.
Point star
Strict Pass-by-Value: Java always passes copies of primitive values.
Point star
Argument Matching: Arguments provided at call site must match parameter types.

Common Beginner Traps & How to Fix Them

Mistake:Expecting primitive caller variable to change inside method

Why it happens: Java copies the primitive value; it does not pass memory pointers for primitives.

How to fix: Return the updated value from the method and reassign it in the caller: x = update(x);

Pro Tip: Use descriptive parameter names so anyone reading the method signature understands what to pass.

Live Interactive Example

Hit Run Code to see it live
Multi-Parameter Greeting and Pass-by-Value
Java 13
1
2
3
4
5
6
7
8
9
10
11
Output Console
Click "Run Code" to view the rendered output.
How it works: printReceipt receives 3 parameters, calculates the subtotal, and formats the output.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Build a formatted user badge method

  • PointWrite a static method "displayBadge" that takes (String role, String username).
  • PointPrint "[" + role + "] " + username.
  • PointIn main, call displayBadge("ADMIN", "Sarah").
1
2
3
4
5
6
7
8
9
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates