📘 Java Learning – Exception Handling (Core Concepts) While strengthening my Core Java fundamentals, I learned how exception handling helps applications fail gracefully instead of crashing abruptly. Here’s a practical breakdown 👇 🚨 What is an Exception? An exception is an unwanted and unexpected event that disturbs the normal flow of a program. 🧪 Example: int x = 10 / 0; // ArithmeticException 🎯 Why Exception Handling? Exception handling does not repair the problem. It provides an alternative execution path so the program can continue or terminate properly. 📌 Main goal: Graceful termination of the program 🧠 Runtime Stack Mechanism • JVM creates a runtime stack for every thread • Each method call creates a stack frame • Stack frame contains local variables and method call information • When a method completes, its stack frame is removed • When the thread ends, the stack is destroyed 🧪 Example: void m1() { m2(); } void m2() { System.out.println(10 / 0); } 📌 Exception occurs in m2() → JVM starts stack unwinding. ⚙️ Default Exception Handling in Java When an exception occurs: 1️⃣ Exception object is created with: Exception name Description Stack trace 2️⃣ JVM checks for handling code (try-catch) 3️⃣ If not found: • Current method terminates abnormally • Stack frame is removed • JVM checks the caller method 4️⃣ If main() also doesn’t handle it: • JVM invokes Default Exception Handler 🧪 Output format: ExceptionName: description at ClassName.method(line number) ⭐ Key Takeaways • Exceptions disturb normal program flow • JVM uses runtime stack to track method calls • Default exception handling prints diagnostic details • Proper handling leads to stable and maintainable applications Building strong Java fundamentals — one exception at a time ☕🚀 #Java #CoreJava #ExceptionHandling #JVM #JavaInternals #BackendDeveloper #JavaFullStack #LearningJourney
Java Exception Handling Fundamentals
More Relevant Posts
-
📘 Java Learning Journey — Day 13: Variables & Memory Management Today, I learned about variables and how Java manages memory at runtime. A variable is a memory location used to store values and manipulate data in a program. Every variable is associated with a specific data type, which defines the type of data it can hold. 🔹 Types of Variables in Java 1️⃣ Local Variables Declared inside a method or block Accessible only within that method or block No default values are assigned Memory is allocated in the Stack Segment Memory is deallocated automatically when the method or block execution ends 2️⃣ Instance Variables Declared inside a class, outside any method Accessible throughout the class using object reference Default values are provided by JVM Memory is allocated in the Heap Segment Exists as long as the object exists 🔹 Java Runtime Memory Structure (JRE) When a Java program runs, RAM allocates memory called the Java Runtime Environment (JRE). It consists of four major segments: Code Segment – Stores compiled machine-level (bytecode) instructions Static Segment – Stores static members Stack Segment – Stores local variables and object references Heap Segment – Stores objects and instance variables 🔹 Object Creation & Memory Allocation When execution starts from the main method: Objects are created using the new keyword The object is stored in the Heap Segment The reference variable is stored in the Stack Segment Example: Demo d = new Demo(); Here, new instructs the JVM to create an object in heap memory, while d holds the reference in stack memory. 🚀 This session helped me clearly understand variable scope, lifetime, and JVM memory allocation, which are crucial for writing efficient and optimized Java programs. #Java #CoreJava #Variables #JVM #MemoryManagement #LearningJourney #SoftwareDevelopment
To view or add a comment, sign in
-
-
Day 2 – Learning Java Full Stack Java may look simple on the surface, but today I learned what actually happens behind the scenes when a Java program runs. Here’s a clear breakdown of my learning 👇 🔹 Execution of a Java Program A Java program follows a two-step process: 1️⃣ Compilation 2️⃣ Interpretation (Execution) 🔹 Step 1: Compilation Java source code must be saved with a .java extension The javac compiler checks for syntax errors If a syntax error exists → compile-time error (bytecode is NOT generated) If no errors → bytecode (.class file) is generated Important: Without successful compilation, execution never happens. 🔹 Step 2: JVM Verification & Execution Once bytecode is generated, JVM performs multiple checks: ✔️ Confirms bytecode is generated by javac ✔️ Verifies bytecode is not modified ✔️ Checks for logical errors during execution If all checks pass → ➡️ JVM converts bytecode into machine code and executes it. If a logical error occurs → ➡️ Exception is raised, and execution stops immediately. 🔹 Understanding Exceptions with Examples Division by zero → ArithmeticException When an exception occurs: Statements before the error execute Statements after the error do NOT execute 🔹 Key Commands I Practiced javac Demo.java → compilation java Demo → execution And revisited the basic structure: Class declaration main() method → entry point of execution Key takeaway: Java doesn’t blindly execute code. It verifies, validates, and protects execution through compiler checks, JVM verification, and exception handling. Sharing my learning as I go — hoping this helps someone understand Java execution more clearly 🙌 More insights coming soon. #Java #JavaFullStack #JVM #ExceptionHandling #LearningInPublic #BackendDevelopment #ProgrammingBasics
To view or add a comment, sign in
-
-
Day8 🚀: Variables & Memory Structure in Java Today’s learning was about what is variable and Types of variables and how Java uses RAM when a program executes. and how program execution works in java This helped me understand what happens behind the scenes when we run a Java program. A variable is a container that stores data values. In Java, every variable must be declared with a specific data type. 🔹 Syntax: data Type variable Name = value; 🔹 Example: int age = 21; double salary = 25000.50; char grade = 'A'; String name = "Theja"; 🔹 Types of Variables Covered 1️⃣ Local Variables *Declared inside methods *Stored in Stack memory *Created when method starts and destroyed when method ends 2️⃣ Instance Variables *Declared inside a class but outside methods *Stored in Heap memory *Each object has its own separate copy 🔹 How Java Uses RAM During Execution When we run a Java program, memory is divided into different segments: 🧠 1. Code Segment °Stores the compiled bytecode °Contains the program instructions 🧠 2. Static Segment °Stores static variables °Memory is allocated only once 🧠 3. Stack Segment °Stores local variables °Stores method calls °Works in LIFO (Last In First Out) order 🧠 4. Heap Segment °Stores objects and instance variables °Managed by Garbage Collector 🔹 How Program Execution Works in Java 1️⃣ Code is written and compiled into bytecode 2️⃣ JVM loads the class into memory 3️⃣ main() method is pushed into Stack 4️⃣ Objects are created in Heap 5️⃣ Variables are allocated memory 6️⃣ After execution, unused objects are removed by Garbage Collector 🔹 What I Understood Today Understanding variables is not enough. Knowing where they are stored in memory and how Java manages RAM gives deeper clarity about performance and program behavior. Learning how Java works internally is making my foundation stronger 💻🔥 #Java #MemoryManagement #JVM #Programming #LearningJourney #Day8
To view or add a comment, sign in
-
-
📌 Is Java really an object-oriented language? This question comes up often, and the answer is more nuanced than a simple yes or no. I recently wrote an article exploring why Java is not 100% object-oriented, what “pure object orientation” actually means, and why practical languages make intentional trade-offs. Sharing the article here for anyone interested in Java, OOP concepts, or software design thinking 👇. #Java #ObjectOrientedProgramming #SoftwareEngineering #ProgrammingConcepts
To view or add a comment, sign in
-
✨ Understanding the Object Class in Java ✨ In Java, everything starts from one powerful root — the Object Class. If you truly understand this class, you understand the foundation of Java OOP. 🚀 🔵 🔹 What is Object Class? ✔️ The Object class is the parent of all classes in Java. ✔️ Every class automatically extends it (directly or indirectly). ✔️ It provides common behavior to all objects. It acts as the backbone of Java’s Object-Oriented Programming structure. 🧩 🔹 Why is it Important? Because of the Object class, every Java object can: ✔️ Be compared (equals()) ✔️ Be printed (toString()) ✔️ Generate a hash value (hashCode()) ✔️ Get runtime class information (getClass()) Without explicitly writing it, we inherit powerful functionality. ⚙️ 🔹 Key Methods from Object Class 📌 toString() – Converts object into readable String 📌 equals() – Compares two objects logically 📌 hashCode() – Generates unique hash value 📌 getClass() – Returns runtime class information These small methods build strong OOP design. 🌟 Key Takeaway: The Object class may look simple, but it is the root of Java architecture. Strong fundamentals in Object class → Strong confidence in OOP concepts. 💻✨. Learning the roots makes the branches stronger. 🌳 Grateful to my mentor Anand Kumar Buddarapu sir for guiding me in strengthening my Java fundamentals. 🙏 Thanks to: Saketh Kallepu Uppugundla Sairam #Java #CoreJava #ObjectOrientedProgramming #OOPS #JavaDeveloper #Programming #CodingJourney #SoftwareDevelopment #TechLearning #Developers
To view or add a comment, sign in
-
-
Day 1 of Learning Java Full Stack Today I learned the basics of java which includes : 1.What is java and its key aspects. ->Java is a object oriented programing Language and platform independent programming language and it follows (WORA) Principle that is Write Once Run Anywhere ->Java is used in Web development ,Mobile Application ,Enterprise Application ,Embedded Application. 2.what are the features of java. ->Java is created with the goal of being a flexible, secure, and easy-to-use language. Java has many feature but the main features of java are Platform independent, Object oriented, Simple and Easy to Learn, Robust and Secure, Multithreading, Rich API and Many more. 3.what are the editions of java. ->Java is divided into 4 Editions 1.Java Standard Edition. 2.Java Enterprise Edition. 3.Java Micro Edition. 4.JavaFX. 4.How the java code is Executed. ->As we know that the code which is Written has to follow some steps to get the output. 1.Save the File Using (.java). 2.Convert the code into Bytecode as (.class). 3.JVM(Java virtual Machine) will Execute the code. 4.Output is Displayed. 5.What is the importance of JVM and its installation. ->JVM is a Middleman between the Code and Computer. ->The JVM translates that Bytecode into whatever language your specific operating system understands ->JVM will Execute the (.class) it can not execute (.Java) file Directly. -> And completed my Installation of JVM of 25th version 6.HelloWorld Program of Java. ->public class HelloWorld { public static void main(String [ ] args) { System.out.println("Hello, World!"); } } 7.What is compiler and interpreter -> Compiler will Translate the entire Source code from High level Language to Low level Language and Execute "at once". _>When it comes to interpreter it will Translate and Executes the Source code "Line by Line". 8.what is class and objects in java. ->Class is a Blueprint to create an Object. ->Object is an instance of class. 9.what are keyword and how many keywords are in java. ->Keywords are the pre-defined words which are present in Java. ->There are 52 Keywords in java ->3 Literals in Java : Integer Literals, Floating Point Literals, Boolean Literals. ->13 Unreserved Keywords but we mainly use "goto" and "constant" 10.what is Access modifier and its Types ->Access Modifiers are the Keywords used to set the visibility and Accessibility of Classes, Methods, Variables, constructors. ->There are 4 Different types of Access Modifiers They are : 1.Public 2.Private 3.Protected 4.Default ->They also helps to set the Security Level to determine whom to "See and and Use" the Code.
To view or add a comment, sign in
-
🚀 Java Mastery || Polymorphism Polymorphism means one reference, many behaviors. It allows the same operation to work differently based on the object involved, making Java programs flexible and easy to maintain. Instead of fixing behavior at the beginning, Java can decide the behavior at runtime, which is very useful in real applications. 🔹 Compile-Time Polymorphism Decision is made during compilation Based on method signatures Faster but less flexible Mainly improves readability This is also called early binding. 🔹 Runtime Polymorphism ⭐ Decision is made while the program runs Depends on the actual object Achieved through method overriding Commonly used in real-world Java projects This is the true form of polymorphism. 🔼 Upcasting & 🔽 Downcasting Upcasting Child object treated as Parent type Safe and automatic Supports runtime polymorphism Helps in loose coupling Downcasting Parent reference converted back to Child type Explicit and risky Used only when child-specific behavior is needed Prefer upcasting whenever possible. 🔓 Loose Coupling vs 🔒 Tight Coupling Loose Coupling Depends on abstractions Easy to change and maintain Tight Coupling Depends on concrete classes Hard to modify Polymorphism helps achieve loose coupling. 💡 Pro Tip 👉 Polymorphism works with methods, not variables. Methods are resolved at runtime, variables at compile time. 🔮 What’s Next? Java Mastery || Abstraction Learning how Java hides implementation details and exposes only what is needed.
To view or add a comment, sign in
-
-
While solving a competitive programming problem, I revisited an interesting concept in Java’s BigInteger class — especially the meaning of certainty in isProbablePrime(). 🔹 Problem Statement Given a number n (which can be very large), determine whether it is prime or not prime. 📌 Note: The number may contain hundreds of digits, so primitive data types (int, long) are not sufficient. 🔹 Why normal prime checking fails ❌ Traditional logic like: using for loop and finding the primenumber for (int i = 2; i <= sqrt(n); i++) does not work because: 1. int / long overflow for large inputs 2. sqrt() cannot be calculated for huge numbers 3. Time complexity becomes impractical 🔹 Correct Approach using BigInteger Java provides a built-in method:-- isProbablePrime(int certainty)--- Here, certainty means: The level of confidence that the number is prime (The probability of error is less than 1 / 2^certainty) 🔹 Java Program (Competitive-ready) import java.io.*; import java.math.BigInteger; public class Solution { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); String n = br.readLine().trim(); BigInteger number = new BigInteger(n); if (number.isProbablePrime(1)) { System.out.println("prime"); } else { System.out.println("not prime"); } } } ✔️ Handles very large numbers ✔️ Passes hidden test cases ✔️ Fast and reliable 🔹 Key Learning 💡 certainty is not the number to test It controls how confident Java should be Even certainty = 1 is sufficient for most competitive platforms 📚 Takeaway: When dealing with very large numbers, rely on BigInteger’s probabilistic algorithms instead of manual prime-checking logic. #Java #BigInteger #CompetitiveProgramming #ProblemSolving #LearningEveryDay #CodingTips
To view or add a comment, sign in
-
🌱 Java Streams & Method References — Simple Explanation for Beginners Many beginners get confused when they see code like this: people.stream().map(Person::getName) It looks like Java is calling an instance method without creating an object 🤔 But that is NOT true. Let’s understand with a very simple example 👇 Step 1️⃣ We create objects first Person p1 = new Person("Amit"); Person p2 = new Person("Rahul"); List<Person> people = List.of(p1, p2); ✅ Objects are created here Nothing magical yet. Step 2️⃣ Now we use Stream people.stream() .map(person -> person.getName()) .toList(); What happens internally is exactly like this: for (Person person : people) { person.getName(); } 🔹 The stream does NOT create objects 🔹 It just takes existing objects one by one Step 3️⃣ What does this line mean? person -> person.getName() It means: “When you give me a Person object, I’ll call getName() on it.” The object already exists — the stream supplies it automatically. Step 4️⃣ Method reference is just a shortcut This: map(person -> person.getName()) Is the same as: .map(Person::getName) ✔ Shorter ✔ Cleaner ✔ Still follows OOP 🚫 What Java is NOT doing ❌ Calling getName() without an object ❌ Creating objects behind the scenes ❌ Breaking OOP rules 🧠 Simple way to remember Streams don’t create objects. They only process objects that already exist. Or: Streams hide the loop, not the object. #Java #BeginnerFriendly #OOP #Streams #MethodReference #LearningJava
To view or add a comment, sign in
-
🚀 Day 30 – Java Static Keyword Today’s learning from my Java Notes was all about the powerful static keyword. 📘 The static keyword in Java is used to define members that belong to the class, not to the object. 🔹 Key Understanding: ✅ Static Members belong to the Class Static Variables Static Methods Static Blocks ✅ Non-Static (Instance) Members belong to Objects Instance Variables Instance Methods Instance Blocks Constructors 💡 Rules of Static: 1️⃣ Static variables can be accessed by both static and instance members. 2️⃣ Instance variables can be accessed only by instance members. 3️⃣ Static members cannot directly access instance variables. 📌 Static Variables: Belong to the class Initialized only once when the class is loaded Single copy shared by all objects Accessed using: ClassName.variableName 📌 Static Methods: Belong to the class Can access only static data Cannot call non-static methods directly Accessed using: ClassName.methodName() 📌 Static Block: Executes only once when the class loads Used to initialize static variables Runs before the main() method 🔄 Flow of Execution: 1️⃣ Static variables & static block 2️⃣ Main method 3️⃣ Instance block 4️⃣ Constructor 5️⃣ Instance method #Day30 #Java #StaticKeyword #JavaLearning #BackendDevelopment
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