Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Is there a canonical book for learning Java as an experienced developer?

Let me elaborate a little:

I used to be a C/C++ programmer where I used data structure concept like trees, queues stack etc and tried to optimize as much as possible, minimum no. of loops, variables and tried to make it efficient. It's been a couple of years that I started writing java codes, but it is simply not that efficient in terms of performance, memory intensive etc.

To the point:

I want to enter programming challenges using java so I need to improve my approach at things I program. So please suggest me some books that can help me learn to program better and have a chance in solving challenges in programming.

share|improve this question

marked as duplicate by ChrisF Mar 23 '12 at 11:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 8 down vote accepted

Java is somewhat more distant from the actual machine than C++ due to the JVM design. The general suggestion is to write very clean code so the JVM has the best possible conditions to compile it into machine code and know the various runtime implementations to choose the most appropriate at hand.

That said, the currently mostly recommended book to go from that is "Effective Java" by Joshua Bloch. See for ISBN numbers and links. Highly recommended.

share|improve this answer
+ 1 for Effective Java – artjom Mar 23 '12 at 8:57
@Ravn Andersen: looks nice thanks. Hopefully this book will be easier to start with. Then I can move along with books mentioned by Mako & gnat. – Abhishek Simon Mar 23 '12 at 10:06

I think Effective Java (already mentioned) makes a pretty good start.

For more comprehensive references list, my favorite is one at Angelika Langer Links - Java Performance:


"Java Platform Performance: Strategies and Tactics" by Steve Wilson & Jeff Kesselman
The book and related resources are available online at .

"Inside the Virtual Machine" by Bill Venners
Sample chapters of the book are available online at .

"Performant Java programmieren" by Hendrik Schreiber
Additional information (errata, links, downloads) can be found at .

"Garbage Collection" by Richard Jones & Rafael Lins An excellent book on garbage collection algorithms in general; more information at .

Links & Resources

Sun Microsystems A collection of links and resources at Sun Microsystems can be found at .

Jack Shirazi Further resources for Java performance tuning including a list of tools can be found at .

Articles, Papers & Specifications

JSR-163: Java Platform Profiling Architecture
The profiling architecture as designed for release in J2SE 5.0. The specification group's page can be found at .

WHITE PAPER: J2SE 5.0 Performance White Paper
The paper gives an overview of the performance and scalability improvements made in the J2SE 5.0 release along with various benchmarks to demonstrate the impact of these improvements. It has numerous links to further resources.

For deeper drilling into Java performance topics, articles by Brian Goetz in Java theory and practice and Threading Lightly series are hard to beat:

share|improve this answer
Great load of information. Thanks. I must start with Effective Java and then move along with your suggestions. – Abhishek Simon Mar 23 '12 at 10:08
Just for the record. Java is memory hungry and if the operating system starts to swap the Java program performance goes down quickly regardless of any performance trick inside the JVM. – user1249 Mar 23 '12 at 10:30
@ThorbjørnRavnAndersen agree, this is worth keeping in mind – gnat Mar 23 '12 at 12:17

Thorbjørn Ravn Andersen answered this really well, I'll put in a slightly different slant.

+1 - The JIT (Just In Time) compiler is generally very aggressive in its runtime optimisations and it learns as it goes. Keeping your methods to ~<35 byte codes for example will ensure that they get inlined and there are many other tricks as well. Also see Charlie Hunt's recent book on Java performance

share|improve this answer
@Martin: Nice information.. i'd like to know about such tips in java. Thanks – Abhishek Simon Mar 23 '12 at 10:07

Considering the fact that you were a C/C++ programmer that appears to understand how to do things efficiently, you can really just do the same things you did when programming in C/C++ to optimize Java code.

A great all around resource for data structures and algorithms, however, is Introduction to Algorithms (CLRS). All of the code snippets are java-style syntax

share|improve this answer
Thanks, also it's been quite some time doing things efficiently in C/C++, so I might need to brush up lot, but that would be in Java – Abhishek Simon Mar 23 '12 at 8:39
Performant Java also means playing along with the JVM, so it's not just like C++. In C++, you can optimize for the particularities of the bare metal; in Java, you need to optimize for the JVM. Particularly memory allocation behaves differently (bare-metal malloc() vs. JVM garbage-collected allocation), and you need to adapt to that. – tdammers Mar 23 '12 at 9:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.