aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Understanding DBClient in Max's book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Understanding DBClient in Max Watch "Understanding DBClient in Max New topic
Author

Understanding DBClient in Max's book

Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
As I understand so far about this interface, it serves two purposes:

1. wrap around on top of the low level db operation (which is the DBAccess interface); if the sampleproject takes a thin-client approach, then the business logic may go into this level.

2. expose the relevant db operation to remote/local client (at this layer, no extension to Remote b/c there will be another interface to extend Remote).

All methods in this interface throw IOException. This confused me a lot. In its implementation, I don't see the need to throw this ioex; so the #1 is irrelevant.

Is #2 relevant? No. Although I see some other threads (a search for "dbclient ioexception" will return) said this is for rmi's remote ex, I don't think so. the sample project compiles, in term of rmi, is because the remote implementation, DVDDatabaseRemote, throws both io ex and remote ex.

So, why is the ioexception thrown in DBClient? Is it related to the socket connection?

At least, I didn't see the need to throw IO ex in DBClient, so far, if use rmi.

Thanks for any input.


--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
Joakim Eriksson
Greenhorn

Joined: Sep 13, 2004
Posts: 25
DBClient has to throw an IOException because the DVDDatabaseRemote interface extends DBClient and DVDDatabaseRemote throws RemoteExceptions.

IOException is the superclass of RemoteException.

/J.
Joakim Eriksson
Greenhorn

Joined: Sep 13, 2004
Posts: 25
I think it looks like it does because of how exceptions works in overridden methods.

Max probably has a better explaination.
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Joakim, thanks for your reply.

DVDDatabaseRemote does extends DBClient and its implementation does throw remote ex; io ex indeed is super class of remote ex. However, look close to the DVDDatabaseImpl, methods all throw both remote and io ex's. If following what you said, you can remove io ex in these methods, then javac will complain to you. Therefore, the fact that io ex is super of remote ex has nothing to do here with the rmi interface (DBClient itself doesn't extend Remote!!! I think this is a misunderstanding also presented in some other thread). This is so far what I know. Yes, I guess there may be the reason for the ex being here and Max may explain to us better.

Thanks anyway.
Joakim Eriksson
Greenhorn

Joined: Sep 13, 2004
Posts: 25
no no no

I think that you can remove RemoteException from all methods that already throws IOException in the DVDDatabaseImpl though.

Of course you cannot remove the IOExceptions, then you wouldnt be implementing the DBClient.

--------------------------
As I mentioned in a post earlier in this forum it would be clearer if it worked like this:

DBClient extends DBUniversal
and
DVDDatabaseClient extends DBUniversal, Remote

in DBUniversal everything throws IOExceptions
in DBClient methods just throws what is needed for "local mode"
in DVDDatabaseClient methods throw what is needed for "local mode" and Remote

However DVDDatabaseClient does not extend DBClient.

This also means that connection in GUIController would be of the type DBUniversal instead, which makes sense since the controller should handle both local and remote connections.

The difference between the interfaces are just what exceptions they throw, and thus enforce on their implementations.

The way I'm suggesting gives more code (thus is more prone to error) but it is much less confusing in my opinion.

All comes from this:

public interface InterfA{
public abstract void method() throws ExceptA, ExceptB;
}

public interface InterfB{
public abstract void method() throws ExceptB, ExceptC;
}

public interface InterfC extends InterfA,InterfB{
}

public class MyClass implements InterfC{
public void method() throws ExceptB{ // cannot throw ExceptA
// or ExceptC or compile error
//code
}
}

however what we see in Max code is this:

public class MaxClass implements InterfC{
public void method() throws ExceptB,ExceptC{
//code
}
}

and it works because:

in this case:

public class ExceptC extends ExceptB{
}

or

that "RemoteException extends IOException".


----
This confused me a lot to start with. But maybe I'm less skilled than most other ppl reading his code. I can't explain it any better than this, so I hope you get what I'm saying.

/J
[ September 16, 2004: Message edited by: Joakim Eriksson ]
Joakim Eriksson
Greenhorn

Joined: Sep 13, 2004
Posts: 25
Damn, I think I understand now...

Max, my apologies, your code is fine, I'm just slow.
I misinterpreted DBClient to mean DBLocal, where it is just
really DBClient as it is written (and closer to what I suggested for DBUniversal). Basically you just rationalized away one interface.

Sorry,

/J
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145

I think that you can remove RemoteException from all methods that already throws IOException in the DVDDatabaseImpl though.

Of course you cannot remove the IOExceptions, then you wouldnt be implementing the DBClient.


If this is the case, then why do we throw io ex rather than remote ex, while remote ex provides a bit more specific information? Or do we need to wrap some other ex into io ex in client side? Still not convencing.
Joakim Eriksson
Greenhorn

Joined: Sep 13, 2004
Posts: 25
Because RemoteException is a part of the RMI framework and we do not want to use anything related to RMI in our controller and "local code" to
"prove" that we are not using any network code. (a guess)

Otherwise there is no real benefit, unless you plan to use some code later that actually must throw IOException.

/J
[ September 16, 2004: Message edited by: Joakim Eriksson ]
Joakim Eriksson
Greenhorn

Joined: Sep 13, 2004
Posts: 25
In Max database his read/write methods in DVDDatabase do throw IOException.
Thus the DVDDbAdapter just passes them on (which is fine and logical).

For his code throwing IOException even in the "local code" makes sense, but most real assignments (SCJD) won't allow you to do that from the Data.java class.

Basically given the context of trying to retrofit his designs onto something similar to the SCJD assignment (my own assignment) I was confused. But it makes perfect sense once I understood what was the purpose of DBClient.

/J
Brent Smith
Greenhorn

Joined: Sep 19, 2004
Posts: 5
I have seen several references now to "Max's" book. What exactly is the title of this book? Several posts have mentioned that it was helpful to them and I may want to buy it myself.

Thanks.


SCJP 1.4
mike acre
Ranch Hand

Joined: Sep 23, 2003
Posts: 197
Brent,

ISBN: 1590590309

Actually, unless you know shag all Java, there is little to learn from it.

It gives a good overview for the exam and what it entails, but apart from that there is more depth to a box of rice-krispies. There is certainly more depth to most of the programmer cert books out there.
The worked example it doesn't work through, misses out a great deal of the important issues or neatly circumvents them!

I would personally recommend the Sybex book (ISBN: 0782428254) or even the mcgraw hill one (ISBN: 0072191694) although I've only given the latter a cursory flick though.

Although they are all out of date, I don't think there is anything available that is written in light of the current assignments.


SCJP 1.4, SCJD
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11509
    
  95

Hi Brent,

The book in question is The Sun Certified Java Developer Exam with J2SE 1.4. In my opinion it is the best book for SCJD. It covers nearly every aspect of the assignment (although like every such book it does differ from the real assignment so as not to give away a complete solution), and explains how to work on the assignment from scratch - that is, how to develop a solution from the instructions you have been given.

Now if you are already a developer (not just a programmer who needs to be given clear instructions on every task) and you have already dealt with all the technologies used in the assignment, then you may not need this book - but then, why would you be looking for books anyway?

My best advice would be for you to see if any local book stores have a copy of the book, then go and read part of the book - see if it makes sense and speaks to you.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
I hate to disagree with Mike's assessment of Max's book, but I thought it was a wonderful starting point to the assignment. I purchased it and worked through the code before even downloading the SCJD assignment. When I did download the assignment, I was faced with a good deal of similarities between the book's sample app and the assignment.


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
mike acre
Ranch Hand

Joined: Sep 23, 2003
Posts: 197
Originally posted by Paul Bourdeaux:
I hate to disagree with Mike's assessment of Max's book...


It's okay, I realise I'm in the minority.
I think if the reader has the goal of getting through the certs as fast as possible, with little background in Java, then perhaps it is a good book. But personally having studied the language for 3 years before even taking SCJP, I found it a little too basic.
But then I think that most of the respected posters and popular design approaches on this forum are way out of scope for this cert.
I think when people read Mr X raving on about DAO or full MVC approach or even my Transfer objects they should take it with a pinch of salt and ask themselves is this really required, can I not simplify this alot for the sake of the cert.
I don't know how Anton has managed to get his desing to weigh in as light as he has (~20 classes 2000 lines of code IIRC). But that sort of weight is probably more what is expected from SCJD. I know that a common criticism/comment from Sun is that assignments are typically a little OTT.
Joakim Eriksson
Greenhorn

Joined: Sep 13, 2004
Posts: 25
Originally posted by mike acre:


It's okay, I realise I'm in the minority.
I think if the reader has the goal of getting through the certs as fast as possible, with little background in Java, then perhaps it is a good book. But personally having studied the language for 3 years before even taking SCJP, I found it a little too basic.
But then I think that most of the respected posters and popular design approaches on this forum are way out of scope for this cert.
I think when people read Mr X raving on about DAO or full MVC approach or even my Transfer objects they should take it with a pinch of salt and ask themselves is this really required, can I not simplify this alot for the sake of the cert.
I don't know how Anton has managed to get his desing to weigh in as light as he has (~20 classes 2000 lines of code IIRC). But that sort of weight is probably more what is expected from SCJD. I know that a common criticism/comment from Sun is that assignments are typically a little OTT.



Basically what you are saying is go for the easiest solution available, that still can be defended as fullfilling the requirements.

If you want your cert asap, I can't argue with that.

However, I did not choose the minimalistic path, and to me, this assignment is not only about the cert.

/J
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
I didn't realize my simple post has so many reply. As to the cert, I only has Max' book. However, I am not just doing cert for cert. More or less, you will learn from doing the project. I agree with Joakim, I take it as a learning process and try to learn as much as I can. So I have studied many tutorials, articles, books on various topics such as threading, swing, pattern, rmi, regular expression, etc. I am glad I chose to take this exam. But to the new beginner, I think Max' book is a good start but don't expect you can learn it the next day.

Good luck
Robert Chisholm
Ranch Hand

Joined: Jul 18, 2004
Posts: 69
Seems that I agree with Andrew. If you're a developer already, then it's probably a reference manual. But, what's wrong with that?... I don't use custom RMI solutions or Swing much so it had some pointers.


SCJP 1.4<br />(WIP) SCJD B&S v2.3.3
mike acre
Ranch Hand

Joined: Sep 23, 2003
Posts: 197
A reference manual is the one thing it most definitely is not.

And no I don't think the minimalist approach is the way to go because it is the fastest way to get cert I think it is the best way to go to meet the spec. Minimalist spec == minimalist approach. Note I don't mean boiler plate the lot. I think Max's approach in his book is spot on - this is minimalist. By all means use complex approaches as a learning exercise. Then discover the error of your ways and rip them all out for the submission.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Understanding DBClient in Max's book