aspose file tools*
The moose likes Java in General and the fly likes Any defect in the attached code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Any defect in the attached code" Watch "Any defect in the attached code" New topic
Author

Any defect in the attached code

Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
HI GUys,

Can you spot any issues on the below code apart from the one i spotted(in bold)...



SCJP 1.4, SCWCD 1.4
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3366
    
    9
It looks like someone is already reviewing this code for you. Why do you want us to look at it?
Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
Stephan van Hulst wrote:It looks like someone is already reviewing this code for you. Why do you want us to look at it?



Yes it was me who reviewed the code, I want to know if anything i missed in my review???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
What kind of issues?


Ping & DNS - updated with new look and Ping home screen widget
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3366
    
    9
And please just post the fixed code. Not much point it looking for mistakes in code that is obviously mistaken.
Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
Stephan van Hulst wrote:And please just post the fixed code. Not much point it looking for mistakes in code that is obviously mistaken.


Updated the fixed code....

Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
Ulf Dittmer wrote:What kind of issues?


i am looking for runtime error(if any)?
Also is there any better way of coding the sort method?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3366
    
    9
Well, you can just make your Name class implement Comparable, and then use the Collections.sort() method.

I assume you're implementing your own sort method as an exercise though. Anyway, there are several things you could consider wrong. Your method

1) is destructive, it destroys the list you pass into it. This is not considered very wanted behavior.
2) discards names that are 'greater' than "zzz, zzz", and inserts this name instead.
3) creates new instances for each name in the list, and adds them to the new list. Why not add the names directly?
4) uses a do-while loop. Don't use do-while loops. Use while loops instead.

Your Name class implements equals() wrongly, and on top of that, it doesn't implement hashCode(). Read the contract for Object.equals() and Object.hashCode().
Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
HI stephan, thanks a lot for your comments....your reviews are very helpful
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Any defect in the attached code
 
Similar Threads
How can I map beans with static builder classes in CASTOR
help with loop
Sorting a large CSV file
JSF h:dataTable
Am I misunderstanding the basics of JSF 2.0?