🚀 Starting My Java Learning Journey – Day 6 🔹 Topic: Loops in Java Loops in Java are used to execute a block of code repeatedly until a certain condition is met. Java mainly provides three types of loops: 1️⃣ for Loop Used when the number of iterations is known. Example: public class Main { public static void main(String[] args) { for(int i = 1; i <= 5; i++) { System.out.println(i); } } } 2️⃣ while Loop Used when the number of iterations is not known beforehand. Example: public class Main { public static void main(String[] args) { int i = 1; while(i <= 5) { System.out.println(i); i++; } } } 3️⃣ do-while Loop The do-while loop executes the code at least once even if the condition is false. Example: public class Main { public static void main(String[] args) { int i = 1; do { System.out.println(i); i++; } while(i <= 5); } } 💡 Key Point: Loops help automate repetitive tasks and make programs more efficient. #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #JavaLoops
Java Loops Explained: for, while, do-while
More Relevant Posts
-
Day 40 of Learning Java: Method Overloading Instead of creating different method names for similar tasks, we can use the same method name but change the parameters — and Java figures out which one to call. -So what exactly is Method Overloading? It’s when multiple methods in the same class have: ✔ Same name ✔ Different parameter list That’s it. Simple idea, but very powerful. -Ways to overload a method • Change the type of parameters • Change the number of parameters • Change the order of parameters Example- Think of a login system: Login using username + password Login using mobile + password Both are login actions, right? So instead of writing different method names, we just overload: login(String username, String password) login(long mobile, String password) Same method name → different ways to use it -Another relatable one Payment systems 👇 COD UPI Card Net Banking Instead of: paymentByUPI(), paymentByCard()… We can just do: payment() payment(String upi) payment(long card) payment(String user, String pass) - Important things I learned • Just changing return type won’t work (it gives error) • Overloading happens at compile time • Works with static, private, and even final methods • Yes, even main() can be overloaded (but JVM only runs the standard one) #Java #LearningInPublic #100DaysOfCode #Programming #OOP #CodingJourney
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 9 🔹 Topic: Method Overloading in Java Method Overloading is a feature in Java that allows a class to have multiple methods with the same name but different parameters. It helps improve code readability and flexibility. 📌 Ways to Achieve Method Overloading 1️⃣ Different number of parameters 2️⃣ Different data types of parameters 📌 Example Program public class Main { // Method with two int parameters static int add(int a, int b) { return a + b; } // Method with three int parameters static int add(int a, int b, int c) { return a + b + c; } public static void main(String[] args) { System.out.println(add(5, 10)); System.out.println(add(5, 10, 15)); } } Output: 15 30 💡 Key Points: ✔ Method overloading allows multiple methods with the same name ✔ Methods must differ in number or type of parameters ✔ Helps make programs more flexible and readable #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #MethodOverloading
To view or add a comment, sign in
-
🚀 Learning Update: Understanding How a Java Program Actually Executes Today’s session helped me gain a deeper understanding of how Java programs execute internally beyond just writing code. 🔹 Java Compilation Process A Java program written in high-level language is first compiled using the Java Compiler (javac) which converts it into bytecode (.class files). If a file contains multiple classes, the compiler generates separate class files for each class. 🔹 Program Execution in JVM When we run a Java program: 1️⃣ The JVM loads the class containing the main method. 2️⃣ The bytecode is converted into machine-level instructions. 3️⃣ The program is executed inside the Java Runtime Environment (JRE). 🔹 Memory Structure in Java (JRE) During execution, the program uses different memory areas: • Code Segment – Stores compiled bytecode • Stack Segment – Stores method stack frames • Heap Segment – Stores objects created using new • Static Segment – Stores static variables 🔹 Role of Class Loader The Class Loader dynamically loads classes into memory when they are required during program execution. 🔹 Static vs Instance Concept • Static elements → belong to the class • Instance elements → belong to objects This concept explains why static methods can be accessed without creating an object, while instance methods require object creation. 💡 Key Insight: Understanding how JVM, class loading, memory segments, and object creation work internally helps in writing better and more optimized Java programs. Excited to keep exploring deeper concepts in Core Java and Object-Oriented Programming. #Java #JVM #Programming #OOP #SoftwareDevelopment #LearningJourney #JavaDeveloper TAP Academy
To view or add a comment, sign in
-
-
🚀 Day 29 | Core Java Learning Journey 📌 Topic: TreeSet in Java Today, I learned about TreeSet, an important class in the Java Collections Framework used when we need sorted and unique elements. 🔹 TreeSet in Java ✔ TreeSet is a class that implements NavigableSet ✔ It also indirectly implements SortedSet and Set ✔ Introduced in JDK 1.2 ✔ Stores unique elements only (no duplicates allowed) 🔹 Data Structure Used ✔ Based on Self-Balancing Binary Search Tree (Red-Black Tree) ❗ (important correction) ✔ Elements are stored in sorted order 🔹 Key Features ✔ Does NOT follow insertion order ✔ Follows natural sorting order (default) ✔ Allows custom sorting using Comparator ✔ Does NOT allow null elements ❌ ✔ Stores homogeneous data (same type, for proper comparison) 📌 Important Methods • add() – add element • remove() – delete element • contains() – check element • first() – returns first (smallest) element • last() – returns last (largest) element • higher() – next greater element • lower() – next smaller element 📌 Performance ✔ Operations like add, remove, search → O(log n) 📌 When to Use TreeSet? ✔ When you need: ✅ Sorted data ✅ Unique elements ✅ Range-based operations 💡 Note: Unlike HashSet, TreeSet focuses on sorting rather than speed. 🙏 Special thanks to Vaibhav Barde Sir for the guidance! 🔥 #CoreJava #JavaLearning #JavaDeveloper #TreeSet #SortedSet #NavigableSet #JavaCollections #Programming #LearningJourney
To view or add a comment, sign in
-
-
📘 **Day 17 – Java Learning Journey** Today I explored one of the most important concepts in Java: **Strings**. Here are some key points I learned while practicing and analyzing my notes: 🔹 **What is a String?** A String is a sequence (collection) of characters enclosed within double quotes. Example: `"Java"` 🔹 **Strings are Objects in Java** Unlike primitive data types, Strings are objects created from the `String` class. 🔹 **Immutable Nature of Strings** Strings in Java are **immutable**, meaning once a String object is created, its value cannot be changed. 🔹 **Different Ways to Create Strings** 1️⃣ `String s = "Java";` → Stored in the **String Constant Pool** 2️⃣ `String s = new String("Java");` → Stored in **Heap Memory** 3️⃣ Using character arrays 🔹 **String Comparison Methods** ✔ `==` → Compares **references (memory location)** ✔ `.equals()` → Compares **values/content** ✔ `.compareTo()` → Compares **character by character** ✔ `.equalsIgnoreCase()` → Compares **ignoring case differences** 🔹 **String Concatenation** Strings can be combined using: • `+` operator • `concat()` method Understanding concepts like **String Constant Pool, Heap Memory, and Reference Comparison** helped me clearly see how Java manages memory. Every day I’m learning something new and strengthening my Java fundamentals step by step. 🚀 #Java #Programming #LearningJourney #JavaDeveloper #ComputerScience #Coding TAP Academy
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 5 🔹 Topic: Control Statements in Java Control statements are used to control the flow of execution of a program based on certain conditions. In Java, the main control statements are: 1️⃣ if Statement The if statement executes a block of code only if the condition is true. Example: public class Main { public static void main(String[] args) { int num = 10; if (num > 0) { System.out.println("Number is positive"); } } } 2️⃣ if-else Statement The if-else statement executes one block of code if the condition is true and another block if it is false. Example: public class Main { public static void main(String[] args) { int num = -5; if (num > 0) { System.out.println("Positive number"); } else { System.out.println("Negative number"); } } } 3️⃣ switch Statement The switch statement is used when we want to compare one value with multiple possible cases. Example: public class Main { public static void main(String[] args) { int day = 2; switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; default: System.out.println("Other day"); } } } 💡 Key Point: Control statements help make programs dynamic and decision-based. #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #ControlStatements
To view or add a comment, sign in
-
🚀 Day 30 | Core Java Learning Journey 📌 Topic: Map Hierarchy in Java Today, I explored the Map Hierarchy in Java Collections Framework — understanding how different Map interfaces and classes are structured and related. 🔹 What is Map in Java? ✔ Map is an interface that stores key-value pairs ✔ Each key is unique and maps to a specific value ✔ It is part of java.util package 🔹 Map Hierarchy (Understanding Structure) ✔ Map (Root Interface) ⬇ ✔ SortedMap (extends Map) ⬇ ✔ NavigableMap (extends SortedMap) ⬇ ✔ TreeMap (implements NavigableMap) 🔹 Important Implementing Classes ✔ HashMap • Implements Map • Does NOT maintain order • Allows one null key ✔ LinkedHashMap • Extends HashMap • Maintains insertion order ✔ TreeMap • Implements NavigableMap • Stores data in sorted order • Does NOT allow null key ✔ Hashtable • Implements Map • Thread-safe (synchronized) • Does NOT allow null key/value 🔹 Key Differences ✔ HashMap → Fast, no ordering ✔ LinkedHashMap → Maintains insertion order ✔ TreeMap → Sorted data ✔ Hashtable → Thread-safe but slower 📌 When to Use What? ✅ Use HashMap → when performance is priority ✅ Use LinkedHashMap → when insertion order matters ✅ Use TreeMap → when sorting is required ✅ Use Hashtable → when thread safety is needed 💡 Key Takeaway: Understanding Map hierarchy helps in choosing the right data structure based on use-case rather than just coding blindly. 🙏 Special thanks to Vaibhav Barde Sir for the guidance! 🔥 #CoreJava #JavaLearning #JavaDeveloper #Map #HashMap #TreeMap #LinkedHashMap #Hashtable #JavaCollections #Programming #LearningJourney
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 10 🔹 Topic: Recursion in Java Recursion is a process where a method calls itself to solve a problem. It is mainly used to break down complex problems into smaller, simpler sub-problems. A recursive function must have: ✔ Base Case → condition to stop recursion ✔ Recursive Call → method calling itself Example: Factorial of a Number public class Main { static int factorial(int n) { if (n == 1) { // base case return 1; } return n * factorial(n - 1); // recursive call } public static void main(String[] args) { int result = factorial(5); System.out.println("Factorial: " + result); } } Output: Factorial: 120 ✔ Recursion solves problems by calling the same method repeatedly ✔ Every recursive method must have a base case ✔ Useful for problems like factorial, Fibonacci, tree traversal #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #Recursion
To view or add a comment, sign in
-
🚀 Starting My Java Learning Journey – Day 13 ♦Topic: Exception Handling in Java Exception Handling is used to handle runtime errors so that the program does not crash abruptly. It helps in maintaining the normal flow of the program. ✅ Types of Exceptions 1)Checked Exceptions → Checked at compile time 2) Unchecked Exceptions → Occur at runtime ✅ Keywords Used in Exception Handling ✔ try → block where code is written ✔ catch → handles the exception ✔ finally → always executes (optional) ✔ throw → used to explicitly throw an exception ✔ throws → declares exceptions ✅ Example Program public class Main { public static void main(String[] args) { try { int result = 10 / 0; // may cause exception System.out.println(result); } catch (ArithmeticException e) { System.out.println("Cannot divide by zero"); } finally { System.out.println("Execution completed"); } } } Output: Cannot divide by zero Execution completed 💡 Key Points: ✔ Prevents program crash ✔ Helps handle runtime errors ✔ Improves program reliability #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #ExceptionHandling
To view or add a comment, sign in
-
🚀 Understanding Strings in Java – A Fundamental Concept for Every Developer While learning Java, one of the most important topics to understand is Strings and how Java manages them in memory. 🔹 A String is a sequence of characters enclosed in double quotes, like "JAVA". 🔹 In Java, Strings are treated as objects and stored in the heap memory. 📌 Key Concepts I Learned: ✅ Immutable vs Mutable Strings Immutable: Cannot be changed after creation (e.g., names, date of birth). Mutable: Values that may change, like passwords or email IDs. ✅ String Pool & Memory Allocation Constant Pool → Created without new keyword (String s = "JAVA";) Non-Constant Pool → Created using new keyword (new String("JAVA")) Duplicate literals share the same memory reference in the pool. ✅ String Comparison Methods in Java == → Compares memory reference equals() → Compares actual string value compareTo() → Compares character by character equalsIgnoreCase() → Compares values ignoring case 💡 Example Insight: Two "JAVA" literals may refer to the same memory location, but new String("JAVA") always creates a new object. Understanding these fundamentals helps write efficient and optimized Java programs. 📚 Currently exploring more core Java concepts and strengthening my programming foundation in TAP Academy . #Java #Programming #JavaDeveloper #Coding #SoftwareDevelopment #LearningJava #CoreJava #Developers
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
4. Enhanced for Loop (for-each) Best for iterating over arrays or collections — cleaner and less error-prone. int[] numbers = {1, 2, 3, 4, 5}; for (int num : numbers) { System.out.println(num); }