RE: Word List Creator 06-22-2013, 06:51 PM
#5
That's a nice and useful idea you implemented here.
A scanner is used to create tokens from a text. It's not mainly used for reading Files (but it has the functionality). The scanner has more functionality than you need there, so I would prefer the BufferedReader. It makes your intentions (you don't want to tokenize) more clear.
The second suggestion of @Psycho_Coder is a very good one and I would have done the same.
No, it is not the same process and also not a similar one that is used in a set. A HashSet has a much better performance. It uses hashing to store the values, therefor it can immediately (O(1) for the average case) determine if a value has been stored already.
You on the other hand read the values, write the values, read the values, sort the values and write them again. The sorting is O(n^2) which is much worse. When it comes to reading large files, you might get into trouble soon.
Actually it should be mandatory like it is in C#, but Java is older and they build in the @Override annotations later, while preserving the backward compatibilty, so they couldn't make it mandatory.
It is a bad habit not using these annotations, they prevent bugs (i.e. spelling error when overriding methods) and they make the code more readable. Btw: If you use Eclipse you can tell it to add the override annotation on save operations.
Other than that:
Close your streams within a finally block.
Start your GUI (WLC) like this or you get into trouble, because Swing isn't thread save:
Quote:1. You have used BufferedReader , you would also have have used Scanner class as this takes less space than BufferedReader class, but the reason for which you have used BufferedReader is because Scanner is not thread safe.
A scanner is used to create tokens from a text. It's not mainly used for reading Files (but it has the functionality). The scanner has more functionality than you need there, so I would prefer the BufferedReader. It makes your intentions (you don't want to tokenize) more clear.
Quote:Now that you mentioned it, I guess I could have used it to make it a little easy for me. But in the end, it would mean about the same since a similar processing is done in that very class to remove duplicates. Still, I think that would be a lot easier for me
The second suggestion of @Psycho_Coder is a very good one and I would have done the same.
No, it is not the same process and also not a similar one that is used in a set. A HashSet has a much better performance. It uses hashing to store the values, therefor it can immediately (O(1) for the average case) determine if a value has been stored already.
You on the other hand read the values, write the values, read the values, sort the values and write them again. The sorting is O(n^2) which is much worse. When it comes to reading large files, you might get into trouble soon.
Quote:Why would I do that? Isn't it unnecessary?
Actually it should be mandatory like it is in C#, but Java is older and they build in the @Override annotations later, while preserving the backward compatibilty, so they couldn't make it mandatory.
It is a bad habit not using these annotations, they prevent bugs (i.e. spelling error when overriding methods) and they make the code more readable. Btw: If you use Eclipse you can tell it to add the override annotation on save operations.
Other than that:
Close your streams within a finally block.
Start your GUI (WLC) like this or you get into trouble, because Swing isn't thread save:
Code:
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new WLC();
}
});I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.
Expressed feelings are just an attempt to simulate humans.
![[Image: 2YpkRjy.png]](http://i.imgur.com/2YpkRjy.png)


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)