📘 Core Java – Day 10 Topic: Types of Methods in Java In Java, a method is a block of code that performs a specific task and is defined inside a class. Methods help achieve code reusability, modularity, and readability. 🔹 Method Signature Syntax: returnType methodName(parameters) { // method body } Explanation: methodName: Name of the method (can be any valid identifier) parameters: Inputs passed to the method method body: Code that performs the task returnType: Type of value returned after execution 🔸 Types of Methods in Java Java methods are classified based on input (parameters) and output (return value). 1️⃣ No Input and No Output Method Does not take any parameters Does not return any value Used mainly for displaying messages or simple tasks Example: void greet() { System.out.println("Welcome to Core Java"); } 2️⃣ No Input and Output Method Does not take any parameters Returns a value Used when the result is generated internally Example: int getNumber() { return 100; } 3️⃣ Input and No Output Method Takes parameters as input Does not return any value Used to perform operations like printing results Example: void printSquare(int num) { System.out.println(num * num); } 4️⃣ Input and Output Method Takes parameters as input Returns a value Most commonly used in real-world applications Example: int add(int a, int b) { return a + b; } 📌 Learning Core Java step by step — Day 10 completed! #CoreJava #JavaProgramming #LearningJourney #Day10 #ProgrammingBasics #StudentDeveloper
Java Methods: Types, Syntax, and Examples
More Relevant Posts
-
Understanding Collection and List in Java 🔹 What is Collection in Java? The Collection Framework in Java is a unified architecture that provides interfaces and classes to store and manipulate groups of objects dynamically. It is available in the java.util package and offers ready-made data structures like List, Set, Queue, and more. Why use Collections instead of arrays? ✔ Dynamic size (grow/shrink at runtime) ✔ Built-in utility methods ✔ Better performance handling ✔ Easy data manipulation 🔹 What is List in Java? A List is a child interface of the Collection interface. A List: ✔ Maintains insertion order ✔ Allows duplicate elements ✔ Allows null values ✔ Supports index-based access It is mainly used when order and duplicates matter. 🔹 Types of List in Java 1️⃣ ArrayList Uses a dynamic array internally Fast for reading (random access) Slower for insert/delete in the middle Most commonly used List implementation 2️⃣ LinkedList Uses a doubly linked list internally Fast insertion and deletion Slower random access compared to ArrayList 3️⃣ Vector (Legacy Class) Similar to ArrayList Thread-safe (synchronized) Slower due to synchronization Rarely used in modern applications 4️⃣ Stack (Extends Vector) Follows LIFO (Last In First Out) Methods: push(), pop(), peek() In modern applications, Deque is preferred over Stack Additional Useful Methods: 1. remove(index) 2. remove(Object) 3. clear() 4. contains() 5. isEmpty() 6.add() 📌 Summary Collection provides the framework to manage groups of objects. List is an ordered collection that allows duplicates and index-based access. ArrayList and LinkedList are the most commonly used implementations in real-world applications. Frontlines EduTech (FLM) #Java #Collection #list
To view or add a comment, sign in
-
-
Java Fundamentals Series – Day 5 Garbage Collection in Java : In Java, developers do not need to manually free memory. JVM automatically manages memory using Garbage Collection (GC). The Garbage Collector is an Mechanism were default implemented inside JVM which is Invoke automatically In java there has a method gC() which is present inside the System Class this gC() method is a static method so there is no need for object to invoke this method so we can able to access this particular method by the class name *** System.gC() ***. By help of this method we just provide the request to JVM to call the ** Garbage Collector ** but we cannot assure that it may or may not be call the GC . It is totally depends on JVM here we just provide request. What is Garbage Collection? Garbage Collection is the process of automatically removing unused objects from Heap memory. Why GC is Important? 1 Prevents memory leaks 2 Frees unused memory 3 Improves application performance How GC Works? 1 JVM identifies objects that are no longer referenced 2 These objects become eligible for garbage collection 3 GC reclaims the memory occupied by them 4 It removes the memory for anonymous. object Method : void finalize(): Incase we needed to do some set of work before GC get Called in that particular time we can use this finalize () this method is defined as protected for example - closing the file this like operation.we can able to provide inside this finalize() method #Java #GarbageCollection #JVM #BackendDeveloper #Placements
To view or add a comment, sign in
-
Day 4 of 10 – Core Java Recap: Looping Statements & Comments 🌟 Continuing my 10-day Java revision journey 🚀 Today I revised Looping Concepts and Comments in Java. 🔁 1️⃣ Looping Statements in Java Looping statements are used to execute a block of code repeatedly based on a condition. 📌 Types of loops: ✔ for loop Used when the number of iterations is known. Syntax: for(initialization; condition; updation) { // statements } ✔ while loop Checks condition first, then executes. Syntax: while(condition) { // statements } ✔ do-while loop Executes at least once, then checks condition. Syntax: do { // statements } while(condition); ✔ for-each loop (Enhanced for loop) Used to iterate over arrays and collections. Syntax: for(dataType variable : arrayName) { // statements } 🔹 Nested Loops A loop inside another loop Commonly used for patterns and matrix problems ⛔ break and continue ✔ break → Terminates the loop completely ✔ continue → Skips current iteration and moves to next iteration 📝 2️⃣ Comments in Java Comments are used to provide extra information or explanation in the code. They are not executed by the compiler. 📌 Types of Comments: ✔ Single-line comment // This is a single-line comment ✔ Multi-line comment /* This is a multi-line comment */ ✔ Documentation Comment (Javadoc) /** Documentation comment */ Used to generate documentation Applied at class level, method level Helps describe package, class, variables, and methods 📌 Common Documentation Tags: @author @version @param @return @since 💡 Key Learnings Today: Understood how loops control program flow Learned the difference between for, while, and do-while Practiced nested loops Understood the importance of proper code documentation Building strong fundamentals step by step 💻🔥 #Java #CoreJava #Programming #JavaDeveloper #CodingJourney #Learning
To view or add a comment, sign in
-
📘 Core Java Day 34| What Are Cursors in Java? Before enhanced for-each loops and Streams, Java used cursors to iterate over collections. A cursor is an object used to traverse elements one by one from a collection. What Is a Cursor? - In Java, a cursor is an iterator-like mechanism that allows us to: - Access elements sequentially - Traverse a collection safely - Perform read or remove operations during iteration Types of Cursors in Java - Java provides three types of cursors: 1 ) Enumeration (Legacy Cursor) Used with legacy classes like Vector and Stack Can only read elements Does not support element removal Works only in forward direction Considered outdated and limited. 2) Iterator (Most Common) Applicable to all collection classes Supports element removal Forward-only traversal Replaced Enumeration in modern Java This is the most commonly used cursor in interviews and real projects. 3) ListIterator (Advanced Cursor) - Works only with List implementations - Supports forward and backward traversal - Allows add, update, and remove operations - Provides index-based navigation
To view or add a comment, sign in
-
-
Understanding Exception Handling in Java is fundamental for writing reliable and maintainable applications. This week, I strengthened my knowledge of checked & unchecked exceptions along with synchronous and asynchronous execution models. 🔹 Checked Exceptions These are exceptions that are checked at compile time. The compiler forces us to handle or declare them using try-catch or throws. Examples include: IOException SQLException Checked exceptions ensure that critical scenarios like file handling or database connectivity are handled explicitly. 🔹 Unchecked Exceptions These occur at runtime and are not checked at compile time. They usually indicate programming errors. Examples include: NullPointerException ArithmeticException Unchecked exceptions highlight logical mistakes that should be prevented through proper validation and clean coding practices. I also explored the difference between Synchronous and Asynchronous Execution in Java: 🔹 Synchronous Execution Tasks execute one after another. Each operation waits for the previous one to complete. This model is simple but can block execution if a task takes longer. 🔹 Asynchronous Execution Tasks execute independently without blocking the main thread. Java supports asynchronous programming using: Thread CompletableFuture Asynchronous programming improves responsiveness and performance, especially in modern applications like web services and distributed systems. Grateful to my mentor Anand Kumar Buddarapu for guiding me through these core concepts and helping me understand not just the theory, but the practical implementation and real-world importance of structured exception handling and execution flow in Java.
To view or add a comment, sign in
-
🚀 Learning Core Java – Understanding Strings in Java Today, I explored an important concept in Java — Strings. In Java, Strings are objects, not primitive data types. They are stored in the heap memory, and Java manages them in a special way for memory optimization. ⸻ 🔹 Types of Strings in Java Strings can be categorized into: ✔ Immutable Strings Once created, their value cannot be changed. Any modification results in a new object being created. The String class is immutable. ✔ Mutable Strings Strings that can be modified without creating new objects. (Examples include StringBuilder and StringBuffer.) ⸻ 🔹 Ways to Create a String A String can be created in three common ways: 1️⃣ Using string literal Example: Creating a string directly with double quotes. 2️⃣ Using the new keyword Example: Creating a string object explicitly using new String(). 3️⃣ Using a character array Example: Creating a character array and converting it into a String. ⸻ 🔹 Memory Allocation of Strings in Heap Heap memory is divided into two important parts: ✔ String Constant Pool (SCP) When a string is created without the new keyword, memory is allocated inside the String Constant Pool. • It does not allow duplicate values. • If the same string already exists, it reuses the existing object. ✔ Non-Constant Pool (Heap Area) When a string is created using the new keyword, memory is allocated in the normal heap (non-constant pool). • It allows duplicate objects, even if the content is the same. ⸻ 🔎 Key Insight: Using the String Constant Pool helps Java optimize memory by avoiding duplicate objects, making string handling more efficient. Understanding how Strings are stored in memory is essential for writing optimized and performance-efficient Java applications. Excited to keep strengthening my Core Java fundamentals! 🚀 🔹 Suggested Hashtags #CoreJava #JavaProgramming #StringsInJava #JavaMemory #StringPool #ProgrammingFundamentals #JavaDeveloper #LearningJourney
To view or add a comment, sign in
-
-
Discover the power of switch statements and expressions in Java. Learn how to efficiently control program flow with concise syntax
To view or add a comment, sign in
-
DAY 12 : CORE JAVA 🔎 Pass by Value vs Pass by Reference in Java — Explained Simply One of the most commonly asked interview questions in Java is: > Does Java support pass by reference? The correct answer is: 👉 Java is always pass by value. But the confusion starts when objects are involved. Let’s break it down with a simple real-world understanding. 1️⃣ Pass by Value (Primitive Types) When we pass primitive variables like int, double, or char, Java sends a copy of the value to the method. 💡 Real-world example: Imagine giving someone a photocopy of your document. If they make changes, your original document remains unchanged. In Java: Changes inside the method do NOT affect the original variable. 2️⃣ Objects in Java (Why it Feels Like Pass by Reference) When we pass an object, Java passes a copy of the reference (address) — not the actual object. 💡 Real-world example: Think of giving someone your house key. They can enter and rearrange the furniture (modify object data). But if they change the key to point to another house, your original house doesn’t change. So: Object data can be modified. But the reference itself is still passed by value. 🎯 The Key Takeaway ✔ Java does NOT support true pass by reference. ✔ Java is strictly pass by value. ✔ For objects, the reference is passed by value. Understanding this concept clearly helps avoid logical errors and improves problem-solving during interviews. Small concepts. Big clarity. 🚀 TAP Academy #Java #Programming #OOPS #InterviewPreparation #SoftwareDevelopment
To view or add a comment, sign in
-
-
Understanding Try-With-Resources in Java Writing clean and efficient code is an important skill for every Java developer. One powerful feature that helps in resource management is Try-With-Resources, introduced in Java 7. This feature automatically closes resources like files, database connections, and streams once the execution is completed — even if an exception occurs. ✨ Why is Try-With-Resources important? ✔ Eliminates manual resource closing ✔ Reduces boilerplate code ✔ Prevents memory/resource leaks ✔ Improves code readability linkedin post and mentions Here’s your LinkedIn post with mentions 👇 🔹 Understanding Try-With-Resources in Java Writing clean and efficient code is an important skill for every Java developer. One powerful feature that helps in resource management is Try-With-Resources, introduced in Java 7. This feature automatically closes resources like files, database connections, and streams once the execution is completed — even if an exception occurs. ✨ Why is Try-With-Resources important? ✔ Eliminates manual resource closing ✔ Reduces boilerplate code ✔ Prevents memory/resource leaks ✔ Improves code readability 📌 Example: import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class TryWithResourcesExample { public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new FileReader("file.txt"))) { System.out.println(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } } Here, BufferedReader is automatically closed after the try block execution. The resource must implement the AutoCloseable interface to work with Try-With-Resources. Learning and applying such best practices helps in writing production-ready Java applications. Thanks to my mentors Anand Kumar Buddarapu Sir, Uppugundla Sairam Sir, and Saketh Kallepu Sir for continuous guidance and support in improving my Java concepts. #Java #ExceptionHandling #TryWithResources #Programming #LearningJourney
To view or add a comment, sign in
-
-
🔵 Set in Java – Collections Framework Set is an interface in the Java Collections Framework that represents a collection of unique elements. Unlike List, a Set does not allow duplicate values and focuses on maintaining uniqueness. 🔹 What is Set in Java? A Set is used when duplicate data is not allowed, such as: Unique user IDs Email addresses Roll numbers Product codes 📌 Set does not support index-based access. 🔹 Key Characteristics of Set ✔ Does not allow duplicate elements ✔ Allows at most one null value (depends on implementation) ✔ No index-based access ✔ Faster search operations ✔ Order is not guaranteed (except some implementations) 🔹 Set Hierarchy (Important) Set (Interface) HashSet LinkedHashSet SortedSet (Interface) TreeSet 🔹 Types of Set Implementations 1️⃣ HashSet ✔ No insertion order ✔ Fastest performance ✔ Uses Hashing ✔ Allows one null value 👉 Best for fast search & uniqueness 2️⃣ LinkedHashSet ✔ Maintains insertion order ✔ Slightly slower than HashSet ✔ Allows one null value 👉 Best when order + uniqueness are required 3️⃣ TreeSet ✔ Stores elements in sorted order ✔ Does not allow null values ✔ Slower than HashSet ✔ Uses Red-Black Tree 👉 Best for sorted unique data 🔹 Commonly Used Set Methods add() – Add element remove() – Remove element contains() – Check existence size() – Number of elements isEmpty() – Check empty clear() – Remove all elements TAP Academy , Rohit Ravindern, Somanna M G ,kshitij kenganavar ,Sharath R ,Ravi Magadum , Hemanth Reddy , Poovizhi VP #Java #CoreJava #JavaCollections #SetInterface #BackendDevelopment #JavaDeveloper #FullStackDeveloper #Programming #CodingLife #LearningJava #ComputerScience #SoftwareEngineering #Developers #LinkedInTech
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