Java Assignment – Serialization & Deserialization: I recently worked on a Java program that demonstrates object serialization and deserialization using file handling. This assignment helped me understand how Java converts objects into a byte stream to store them in a file, and later retrieves them back into their original form. The program includes: ✅ A Customer class with attributes, constructor, and getCustomerObject() method. ✅ A StoreCustomerObject class to write multiple Customer objects into a file using ObjectOutputStream. ✅ A RetrieveCustomerObject class to read and display objects from the file using ObjectInputStream. File Used: CustomerObject.txt Key Concepts: Object Serialization, Deserialization, File Handling, and OOP in Java. #Java #Serialization #Deserialization #OOP #LearningInPublic #FileHandling #CodingJourney #SoftwareDevelopment
More Relevant Posts
-
💡 Understanding Interfaces in Java: 1)In Java, an Interface is a blueprint of a class. 2)It defines abstract methods that must be implemented by the class that uses it. 3)Interfaces help achieve abstraction, polymorphism, and multiple inheritance. 🧩 Example: interface Vehicle { void start(); void stop(); } class Car implements Vehicle { public void start() { System.out.println("Car started"); } public void stop() { System.out.println("Car stopped"); } } ⚙️ Types of Interfaces in Java: 1️⃣ Normal Interface 👉 Contains two or more abstract methods. Used commonly in real-world applications. 2️⃣ Functional Interface 👉 Contains only one abstract method. (Example: Runnable, Comparable) ✅ Used in Lambda Expressions. 3️⃣ Marker Interface 👉 Has no methods or fields. Used to mark or tag a class. (Example: Serializable, Cloneable). 4️⃣ SAM Interface (Single Abstract Method) 👉 Another name for a Functional Interface — ensures only one abstract method exists. 💬 Why Use Interfaces? ✔ Promotes loose coupling ✔ Makes code scalable and flexible ✔ Enables multiple inheritance #Java #OOP #Interface #Programming #Coding #TechLearning #JavaDeveloper #SoftwareEngineering #
To view or add a comment, sign in
-
Java Interfaces — Default vs Static Methods & Ambiguity Today I explored how Java handles multiple inheritance with interfaces, especially when both interfaces contain the same default method. ✅ Default methods are inherited ✅ Static methods belong to the interface — called using the interface name ⚠️ If two interfaces have the same default method, the implementing class must override it to avoid ambiguity. 🎯 Key Takeaways When two interfaces have the same default method, Java forces us to override & resolve the conflict We can call specific parent interface default methods using InterfaceName.super.method() Static methods in interfaces do not participate in inheritance → call like AAA.clear() 💬 What I learned today Java gives power with multiple interface inheritance, but also ensures clarity by requiring us to resolve ambiguity manually. Special thanks to my mentor Anand Kumar Buddarapu sir #Java #OOP #Interface #Programming #LearningJourney #CodeLife #SoftwareEngineering #JavaDeveloper #MultipleInheritance #TechLearning
To view or add a comment, sign in
-
💡 Understanding Interfaces in Java: 1)In Java, an Interface is a blueprint of a class. 2)It defines abstract methods that must be implemented by the class that uses it. 3)Interfaces help achieve abstraction, polymorphism, and multiple inheritance. 🧩 Example: interface Vehicle { void start(); void stop(); } class Car implements Vehicle { public void start() { System.out.println("Car started"); } public void stop() { System.out.println("Car stopped"); } } ⚙ Types of Interfaces in Java: 1️⃣ Normal Interface 👉 Contains two or more abstract methods. Used commonly in real-world applications. 2️⃣ Functional Interface 👉 Contains only one abstract method. (Example: Runnable, Comparable) ✅ Used in Lambda Expressions. 3️⃣ Marker Interface 👉 Has no methods or fields. Used to mark or tag a class. (Example: Serializable, Cloneable). 4️⃣ SAM Interface (Single Abstract Method) 👉 Another name for a Functional Interface — ensures only one abstract method exists. 💬 Why Use Interfaces? ✔ Promotes loose coupling ✔ Makes code scalable and flexible ✔ Enables multiple inheritance #Java #OOP #Interface #Programming #Coding #TechLearning #JavaDeveloper #SoftwareEngineering
To view or add a comment, sign in
-
☕ Day 18 of my “Java from Scratch” series — “Command Line Arguments in Java” Ever wondered how we can pass inputs directly while running a Java program? 🤔 That’s where Command Line Arguments come in! 📘 What are Command Line Arguments? We can pass arguments to our program at runtime through the terminal. 🧩 Syntax: java ClassName argument1 argument2 ✅ Example: java HelloWorld Hi Java 🧾 Output: Hi Java 💡 Code: public class HelloWorld { public static void main(String[] args) { System.out.println(args[0]); System.out.println(args[1]); } } 🧠 Real-time Use Case: In real-world applications, we pass arguments like port numbers, log levels, and config paths to the JVM while running the application. ⚙️ How to pass arguments in Eclipse IDE: 1️⃣ Right-click on your main class 2️⃣ Go to Run As → Run Configurations 3️⃣ Select your class 4️⃣ Click Arguments on the right 5️⃣ Enter your program arguments 6️⃣ Click Run 🚀 📌 Note: Even if we pass numbers as arguments, Java treats them as Strings. #Java #Programming #JavaFromScratch #LearningSeries #Developers #Coding #CommandLineArgumentsInJava #Tech #SoftwareDeveloper #JavaLearning #InterviewConceptsInJava #NeverGiveUp
To view or add a comment, sign in
-
Hello everyone!! 💻 Java Practice: Comparable vs Comparator 🚀 Today I worked on two Java programs to understand and implement sorting techniques using both Comparable and Comparator interfaces. 📘 Program 1 – ProductComparable In this program, I created a Product record class that implements the Comparable interface. Sorting was done based on the price of each product. Used Arrays.sort() to automatically sort objects using the natural ordering defined in compareTo() method. 📗 Program 2 – CustomerComparator In this example, I implemented sorting using different comparators: Sorted customers by ID, Name, and Bill Amount using custom Comparator objects and lambda expressions. Demonstrated the flexibility of Comparator for multiple sorting criteria. ⚙️ Key Learnings: ✅ Difference between Comparable (natural ordering) and Comparator (custom ordering). ✅ How to use Arrays.sort() for object arrays. ✅ Improved understanding of lambda expressions in Java. #Java #Learning #Comparable #Comparator #CodingPractice #NareshIT #JavaFullStack #Programming #ObjectOrientedProgramming
To view or add a comment, sign in
-
Understanding ClassCastException in Java Today I ran into a classic Java runtime exception: java.lang.ClassCastException 😅 At first, it seemed confusing — my code compiled perfectly, but crashed at runtime. After debugging, I realized the cause 👇 🧠 What it means ClassCastException occurs when we try to cast an object to a class, but the object is not actually an instance of that class. In simple terms: ✅ The code compiles fine ❌ But at runtime, Java refuses the cast and throws an exception 📦 Example Object obj = "Hello World"; // a String object Integer num = (Integer) obj; // trying to cast String to Integer This will throw: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer 🔹 How to Avoid Use instanceof before casting: if(obj instanceof Integer){ Integer num = (Integer) obj; } Use generics for type-safe collections: List<String> list = new ArrayList<>(); String str = list.get(0); // No cast needed 💬 Lesson Learned Even if the compiler is happy, the runtime JVM enforces type safety. Always ensure your object is of the correct type before casting. #Java #JavaDeveloper #SpringBoot #BackendDevelopment #Debugging #ErrorHandling #ProgrammingTips #SoftwareEngineering #CodeWithMe #LearningByDoing
To view or add a comment, sign in
-
🕒 Java Program: Display Current Date and Time #Day6 Created a simple Java program that uses the LocalDateTime class from the java.time package to display the current system date and time. This project demonstrates the use of Java’s modern date-time API for handling real-time data. ✨ Key Highlights: Utilizes LocalDateTime.now() to fetch current date & time Demonstrates Java’s built-in time API Clean and beginner-friendly example #Java #DateTime #JavaProgramming #Coding #LearningByCoding #TimeAPI
To view or add a comment, sign in
-
-
☘️ 1. Exception Hierarchy in Java In Java, every error or unusual event starts from the top-level class Throwable. From there, Java divides problems into two major categories: 1️⃣ Exception These are issues that your program can handle. Common examples include invalid input, missing files, number format issues, etc. 2️⃣ Error These indicate serious problems generated by the JVM itself. They’re not meant to be handled by programmers — like OutOfMemoryError or StackOverflowError. Within Exception, Java further classifies them into: ✔ Checked Exceptions ✔ Unchecked Exceptions ☘️ 2. Checked vs Unchecked Exceptions ✔ Checked Exceptions Verified by the compiler at compile time. Java forces you to handle them using try-catch or throws. Mostly occur when interacting with external systems (files, databases, networks). These help catch issues before the program runs. ✔ Unchecked Exceptions Not checked during compilation; they appear only at runtime. Usually caused by logical mistakes inside the code (like dividing by zero, null access, wrong index). Handling them is optional — but if not handled, the program crashes at runtime. Thanks to Anand Kumar Buddarapu sir for guiding me in strengthening these concepts. #Java #ExceptionHandling #JavaDeveloper #CodingConcepts #JavaExceptions #CheckedException #UncheckedException
To view or add a comment, sign in
-
-
🔹 Try-with-Resources in Java In Java, managing resources like files, connections, or streams can lead to memory leaks if not closed properly. That’s where Try-with-Resources comes in — a powerful feature introduced in Java 7 to automatically close resources after use. ✅ How it works: The resource (like BufferedReader) declared inside the try() parentheses is automatically closed once the block exits — no need for an explicit finally block. It helps write cleaner and safer code. Ideal for handling files, database connections, sockets, etc. 🎯 Interview Question: 👉 Will all classes automatically close when declared inside a try-with-resources block? Answer: No. Only those classes that implement the AutoCloseable or Closeable interface will be automatically closed. If a class doesn’t implement these, Java won’t know how to close it automatically. 💡 Pro Tip: You can declare multiple resources inside the same try block — they’ll all be closed in the reverse order of their creation. #Java #SpringBoot #CleanCode #JavaDeveloper #CodeTips #TryWithResources #Programming #TechPost
To view or add a comment, sign in
-
-
💡 Today’s Java Practice: Understanding Shallow Copy in OOP I implemented a simple example using Character and Healthstatus classes to visualize how shallow copying affects object references in Java. When we copy one object into another using the same reference, any change made in one reflects in the other — that’s the core idea of shallow copy. 🧠 This concept helped me understand memory references and object cloning better! #Java #OOP #LearningJourney #CodingPractice #CoreJava
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