Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are being given a class called UserSandD.java. This class is the same as the User class from problem 1, but it also implements the

You are being given a class called UserSandD.java. This class is the same as the User class from problem 1, but it also implements the Serializable interface. Write a program called SerializeUserSandD.java that instantiates a UserSandD object and then saves a serialized copy of the object into a file called usersandd.ser on your hard drive. Write another program called DeserializeUserSandD.java that opens, reads and then deserializes the contents of the usersandd.ser file, and then prints out the username and password of the deserialized object on-screen. Examine the contents of the usersandd.ser file. See if you can interfere with the values of the attributes saved into it so that when you deserialize it the values are changed in the deserialized object in memory.

====This is UserSandD.java===

import java.io.Serializable;

public final class UserSandD implements Serializable { String username="n/a"; String password="n/a";

public UserSandD() { }

public UserSandD(String username, String password) { try { if (username==null || password==null) throw new IllegalArgumentException("Missing user data");

this.username=username; this.password=password; } catch (IllegalArgumentException e) { e.printStackTrace(); } }

public void setUsername(String username) { this.username=username; }

public void setPassword(String password) { this.password=password; }

public String getUsername() { return username; }

public String getPassword() { return password; }

public boolean validate(String username, String password) { boolean valid=false;

if (this.username.equals(username) && this.password.equals(password)) valid=true;

return valid; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

What is a production report? What purpose does this report serve?

Answered: 1 week ago

Question

2. What are your challenges in the creative process?

Answered: 1 week ago