• 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

Denny's DVD design

 
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am preparaing for the OCMJD exam and I read Andrew Monkhouse and Terry Camerlengo's book (SCJD Exam with J2SE 5 platform second edition) . I read and run their source code and I have a few questions that I'd like you to answer please. Source code follows.

1- If the member class ReservationsManager and DvdFileAccess are already declared as static in the DvdDatabase class, do we really need to declare ReservationsManager member classes and DvdFileAccess member classes static again ( I am talking about private static Map<String, DvdDatabase> reservations, private static Lock lock, private static Condition lockReleased for class ReservationsManager and private static Map<String, Long> recordNumbers, private static ReadWriteLock recordNumbersLock, private static String emptyRecordString, private static String dbPath for class DvdFileAccess) ? Isn't it redundant ( I am not a java expert, that's why I am asking) ? Shouldn't they all just be private only with no static attribute? If not, which member should remain static ?

Below the source code for the Database class as it appears in the book's source code :



Below the source code for the ReservationsManager class as it appears in the book's source code :



Below the source code for the DvdFileAccess class as it appears in the book's source code :



Thanks for your help.

Sincerely,

borkev
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bor Kev wrote:1- If the member class ReservationsManager and DvdFileAccess are already declared as static in the DvdDatabase class...



But they aren't declared in the DvdDatabase class. They are top-level classes, which stand on their own. They are not inner classes of DvdDatabase.

Perhaps you are referring to the fact that DvdDatabase has a static variable of type ReservationsManager? That's a perfectly normal thing to do -- classes use static variables all the time, and you don't have to look at how their types are declared. You've seen static String variables, for example? And you didn't decide to look at how the String class was implemented, did you?
 
Bor Kev
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Paul Clapham,

I apologize because I used the wrong terminology. As you mentioned, ReservationsManager and DvdFileAccess are top level classes, which stand on their own and they are not inner classes. I know that. Indeed, I was referring to the fact that Database has a static variable of type ReservationsManager and DvdFileAccess. I am perfectly aware that this is common practice. However, in the context of preparing for the OCMJD certification, I need to understand the ins and out of methods created by the authors as opposed to understand the implementation of methods that belong to the Java API libraries (i.e such as the String class as you mentioned). It is very important for me to understand so that when I get to create my own classes I can undertsand the subtleties. So, my question is not whether or not it is a perfectly normal thing to do or not (which I know it is) but rather :

If the member class ReservationsManager and DvdFileAccess are already mentioned as static members in the DvdDatabase class, do we really need to mention ReservationsManager member classes and DvdFileAccess member classes static again ( I am talking about private static Map<String, DvdDatabase> reservations, private static Lock lock, private static Condition lockReleased for class ReservationsManager and private static Map<String, Long> recordNumbers, private static ReadWriteLock recordNumbersLock, private static String emptyRecordString, private static String dbPath for class DvdFileAccess) ? Isn't it redundant ( I am not a java expert, that's why I am asking) ? Shouldn't they all just be private only with no static attribute? If not, which members should remain static ?

Note : I sent an email to the authors (Andrew Monkhouse & Terry Camerlengo) through the book's editor company but I haven't received an answer yet. I also understand that the book was published on December 15, 2005 (i.e more than 10 years ago) so I totally understand that the authors have moved on and are busy with other projects. That's why I am reaching out to the Java community. The book is excellent by the way and I learnt a lot from it. I don't mean to expose potential flaws , I just want to understand better. I strongly recommend the book for those preparing for OCMJD certification.
Sincerely,

borkev
 
reply
    Bookmark Topic Watch Topic
  • New Topic