💡 Understanding Call by Value vs Call by Reference in Java 🔹 Call by Value In this approach, a copy of the actual value is passed to the method. Any changes made inside the method do not affect the original variable. Example: void modify(int x) { x = 50; } Here, modifying x inside the method won’t impact the original variable’s value. 🔹 Call by Reference (Conceptual) Here, instead of the value itself, the reference (or address) of the variable is passed. Changes made inside the method directly affect the original object. Example: void modify(int[] arr) { arr[0] = 50; } Since the array’s reference is passed, modifying it updates the original array. 🔸 Call by Value → Works on Copies 🔸 Call by Reference → Works on Original Data Thank you to Anand Kumar Buddarapu sir for explaining this concept clearly and guiding me through it! #Java #ProgrammingConcepts #CodingBasics #LearningJourney
Understanding Call by Value vs Call by Reference in Java
More Relevant Posts
-
💡 What I Learned Today: Checked vs Unchecked Exceptions in Java While strengthening my Java fundamentals, I revisited a core concept in Exception Handling — the difference between Checked and Unchecked exceptions. 🔹 Checked Exceptions - These must be handled at compile time using try-catch or throws. - Common examples: IOException, SQLException. - Useful when the error is expected and can be recovered from (e.g., file not found, network issues). 🔹 Unchecked Exceptions - These occur at runtime and don’t require mandatory handling. - Examples: NullPointerException, ArithmeticException. - Usually caused by programming logic errors. 📌 Quick takeaway: Checked → External issues you can anticipate Unchecked → Internal issues you should fix in code logic Understanding this difference helps write cleaner, safer, and more predictable Java applications. #Java #ExceptionHandling #JavaDeveloper #CodingTips #LearningJourney
To view or add a comment, sign in
-
🚀 Modern Java Feature for Auto-Closing Database Connections 🤔 Are you still closing DB connections manually? Wait.... use Try-With-Resources, the Java’s smarter way to manage cleanup 👇 When you open a file, stream, or connection, you must close it to prevent leaks. ❌ Before Java 7, we did it the hard way 👇 BufferedReader reader = null; try { reader = new BufferedReader(new FileReader("data.txt")); System.out.println(reader.readLine()); } finally { if (reader != null) reader.close(); } ✅ Then came Try-With-Resources — 🔥No finally block 👇 BufferedReader reader = new BufferedReader(new FileReader("data.txt")); try (reader) { System.out.println(reader.readLine()); } 💡 How it works 👇 🔹Any class implementing AutoCloseable (like BufferedReader) can go inside try(). 🔹JVM automatically calls close() when the block ends, even on exceptions. 💬 What do you think ? #ModernJava #JavaDeveloper #CleanCode #ProgrammingTips #DevelopersCommunity #CodeSmarter
To view or add a comment, sign in
-
Even & Odd Numbers in Java | Step-by-Step Array Program Explained public class EvenOddArray { public static void main(String[] args) { int[] numbers = {10, 15, 22, 9, 8}; System.out.println("Even Numbers:"); for (int num : numbers) { if (num % 2 == 0) { System.out.print(num + " "); } } System.out.println("\nOdd Numbers:"); for (int num : numbers) { if (num % 2 != 0) { System.out.print(num + " "); } } } } #JavaProgram #EvenOddNumbers #JavaTutorial #CodingForBeginners #SoftwaretestingbyKP
Java Program to Find Even and Odd Numbers from an Array | SoftwaretestingByKP
https://www.youtube.com/
To view or add a comment, sign in
-
🔐Access Modifiers in Java One of the most fundamental concepts in Java — Access Modifiers. They play a key role in encapsulation, security, and clean code structure. 🔸 What I learned: public → Accessible from anywhere in the project. protected → Accessible within the same package and by subclasses. default (package-private) → Accessible only within the same package. private → Accessible only within the same class. Understanding these levels of access helps us write modular, secure, and maintainable Java applications. Thanks to Anand Kumar Buddarapu sir for guiding and supporting me in strengthening my Java fundamentals. #Java #OOP #AccessModifiers #ProgrammingJourney #CodeBetter
To view or add a comment, sign in
-
-
Functions, methods, and classes in Java: Function: A block of code that performs a specific task. Method: A function that belongs to a class or object (in Java, all functions are methods). Class: A blueprint that defines attributes (fields) and behaviors (methods) of an object. Here are 3 things that helped me write better Java code 👇 1️⃣ Keep methods short – each method should do one thing well. 2️⃣ Use meaningful names – “calculatePrice()” > “xyz()”. 3️⃣ Encapsulate logic inside classes – group related data and behavior. Clean, modular code is easier to test, reuse, and debug. #Java #CleanCode #OOP #CodingTips #SoftwareEngineering #JavaCommunity #CodeSmarter
To view or add a comment, sign in
-
🔹 Try-with-Resources in Java In Java, managing resources like files, connections, or streams can lead to memory leaks if not closed properly. That’s where Try-with-Resources comes in — a powerful feature introduced in Java 7 to automatically close resources after use. ✅ How it works: The resource (like BufferedReader) declared inside the try() parentheses is automatically closed once the block exits — no need for an explicit finally block. It helps write cleaner and safer code. Ideal for handling files, database connections, sockets, etc. 🎯 Interview Question: 👉 Will all classes automatically close when declared inside a try-with-resources block? Answer: No. Only those classes that implement the AutoCloseable or Closeable interface will be automatically closed. If a class doesn’t implement these, Java won’t know how to close it automatically. 💡 Pro Tip: You can declare multiple resources inside the same try block — they’ll all be closed in the reverse order of their creation. #Java #SpringBoot #CleanCode #JavaDeveloper #CodeTips #TryWithResources #Programming #TechPost
To view or add a comment, sign in
-
-
Collection vs Collections in Java — Know the Difference! Collection (Interface) :- It is an interface which should be used when we want to represent a group of individual object then we need to go for collection. 1. Belongs to java.util package 2. It’s the root interface of the Java Collections Framework 3.Implemented by interfaces like List, Set, and Queue 4. All the commonly used method required for all the collection is a part of Collection(I). Collections (Class) :- It is a utility class which defines in java.util which defines utility methods for Collection Objects. 1. Methods like sort(), reverse(), max(), min(), shuffle() #Java #CollectionsFramework #LearningJava #Coding
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development