Java Tutorial Series: This lesson is part of our comprehensive Complete Java Tutorial: Learn Java from Beginner to Advanced.

This guide explains the topic from beginner level through practical Java development, common mistakes, debugging, design considerations, examples, and practice. The goal is to understand not only the syntax, but when and why the feature should be used in a real Java project.

Parameters vs Arguments

A parameter is a variable in a method declaration. An argument is the value or expression supplied when the method is called.

static int multiply(int number, int factor) { return number * factor; }
int result = multiply(5, 4);

Multiple Parameters

Methods can accept multiple parameters, but parameter lists should remain understandable. Group related information into a class when a method starts requiring many unrelated values.

static double total(double price, int quantity, double discount) {
    return price * quantity - discount;
}

Primitive Arguments and Pass-by-Value

Java passes arguments by value. For primitives, the method receives a copy, so changing the parameter does not change the caller variable.

static void change(int x) { x = 100; }
int value = 10;
change(value);
System.out.println(value); // 10

Object References and Pass-by-Value

When an object is passed, the copied value is a reference to the object. A method can therefore modify the referenced object state, but assigning the parameter to another object does not replace the caller reference.

static void updateName(User user) { user.name = "Updated"; }

Null Arguments

Reference parameters may receive null unless the design prevents it. Define what null means and validate it where necessary.

static int length(String text) {
    if (text == null) return 0;
    return text.length();
}

Varargs

A varargs parameter accepts zero or more arguments of a declared type. Inside the method it can be processed like an array.

static int sum(int... values) {
    int total = 0;
    for (int value : values) total += value;
    return total;
}

Type Compatibility

Java checks argument types against parameter types. Widening conversions can be allowed, while incompatible types fail at compile time.

static void show(double value) { System.out.println(value); }
show(10);

Designing Parameter Lists

  • Use meaningful parameter names
  • Prefer precise types
  • Document units when unclear
  • Avoid excessive boolean flags
  • Group related data when it represents one concept

Common Mistakes

  • Calling Java pass-by-reference
  • Mutating shared objects unexpectedly
  • Ignoring null handling
  • Passing too many unrelated values
  • Confusing parameter and argument terminology

Practice

Demonstrate primitive pass-by-value. Demonstrate object-state mutation. Write a varargs sum method. Design parameters for an order-processing method.

Frequently Asked Questions

What is a parameter?

A variable declared in a method definition.

What is an argument?

The value or expression supplied during a method call.

Does Java use pass-by-reference?

No. Java passes arguments by value, including object references.

Conclusion

Mastering this topic gives you a stronger foundation for multi-file Java programs and professional development. Focus on understanding the concept, writing small examples yourself, testing edge cases, and recognizing how the feature fits into larger application structure.

Learn More

  • Java classes and objects
  • Java data structures
  • Java exception handling
  • Java project structure
  • Java testing and debugging
  • Java application development

Continue Learning Java

Continue through the Java path: methods → parameters and arguments → overloading → scope and variables → packages → imports → access modifiers → classpath and project structure. These concepts prepare you for object-oriented programming and larger Java applications.

Extended Practice

  • Write the main example without copying it.
  • Change inputs and test normal, boundary, and invalid cases.
  • Explain the execution flow in your own words.
  • Refactor one example to make its responsibility clearer.
  • Explain where the concept appears in a real Java application.