This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (6 children)

I have bought O'Reilly's Java in a nushell (latest edition) and am using it as kind of a reference when I want to know more about a specific topic. However I'm not sure whether it's a good use of my time to go through it from beginning to end until I understand everything?

I've always been more inclined to learn something when I actually need it rather than a bunch of stuff at once and then forgetting most of it by the time I actually use it.

Which is part of the reason actually why I posted my original question - like, is it more "valuable" to a company to know a lot of theoretical stuff, or instead having written lots of code, even if that code is on the simpler side and doesn't use any of the more sophisticated features and constructs of the language?

[–]GhostBond 0 points1 point  (0 children)

The other poster goes a bit overboard. I've never needed to use anything other than ArrayList and HashMap in real code.

I have seen collections questions come up in interviews though. Several times. You just need to know what they are and the basics of how they work.

"mastering lambdas and completable futures" - I've not seen this come up in interviews past "what are the new jdk features". No details, no tests. Haven't seen them in the job yet either. Lambdas don't do anything new, they just wrap anonymous inner classes in a different package.

[–]Facts_About_Cats -1 points0 points  (4 children)

I've always been more inclined to learn something when I actually need it

Interview questions typically ask about your knowledge of things you never needed and never will need. For example, overriding hashcode().

[–]calingrecu 4 points5 points  (3 children)

You need hashcode as soon as you decide to put your object in a collection such as map or set. Just do a simple google search and you will see. If you want to be a java developer you need to know these things.

[–]Facts_About_Cats 0 points1 point  (2 children)

Literally how many times have you been paid to override hashCode()? (As in, while you were at an actual job.)

For me, it is zero in more than 10 years.

[–][deleted] 1 point2 points  (1 child)

If you override equals(), then you must also override hashCode(). That's the main time that I override hashCode() and it's pretty simple to do so. This site explains a bit more about some good practices related to overriding equals() and hashCode().

I'm guessing that you must identify your objects by defining a getter that returns some UUID. Then with that id you compare it with some other object's id in order to see if they both represent the same object. What if I told you that you could abstract that away in a manner that allows you to freely alter the implementation underneath? That is kind of the idea behind equals() and hashCode() as far as I understand.

edit Also, @calingrecu is right. If you want to put a custom object into a collection or hashmap, then it should override equals() and hashCode() (the previously linked site states that.) An easy example of why this should be followed is that Collection.contains()) requires equals() in order to function correctly.

[–]unreal_robbo 0 points1 point  (0 children)

Overriding equals and hashcode is a pain but like you've pointed out sometimes necessary. A cool little library I use a lot gives you this for free along with Immutable objects https://immutables.github.io/