🌟 Day 14 of My Java Learning Journey 🔥 💯 Hey everyone! 👋 ~ Today’s topic was all about decision-making in Java — how a program chooses which path to follow based on given conditions. 💡 . I explored how to find the greatest number among multiple values using nested if-else statements, one of the core parts of selection statements in Java. 💻 Here’s the code I worked on today: 👇 -------------------------------------code start-------------------------------------- public class FindGreaterNumberDemo2 { public static void main(String[] args) { int p = 11; int q = 22; int r = 33; int s = 44; if (p > r && p > s && p > q) { System.out.println("p is greater number "); } else if (q > s && q > p && q > r) { System.out.println("q is greater number"); } else if (r > p && r > s && r > q) { System.out.println("r is greater number"); } else { System.out.println("s is greater number"); } } } -------------------------------------code output------------------------------------ s is greater number ---------------------------------------code end-------------------------------------- . 🔍 Explanation: We have four integer variables: p, q, r, and s. Using an if-else-if ladder, we compare each number with the others using the logical AND (&&) operator. The first condition that turns out true will print which number is the greatest. If none of them match, the else block executes, showing that s is the greatest. . 💡 Key Takeaway: Selection statements like if, else if, and else help control the program’s logic — deciding what happens next depending on the condition. . 🚀 What’s next? In the upcoming posts, I’ll share many more real-world examples related to selection statements, so we can deeply understand how decision-making works in Java programs. Stay tuned — it’s gonna get crazy cool and more practical! 💻🔥 . #Java #100DaysOfCode #Day14 #JavaLearningJourney #FlowControl #IfElse #SelectionStatements #DevOps #Programming #CodingJourney #LearnJava #TechLearner #CodeNewbie .
"Learning Java: Day 14 on Decision-Making with If-Else Statements"
More Relevant Posts
-
🎯 Day 15 of My Java Learning Journey 🎯 . Hey everyone! 👋 .. Today I explored Selection Statements again — but this time, I focused on finding the smallest number among four values using if-else if ladder in Java. Here’s the code I wrote 👇 --------------------------------------code start--------------------------------------- public class FindSmallerNumberDemo2 { public static void main(String[] args) { int l = 1; int m = 2; int n = 3; int o = 4; if (l < m && l < n && l < o) { System.out.println("l is smaller"); } else if (m < o && m < n && m < l) { System.out.println("m is smaller"); } else if (o < n && o < m && o < l) { System.out.println("o is smaller"); } else { System.out.println("n is smaller"); } } } --------------------------------------code output---------------------------------- l is smaller number -------------------------------------code end--------------------------------------- . 💡 Explanation: I’ve declared four integer variables — l, m, n, and o. The if statement checks multiple conditions using logical AND (&&) to make sure one number is smaller than all others. . If the first condition fails, the program moves to the next else if condition. Finally, if none of the earlier conditions are true, the else block executes — meaning the last variable n is the smallest. . 🧠 This program is a simple way to understand how comparison and logical operators work together in decision-making statements. In the next few posts, I’ll share more concepts related to selection and looping statements in Java 🚀 . #Day15 #JavaLearningJourney #100DaysOfCode #LearnJava #Programming #DevOps #Coding #JavaBeginners #SelectionStatement #IfElseInJava .
To view or add a comment, sign in
-
-
🚀 Java Learning Journey – Day 22 🔥 Understanding Switch Case with Expressions (Java) Today I explored how switch-case works when we use expressions inside the case labels. ~ In Java, expressions like (0+1) or (1+2) get evaluated first, and then matched with the switch variable. The interesting part is fall-through, which happens when we don’t use a break statement. This helps in understanding how multiple cases can run together. ✅ Here’s the code I practiced today: -------------------------------------code start------------------------------------ public class SwitchDemo2 { public static void main(String[] args) { int x = 0; //x=0 (E) | x=1 (A,B) | x=2 (B) | x=3 (C,D,E) | x=4 (D,E) | x=5 (E) switch (x) { case (0+1): System.out.println("A"); case (1+1): System.out.println("B"); break; case (1+2): System.out.println("C"); case (2+2): System.out.println("D"); default: System.out.println("E"); } } } ----------------------------------code output------------------------------------ E -------------------------------------code end------------------------------------ 🧠 Key Takeaways case expressions are evaluated before matching. Without break, execution continues to the next case (fall-through). Helps in understanding how switch-case flows internally. 🌱 Personal Note: I’m continuously learning Java and exploring DevOps tools and practices to build a strong foundation for full-stack and automation development. If you like my daily progress posts, please support with a like, comment, or share ~ it truly motivates me to keep learning and sharing. 🙌 I’m also looking for internship opportunities in Java development or DevOps to apply my skills in real-world projects, learn from professionals, and grow further. If you know of any such opportunities or can guide me, I’d really appreciate your help 🙏 #JavaLearningJourney #day22 #Java #Programming #LearningInPublic #SwitchCase #JavaBeginners #CodeNewbie #FallThrough #DeveloperJourney #DevOps #TechJourney #LearningEveryday
To view or add a comment, sign in
-
-
😍 Day 17 of My Java Learning Journey – Finding Odd or Even Numbers 🔢 . Hey everyone 👋 . Today, I explored a simple but important concept 💯 ~ how to check whether numbers are odd or even in Java using conditional statements (if-else). . Here’s the code I practiced today: 👇 --------------------------------------code start-------------------------------------- public class FindOddOrEvenNumberDemo { public static void main(String[] args) { int c = 32; int d = 21; if (c % 2 == 0 && d % 2 == 0) { System.out.println("c & d both are even number"); } else if (c % 2 != 0 && d % 2 != 0) { System.out.println("c & d both are odd number"); } else if (c % 2 == 0) { System.out.println("c is even number and d is odd number"); } else { System.out.println("c is odd number and d is even number"); } } } ------------------------------------code output------------------------------------ c is even number and d is odd number ------------------------------------code end--------------------------------------- 💡 Explanation: The expression number % 2 gives the remainder when dividing the number by 2. If the remainder is 0, the number is even. If the remainder is not 0, the number is odd. . I used multiple if-else conditions to check all possibilities: Both numbers are even. Both numbers are odd. One is even and the other is odd. . 👉 In this example, c = 32 (even) and d = 21 (odd), so the output will be: ~ c is even number and d is odd number. . Building these logic-based programs helps strengthen my understanding of control flow and conditions in Java, which are essential for solving real-world coding problems. . #Java #Coding #LearnJava #100DaysOfCode #DevOps #JavaLearningJourney #Day16 #Programming #CodeWithYuvi #LogicBuilding .
To view or add a comment, sign in
-
-
🚀 Java Learning Series — Day 3 Topic: Exception and Its Types ☕ When we write a program, things don’t always go as planned Right??? Java gives us "Exceptions" — Special ways to handle those unexpected Bugs so our code doesn’t crash suddenly. ------------------------------------- 💡 Definition: An Exception is like a signal that something went wrong during program execution. Instead of stopping everything, Java lets us catch and handle it. ------------------------------------- ✅ Dont miss to read the Interview questions from this Topic in the end 💀😋 ------------------------------------- 🧩 Types of Exceptions: 1. CHECKED EXCEPTIONS → Problems Java expects you to handle before running (e.g., reading a missing file). ----Must fix---- 2. UNCHECKED EXCEPTIONS → Problems that happen while running (e.g., dividing by zero). 3. ERRORS (Bugs) → Serious system-level problems (e.g., memory full, system crash). ------------------------------------- 🧠 Simple Example: class ExceptionTypesStory { public static void main(String[] args) { try { int apples = 5; int kids = 0; int eachGets = apples / kids; // Oops! Unchecked exception System.out.println("Each kid gets: " + eachGets); } catch (ArithmeticException e) { System.out.println("Oops! Can't divide apples by zero kids."); } //See here how I handled the error 👇🏃 try { Thread.sleep(500); // Checked exception } catch (InterruptedException e) { System.out.println("Someone woke me up too early!"); } System.out.println("###_Story_over_###"); //Everything handled 😜smoothly } } ------------------------------------- ⚙️ Real-World Connections: 1. Online Shopping App– Item goes out of stock → Exception handled, shows “Out of Stock” instead of crashing. 2. Bank App – Network drops during payment → Checked exception, retried safely. 3. Music Player – Song file missing → Checked exception handled, plays next song. 5. Web Browser – Out of memory loading heavy tabs → Error, can’t recover easily. ------------------------------------- 🔥 Interview-Style Quick Questions — Exceptions in Java 1️⃣ What is the difference between Checked and Unchecked Exceptions? 2️⃣ Can we handle Errors using try-catch? If not, why? 3️⃣ Is it mandatory to handle Checked Exceptions? 4️⃣ What happens if you don’t handle an Unchecked Exception? 5️⃣ Can a single catch block handle multiple exceptions? 6️⃣ What is the parent class of all exceptions in Java? 7️⃣ What happens if you put finally block before catch? 8️⃣ Can we have a try block without catch? 9️⃣ What’s the difference between throw and throws in exception context? 🔟 Why is Exception Handling important in large-scale applications? #Java #100DaysOfJava #CodingJourney #ExceptionHandling #SoftwareEngineer #SoftwareEngineering #LearningNeverStops #MERNtoJavaJourney
To view or add a comment, sign in
-
-
🌟 Day 7 of My Java Learning Journey ~> Understanding == vs .equals() in Java 🔥 Hey connections 👋 Today I explored one of the most commonly confusing topics in Java — the difference between == and .equals(). Let’s break it down simply 👇 💡 == Operator Used to compare memory references (i.e., whether two variables point to the same object in memory). Works perfectly for primitive data types like int, char, boolean, etc. But when used with objects (like String), it only checks if both references point to the same object, not if their values are equal. 🧩 Example: -------------------------------------code start---------------------------------------- String s1 = new String("Java"); String s2 = new String("Java"); System.out.println(s1 == s2); // false (different memory locations) System.out.println(s1.equals(s2)); // true (same value) --------------------------------------code end--------------------------------------- 💬 .equals() Method Comes from the Object class. Used to compare the actual content (values) of two objects. In most Java classes (like String, Integer, etc.), it’s overridden to check value equality. 🧩 Example: ----------------------------------code start------------------------------------------- String name1 = "Yuvi"; String name2 = "Yuvi"; System.out.println(name1 == name2); // true (same memory due to String pool) System.out.println(name1.equals(name2)); // true (same value) ----------------------------------code end------------------------------------------- 🚀 Quick Summary ~ Comparison TypeWorks OnChecks==Primitives ~ Object referencesMemory location.equals()ObjectsActual values/content ✨ Remember: Use == for primitive data types Use .equals() for comparing object values 💭 This small concept makes a big difference when working with strings, collections, and custom objects. #Java #Coding #LearningJourney #JavaDeveloper #OOPs #Programming #100DaysOfCode #DevOps #JavaLearning #SoftwareDevelopment #LinkedInLearning
To view or add a comment, sign in
-
-
Java with DSA Challenge Day 5 Challenge Problem: Check Prime Number Today’s challenge was to determine whether a given integer n is a prime number or not. A prime number is a number greater than 1 that is divisible only by 1 and itself. Example: Input: n = 17 Output: True Explanation: 17 is divisible only by 1 and 17. This problem is a fundamental concept in number theory and serves as a great way to understand time complexity optimization in algorithms. Code Snippet // User function Template for Java class Solution { public static boolean prime(int n) { // 0 and 1 are not prime numbers if (n <= 1) return false; // 2 and 3 are prime numbers if (n <= 3) return true; // Eliminate multiples of 2 and 3 if (n % 2 == 0 || n % 3 == 0) return false; // Check divisibility up to √n using 6k ± 1 rule for (int i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; // number is prime } public static void main(String[] args) { int n1 = 17, n2 = 56; System.out.println(n1 + " is prime? " + prime(n1)); // true System.out.println(n2 + " is prime? " + prime(n2)); // false } } Code Explanation 1.Base Case Handling Numbers ≤ 1 are not prime, so we return false. 2. Small Prime Numbers 2 and 3 are prime by definition, so we return true. 3. Eliminate Multiples of 2 and 3 Any number divisible by 2 or 3 (except 2 and 3 themselves) cannot be prime. 4. Using the 6k ± 1 Rule All primes greater than 3 can be written as 6k ± 1. So, instead of checking every number, we only check divisibility for numbers of this form up to √n. This reduces unnecessary iterations and makes the code much faster. 5.Return True If no divisors are found, the number is prime. Complexity Time Complexity: O(√n) Space Complexity: O(1) Output 17 is prime? true 56 is prime? false Reflection This problem shows how even a simple concept like checking prime numbers can be optimized using mathematical insights like the 6k ± 1 rule. #Java #DSA #100DaysOfCode #CodingChallenge #ProblemSolving #GeeksforGeeks #Algorithms #LearnToCode #JavaDeveloper #SoftwareEngineering #DataStructures #Developer
To view or add a comment, sign in
-
-
🚀 Day 57 & 58 of My Java Full Stack Learning Journey Topic: ABSTARCTION IN JAVA 💡 Today, I dived deep into one of the most powerful OOPs concepts — Abstraction. It’s like magic 🪄 — showing only what’s necessary and hiding all the complexity behind the scenes. Just think about using an ATM 💳 — We simply insert the card, press a few buttons, and get the cash. But do we know how the machine internally communicates with the bank server? Nope! 👉 That’s exactly what Abstraction does in Java. 💬 What I Learned: ✨ Abstraction hides implementation details and shows only essential features. ✨ It increases security, reduces complexity, and improves maintainability. ✨ It can be achieved in two ways: 1️⃣ Abstract Classes — allow partial implementation. 2️⃣ Interfaces — define only method declarations (until Java 7). With Java 8+, interfaces became more powerful: ✅ default methods ✅ static methods ✅ private methods (from Java 9) And yes — I also explored Functional Interfaces with Lambda Expressions, which make code cleaner and more expressive! ⚡ 🧩 Quick Example: interface Bank { void deposit(double amount); void withdraw(double amount); } abstract class Account { double balance; abstract void openAccount(); void showBalance() { System.out.println("Current Balance: " + balance); } } class SBI extends Account implements Bank { void openAccount() { System.out.println("SBI Account Opened ✅"); } public void deposit(double amount) { balance += amount; } public void withdraw(double amount) { balance -= amount; } } public class TestAbstraction { public static void main(String[] args) { Account acc = new SBI(); acc.openAccount(); ((SBI) acc).deposit(5000); ((SBI) acc).withdraw(2000); acc.showBalance(); } } Output: SBI Account Opened ✅ Deposited: 5000.0 Withdrawn: 2000.0 Current Balance: 3000.0 🧠 My Takeaway: 💭 Abstraction helps developers focus on what to do, not how to do it. It’s like separating the “menu” from the “recipe” — we just choose what we need, and the behind-the-scenes logic takes care of the rest! I’m enjoying how each OOP concept builds a stronger foundation for becoming a confident Full Stack Developer 💪 #Java #Abstraction #OOPsConcepts #FullStackDevelopment #180DaysOfCode #LearningJourney #JavaProgramming #WomenInTech #TechLearner #CodeWithLaya #DevelopersCommunity #Motivation
To view or add a comment, sign in
-
🚀 Day 21 of My Java Learning Journey ~ Switch Statement Without Break – Fall-Through Behavior Explained 💡 . Hey everyone 👋 Today, I learned how the switch statement behaves when we don’t use the break keyword. This is an important Java concept called fall-through, where execution continues into the next cases until the switch ends. Here’s the program I practiced 👇 --------------------------------------code start--------------------------------------- public class SwitchDemoWithoutBreak { public static void main(String[] args) { int m = 9; switch (m) { case 1: System.out.println("the month is january"); case 2: System.out.println("the month is February"); case 3: System.out.println("the month is March"); case 4: System.out.println("the month is April"); case 5: System.out.println("the month is May"); case 6: System.out.println("the month is June"); case 7: System.out.println("the month is July"); case 8: System.out.println("the month is August"); case 9: System.out.println("the month is September"); case 10: System.out.println("the month is October"); case 11: System.out.println("the month is November"); case 12: System.out.println("the month is December"); default: System.out.println("You have entered the number out of range"); } } } -----------------------------------code output--------------------------------------- the month is September the month is October the month is November the month is December You have entered the number out of range --------------------------------------code end--------------------------------------- 🧠 Explanation: The switch statement checks the value of m. Since there is no break statement in any case, Java continues executing all cases from the matching case until the end. This behavior is known as fall-through. Since m = 9, the program starts printing from case 9 all the way to default. 👉 This helps you understand why break statements are important when you want to stop execution after a specific matched case. 🌱 Personal Note: I’m learning Java consistently every day and improving my understanding of core concepts. Along with Java, I’m also exploring DevOps tools to strengthen my development and automation skills. If you find my daily learning posts helpful, please support with a like, comment, or share — it really motivates me to keep going! 🙌 I’m also actively looking for internship opportunities in Java development or DevOps. If you know of any openings or can guide me, I’d truly appreciate your help 🙏 . hashtag#Java hashtag#LearningJourney hashtag#Day21 hashtag#SwitchCase hashtag#FallThrough hashtag#JavaDeveloper hashtag#CodingInPublic hashtag#DevOps hashtag#Internship hashtag#CareerGrowth hashtag#CodeWithYuvi ....... ...
To view or add a comment, sign in
-
-
Advanced Java Concepts 1️⃣ What are Java Streams, and how do they improve performance? 2️⃣ Explain the difference between parallel and sequential streams. 3️⃣ How does the CompletableFuture API work in Java 8 and beyond? 4️⃣ What is the difference between Callable and Runnable in multithreading? 5️⃣ Explain the working of the Fork/Join framework in Java. Java Performance & Optimization 6️⃣ How does the JVM Garbage Collector optimize memory usage? 7️⃣ What are Java Memory Leaks, and how can you detect them? 8️⃣ Explain Just-In-Time (JIT) Compilation and its role in performance. 9️⃣ How can you optimize Java applications for high-concurrency systems? 🔟 What are the best practices for reducing latency in multithreaded apps? Pro Tip: Master these questions with hands-on coding examples — they test not just theory, but your understanding of Java internals, performance tuning, and concurrency handling. I searched 300 free courses, so you don't have to. Here are the 35 best free courses. 1. Data Science: Machine Learning Link: https://lnkd.in/gUNVYgGB 2. Introduction to computer science Link: https://lnkd.in/gR66-htH 3. Introduction to programming with scratch Link: https://lnkd.in/gBDUf_Wx 3. Computer science for business professionals Link: https://lnkd.in/g8gQ6N-H 4. How to conduct and write a literature review Link: https://lnkd.in/gsh63GET 5. Software Construction Link: https://lnkd.in/ghtwpNFJ 6. Machine Learning with Python: from linear models to deep learning Link: https://lnkd.in/g_T7tAdm 7. Startup Success: How to launch a technology company in 6 steps Link: https://lnkd.in/gN3-_Utz 8. Data analysis: statistical modeling and computation in applications Link: https://lnkd.in/gCeihcZN 9. The art and science of searching in systematic reviews Link: https://lnkd.in/giFW5q4y 10. Introduction to conducting systematic review Link: https://lnkd.in/g6EEgCkW 11. Introduction to computer science and programming using python Link: https://lnkd.in/gwhMpWck 12. Introduction to computational thinking and data science Link: https://lnkd.in/gfjuDp5y 13. Becoming an Entrepreneur Link: https://lnkd.in/gqkYmVAW 14. High-dimensional data analysis Link: https://lnkd.in/gv9RV9Zc 15. Statistics and R Link: https://lnkd.in/gUY3jd8v 16. Conduct a literature review Link: https://lnkd.in/g4au3w2j 17. Systematic Literature Review: An Introduction Link: https://lnkd.in/gVwGAzzY 18. Introduction to systematic review and meta-analysis Link: https://lnkd.in/gnpN9ivf 19. Creating a systematic literature review Link: https://lnkd.in/gbevCuy6 20. Systematic reviews and meta-analysis Link: https://lnkd.in/ggnNeX5j 21. Research methodologies Link: https://lnkd.in/gqh3VKCC 22. Quantitative and Qualitative research for beginners Link: https://shorturl.at/uNT58 Follow MD. ASIF AHMED for more #JavaInterview #JavaDeveloper #SystemDesign #OOP #ProgrammingAssignmentHelper
To view or add a comment, sign in
-
-
🚀 Day 20 of My Java Learning Journey ~ Switch Statement with Break 💯 . Hey everyone 👋 Today, I learned about the switch statement in Java ~ a control flow statement that helps us choose one action out of many based on a given value. Here’s the program I practiced 👇 --------------------------------------code start--------------------------------------- public class SwitchDemoWithBreak { public static void main(String[] args) { int x = 2; switch (x) { case 1: System.out.println("Today is Monday"); break; case 2: System.out.println("Today is Tuesday"); break; case 3: System.out.println("Today is Wednesday"); break; case 4: System.out.println("Today is Thursday"); break; case 5: System.out.println("Today is Friday"); break; case 6: System.out.println("Today is Saturday"); break; case 7: System.out.println("Today is Sunday"); break; default: System.out.println("You have entered the number out of range"); } } } -----------------------------------code output--------------------------------------- Today is Tuesday --------------------------------------code end--------------------------------------- 🧠 Explanation: The switch statement checks the value of x and executes the matching case. Each case represents a possible value of x. The break statement prevents execution from continuing into the next case. The default block runs when no case matches. 👉 In this example, since x = 2, it prints: “Today is Tuesday” ✅ 🌱 Personal Note: I’m continuously learning Java and exploring DevOps tools and practices to build a strong foundation for full-stack and automation development. If you like my daily progress posts, please support with a like, comment, or share ~ it truly motivates me to keep learning and sharing. 🙌 I’m also looking for internship opportunities in Java development or DevOps to apply my skills in real-world projects, learn from professionals, and grow further. If you know of any such opportunities or can guide me, I’d really appreciate your help 🙏 . #Java #LearningJourney #Day20 #CodingInPublic #SwitchCase #BreakStatement #JavaDeveloper #DevOps #Internship #CareerGrowth #CodeWithYuvi ..... ... .
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