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
Java Looping Statements & Comments Recap
More Relevant Posts
-
DAY 24: CORE JAVA 💻 Understanding Buffer Problem & Wrapper Classes in Java While working with Java input using Scanner, many beginners face a common issue called the Buffer Problem. 🔹 What is the Buffer Problem? When we use "nextInt()", "nextFloat()", etc., the scanner reads only the number but leaves the newline character ("\n") in the input buffer. Example: Scanner scan = new Scanner(System.in); int n = scan.nextInt(); // reads number String name = scan.nextLine(); // reads leftover newline ⚠️ The "nextLine()" does not wait for user input because it consumes the leftover newline from the buffer. ✅ Solution: Use an extra "nextLine()" to clear the buffer. int n = scan.nextInt(); scan.nextLine(); // clears the buffer String name = scan.nextLine(); 📌 This is commonly called a dummy nextLine() to flush the buffer. 🔹 Wrapper Classes in Java Java provides Wrapper Classes to convert primitive data types into objects. Primitive Type| Wrapper Class byte| Byte short| Short int| Integer long| Long float| Float char| Character 💡 Wrapper classes allow: - Converting String to primitive values - Storing primitive data in collections - Using useful utility methods Example: String s = "123"; int num = Integer.parseInt(s); // String → int 🔹 Example Use Case Suppose employee data is entered as a string: 1,Swathi,30000 We can split and convert values using wrapper classes: String[] arr = s.split(","); int empId = Integer.parseInt(arr[0]); String empName = arr[1]; int empSal = Integer.parseInt(arr[2]); 🚀 Key Takeaways ✔ Always clear the buffer when mixing "nextInt()" and "nextLine()" ✔ Wrapper classes help convert String ↔ primitive types ✔ They are essential when working with input processing and collections 📚 Concepts like these strengthen the core Java foundation for developers and interview preparation. TAP Academy #Java #CoreJava #JavaProgramming #WrapperClasses #Programming #SoftwareDevelopment
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
-
🚀 Java 8 – One of the Most Important Releases in Java History Java 8 introduced powerful features that completely changed how developers write Java code. It brought functional programming concepts, cleaner syntax, and more efficient data processing. Here are some of the most important features every Java developer should know 👇 🔹 1. Lambda Expressions Lambda expressions allow writing concise and readable code for functional interfaces. Example: List<String> names = Arrays.asList("Ali", "Sara", "John"); names.forEach(name -> System.out.println(name)); Instead of writing a full anonymous class, we can use a short lambda expression. 🔹 2. Functional Interfaces An interface with only one abstract method is called a functional interface. Example: @FunctionalInterface interface Calculator { int add(int a, int b); } Lambda expressions work with functional interfaces. 🔹 3. Stream API Stream API allows developers to process collections in a functional style. Example: List<Integer> numbers = Arrays.asList(1,2,3,4,5,6); numbers.stream() .filter(n -> n % 2 == 0) .forEach(System.out::println); Benefits: ✔ Less boilerplate code ✔ Better readability ✔ Easy parallel processing 🔹 4. Method References Method references make lambda expressions even shorter and cleaner. Example: names.forEach(System.out::println); Instead of: names.forEach(name -> System.out.println(name)); 🔹 5. Optional Class "Optional" helps avoid NullPointerException. Example: Optional<String> name = Optional.ofNullable(null); System.out.println(name.orElse("Default Name")); 💡 Why Java 8 is still widely used ✔ Introduced functional programming in Java ✔ Improved code readability ✔ Simplified collection processing ✔ Reduced boilerplate code Java 8 fundamentally changed the way modern Java applications are written. #Java #Java8 #Programming #SoftwareDevelopment #JavaDeveloper #Coding
To view or add a comment, sign in
-
-
☕ Java Generics – Upper Bounded Wildcards Explained In Java Generics, the question mark (?) represents a wildcard, meaning an unknown type. Sometimes, we need to restrict the type of objects that can be passed to a method — especially when working with numbers or specific class hierarchies. That’s where Upper Bounded Wildcards come into play. 🔹 What is an Upper Bounded Wildcard? To restrict a wildcard to a specific type or its subclasses, we use: <? extends ClassName> This means: 👉 Accept ClassName or any of its subclasses. For example, if a method should only work with numeric types, we restrict it to Number and its subclasses like Integer, Double, etc. As explained in the document (Page 1), the syntax uses ? followed by the extends keyword to define the upper bound. 🔹 Practical Example From the example shown (Page 2), a method calculates the sum of elements in a list: public static double sum(List<? extends Number> numberlist) { double sum = 0.0; for (Number n : numberlist) sum += n.doubleValue(); return sum; } 📌 Why ? extends Number? ✔ Ensures only numeric types are allowed ✔ Accepts List<Integer> ✔ Accepts List<Double> ✔ Maintains type safety 🔹 Usage in Main Method List<Integer> integerList = Arrays.asList(1, 2, 3); System.out.println("sum = " + sum(integerList)); List<Double> doubleList = Arrays.asList(1.2, 2.3, 3.5); System.out.println("sum = " + sum(doubleList)); 🔹 Output (Page 3) sum = 6.0 sum = 7.0 This demonstrates how the same method works seamlessly with different numeric types. 💡 Upper bounded wildcards improve flexibility while maintaining compile-time type safety. They are essential for writing reusable and robust generic methods in Java. #Java #Generics #UpperBoundedWildcards #JavaProgramming #OOP #FullStackJava #Developers #AshokIT
To view or add a comment, sign in
-
ArrayList ✈️ In Java, an ArrayList is a member of the Java Collections Framework and resides in the java.util package. While a standard Java array (e.g., int[]) is fixed in length, an ArrayList is a resizable-array implementation of the List interface. How It Works: The "Growing" Mechanism When you add an element to an ArrayList, Java checks if there is enough room in the underlying memory. If the internal array is full, the ArrayList performs the following: It allocates a new, larger array ✅Key Features in Java Type Safety: It uses Generics, allowing you to specify what type of data it holds (e.g., ArrayList<String>). Wrapper Classes: It cannot store primitive types (like int, double, char) directly. Instead, Java uses "Autoboxing" to convert them into objects (like Integer, Double, Character). Nulls and Duplicates: It allows you to store duplicate elements and null values. Unsynchronized: By default, it is not thread-safe. If multiple threads access it simultaneously, you must handle synchronization manually. It copies all existing elements to the new array. It updates its internal reference to this new array. ✅ArrayList vs. LinkedList A common interview question is when to use ArrayList over LinkedList. ArrayList: Best for frequent access and storing data where you mostly add/remove from the end. LinkedList: Best if you are constantly inserting or deleting items from the beginning or middle of the list. Would you like me to explain the specific differences between ArrayList and Vector, or perhaps show you how to sort an ArrayList using Collections.sort(). Huge thanks for the mentorship on Java ArrayList Anand Kumar Buddarapu Saketh Kallepu Uppugundla Sairam #ArrayList #Java #DataStructures #Programming #Coding #SoftwareEngineering #Backend #JavaDeveloper #Algorithms #TechTips #ComputerScience
To view or add a comment, sign in
-
🚀 Mastering Core Java | Day 10 📘 Topic: Exception Handling Today’s session focused on Exception Handling, a critical concept in Java that helps manage runtime errors gracefully and ensures smooth program execution. 🔑 What is an Exception? An unexpected event that disrupts normal program flow Occurs during execution (e.g., invalid input, missing files, divide by zero) If not handled, it can cause program termination 🧠 Why Exception Handling is Important? Prevents application crashes Improves program reliability and stability Separates error-handling logic from core business logic Makes debugging and maintenance easier 🧩 Key Keywords in Exception Handling: try – Contains risky code catch – Handles the exception finally – Executes whether an exception occurs or not throw / throws – Used to explicitly pass exceptions Simple Syntax & Example: try { int result = 10 / 0; } catch (ArithmeticException e) { System.out.println("Cannot divide by zero"); } finally { System.out.println("Execution completed"); } 📌 Types of Exceptions: Compile‑Time (Checked) – Detected at compile time Examples: IOException, SQLException Run‑Time (Unchecked) – Occur during execution Examples: NullPointerException, ArrayIndexOutOfBoundsException, ArithmeticException 💡 Key Takeaway: Exception Handling allows applications to handle errors gracefully, improving user experience and making systems more robust. Grateful to my mentor Vaibhav Barde sir for the clear explanations and real‑world examples, which made this concept easy to understand and apply. 📈 Continuing to strengthen my Core Java and OOP fundamentals step by step. #ExceptionHandling #CoreJava #JavaLearning #Day10 #OOPConcepts #SoftwareDevelopment #LearningJourney #ProfessionalGrowth
To view or add a comment, sign in
-
-
🚀 Understanding Multithreading in Java Multithreading is one of the most powerful features in Java that allows a program to perform multiple tasks simultaneously. It improves application performance and better utilizes CPU resources. 🔹 What is Multithreading? Multithreading is a process of executing multiple threads (smallest units of a process) concurrently within a single program. Example: A web application can handle multiple user requests at the same time using threads. 🔹 Why Multithreading is Important? ✔ Improves application performance ✔ Better CPU utilization ✔ Enables parallel processing ✔ Allows responsive applications (UI not freezing) 🔹 Ways to Create Threads in Java 1️⃣ Extending the Thread class class MyThread extends Thread { public void run() { System.out.println("Thread is running..."); } } 2️⃣ Implementing the Runnable interface class MyRunnable implements Runnable { public void run() { System.out.println("Thread is running..."); } } 🔹 Key Concepts in Multithreading • Thread Lifecycle • Synchronization • Deadlock • Thread Pool • Executor Framework 🔹 Simple Example class TestThread { public static void main(String[] args) { Runnable r = () -> System.out.println("Thread executed"); Thread t1 = new Thread(r); Thread t2 = new Thread(r); t1.start(); t2.start(); } } 💡 Takeaway: Multithreading helps build scalable and high-performance applications. Understanding synchronization and thread management is essential for backend developers. #Java #Multithreading #JavaDeveloper #BackendDevelopment #Programming #SoftwareDevelopment
To view or add a comment, sign in
-
Understanding Map in Java — One of the Most Important Concepts in the Collections Framework The Map interface in Java is a powerful data structure used to store data in key–value pairs, where every key is unique and maps to a specific value. Let’s simplify it: Key Characteristics: - Stores data as Key → Value pairs - Keys must be unique (duplicate keys overwrite values) - Duplicate values are allowed - No indexing — access data using keys Common Map Implementations: - HashMap → Fastest performance (O(1)), no order guarantee - LinkedHashMap → Maintains insertion order - TreeMap → Sorted keys (O(log n)) - ConcurrentHashMap → Thread-safe for multi-threaded applications Most Used Methods: - put() – Add or update data - get() – Retrieve value - remove() – Delete entry - containsKey() – Check key existence - entrySet() – Iterate key-value pairs Interview Tip: - If ordering matters → use LinkedHashMap - If sorting is needed → use TreeMap - If performance matters → use HashMap Java Collections become much easier once you truly understand how Map works. What Map implementation do you use most in your projects #Java #JavaDeveloper #SpringBoot #BackendDevelopment #JavaCollections #Programming #SoftwareDevelopment #Coding #TechLearning
To view or add a comment, sign in
-
-
DAY 26: CORE JAVA 🚀 Understanding the Use Cases of Static Variables and Static Methods in Java In Java, the "static" keyword plays a powerful role in managing shared data and class-level behavior. It allows variables and methods to belong to the class itself rather than to individual objects. Let’s explore why and when we use them. 👇 🔹 Static Variables (Class Variables) Static variables are shared among all objects of a class. Only one copy exists in memory, making them highly efficient. ✅ Use Cases • Storing common data shared by all objects (e.g., interest rate, company name, configuration values) • Reducing memory usage since the variable is created only once • Accessing class-level constants and configuration settings Example: class Businessman { static float rate = 15.2f; // shared interest rate } Here, every object of "Businessman" will use the same interest rate value. 🔹 Static Methods Static methods belong to the class, not the object. They can be called without creating an instance of the class. ✅ Use Cases • Utility or helper methods (e.g., Math calculations) • When method logic does not depend on instance variables • Entry point of Java programs ("main()" method) Example: class Test { static void display() { System.out.println("Inside static method"); } } Called as: Test.display(); 🔹 Key Advantages ✔ Efficient memory utilization ✔ Easy access without object creation ✔ Useful for shared data and utility functions ✔ Improves program organization and readability 📌 Real-world example: In a simple interest calculator, the interest rate can be static because it remains the same for all customers. 💡 Takeaway: Use static variables for shared data and static methods for operations that do not depend on object state. TAP Academy #Java #Programming #JavaDevelopment #Coding #SoftwareEngineering #LearnToCode
To view or add a comment, sign in
-
-
In Java, enum types are often introduced as just a list of constants. But they are actually much more powerful: they are real classes, with constructors, methods, and even different behavior for each constant. In this article I explore some lesser-known uses of enums that can make Java code more expressive and robust. ✍️ Stranger Things in Java: Enum Types Happy 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