aspose file tools*
The moose likes Jobs Discussion and the fly likes Java interview - Do I need to know how iterators are implemented ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Careers » Jobs Discussion
Bookmark "Java interview - Do I need to know how iterators are implemented ?" Watch "Java interview - Do I need to know how iterators are implemented ?" New topic
Author

Java interview - Do I need to know how iterators are implemented ?

Andy Jack
Ranch Hand

Joined: Nov 22, 2012
Posts: 257
I was looking at the Java code for some iterators. I am not sure if this is something I should know well. Is it okay if I know only what an iterator can do for me and how to use it ?

Thanks


Java Newbie with 72% in OCJP/SCJP - Super Confused Jobless Programmer.
I am a "newbie" too. Please verify my answers before you accept them.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

I believe it is much more important to know how to use an Iterator than it is to know how to implement one, especially for an entry level position.

That said, I love to ask questions that the interviewee doesn't expect and can't know to prepare for. So that would make a quick "implement an Iterator for a Vector, assuming that there is not one already" a good test. I'd give you the Javadoc for Iterator, and give a whiteboard.
Andy Jack
Ranch Hand

Joined: Nov 22, 2012
Posts: 257
Pat Farrell wrote:I believe it is much more important to know how to use an Iterator than it is to know how to implement one, especially for an entry level position.

That said, I love to ask questions that the interviewee doesn't expect and can't know to prepare for. So that would make a quick "implement an Iterator for a Vector, assuming that there is not one already" a good test. I'd give you the Javadoc for Iterator, and give a whiteboard.


Thanks. You mentioned that application is more important for an entry level position. So, would the inner details of iterators be important for higher positions ? If so, then why ?
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Andy Jack wrote: So, would the inner details of iterators be important for higher positions ? If so, then why ?

Suppose you were interviewing at Google for their Guava team. (if you don't know about Guava, google for it, its a great library). They write a lot of classes that implement the Collection interface, so they have to implement an Iterator for their new classes. Nearly everything that Google does is about searching through lists and producing new result lists. So for that job, you would have to at least be able to clearly define and implement a good iterator.

More importantly, the whole point of Object Oriented Programming is to use abstraction to hide implementation details. A more senior position would often create the abstractions and implement them, while more junior folks use them.

If you look at the source code to Google's Guava (its open source, easily available) you will see examples of good professional software. Its well documented in the complete Javadocs. The code itself is concise and aims for maximum reuse of other classes, and reflects the clean design of the whole package that is Guava. You would expect that the Iterator implementation for an ImmutableList would be very similar and have a lot of reuse of code from say their ImmutableSet class.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

As a different opinion, I wouldn't expect someone to know how existing iterators are implemented unless you say you've written an Iterator. It's not something most people give deep thought.

I could envision an interviewer asking it though. Most people should be able to figure it out.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Andy Jack wrote:I was looking at the Java code for some iterators. I am not sure if this is something I should know well. Is it okay if I know only what an iterator can do for me and how to use it ?

Thanks


Yes it is ok. Until an interviewer asks you how to implement one

Most interviewers will not ask you how the internals of any system / utility class works. However it is always nice to know. Iterators have several interesting properties to explore.

1. How do you make sure iterators work properly when used across threads. Should you care ?
2. Does the immutability of a data structure affect how iterators behave ?
3. When should an iterator throw ConcurrentModificationExceptions ?
4. How do system classes know that the data structure that the iterator is operating on has changed ?
5. How can you make any arbitrary class function inside a for-each loop ?

and so on...

Explore several iterators before saying you know how to implement one. Try implementing an iterator to boost your confidence.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Timothy Brown
Greenhorn

Joined: Mar 12, 2012
Posts: 7
My experience in interviews so far has been more along the lines of recreating elements in the Java API's, not using them. I don't want to state the exact question, because I signed a form that I wouldn't, but essentially, say you didn't have the Collections API and really needed one of the commonly used data structures. Ok, now build me one, handle collisions, and while you're at it, make it fully generic. A different interview had me check to see if a tree was in balance. Another one yet was to count unique shortest-paths on a graph using a depth first search - recursively, and then prove mathematically my answer was correct. So, to answer your questions specifically, don't worry so much about knowing Java as a language, know how to program USING Java as your language. The questions you'll likely get will not matter what language you use at all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java interview - Do I need to know how iterators are implemented ?