• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding Methods to the Interface

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,

Did anyone here add some of their own methods to the interface from Sun/Oracle? Can we do that?

Thanks,
Matt
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also added several. Plus I added "RemoteException" to each
throws clause. I'm hoping this is okay. What do others think?

Jim...
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Jim,

I found this post by Roel in regards to this issue:

https://coderanch.com/t/522835/java-developer-SCJD/certification/read-method-UB

Not a big deal to fix it, though.

Matt
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
creating another interface which extends the required-to-implement one and adding a few extra methods is certainly not a problem. I did that (and passed).

But you should NOT change method signatures of given methods, so you can not add a throws-clause with a checked exception. That will result in automatic failure. You can always wrap a possible IOException in a RuntimeException and throw that exception instead. So you don't need to change the method signature
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also did as Roel did and passed:

  • I left the supplied interface unchanged. You're in trouble if you change it.
  • I added my own methods to an extended interface.
  • I documented my reasons for adding the methods.

  •  
    Matt Pavlovich
    Ranch Hand
    Posts: 98
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Roel and Robert,

    Thanks for your input, guys. Two questions, though. Did you format the provided interface with the appropriate Javadoc formatting or did you leave it? Also, with your extended interface, did you then implement both interfaces in your Data class? I am using the Data class as a facade, so all my methods from both these interfaces are in it, which from a test requirement standpoint required me to implement both interfaces (not just the extended one), though from a strictly coding perspective such a move is redundant.

    Thanks,
    Matt
     
    Bartender
    Posts: 4568
    9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you extend the interface, then by implementing that interface you automatically implement the DB interface as well.
     
    Matt Pavlovich
    Ranch Hand
    Posts: 98
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Matthew,

    You are 100% correct. Thus my reason for saying it was redundant to implement both with "implements DB, InterfaceExtension". My issue is with the wording of the exam: "Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface: ". So yes, technically, when I implement my extended interface, the one from Oracle is automatically implemented. However, I don't want to be automatically failed because my project lacks " implements DB" in the code of my Data class. It is a trivial technicality given that DB does get implemented from implementing the interface that extends it. However, it's not worth risking me being failed over something silly that Oracle expects to be on in my code, regardless of what interfaces I have extended. In other words, I don't want to fail over one line of code. ;)

    Hopefully Roel or Robert will clarify if they took the exam super literal (as I am) or if they passed by just coding:


    It's nit-picky, but worth it if it saves me $200.

    Thanks.
    Matt
     
    Roel De Nijs
    Sheriff
    Posts: 11604
    178
    Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    if your Data class passes the test aDataInstance instanceof DB, you have met the must requirement of implementing the interface
     
    Matt Pavlovich
    Ranch Hand
    Posts: 98
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Perfect. Thank you.
     
    All that thinking. Doesn't it hurt? What do you think about this tiny ad?
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic