Day 9:- Conditional Statements A Journey with Frontlines EduTech (FLM) and Fayaz S Conditional statements 👉 if- else If -else is a conditional statement used to execute different blocks of code base on a condition. if statement:- -- It excute code only if the condition is true -- if the condition is true.it prints the message -- id false nothing happens Example:- { int age = 18; if(age >=18); System.out.println("he is major"); } If-else :- It executes one block if the condition is true and another block if it is false. Syntax:- if(condition){ System.out.println(block); } else{ // else block } if-else-if:- It is used multiple conditions are checking. Syntax:- if(condition) { // Code } else if(condition 2) { // Code } else { // Code } #Corejava #ConditionalStatements #java #frontlinesmediaedutech
Java Conditional Statements Explained
More Relevant Posts
-
Recently revisited an important Java Streams concept: reduce() - one of the most elegant terminal operations for aggregation. Many developers use loops for summing or combining values, but reduce() brings a functional and expressive approach. Example: List<Integer> nums = List.of(1, 2, 3, 4); int sum = nums.stream() .reduce(0, Integer::sum); What happens internally? reduce() repeatedly combines elements: 0 + 1 = 1 1 + 2 = 3 3 + 3 = 6 6 + 4 = 10 Why it matters: ✔ Cleaner than manual loops ✔ Great for immutable / functional style code ✔ Useful for sum, max, min, product, concatenation, custom aggregation ✔ Common in backend processing pipelines Key Insight: Integer::sum is just a method reference for: (a, b) -> a + b Small concepts like this make code more readable and scalable. Still amazed how much depth Java Streams offer beyond just filter() and map(). #Java #Programming #BackendDevelopment #SpringBoot #JavaStreams #Coding #SoftwareEngineering
To view or add a comment, sign in
-
Topic: Avoiding Premature Abstraction Not everything needs to be abstracted from day one. Developers often try to generalize code too early. This leads to: • Unnecessary complexity • Hard-to-read code • Over-engineered solutions A better approach: • Solve the current problem first • Refactor when patterns emerge • Introduce abstraction when it’s actually needed Because abstraction without clarity creates confusion. Good design evolves over time — it’s not forced early. Simple code today is better than complex code for a problem that doesn’t exist yet. When do you decide it’s the right time to abstract? #CleanCode #SoftwareEngineering #BackendDevelopment #Java #SystemDesign
To view or add a comment, sign in
-
Solved: Product of Array Except Self 💡 Key Takeaway: Instead of recalculating product for every index, we can use prefix and suffix products to build the result efficiently. 👉 Approach I followed: - First pass → store left (prefix) product - Second pass → multiply with right (suffix) product - No division used 📊 Time Complexity: O(n) 📦 Space Complexity: O(1) 🔍 What made it interesting: Understanding how left and right contributions combine at each index to avoid redundant calculations. Consistency + clarity is slowly building confidence 💪 #DSA #Java #LeetCode #CodingJourney #BackendDeveloper #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Day 52 of #100DaysOfLeetCode Solved: Daily Temperatures (Monotonic Stack) Today’s focus was on understanding how to optimize from a brute-force O(n²) approach to an efficient O(n) solution using a stack. Key takeaways: Learned how to identify “next greater element” patterns Understood how monotonic stacks help avoid redundant work Practiced writing clean and optimized code Consistency is starting to pay off. Onto the next one. #DSA #Java #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Topic: Importance of Naming in Code Good naming is one of the simplest ways to improve code quality. Poor naming leads to: • Confusion • Misunderstanding of logic • Slower development • Harder maintenance Good naming should be: • Clear and descriptive • Consistent across the codebase • Reflective of intent Examples: Bad: data, temp, x Good: userAccountBalance, paymentStatus, orderList Naming is not just a small detail. It directly impacts how easily others understand your code. Because code is read more often than it is written. What naming conventions do you follow in your projects? #CleanCode #SoftwareEngineering #Java #BackendDevelopment #Coding
To view or add a comment, sign in
-
🚀 Day 7 – Exception Handling: More Than Just try-catch Today I focused on how exception handling should be used in real applications—not just syntax. try { int result = 10 / 0; } catch (Exception e) { System.out.println("Error occurred"); } This works… but is it the right approach? 🤔 👉 Catching generic "Exception" is usually a bad practice 💡 Better approach: ✔ Catch specific exceptions (like "ArithmeticException") ✔ Helps in debugging and handling issues more precisely ⚠️ Another insight: Avoid using exceptions for normal flow control Example: if (value != null) { value.process(); } 👉 is better than relying on exceptions 💡 Key takeaway: - Exceptions are for unexpected scenarios, not regular logic - Proper handling improves readability, debugging, and reliability Small changes here can make a big difference in production code. #Java #BackendDevelopment #ExceptionHandling #CleanCode #LearningInPublic
To view or add a comment, sign in
-
𝗢𝗽𝘁𝗶𝗼𝗻𝗮𝗹.𝗼𝗿𝗘𝗹𝘀𝗲() 𝗘𝘅𝗲𝗰𝘂𝘁𝗲𝘀 𝗘𝘃𝗲𝗻 𝗪𝗵𝗲𝗻 𝗩𝗮𝗹𝘂𝗲 𝗣𝗿𝗲𝘀𝗲𝗻𝘁 ⚠️ Looks harmless. It’s not. User user = findUserInCache(userId) .orElse(loadUserFromDatabase(userId)); Many developers read this as: 👉 "load from DB only if cache missed" But that is not what happens. 🔥 What actually happens orElse(...) is eager. That means the argument is evaluated before orElse() is called. So even when user is already present in cache, this still runs: 👉 loadUserFromDatabase(userId) Effectively: User fallback = loadUserFromDatabase(userId); // always executed User user = findUserInCache(userId).orElse(fallback); 💥 Why this hurts in production That fallback is often not cheap. It can be: 🔹 DB query 🔹 remote API call 🔹 disk read 🔹 heavy object construction So what looked like a safe fallback becomes hidden work on every request. 👉 extra CPU 👉 unnecessary IO 👉 more latency 👉 performance regression that is easy to miss in review ✅ The correct approach Use orElseGet(...) when fallback is expensive. User user = findUserInCache(userId) .orElseGet(() -> loadUserFromDatabase(userId)); Now the fallback runs only if Optional is empty. ⚠️ When orElse() is fine orElse() is still okay when the fallback is trivial: String name = maybeName.orElse("unknown"); Constant value, already computed value, or something very cheap. 🧠 Takeaway orElse() is not lazy. If you pass a method call there, that method may execute even when the value is already present. That is exactly the kind of tiny thing that later turns into: "Why is the DB getting hit so much?" 🤦 Have you ever seen a small Java convenience API cause a very non-convenient production problem? 👀 #java #springboot #performance #backend #softwareengineering #programming #coding
To view or add a comment, sign in
-
-
#repost Day1 - 𝐒𝐦𝐚𝐥𝐥 𝐂𝐨𝐧𝐜𝐞𝐩𝐭, 𝐁𝐢𝐠 𝐈𝐦𝐩𝐚𝐜𝐭 – 𝐉𝐚𝐯𝐚 𝐈𝐧𝐝𝐞𝐱𝐢𝐧𝐠 💡 In Java, array index starts from 0 because it represents the distance (offset) from the starting point in memory. 👉 Index 0 → First element (0 steps from start) 👉 Index 1 → Second element (1 step away) This makes calculations simple and fast: 𝑨𝒅𝒅𝒓𝒆𝒔𝒔 = 𝑩𝒂𝒔𝒆 + (𝑰𝒏𝒅𝒆𝒙 × 𝑺𝒊𝒛𝒆) 💡 Starting from 0 𝐚𝐯𝐨𝐢𝐝𝐬 𝐞𝐱𝐭𝐫𝐚 𝐜𝐚𝐥𝐜𝐮𝐥𝐚𝐭𝐢𝐨𝐧𝐬 𝐚𝐧𝐝 𝐢𝐦𝐩𝐫𝐨𝐯𝐞𝐬 𝐩𝐞𝐫𝐟𝐨𝐫𝐦𝐚𝐧𝐜𝐞. That’s why most languages follow 0-based indexing. #java #coding #developer #learning #springboot
To view or add a comment, sign in
-
-
Day 42 of consistency 💻🔥 Solved Add Two Numbers using linked lists — a classic problem that really tests understanding of pointers, carry handling, and edge cases. Key takeaways: Handling carry efficiently is crucial Dummy nodes make list problems much cleaner Iterative approach keeps space optimal Not the fastest runtime yet, but improvement is a process — optimizing step by step. Consistency > Perfection. #Day42 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
One mistake I see often in Java projects: 👉 Over-engineering simple problems. We sometimes introduce: Too many layers Unnecessary abstractions Complex design patterns …for problems that could be solved with a few clean classes. I’ve been there too. Early in my career, I thought “more design = better code.” But in real-world systems, complexity becomes your biggest enemy. Now I follow a simple rule: ✔ Start simple ✔ Design for current needs ✔ Evolve only when required 💡 Insight: Good engineering is not about adding complexity — it’s about avoiding it. #Java #SoftwareEngineering #CleanCode #SystemDesign #TechInsights
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