


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



import java.io.*;
public class Data implements Serializable { public static void main(String[] args) throws ClassNotFoundException, IOException { Data d = new Data(); ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("data.out")); out.writeObject("Data storage"); out.writeObject(d); out.close();
ObjectInputStream in = new ObjectInputStream( new FileInputStream("data.out"));
String s = (String)in.readObject(); Data d2 = (Data)in.readObject(); } }
import java.io.*;
public class GetAlienClass { public static void main(String[] args) throws IOException, ClassNotFoundException { ObjectInputStream in = new ObjectInputStream( new FileInputStream("alien.obj")); Object obj = in.readObject();
// Here you will get ClassNotFoundException System.out.println(obj.getClass()); } }
import java.io.; import java.util.;
class LoginCredentials implements Serializable {
private String username; private transient String password;
LoginCredentials(String name, String password) { username = name; this.password = password; }
public static void main(String[] args) throws IOException, ClassNotFoundException { LoginCredentials = new LoginCredentials("peter","mikhalenko"); } }