FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/serialization/Logon.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
serialization
/
Logon.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (60 loc) · 1.69 KB
Breadcrumbs
OnJava8-Examples
/
serialization
/
Logon.java
Copy path
File metadata and controls
61 lines (60 loc) · 1.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// serialization/Logon.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Demonstrates the "transient" keyword
import
java
.
util
.
concurrent
.*;
import
java
.
io
.*;
import
java
.
util
.*;
import
onjava
.
Nap
;
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
;
}
@
Override
public
String
toString
() {
return
"logon info:
\n
username: "
+
username
+
"
\n
date: "
+
date
+
"
\n
password: "
+
password
;
}
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.dat"
))
) {
o
.
writeObject
(
a
);
}
catch
(
IOException
e
) {
throw
new
RuntimeException
(
e
);
}
new
Nap
(
1
);
// Now get them back:
try
(
ObjectInputStream
in
=
new
ObjectInputStream
(
new
FileInputStream
(
"Logon.dat"
))
) {
System
.
out
.
println
(
"Recovering object at "
+
new
Date
());
a
= (
Logon
)
in
.
readObject
();
}
catch
(
IOException
|
ClassNotFoundException
e
) {
throw
new
RuntimeException
(
e
);
}
System
.
out
.
println
(
"logon a = "
+
a
);
}
}
/* Output:
logon a = logon info:
username: Hulk
date: Sun Jan 24 08:49:30 MST 2021
password: myLittlePony
Recovering object at Sun Jan 24 08:49:31 MST 2021
logon a = logon info:
username: Hulk
date: Sun Jan 24 08:49:30 MST 2021
password: null
*/
Back
|
FazBrowse Home
|
New Git URL