This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

SCJD (Apress)

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim Yingt at JavaRanch,

I have a question. I'm reading the SCJD from
At the page of 143 - 144,

private DVD retrieveDVD(long locationInFile ) throws IOException {

Class RecordFieldReader { } //as a inner class, and
RecordFieldReader readRecord = new RecordFieldReader();

}, which read a DVD and return

What is the benefit of designing like the above?
I am looking at each record, the class has to be redefined and get a instantiated.
So, if I have million records, I have to define the inner class milliontimes and instantiate
this class million times. If the benefit of design like this surpasses my concerns
written above, I would like to know exactly.

Would you be kind enough to explain to me?
It would be really appreciated. Thanks -

---Paul Seldon
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I havent seen the book so I can't really comment on the thought behind the design. However if I was reading a million records I would be much more concerned about the IO overhead of these operations (I doubt you will ever be using a flat file db to deal with a million clients). The time it would take initialise an inner class each time is very small in relation to this.

author and jackaroo
Posts: 12199
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Could you please take another look at the JavaRanch official policy on displayed names, which you agreed to when you joined JavaRanch? Please adjust your displayed name so that it appears real (not doubled up). You can adjust it here.

The primary benefit of the way we wrote that code is that it keeps the inner class together with the method that uses it. This helps with readability and maintainability.

Paraphrasing Mark, if performance were an issue, then I would use a professional tool to work out where the performance bottleneck was, then fix that particular area.

There might be a performance gain in refactoring that particular bit of code, but without knowing if that were the code that causes the bottleneck, I could end up wasting my time in fixing the wrong problem.

Oh - and a side not to Mark. Some site that we all visit has nearly 150,000 registered users (which means that there are a far greater number of users since you don't need to be registered to view articles), and I suspect over 1/2 million topics, most with multiple replies, all working off flat files. It is possible

Regards, Andrew
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic