0Pricing
Java Academy · Lesson

Defining Methods & Parameters

Define methods, read method signatures, and pass arguments to parameters correctly.

Defining Methods & Parameters is a free Java Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What is a method

What is a method? A reusable block of code with a signature (name + parameter list + return type). You call a method to perform a task and optionally get a result.

Method signature

Method signature includes: return type (e.g., int), method name (e.g., add), and parameter types with names (e.g., (int a, int b)). Modifiers like public or static adjust access and binding.

Define & call

Define add with two int parameters and return the sum. In main, call the method using arguments.

public class Main {
  // Add two integers and return the sum
  static int add(int a, int b) {
    return a + b;
  }

  public static void main(String[] args) {
    // Call the method with arguments 2 and 3
    int result = add(2, 3);
    System.out.println("add(2, 3) = " + result);
  }
}

Params vs args

Parameters are placeholders in the method; arguments are the actual values you pass on call.

public class Main {
  // Greet the user by name (parameter)
  static void greet(String name) {
    System.out.println("Hello, " + name + "!");
  }

  public static void main(String[] args) {
    // "Alice" is an argument; it is copied into parameter `name`
    greet("Alice");
    greet("Bob");
  }
}

Return vs void

void methods do not return a value; others return the specified type (e.g., double). Use return to send a result back.

public class Main {
  // Convert Celsius to Fahrenheit and return the result
  static double cToF(double c) {
    double f = c * 9.0 / 5.0 + 32.0;
    return f;
  }

  // Print a line (no value returned)
  static void line() {
    System.out.println("----------");
  }

  public static void main(String[] args) {
    double out = cToF(25.0);
    System.out.println("25C -> " + out + "F");
    line();
  }
}

Params order

Arguments match parameters by position and type. Remember: order matters.

public class Main {
  // Compute the area of a rectangle
  static int area(int width, int height) {
    return width * height;
  }

  public static void main(String[] args) {
    // Argument order must match parameter order by position
    int a1 = area(3, 5); // width=3, height=5
    int a2 = area(5, 3); // width=5, height=3
    System.out.println("area(3,5) = " + a1);
    System.out.println("area(5,3) = " + a2);
  }
}

Signature check

Quick check: Which is a valid Java method signature?

Recap & next

Recap: You defined methods, passed arguments to parameters, returned values, and understood void. Next: return values in depth and overloading.

Frequently asked questions

Is the “Defining Methods & Parameters” lesson free?

Yes — the full text of “Defining Methods & Parameters” is free to read here on the web, and the Java Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.

What will I learn in “Defining Methods & Parameters”?

Define methods, read method signatures, and pass arguments to parameters correctly. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Defining Methods & Parameters” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Defining Methods & Parameters
  2. Return Values & Overloading
  3. Scope & Lifetime
← Back to Java Academy