• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Questions on example proj in book

 
Hugh Johns
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looking throught the example project code from Max's book, I have two questions.
1: In the following class, why are the two attributes transient as the class does not seem to be serialized (although it say so in the Javadoc class header)

2: How does the following method throw any exception when there is a catch all Exception handler at the end of the method whoch does not rethrow any exceptions

[Andrew: edited code to make it wrap better]
[ September 03, 2003: Message edited by: Andrew Monkhouse ]
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hugh,
It would have been easier if you'd told us from which chapters/pages those examples are coming from. Without any contextual information, it's difficult to give you some accurate answer. Anyway, I'll try my best.

1: In the following class, why are the two attributes transient as the class does not seem to be serialized (although it say so in the Javadoc class header)

code:
--------------------------------------------------------------------------------
public class DVDDatabase{
private static transient String dbName = "dvd_db";
private static transient String recordExtention = ".dvd";
--------------------------------------------------------------------------------

In the RMI introductory chapter, I read :
RMI uses object serialization to marshal and unmarshal parameters.

So I guess that those fields don't need to be sent accross the network. Sorry to be unprecise, but as I chose sockets, I am not expert in RMI.


2: How does the following method throw any exception when there is a catch all Exception handler at the end of the method whoch does not rethrow any exceptions

code:
--------------------------------------------------------------------------------
public synchronized boolean returnRental(String upc) throws IOException, ClassNotFoundException {
.....
try {
......
}
catch (Exception e) {
System.err.println(e.getMessage());
}
}

If your code excerpt is correct, it doesn't make much sense IMO, except if some IOException or ClassNotFoundException may be thrown in the first "....." part of the method. But think of the fact that an author may simplify its code to help the reader keeping concentrated on what he is just explaining : his intent is never to get the code ready to be copied and pasted...
Best,
Phil.
[ September 03, 2003: Message edited by: Philippe Maquet ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hugh
I had hoped that I might be able to work this out with a little investigation. But no such luck.
The DVDDatbase class in not serializable, and this is even mentioned on page 144. So I agree - setting the variables transient does not seem to add much here.
I did think that possibly DVDDatabase was meant to implement the DBClient interface, which would mean that it would have to throw the same exceptions as declared in the interface. But that would only be a guess. And I have this horrible suspicion that this might end up as a circular argument for why those exceptions are thrown, so I don't want to go there.
If you take out the try...catch block, then those two exceptions are required. So I might question whether the try...catch block should be removed. But again, this is just guess work.
Sorry - no real help.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic