TGViewer
Programming Books Programming Books @programmingbooks_official · 575 subscribers
Post #407 147
⚡ Methods in Java (Functions) ⭐

Now you’ve reached a very important concept — Methods.

This is where your code becomes clean, reusable, and interview-ready.

✅ 1️⃣ What is a Method?

👉 A method is a block of code that performs a task.

Instead of writing the same code again and again → you reuse it.

🔹 Example Without Method:

System.out.println("Hello");
System.out.println("Hello");
System.out.println("Hello");

🔹 With Method:

void sayHello() {
System.out.println("Hello");
}
👉 Now you can call it multiple times.

✅ 2️⃣ Method Syntax

returnType methodName(parameters) {
// code
}

Example:
void greet() {
System.out.println("Hello Java");
}

✅ 3️⃣ Calling a Method

class Test {
static void greet() {
System.out.println("Hello");
}

public static void main(String[] args) {
greet(); // method call
}
}

🔹 4️⃣ Types of Methods

1️⃣ Without parameters, no return
2️⃣ With parameters
3️⃣ With return value
4️⃣ With parameters + return

⭐ 1. No Parameters, No Return

static void show() {
System.out.println("Java");
}

⭐ 2. With Parameters

static void add(int a, int b) {
System.out.println(a + b);
}
Call:
add(5, 3);

⭐ 3. With Return Value

static int square(int x) {
return x x;
}
Call:
int result = square(4);

⭐ 4. Parameters + Return

static int add(int a, int b) {
return a + b;
}

🔹 5️⃣ Method Overloading (Important ⭐)

👉 Same method name, different parameters

Example:
static int add(int a, int b) {
return a + b;
}

static double add(double a, double b) {
return a + b;
}

👉 Java decides method based on arguments

🔹 6️⃣ Recursion (Interview Favorite ⭐)

👉 Method calling itself

Example:

static void printNumbers(int n) {
if (n == 0) return;

System.out.println(n);
printNumbers(n - 1);
}
Call:
printNumbers(5);

Output:
5
4
3
2
1

🔥 7️⃣ Important Keywords

- return: sends value back
- void: no return value
- static: no object needed
- parameters: input values

🔥 Example Program
class MethodDemo {

static int add(int a, int b) {
return a + b;
}

public static void main(String[] args) {

int result = add(10, 5);
System.out.println(result);

}
}

⭐ Common Interview Questions
- What is a method?
- Difference between function and method?
- What is method overloading?
- What is recursion?
- Difference between void and return?

🔥 Quick Revision

- Method → reusable code
- Parameters → input
- Return → output
- Overloading → same name, different args
- Recursion → method calls itself


Claim your Free $5 Bonus Here:
https://bit.ly/3wUxw09

LinkedIn profile 👇

https://www.linkedin.com/in/subarno-roy-3b2251374

Join our WhatsApp Channel 👇

https://whatsapp.com/channel/0029VbAi27y0lwghBe9mE42i

WhatsApp Community Link 👇

https://chat.whatsapp.com/HPJDqRr6G1sKQIqfdJF3pL

1️⃣ Web Development and Web Design
📎 Channel Link:
[ https://t.me/webdevelopmentandwebdesigning ]

---

2️⃣ Programming Books
📎 Channel Link:
[ https://t.me/programmingbooks_official ]

---

3️⃣ Android Development
📎 Channel Link:
[ https://t.me/androiddevelopment_official ]

---

4️⃣ App Development
📎 Channel Link:
[ https://t.me/appdevelopment_official ]

---

5️⃣ Digital Marketing
📎 Channel Link:
[ https://t.me/digitalmarketing_official ]

Share with your College Whatsapp Groups & Friends too

All the best 👍👍
More from @programmingbooks_official
  1. Oct 3, 2026𝗧𝗵𝗼𝘀𝗲 𝘄𝗵𝗼 𝘄𝗮𝗻𝘁 𝗿𝗲𝗳𝗲𝗿𝗿𝗮𝗹𝘀 𝗮𝗻𝗱 𝗝𝗼𝗯𝘀 𝗮𝗻𝗱 𝗜𝗻𝘁𝗲𝗿𝗻𝘀𝗵𝗶𝗽�…
  2. Sep 30, 2026❤️ Here is the list of highly recommended Telegram channels for your free learning ❤️ Get…
  3. Sep 27, 2026🚨 Earn Passive Money Easily 🚨 Since your device is already connected to the internet, yo…
  4. Sep 26, 2026Hackathon National Research & Innovation Challenge Season 3 📌APPLY LINK : https://bit.ly/…
  5. Sep 11, 2026𝗧𝗵𝗼𝘀𝗲 𝘄𝗵𝗼 𝘄𝗮𝗻𝘁 𝗿𝗲𝗳𝗲𝗿𝗿𝗮𝗹𝘀 𝗮𝗻𝗱 𝗝𝗼𝗯𝘀 𝗮𝗻𝗱 𝗜𝗻𝘁𝗲𝗿𝗻𝘀𝗵𝗶𝗽�…
  6. Sep 9, 2026❤️ Here is the list of highly recommended Telegram channels for your free learning ❤️ Get…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →