This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Interface provided by Sun 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 "Interface provided by Sun" Watch "Interface provided by Sun" New topic
Author

Interface provided by Sun

Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
G'day,
My SCJD assignmnet is concern home improvement contractors.
The instruction.html I receive stated that:
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:

package suncertify.db;
public interface DBMain {
...
}
My question is can I add new methods that useful for me but seem missing in interface DBMain? (e.g. gerTotalRec(), getAllRec())
I had sent a mail to Sun and reply from monica (project manger for sun education worldwide) stated that "No, you can't change the interface.".
However I also get reply from some yahoo scjd forum stated that is ok to insert new method and modify the signature (to include the throws RemoteException) as long as I had stated the change in design document.
Any one had pass SCJD can help to cleary my questions?
Thanks

Rgds,
Song Jing, Lim

Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Hi Song Jing
If I were you, I would follow Monica's statement.
It sounds like Sun really want everyone to have one standard Data class. There are many ways that the remainder of the assignment can be coded, and it would be hard to have one specific set of tests to confirm compliance (for example, there would have to be slightly different marking criteria if you used sockets compared to the marking criteria for RMI). But there cannot be very much variation in the way people write the Data class. So the examiners can have a standard section for marking and comparing.
In the UrlyBird instructions, there is the note:
Portions of your submission will be analyzed by software; where a specific spelling or structure is required, even a slight deviation could result in automatic failure.

If you change the interface at all (adding new methods, changing the exceptions thrown ....) then the automated software will not work. Do you really want to risk that?
Even without those instructions, I would not want to follow the other person's advice of changing the interface specified. That interface is what Sun expect you to code to in order to create the Data class. This is not necessarily the interface your clients have to code to in order to get access to the Database.
If you feel that other methods are needed by your application, then perhaps you could extend Data, and put those methods in the extended class?
Regards, Andrew


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

Joined: Feb 11, 2003
Posts: 56
Dear Andrew,
Thanks for reply...
Well, I also think about extend the class...
However my instruction.html stated that the data interface DBMain.java must be implement by Data.java.
What I think about is using adapter design pattern for db access from network (RMI). Either network or local are calling the same interface.
But as instruction.html already stated that DBMain.java must be implement by Data.java so if I use the DBMain.java as interface, I can't addin new method or modify the signature.
Q1) Any idea about how to solve this problem?
Q2) Also is that means I can add in new method in implementation file (data.java)?
Q3) Even so, how can I throw RemoteException in data access class?
Rgds,
Song Jing, Lim
guyue0505
Greenhorn

Joined: May 25, 2003
Posts: 21
Yes I also have this question!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Hi Song Jing
Q2) Also is that means I can add in new method in implementation file (data.java)?
Q3) Even so, how can I throw RemoteException in data access class?

You cannot add new methods in Data.java or throw RemoteException without changing the interface, which you are not allowed to do. So stop trying.
Write Data.java to implement the interface as provided by Sun, without changes.
Once you have done that, you can start thinking about what methods you want to provide to clients, and what exceptions need to be thrown. Then create your own interface to define those methods and those exceptions.
Can you see where this is going?
Regards, Andrew
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
Dear Andrew,
I guess I know what U means...
So the actualy data access class is create by me which is either using inheritan (extend) or using composition from the class requrie by Sun. So like wrapping class.
ie. my 'real' data access interface class call papter.java and implement by database.java. Inside database.java I can either extend the data.java or create a private object of data.java for composition.
Is that U menas? ^_^
Thanks... And u answer had clear this questions I think for few days...
Rgds,
Song Jing, Lim
(http://www.geocities.com/limsongjing/)
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Hi Song Jing
Looks like the right way to me. Good luck.
Regards, Andrew
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Song, you have posted this thread twice. Please try to refrain from duplicate posting. I have responded to the other thread. This is what happens is that there are now two conversations on the same topic, and no one knows which one to post to.
I am going to close the other thread.
Thanks
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
Thanks Andrew
Dear Mark, I'm sorry to post the questions twice. The extra method I plan to add in will be somethign like get return all record. Where when user key in * or empty at search criteria, all data will be return.
Let me work on first then I will back to this topic and let U know what the method I had add in.
Anyway, thanks to all to clearify my questions and give me hint about what I should do. Thanks again.
Rgds,
Song Jing, Lim
Andrew Symantec
Greenhorn

Joined: Apr 24, 2003
Posts: 15
Can Andrew or someone please explain this to me?
You cannot add new methods in Data.java or throw RemoteException without changing the interface, which you are not allowed to do. So stop trying.

From what I understand if you implement an interface you can provide new methods other than those specified in the interface. (Of course you have to implement those methods defined in the interface first).
Thanks
[ June 18, 2003: Message edited by: Andrew Symantec ]
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
It is because on of the requirement from Sun that the data access interface provided by Sun (MYData.java) as well the implementation class (Data.java) can't be change as mention by Monica from Sun Education worldwide (she reply to me via email).
So that why we can use the wrapper class to include the data.java as one of the private member on our own interface (use as adapter class for network/local connection to access database). As well in our own interface (the adapter class) can include new method and throws the RemoteException.
In summary, the interface and implementation calss for data access stated in insturction.html (receive from SCJD assignment) can't be change (no adding or modify the signature).
That is what I undersand.
Rgds,
Song Jing, Lim
Andrew Symantec
Greenhorn

Joined: Apr 24, 2003
Posts: 15
That make sense.
However, from your preivous post. Monica only said "NO you cannot change the interface".
Unless there are more words in her email clearly defined that we cannot change the Data.java class

Thanks
[ June 18, 2003: Message edited by: Andrew Symantec ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
That answer of Monica's seems a bit odd to me - I wonder if there was some misunderstanding somewhere. Certainly from the original instructions we can't change the interface DB.java, and the class Data.java must implement it. But other than Monica's reply (which most people taking the exam would not see) there would be no particular reason to think you couldn't add other methods beyond those specified in the interface, IMO. We're not changing the interface, we're adding other methods beyond the interface. I wonder if maybe (a) Monica thought you wanted to edit DB.java, or (b) Monica meant "there's no need to add public methods to Data beyond what DB specifies, and you may get penalized slightly for doing so". I'd hate to think that people might get some sort of auto-failure for adding a method, since those of us who didn't get Monica's mail have no reason to suspect that. I mean, to be safe I'll keep Data's methods to the minimum required, but I think there's been a slight miscommunication somewhere...


"I'm not back." - Bill Harding, Twister
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Ooops - for some reason, I thought Song Jing's original post implied that Data.java could not have additional methods added to it. Brain not working properly
So I will stick with my comment that you cannot change the interface, but I retract my statement that you cannot add your own methods to the Data.java class.
Regards, Andrew
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
So the final conclusion is:
1) Interface provide by Sun (in my case will be MainDB.java) can't be change.
2) Implementation class for above interface (data.java) can add in the new method like listAllData.
What I plan to do is beyoung that. I will have a class doing the actual data gathering like reading data from file which name database.java. Which will be use by data.java as it member variable.
Then at the remote side. I will have a interface that implement the MainDB.java. This remote interface will be implement by remoteImpl.java and extend the database.java. remoteImpl.java will work as wrapper class like data.java but it use in remote side.
So in local/remote mode, the return will be type MainDB.java. But in local mode the actualy object return is data.java and in network mode the return type is remtoeImpl.java.

I hope my design is ok.
Rgds,
Song Jing
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
bcoz of restriction of modify the interface define by Sun, I face another problem in exception handling.
As mention, the interface DBMain as below.
package suncertify.db;
public interface DBMain {
public String [] read(int recNo) throws RecordNotFoundException;
...
}
My question is for my remoteImpl.java which implement the DBMain for remote connection need to throws RemoteException.
public String [] read(int recNo) throws RecordNotFoundException, RemoteException{
}
But i got compiler error as the interface I implement didn't throw RemoteException.
Any help on this exception problem cause by Interface restriction?
Rgds,
Song Jing, LIm
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface provided by Sun