Java Method Parameters — தமிழ்

</>Coding Tamilan.← Java course & curriculum
Java Masterclass · Lesson 20 / 50 · தமிழ்

Java Method Parameters

Separate the placeholder from the supplied value.

Step-by-step explanationsRunnable JavaPractice + answer

முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.

இந்தப் பாடத்தில்…

  • Explain the key idea behind Method Parameters.
  • Read and run a complete example, then predict what changes.
  • Recognize the topic-specific mistake discussed below.
01 / The concept

அடிப்படையைப் புரிந்துகொள்ளுங்கள்

A parameter is a named input in the method declaration. An argument is the value supplied at a call site. Java passes values by value, including a copy of an object reference; changing a parameter does not reassign the caller variable.

02 / Step by step

விரிவான விளக்கங்கள்

Method Parameters மற்றும் Arguments

Information-ஐ method-க்கு pass பண்றதுக்கு parameters use பண்றோம்.

Parameters method signature-ல specify ஆகும். Method call பண்ணும்போது values-ஐ pass பண்ணோம் — அதை arguments கிறோம்:

Multiple Parameters

ஒரு method-க்கு multiple parameters இருக்கலாம்:

Return Values

Method ஒரு value return பண்றதுக்கு return keyword use பண்றோம். Return type-ஐ method signature-ல போடணும் (void-க்கு பதில்):

Java reference fragmentJAVA
// Pass by value
static void doubleIt(int n) { n = n * 2; }
int x = 5;
doubleIt(x);
System.out.println(x);  // 5 — unchanged

static int square(int n) { return n * n; }
System.out.println(square(7));  // 49

static int sum(int... nums) {
    int total = 0;
    for (int n : nums) total += n;
    return total;
}
System.out.println(sum(1, 2, 3, 4, 5));  // 15

Java-வில் primitive types method-க்கு எப்படி pass ஆகும்?

  1. Pass by reference
  2. Pass by value
  3. Pass by pointer
  4. Pass by name
Reveal answer / விடை

Pass by value

Java எப்போதும் 'Pass by Value'. Primitive types-க்கு value's copy pass ஆகும் — original மாறாது. Objects-க்கு reference-ன் copy pass ஆகும் — object's content மாறலாம், ஆனால் reference itself மாறாது.

03 / Read and predict

முழுமையான உதாரணம்

This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.

Main.java · complete runnable exampleJAVA
public class Main {
    public static void main(String[] args) throws Exception {
        int value = 5;
        Demo.doubleIt(value);
        System.out.println(value);
        System.out.println(Demo.doubled(value));
    }
}
class Demo {
    static void doubleIt(int n) { n = n * 2; }
    static int doubled(int n) { return n * 2; }
}
Predict first. Then reveal the expected output / வெளியீடு
5
10

The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.

04 / Learn by changing

Change it. Run it. Understand it.

Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.

Open Java editor ↗
After the editor loads, choose Load this lesson example, then press RUN.

Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.

05 / Your turn

நீங்களே முயற்சி செய்யுங்கள்

Practice challenge

Assign the returned result back to value, then print it.

Reveal the answer and reasoning / விடை

Use value = Demo.doubled(value);. The caller variable now contains 10.

தவிர்க்க வேண்டிய தவறு: Reassigning a parameter changes the local parameter, not the caller variable.

பாடத்தின் சுருக்கம்

  • Explain the example without reading the output first.
  • Make the change requested in the practice task.
  • Describe why the result changed—or why compilation failed.

Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.

Coding Tamilan · Understand the idea. Try the code. Build the habit.