Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Objects Deserialization

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Assistant,
I while observing this side >" http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=303&p_certName=SQ1Z0-851 " find a little bit mistake with Sample Questions.
Which is below:


OBJECTIVE: 3.3: Develop code that serializes and/or de-serializes objects using the following APIs from java.io: DataInputStream, DataOutputStream, FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutputStream, and Serializable.
4) Given:
2. import java.io.*;
3. public class Network {
4. public static void main(String[] args) {
5. Traveler t = new Traveler();
6. t.x1 = 7; t.x2 = 7; t.x3 = 7;
7. // serialize t then deserialize t
8. System.out.println(t.x1 + " " + t.x2 + " " + t.x3);
9. }
10. }
11. class Traveler implements Serializable {
12. static int x1 = 0;
13. volatile int x2 = 0;
14. transient int x3 = 0;
15. }

If, on line 7, t is successfully serialized and then deserialized, what is the result?
a) 0 0 0
b) 0 7 0
c) 0 7 7
d) 7 0 0
e) 7 7 0 (*)
f) 7 7 7

REFERENCE:
API
Option E is correct. Fields declared as transient or static are ignored by the deserialization process.

My Question is according to this Code the result comes

7 7 7
Press any key to continue...

But we see the answer which is above does not similar to the real one, that is above reference says the ans. is 7 7 0

What should be in correction ? If 7 7 7 is right should the authority make their page correct?

thanks for the patient.
Sincerely,

Zobair

 
author
Posts: 23843
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zobair Imran wrote:Dear Assistant,
I while observing this side >" http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=303&p_certName=SQ1Z0-851 " find a little bit mistake with Sample Questions.
Which is below:


OBJECTIVE: 3.3: Develop code that serializes and/or de-serializes objects using the following APIs from java.io: DataInputStream, DataOutputStream, FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutputStream, and Serializable.
4) Given:
2. import java.io.*;
3. public class Network {
4. public static void main(String[] args) {
5. Traveler t = new Traveler();
6. t.x1 = 7; t.x2 = 7; t.x3 = 7;
7. // serialize t then deserialize t
8. System.out.println(t.x1 + " " + t.x2 + " " + t.x3);
9. }
10. }
11. class Traveler implements Serializable {
12. static int x1 = 0;
13. volatile int x2 = 0;
14. transient int x3 = 0;
15. }

If, on line 7, t is successfully serialized and then deserialized, what is the result?
a) 0 0 0
b) 0 7 0
c) 0 7 7
d) 7 0 0
e) 7 7 0 (*)
f) 7 7 7

REFERENCE:
API
Option E is correct. Fields declared as transient or static are ignored by the deserialization process.

My Question is according to this Code the result comes

7 7 7
Press any key to continue...

But we see the answer which is above does not similar to the real one, that is above reference says the ans. is 7 7 0

What should be in correction ? If 7 7 7 is right should the authority make their page correct?

thanks for the patient.
Sincerely,

Zobair




Not sure what you are asking -- but if you got the incorrect answer, perhaps you can tell us what your code does to "serialize and deserialize"? Otherwise, we can't tell what you did wrong.

Henry

 
Zobair Imran
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dear Henry Wong,

Thanks for your reply. Actually I asked that in your sample question and answer sheet the answer of that question is 770,
but same code when I run in my laptop it says the answer is 777. And that is what my question was. I really did not do anything changed with that code just copied and pasted.
So my question on what basis are you saying the answer is 7 7 0 while I am seeing the answer is 7 7 7.
To be frankly speaking I did not do ever serializing and then deserializing.
May be I myself am confused!. Anyways, Hope you did not mind.
By the way I am really pleased to meet you that it is you Mr. Henry Wong who wrote the book JAVA Threads 2nd Edition replied to me!!! WOW! it feels great.
can you tell me how far changes are there in your new I mean 3rd Edition. After all it is after 1999.

Thanks.
Sincerely,

Zobair
 
Henry Wong
author
Posts: 23843
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zobair Imran wrote:
Thanks for your reply. Actually I asked that in your sample question and answer sheet the answer of that question is 770,
but same code when I run in my laptop it says the answer is 777. And that is what my question was. I really did not do anything changed with that code just copied and pasted.
So my question on what basis are you saying the answer is 7 7 0 while I am seeing the answer is 7 7 7.
To be frankly speaking I did not do ever serializing and then deserializing.
May be I myself am confused!. Anyways, Hope you did not mind.
By the way I am really pleased to meet you that it is you Mr. Henry Wong who wrote the book JAVA Threads 2nd Edition replied to me!!! WOW! it feels great.
can you tell me how far changes are there in your new I mean 3rd Edition. After all it is after 1999.



If you look carefully at the code, you will see that it doesn't actually serialize or deserialize. Instead, there is a comment that points out where the serialize and deserialize code belongs. You can't run it cut-n-paste, you are expected to add the serialization code, otherwise the question is moot, as it is not doing what it is asking.

Henry
 
Zobair Imran
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dear Mr. Henry,

Sorry to disturb you again. Actually I did not follow what was written under commentary mark--> //
I am really Sorry.

I think, you are Infect trying to say something in your Sample question Like following:

import java.io.*;
public class Network {
public static void main(String[] args) {
Traveler t = new Traveler();
t.x1 = 7; t.x2 = 7; t.x3 = 7;
// serialize t then deserialize t

try {

FileOutputStream fileOut = new FileOutputStream("traveler.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(t);
out.close();
fileOut.close();
System.out
.println("Object is serialized & stored in 'traveler.ser'");
} catch (IOException ie) {

ie.printStackTrace();
}

t = null;

try {

FileInputStream fileIn = new FileInputStream("traveler.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
t = (Traveler) in.readObject();
in.close();
fileIn.close();
} catch (IOException i) {

i.printStackTrace();
return;
} catch (ClassNotFoundException c) {

System.out.println("traveler class not found");
c.printStackTrace();
return;
}

System.out.println("\n\nAnd Then...\n");
System.out.println("Deserialized traveler...\n");
System.out.println(t.x1 + " " + t.x2 + " " + t.x3);
}
}
class Traveler implements Serializable {
static int x1 = 0;
volatile int x2 = 0;
transient int x3 = 0;
}

Thank You Very Much Indeed.

Zobair
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!