🚀 Serialization & Deserialization in Java – Learning by Doing While learning Java File Handling, I spent time understanding Serialization and Deserialization, two important concepts used for object persistence and data transfer in real-world Java applications. 🔹 What is Serialization? Serialization is the process of converting a Java object into a byte stream, so it can be: -> Stored in a file -> Sent over a network -> Cached for later use In Java, this is achieved by: -> Implementing the Serializable interface -> Using ObjectOutputStream to write the object Once serialized, the object’s state is preserved even after the program ends. 🔹 What is Deserialization? Deserialization is the reverse process—converting the byte stream back into a Java object. -> This allows the application to: -> Restore object state -> Reuse previously stored data -> Maintain continuity across JVM executions It is done using ObjectInputStream. 🧠 Important Concepts I Learned 📌 Serializable Interface -> It is a marker interface (no methods) -> It tells the JVM that the class is eligible for serialization 📌 Object Streams -> ObjectOutputStream → writes objects to a file -> ObjectInputStream → reads objects from a file 📌 Type Casting -> While deserializing, the returned object must be type-cast back to the original class 📌 Persistence Across JVM -> Serialized objects can be restored even after restarting the program 📌 Exception Handling -> IOException → issues during file operations -> ClassNotFoundException → class mismatch during deserialization 📌 Resource Management -> Streams must be closed properly to avoid memory leaks -> (Can be improved further using try-with-resources) 🌍 Where Serialization is Used in Real Applications -> Saving user session data -> Transferring objects in distributed systems -> Caching objects for performance optimization -> Storing application state 🎯 Takeaway Practicing this example helped me understand how Java preserves object state, how the JVM handles object streams, and why serialization plays a crucial role in backend systems. Special thanks to Prasoon Bidua for amazing guidance Github link:- https://lnkd.in/g44DvBmX #Java #CoreJava #Serialization #Deserialization #JavaIO #FileHandling #BackendDevelopment #LearningJourney #BCA #StudentDeveloper
Java Serialization & Deserialization Concepts
More Relevant Posts
-
🚀 Understanding Java Object Serialization & Deserialization (with Type Information) Java is often praised for its platform independence, and one of the features that truly demonstrates this power is Object Serialization. 🔹 What is Object Serialization? Serialization is the process of converting a Java object into a stream of bytes so that it can be: Stored in a file Sent over a network Persisted for later use What makes Java serialization special is that it doesn’t store only the data, but also the type information of the object. 🔹 What does “Type Information” mean? When a Java object is serialized, the JVM stores: The class name of the object The data types of its fields The actual values of the fields This allows Java to recreate the exact same object during deserialization. 🔹 Serialization Flow 1. An object (e.g., Student) exists in memory 2. ObjectOutputStream converts the object into bytes 3. Both Object Data + Type Information are written into a .ser file 🔹 Deserialization Flow 1. The byte stream is read from the .ser file 2. ObjectInputStream uses the stored type information 3. The JVM reconstructs the original object in memory 🔹 Why is this powerful? ✔ Ensures accurate object reconstruction ✔ JVM independent (serialize on one platform, deserialize on another) ✔ Essential for distributed systems, file storage, and networking 🔹 Key Classes Involved ObjectOutputStream → Serialization ObjectInputStream → Deserialization Serializable → Marker interface that gives JVM permission 🔹 Important Insight Thread safety, execution order, or CPU scheduling is not involved here — serialization is purely about object state + structure. 📌 In short: > Java Serialization is not just about saving data, it’s about preserving the identity and structure of an object across JVM boundaries. Learning these fundamentals makes advanced topics like RMI, distributed systems, and microservices much easier to understand. #Java #Serialization #Deserialization #JVM #JavaProgramming #ComputerScience #BackendDevelopment #LearningInPublic #StudentDeveloper
To view or add a comment, sign in
-
-
📘 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
To view or add a comment, sign in
-
Day 3 – Core Java Series 📘 Object-Oriented Programming (OOP) – Understanding Objects & Orientation Today, I learned about Object-Oriented Programming (OOP), which is one of the most important concepts in Core Java. Object Orientation means the way of looking at the world. In programming, an object represents any real-world entity. The way we observe, model, and represent real-world things in our programs is called object orientation. There are some important rules of Object-Oriented Programming: 🔹 Rule 1: The world is a collection of objects Everything around us can be seen as an object—such as a student, car, phone, or bank account. In Java, we try to represent these real-world entities using objects. 🔹 Rule 2: Every object belongs to a class A class is an imaginary blueprint or template that defines how an object will look and behave, while an object is the real instance created from that class. 👉 Class is imaginary, object is real. 🔹 Rule 3: Every object has two parts Has (State / Properties) – These describe the object and are coded using variables and data types. Example: name, age, color Does (Behavior) – These define what the object can do and are coded using methods. Example: study(), drive(), call() By using Object-Oriented Programming, Java allows us to write clean, reusable, and real-world–oriented code, making applications easier to design, understand, and maintain. 📌 Object orientation helps us think in terms of real-world problems and solve them efficiently using Java. #CoreJava #ObjectOrientedProgramming #OOPConcepts #JavaLearning #LearningJourney #Day3 #ProgrammingBasics
To view or add a comment, sign in
-
🚀 Java Daily Series | Day 1/100 ☕ ✨ Consistency beats motivation. I’m starting a 100-day Java learning series to strengthen my fundamentals and share my learning in a simple and structured way. Java is a high-level, object-oriented, and platform-independent programming language used to build secure and scalable applications. Its main features include platform independence, object-oriented design, robustness, security, and built-in support for multithreading. Java learning is generally categorized into Core Java, which focuses on basics, OOP concepts, and collections, and Advanced Java, which is used for web and enterprise application development. Java also comes in different editions such as Java SE (Standard Edition) for core development, Java EE (Enterprise Edition) for enterprise-level applications, and Java ME (Micro Edition) for embedded and mobile systems. To develop and run Java programs, Java provides JDK (Java Development Kit), JRE (Java Runtime Environment), and JVM (Java Virtual Machine). The javac compiler converts Java source code into bytecode, which is platform independent. This bytecode is loaded into the JVM, where the Interpreter executes it line by line. For better performance, the JIT (Just-In-Time) Compiler converts frequently executed bytecode into native machine code. The complete Java program execution flow starts with writing source code (.java), compiling it using javac to generate bytecode (.class), loading the bytecode into the JVM, interpreting the code initially, optimizing execution using the JIT compiler, and finally producing the output on the system. 🎯 Building strong Java fundamentals with daily consistency 💪 #JavaDeveloper #100DaysOfJava #LearningInPublic #CoreJava #Programming #CodingLife # Meghana M #10000 Coders
To view or add a comment, sign in
-
📘 Java Main Method | Day 5 📅 09/01/2026 Today I learned one of the most important fundamentals in Core Java – 👉 The "main()" method, which acts as the entry point of every Java program. Here’s a simple breakdown 👇 🔹 What is main() method? - Execution of a Java program always starts from "main()" - Without "main()", a Java program will NOT run 🔹 Why is main() compulsory? - Operating System needs a fixed starting point - JVM always looks for: "public static void main(String[] args)" 🔹 Meaning of each keyword - "public" → Accessible to JVM - "static" → No object creation required - "void" → Returns nothing - "main" → Fixed method name - "String[] args" → Command-line arguments 🔹 How execution happens 1️⃣ Click Run 2️⃣ OS gives control to JVM 3️⃣ JVM searches for main() 4️⃣ JVM enters main() 5️⃣ Statements execute 6️⃣ Control returns to OS Building strong Java fundamentals step by step 🚀 Learning in public to stay consistent and improve every day. ☕ Tap Academy Java Fundamentals | Learning in Public #Java #CoreJava #MainMethod #ProgrammingBasics #TapAcademy #LearningInPublic #JavaDeveloper #FullStackJourney
To view or add a comment, sign in
-
-
Unlocking the Power of Standardization in Java ☕ Today's deep dive into Core Java concepts brought me to a crucial topic: Interfaces. I learned that an Interface is essentially a collection of pure abstract methods—method signatures with absolutely no body1. But why do we need them? This infograph provided a perfect example: Imagine three different developers building a calculator. Without rules, one might name their method add(), another addition(), and the third sum(). This inconsistency makes the code difficult for users to navigate. Key Takeaways: ✅ Standardization: Interfaces act as a rulebook. By defining a Calculator interface, every developer is forced to implement the exact same method names (add and sub). ✅ Flexibility: While the method name is enforced, the logic inside can vary. As shown in my practice code, MyCalculator1 can use hardcoded values, while MyCalculator2 uses Scanner for user input—both adhering to the same interface contract. ✅ Syntax: We use the implements keyword to inherit these abstract methods and the @Override annotation to give them life2. Excited to apply this to build cleaner, more scalable applications! 🚀 TAP Academy Sharath R #Java #Coding #SoftwareDevelopment #TapAcademy #LearningJourney #CleanCode
To view or add a comment, sign in
-
-
In this article, I have shared the key Java core concepts that form the foundation of Java programming. Understanding these basics has helped me improve code structure, clarity, and problem-solving skills while learning Java. #Java #JavaProgramming #JavaCore #OOPConcepts #SoftwareEngineering #ProgrammingBasics #LearningJava #StudentDeveloper https://lnkd.in/g37rWZFc
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 Learning – Types of Variables (Part 2: Static & Local Variables) While strengthening my Core Java fundamentals, I gained clarity on how static and local variables differ in purpose, scope, and memory behavior. Here are my key learnings 👇 ▶️ Static Variables • Used when a variable’s value does not change from object to object • Declared at class level using the static keyword • Only one shared copy exists for the entire class 📌 Any change to a static variable affects all objects. ✅ Memory & Lifecycle • Created during class loading • Destroyed during class unloading • Stored in the Method Area • Scope = class scope ✅ Access • Can be accessed using class name (recommended) • Can also be accessed using object reference • Accessible from both static and instance areas ✅ Initialization • JVM provides default values automatically ▶️ Local Variables • Declared inside methods, constructors, or blocks • Used for temporary requirements • Stored in stack memory ✅ Scope & Lifecycle • Created when the block starts execution • Destroyed when the block ends • Scope limited to the declaring block ✅ Initialization Rules • JVM does not provide default values • Must be initialized before use 📌 Best practice: initialize at the time of declaration. ✅ Modifiers • Only final is allowed • Any other modifier causes a compile-time error ⭐ What I Gained from This • Clear distinction between shared and temporary data • Better understanding of scope and memory management • Strong foundation for writing efficient Java code Understanding static and local variables is essential for building optimized and predictable Java applications. #Java #CoreJava #StaticVariables #LocalVariables #JavaInternals #JavaFullStack #LearningJourney #BackendDeveloper
To view or add a comment, sign in
-
📘 Java Learning – Types of Variables (Part 1: Primitive, Reference & Instance Variables) While strengthening my Core Java fundamentals, I focused on understanding how variables are classified in Java and how instance variables behave internally at runtime. Here are my key learnings 👇 ✅ Classification Based on Type of Value Represented ▶️ Primitive Variables • Used to store primitive values • Stores actual data 🧪 Example: int x = 10; ▶️ Reference Variables • Used to refer to objects • Stores the reference (address) of the object, not the actual data 🧪 Example: Student s = new Student(); 📌 Here, s is a reference variable pointing to a Student object. ✅ Classification Based on Purpose & Position of Declaration Based on where and why variables are declared, they are divided into: 1️⃣ Instance variables 2️⃣ Static variables 3️⃣ Local variables 📌 (In this post, focusing only on Instance Variables) ✅ Instance Variables • If the value of a variable changes from object to object, it is called an instance variable • For every object, a separate copy of instance variables is created ✅ Memory & Lifecycle • Instance variables are created at the time of object creation • They are destroyed when the object is destroyed • Scope of instance variables is exactly the same as the object • Stored as part of the object in heap memory ✅ Declaration Rules Must be declared: • Inside the class • Outside methods, constructors, and blocks ✅ Access Rules • Cannot be accessed directly from a static context • Must be accessed using an object reference 📌 From instance methods, instance variables can be accessed directly. ✅ Initialization • Explicit initialization is not mandatory • JVM automatically provides default values 📌 No garbage values for instance variables. ✅ Alternate Names Instance variables are also known as: • Object-level variables • Attributes ⭐ What I Gained from This • Clear understanding of how data differs between objects • Better clarity on object-level memory allocation Understanding instance variables is essential for designing object-oriented programs where each object maintains its own independent state. #Java #CoreJava #Variables #InstanceVariables #JavaInternals #JavaFullStack #BackendDeveloper #LearningJourney
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