Results 1 to 1 of 1
-
Demonstration of the transient keyword
Java Code:import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Date; public class Logon implements Serializable { private Date date = new Date(); private String username; private transient String password; public Logon(String name, String pwd) { username = name; password = pwd; } public String toString() { String pwd = (password == null) ? "(n/a)" : password; return "logon info: \n username: " + username + "\n date: " + date + "\n password: " + pwd; } public static void main(String[] args) throws Exception { Logon a = new Logon("Hulk", "myLittlePony"); System.out.println("logon a = " + a); ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream( "Logon.out")); o.writeObject(a); o.close(); Thread.sleep(1000); // Delay for 1 second // Now get them back: ObjectInputStream in = new ObjectInputStream(new FileInputStream( "Logon.out")); System.out.println("Recovering object at " + new Date()); a = (Logon) in.readObject(); System.out.println("logon a = " + a); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Keyword : volatile
By peiceonly in forum Advanced JavaReplies: 14Last Post: 01-18-2011, 06:15 PM -
finalize keyword
By bugger in forum New To JavaReplies: 6Last Post: 10-01-2008, 12:28 PM -
transient keyword
By Java Tip in forum Java TipReplies: 0Last Post: 12-11-2007, 10:27 AM -
Method with final keyword
By javaplus in forum New To JavaReplies: 2Last Post: 11-29-2007, 09:39 AM -
Use of this keyword
By Java Tip in forum Java TipReplies: 0Last Post: 11-18-2007, 07:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks