我的java發(fā)跡史
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(3)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2007年5月 (8)
2007年4月 (2)
搜索
最新評論
1.?re: Java中的transient[未登錄]
看來我對持久化和序列化的了解連皮毛都算不上阿,這個例子簡單明了,很好,不過這個blog對code的支持不夠友好阿,多謝博主
--Merlin
2.?re: Java中的transient
一看例子就明白了,寫的挺好的。
--風嗜塵
3.?re: Java中的transient[未登錄]
@cheng
很好很強大
--test
4.?re: Java中的transient
例子挺好,明白了,謝啦@cheng
--了了
5.?re: Java中的transient
寫的很好。切中要點
--了凡
閱讀排行榜
1.?Java中的transient(20594)
2.?取模不是取余(2867)
3.?spring 事務的 自動裝配(1414)
4.?大數(shù)階乘算法~~~(792)
5.?quickSort算法~~(621)
評論排行榜
1.?Java中的transient(6)
2.?spring 事務的 自動裝配(4)
3.?計劃~~(1)
4.?取模不是取余(0)
5.?泛型的獲取class(0)
Powered by:
博客園
模板提供:
滬江博客
BlogJava
|
首頁
|
發(fā)新隨筆
|
發(fā)新文章
|
聯(lián)系
|
聚合
|
管理
Java中的transient
Java中的transient,看jdk源碼的時候突然忘了這個是什么了,查了一下,是用于聲明序列化的時候不被存儲的,在這里記下
發(fā)表于 2007-04-22 12:35
劉甘泉
閱讀(20594)
評論(6)
編輯
收藏
評論
#
re: Java中的transient[未登錄]
回復
更多評論
import java.io.*;
import java.util.*;
class Logon implements Serializable {
private Date date = new Date();
private String username;
private transient String password;
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.toString() +
"\n password: " + pwd;
}
public static void main(String[] args) {
Logon a = new Logon("Hulk", "myLittlePony");
System.out.println( "logon a = " + a);
try {
ObjectOutputStream o =
new ObjectOutputStream(
new FileOutputStream("Logon.out"));
o.writeObject(a);
o.close();
// Delay:
int seconds = 5;
long t = System.currentTimeMillis()
+ seconds * 1000;
while(System.currentTimeMillis() < t)
;
// 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);
} catch(Exception e) {
e.printStackTrace();
}
}
} ///:~
cheng
評論于 2009-02-23 20:33
#
re: Java中的transient
回復
更多評論
寫的很好。切中要點
了凡
評論于 2009-12-02 08:53
#
re: Java中的transient
回復
更多評論
例子挺好,明白了,謝啦@cheng
了了
評論于 2010-07-26 09:44
#
re: Java中的transient[未登錄]
回復
更多評論
@cheng
很好很強大
test
評論于 2011-08-09 14:26
#
re: Java中的transient
回復
更多評論
一看例子就明白了,寫的挺好的。
風嗜塵
評論于 2012-02-13 14:55
#
re: Java中的transient[未登錄]
回復
更多評論
看來我對持久化和序列化的了解連皮毛都算不上阿,這個例子簡單明了,很好,不過這個blog對code的支持不夠友好阿,多謝博主
Merlin
評論于 2012-09-12 13:37
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
主站蜘蛛池模板:
渝北区
|
平顶山市
|
荔波县
|
道真
|
馆陶县
|
尖扎县
|
兴安盟
|
育儿
|
新野县
|
日土县
|
子长县
|
孝感市
|
英超
|
元阳县
|
铜川市
|
理塘县
|
城固县
|
常宁市
|
宝应县
|
汾西县
|
辽宁省
|
昆明市
|
天台县
|
新河县
|
鹤峰县
|
桓仁
|
临朐县
|
秦安县
|
阳信县
|
双辽市
|
仁怀市
|
汾阳市
|
于都县
|
荔波县
|
阿瓦提县
|
全椒县
|
常宁市
|
乐平市
|
枝江市
|
延津县
|
鄱阳县
|
import java.util.*;
class Logon implements Serializable {
private Date date = new Date();
private String username;
private transient String password;
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.toString() +
"\n password: " + pwd;
}
public static void main(String[] args) {
Logon a = new Logon("Hulk", "myLittlePony");
System.out.println( "logon a = " + a);
try {
ObjectOutputStream o =
new ObjectOutputStream(
new FileOutputStream("Logon.out"));
o.writeObject(a);
o.close();
// Delay:
int seconds = 5;
long t = System.currentTimeMillis()
+ seconds * 1000;
while(System.currentTimeMillis() < t)
;
// 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);
} catch(Exception e) {
e.printStackTrace();
}
}
} ///:~
很好很強大