Today I'm practice exception in java ✨💻 When an Exception occurs, the JVM creates an exception object containing the error name, description and program state. Creating the exception object and handling it in the run-time system is called throwing an exception. There might be a list of the methods that had been called to get to the method where an exception occurred. This ordered list of methods is called call stack. Now the following procedure will happen: The run-time system searches the call stack for an exception handler It starts searching from the method where the exception occurred and proceeds backward through the call stack. If a handler is found, the exception is passed to it. If no handler is found, the default exception handler terminates the program and prints the stack trace. Exception in thread "abc" Name of Exception : Description // Call Stack #javafullstack #java #corejava #exception #LearningByDoing
Understanding Java Exceptions and Call Stack
More Relevant Posts
-
The Subtle Trap of Optional in Java 💭 Optional was meant to prevent NullPointerException but misuse can make code worse! ❌ Returning Optional from setters ❌ Using Optional fields in entities ❌ Serializing Optional with Jackson (it’ll break your JSON mapping) ✅ Correct use: Method return types to signal absence of value. Example: Optional<User> user = userRepository.findByEmail(email); user.ifPresent(System.out::println); 💭 Have you seen Optional abused in your codebase? #Java #CleanCode #BestPractices
To view or add a comment, sign in
-
-
Day 3 — Exception Handling in Java Continuing the 100 Days of Java + Spring Boot challenge with Faisal Memon. Covered key concepts: try-catch-finally, throw & throws, checked vs unchecked exceptions, and try-with-resources. Resources: https://lnkd.in/gtGcjg2i Consistency is the goal. #Java #SpringBoot #100DaysOfCode #LearningJourney
To view or add a comment, sign in
-
-
Still writing verbose loops in Java? Streams have evolved far beyond map() & filter()—from takeWhile() to mapMulti() to gather(). Mihaela Gheorghe-Roman traces the full journey from Java 8 to 24. Stay current: https://lnkd.in/eiWhNWwB OpenJDK #Java25 #JavaStreams #JDK #Java #ProjectAmber
To view or add a comment, sign in
-
-
🚀 Java Concept Simplified! Did you know? 🤔 In Java, any variable declared inside an interface is implicitly: ✅ public ✅ static ✅ final That means you don’t even need to write these modifiers — the JVM automatically treats them that way! 💡 📘 Example: interface Demo { int VALUE = 100; // same as public static final int VALUE = 100; }
To view or add a comment, sign in
-
-
💥 Master Exception Handling in Java — The Right Way! Just came across a comprehensive PDF that explains Exception Handling in Java from the ground up — and it’s a real gem 💎 Here’s what it covers 👇 ⚙️ Definition & Importance — why exception handling matters for clean, crash-free apps 🧩 Checked vs Unchecked Exceptions — explained with clarity & examples 🧠 try-catch-finally, throw, and throws — when and how to use them effectively 🛠️ Creating Custom Exceptions 💡 Best Practices — logging, cleanup, and handling specific exceptions 🚀 Try-with-resources (Java 7+) for automatic resource management 🔄 Exception Propagation, Chaining & Advanced Scenarios 🎯 Common interview questions with example answers Exception handling isn’t just about fixing errors — it’s about building resilient, production-ready applications that fail gracefully 💪 Follow me to stay updated and strengthen your Java foundations — one concept at a time 🌱 #Java #ExceptionHandling #SpringBoot #Microservices #BackendDevelopment #CodingBestPractices #JavaDevelopers #conceptsofcs #LearningNeverStops
To view or add a comment, sign in
-
💡 What I Learned Today: throw vs throws in Java While revisiting Java Exception Handling, I explored the difference between throw and throws — a small concept with a big impact in real-world projects. 🔹 throw → used inside a method to actually throw an exception. 🔹 throws → used in a method declaration to indicate that the method may throw certain exceptions, delegating responsibility to the caller. ✅ Understanding this distinction helps in writing clean, maintainable, and professional code, especially in projects dealing with files, databases, or network operations. #Java #ExceptionHandling #JavaDeveloper #CodingTips #LearningJourney
To view or add a comment, sign in
-
-
Day43 - Interface in Java. 1. Interface is like a blueprint of a class — it contains methods (usually without body) that a class must implement. 2. It is used to achieve abstraction and multiple inheritance in Java. Interface in Java 7 : 1. Only abstract methods are allowed (no method body). 2. Only public static final variables (constants) are allowed. 3. A class implements an interface using the implements keyword. 4. A class must implement all abstract methods of the interface. Interface in Java 8 Java 8 made interfaces more powerful by allowing default and static methods. 1.Default Methods: Can have a method body inside interface. Used to add new features to interfaces without breaking old code. Must be marked with the keyword default. Interface in Java 9 and above 1. Java 9 added private methods inside interfaces. 2. Private Methods: Used only inside the interface. Helps to avoid code duplication in default and static methods. Cannot be accessed outside the interface. 2.Static Methods: Can be called using Interface name, not through objects. Used for utility or helper methods. Gurugubelli Vijaya Kumar 10000 Coders #Java #Interfaces #CoreJava #OOPS #Abstraction #Java8 #Java9 #LearnJava #CodingConcepts #SoftwareDevelopment
To view or add a comment, sign in
-
💡 Did you know that Sequenced Collections were introduced in Java 21 to solve the lack of a unified API for ordered collections? Before Java 21, many collections were already "sequenced" (such as: List, LinkedHashSet, LinkedHashMap, TreeSet, TreeMap) However, they didn't share a common interface that reflected this property. This led to inconsistent APIs. For example: • To get the first element of a List, you'd use list.get(0), but there was no equivalent for an ordered Set or Map. • To get the last element of a List, you'd use list.get(list.size() - 1), while for a LinkedHashSet, you'd have to iterate through the entire set. • To reverse a list you could use Collections.reverse(list), but for a LinkedHashSet or TreeMap, you’d need to copy elements into another structure. 🔧 Sequenced Collections fix this by introducing new interfaces: 🔹 SequencedCollection<E>: The main interface, which extends Collection<E>. It represents any collection with a defined order. 🔹SequencedSet<E>: Extends SequencedCollection<E> and Set<E>. Implemented by classes like LinkedHashSet. 🔹SequencedMap<K, V>: Extends Map<K, V>. Implemented by classes like LinkedHashMap. Existing classes like List, Deque, LinkedHashSet, and LinkedHashMap have been retrofitted to implement these new interfaces. 🔑 Key Methods The interface SequencedCollection provides a standard set of methods for accessing elements at either end: • getFirst(): Gets the first element • getLast(): Gets the last element • addFirst(E): Adds an element to the beginning. • addLast(E): Adds an element to the end. • removeFirst(): Removes and returns the first element. • removeLast(): Removes and returns the last element. • reversed(): This is a key feature. It returns a reverse-ordered view of the collection. #Java #Java21 #SequencedCollections #SoftwareDevelopment #LearningJava
To view or add a comment, sign in
-
-
🧩 Day 20: Java Collections – Map Interface 🔹 Topics Covered: 1. Introduction to Map Interface Unlike List and Set, a Map stores data as key–value pairs. Each key is unique, but values can be duplicated. Common methods: put(), get(), remove(), containsKey(), containsValue(), keySet(), values(), entrySet()
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