views:

1610

answers:

17

I'm in college. Basically I have already learnt the syntax of java from books and have been programming in java for two years (Not every other day of course, because it's a computer science and not software engineering course). However, I find myself lacking sufficient knowledge of java and feel inadequate.

For example, none of the books taught me that if I override the Object equals method, then I should override the hashCode method as well (if I want the hash containers to work properly). It was only when I couldn't get my program to run as expected and having to debug that I discovered this. I find this unproductive because I felt that it's something that should have been taught, something that should have been known in the first place. I expect that as I do more programming in java I'll run into similar "should have known" kind of problems, so I would just like to pre-empt it by learning more.

Perhaps I have been reading the wrong books, so can you point me to some good java books to read. Or is it the case that books are just to teach you the syntax, while the intricacies of java and the API should just be discovered the hard way. Or I should just read the entire API (granted the API mentions "Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.") and I admit that I didn't read it the first time round.

+12  A: 

I think this applies to almost any language these days:

DO IT

Yup, nice and simple: work out a project, and do it. Write it. Refactor it etc. And just keep going. All languages are the same these days*, but the libraries are vast and different - and thats the bit that takes ages to learn.

So sorry - I can't think of a way to improve your knowledge, short of sitting down and doing something using Java - and learning from that.

Failing that, look on code.google.com for opensource apps and learn from how they do stuff - work out how they hang together, hack something new one it (even if you never submit it back), just to see how you interact with the objects.

*ok, stuff like Erlang and F# are very different to C# and Java, but it holds I think

Nic Wise
+1  A: 

Books will rarely give you a hands on experience of "Real-world" problems. You need to pratice, read forums, Stackoverflow, blogs etc ...

You can take it further, by challenging yourself to try to implement solutions for questions you think you can resolve, this helped me a lot to learn Delphi. You'll get a picture of the problems facing a developer in that field.

CheGueVerra
+1  A: 

Several suggestions come to mind:

FLOSS - find a project on sourceforge (or similar) that looks interesting, download it, and start going through the code.

Documentation - go through Sun's full javadocs; yes, it takes a long time, but it's worth it if you're going to be writing Java regularly.

Document - find a project from sourceforge, work, or somewhere, and document what everything is doing in it.

Books - this is highly subjective, but I like the Black Book and Unleashed series, and O'Reilly books.

Practice - write code and see what happens: it's 'just' code, and can't hurt anything, so try new things and learn through experience.

warren
+2  A: 
  • Write lots of code. I don't care what you write, just so that you write lots of code.
  • Consult the API docs frequently while you're writing; you'll eventually start to memorize them.
  • If it's books you want, read anything by Josh Bloch.
Michael Myers
+4  A: 

I find that the "Head First" books on Java are easy to read and full of information. you might give Head First Java a try. I know for sure Head First Patterns is very good.

If that isn't enough give a thought to Sun Certified Programmer related books. The SCJP exam is quite boring but does concentrate on the little details which are important.

Don't try to read the API. It's good to know what's there but the API isn't all that great. It is sometimes a bit inconsistent, and furthermore, due to the focus on compatibility there are some aspects which would currently have been implemented differently (if at all).

extraneon
+17  A: 

I would definitely recommend reading Effective Java, by Josh Bloch, for starters. I can't overstate how instrumental this book has been in making me a much stronger Java programmer. There is a whole chapter devoted to making proper use of methods inherited from Object, for example. It also covers generics, concurrent programming, enums and much more. It can make you more aware of Java language features in particular, but also a better programmer overall. At my current and previous job, I participated in a group reviewing the book, one item at a time. This provided for useful discussion on the items and everyday application.

The other hands on thing you could do is to solve problems from Project Euler. Having real problems to solve really helps in learning a language. This is how I plan to learn Scala.

Julie
Effective Java is pretty much the only Java book that matters.
Dan Dyer
That's not true. There are quite a number of Java books which are quite good, but get specific about subjects within Java. "Concurrency in Java" by Brian Goetz comes to mind as a great example.
Spencer K
+1  A: 

Effective Java by Bloch. Always on my desk. One of the best practical language books I've read (and it's short!)

eschercycle
A: 

If you have a basic knowledge of programming already then do yourself a favor and go for SCJP certification. It will go through the language step-by-step and teach you all the nuances and you'll have something to put on your resume when it's all said and done.

I read the 1.5 version of this book, but now it's 1.6. I'm assuming it's largely the same and this book was great. Very detailed, easy to read, etc:

http://www.amazon.com/gp/product/0071591060

MattC
A: 

There's an awful lot of material on how to improve in a given language, and more generally, how to improve as a programmer. For myself I find that there are a number of (nearly) discrete stages in this process and that simply getting recommendations doesn't quite reach it as some recommendations, though excellent, don't really apply to where you're at. roughly,

For me it looks something like this-

  1. basic syntax, basic fluency with the language. Mostly "Learn in 21 days" types of books, stuff to get you started. Sounds like you're probably past this. Good exercises are small algorithms, things that let you practice control structures and such - sorting, things like that.

  2. learning the api's and common libraries. How do I write a file again? where's that function to iterate through maps? etc. etc. Best practice for this is to write larger applications that force you to try to figure out practical bits.

  3. Patterns, idiomatic code style, also lots of material here, tends to be less language specific. Questions that tend to come up on larger projects and don't seem to make sense or feel necessary until your projects reach a certain size. GOF design patterns book, Josh Bloch's Effective Java, Fowler's "Refactoring". Bear in mind that lots of people writing commercial code don't get this.

  4. ...

So what would be useful for you depends mostly on what problems cause you the biggest roadblocks. In terms of idiomatic API useage Josh Bloch's books are great, as others on this thread have mentioned.

Steve B.
A: 

I think if you are looking to master the Java language, I would start by preparing to take the SCJP exam. Preparing for this exam will teach you many real world intricacies that you will face. After that I would suggest reading Effective Java by Josh Bloch. As you are working your way through these books I strongly suggest developing a personal project, one that is complex enough to cause you some headaches and flex your newly toned Java muscles.

Good Luck!

Rich Kroll
A: 

Get a mentor. Find someone who has been coding professionally, and when you have a question on why something has been implemented a certain way, ask that person for their input. Also see if they would review your code from time to time, providing maybe a different take on how they would implement parts of your code. It can open up a dialogue on coding styles and implementations and hopefully give you a different look at a problem.

Spencer K
+1  A: 

I've been working for several years now and still learn new things all of the time. Learn by doing, and talk to your peers about your code (code reviews or otherwise).

bpapa
A: 

Even in these days of the internets, Java in a Nutshell is actually a pretty useful book. Mainly, I think, because you can see the API structure and browse it at leisure. Use this book to get a feeling for the bits of the libraries which you will be using all of the time: collections, reflection, String, io (I could go on).

Otherwise, Effective Java is just a fantastic book and it has been recently updated with new material following the changes to the language in v5.

You will only get better through practice and it will take a long time before you rate yourself highly. I think pretty much everything I wrote in my first 5 years was probably rubbish. Don't mistake "complicated" for "clever"; simplicity is clever!

oxbow_lakes
+2  A: 

In college?

Make sure to take a co-op or internship. Using the language in a real work place will push you and force you to improve your knowledge. You will also have mentors available to review your code and comment.

The internship will also make you stand out when it's time to graduate and get a job.

Ken
A: 

Effective Java is the gold standard here.

Fortyrunner
A: 

i am a newer of java

sundar
+1  A: 

I suggest regularly running Findbugs on the code that you write. It will flag up patterns of bugs, for instance, if you had overriden equals() and not hashCode(), Findbugs would have reported a bug, and given good detail about why it is a bug.

It is obviously not intended to teach you design or anything like that, but it will give useful feedback on the code you write, helping you to improve your Java knowledge.

Grundlefleck