Posts

🔥 Java Exception and Error Handling

Java Exceptions and Errors Java Exceptions and Errors ⚠️ What is an Exception? An exception is an event that disrupts the normal flow of a program. It occurs during runtime and is recoverable . Example: Dividing by zero, accessing an invalid array index. ❌ What is an Error? An error is a serious issue beyond the control of the application. Typically unrecoverable and leads to program termination. Example: Hardware failure, memory issues, JVM crash. 🌳 Java Exception Hierarchy All exceptions and errors inherit from the Throwable class: Throwable ├── Exception → Can be handled by code │ ├── Checked → Must be handled │ └── Unchecked → Optional to handle └── Error → Cannot/should not be handled 🧱 Types of Exceptions ✅ Built-in Exceptions Predefined by Java. Handle common runtime issues. Examples: NullPointerException , IOException , ArrayIndex...

Understanding How OOP Concepts Work with Real-Life Examples

Understanding OOP Principles with a Banking System Example 💼 Project: Banking System (as an Example) Let’s explore how Object-Oriented Programming (OOP) principles can be applied in a real-world project like a banking system. 🔐 1. Encapsulation – Hiding Internal Data Consider a class like Account . It has private variables like balance . You can only change the balance using methods like deposit() or withdraw() . ✅ Why? It protects data and ensures only valid changes happen. 👪 2. Inheritance – Reusing Code We create a base class called Account , and then make child classes: SavingsAccount CurrentAccount ✅ Why? Avoids repeating common code in multiple places. 🎭 3. Polymorphism – Same Method, Different Behavior We define an interface called Notification with a method send() . Implementations: EmailNotification , SMSNotification , etc. ✅ Why? We can use send() without worrying about how ...

Rest Template in Java

Image
  RestTemplate : 1) Why do we need RestTemplate?  ==> To communicate with different services in single application. Create Resttemplate object: // create an instance of RestTemplate RestTemplate restTemplate = new RestTemplate ( ) ; 2) Different methods of RestTemplate. exchange() <http_method>ForEntity      ex    getForEntity(),postForEntity() <http_method>ForObject         ex     getForObject(),postForObject() HttpPost Api with parameters:                                          Returns PostForObject(url,request,classType);                         ResponseBody PostForEntity(url,request,responseType);                    Response status,header,body PostForLocation(url,r...

API (Application Programming Inteface)

Image
   API ( Application Programming Interface )  API stands for " Application Programming Interface ". API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other. Example of API : When you use an application on your mobile phone, the application connects to the Internet and sends data to a server. The server then retrieves that data, interprets it, performs the necessary actions and sends it back to your phone. The application then interprets that data and presents you with the information you wanted in a readable way. This is what an API is - all of this happens via API. To explain this better, let us take a familiar real life example. Imagine you’re sitting at a table in a restaurant with a menu of choices to order from. The kitchen is the part of the “system” that will prepare your order. What is missing is the critical link to communicate your order to the kitchen and deliver your food b...

Android Activity Lifecycle

Image
                 "Android Activity Lifecycle" if we are new to Android development then we should learn what an Activity is in Android and what is the lifecycle of an Activity. In this blog, we will learn about, What is an activity  in Android? What is the Activity Lifecycle? Activity Lifecycle : To understand the activity lifecycle, consider an example of a human being. As human beings, we go through certain stages of our life starting from as a kid to a teenager. From an adult and then to an old person. These are the phases or states of life we go through. Similarly, for Activity in Android, we go through state changes in the total duration of the activity. An Android activity undergoes through a number of states during its whole lifecycle. The following diagram shows the whole Activity lifecycle:                                         ...

Android Core Building Blocks

Image
Android Core Building Blocks : An Android Component is a simply piece of code that has well defined life cycle. Android Manifest.xml File :    manifest file which contains the description of each component and how they interact.  The manifest file also contains the app’s metadata, its hardware configuration, and  platform requirements, external libraries, and required permissions. The basic components of any android application :  Activities Intent and broadcast receivers Services Content Providers Widgets and Notifications     1)  Activities :   Whenever we open an Android application, then you see some UI drawn over our screen.  That screen is called an Activity.   Activities are said to be the presentation layer of our applications.An activity is a class that represents a single screen.  For example , when we open our Gmail application, then we see our emails on the screen. Those emails are present in an Activity. If w...