I would suggest you try Head First Java 2nd edition by Kathy Sierra and Bert Bates. Since it is now an old book, you can probably buy a second‑hand copy for a very low price. You will probably want other books when you are more experienced.
There is a whole section in the forums about books. Here are my suggestions:
If you are not a programmer already, or if you learn better visually, I would suggest Head First Java. If you are already a programmer or if you learn better from text books, I would suggest Java in a Nutshell.
All things are lawful, but not all things are profitable.
It's not realistic to expect a single book to cover all concepts about Java. For one, Java is evolving. Secondly, the scope of the Java platform is huge and authors have deadlines so they have to make compromises on what kind of things they cover in their books. Maybe if you get five books about basic to intermediate concepts specific to Java, you could considered that set as having adequate coverage, enough to give you a good foundation at least. But the language itself is only part of the puzzle. I have literally over a hundred books about programming, design, and software development. Maybe a little more than half of those having a focus on Java for their examples but the topics covered by these books are just as or maybe even more important than features of the Java programming language and platform.
Apart from Head First Java, I would also suggest Thinking in Java from Bruce Eckel. I've recently read that book and dare to say it's really great. Not just that it really makes you to think in the language (means use it the way it is supposed to be used), but also covers a lot of details, important API parts and touches other topics like design patterns as well.
Herbert Schildt isn't exactly a very reliable author, but I am really comfortable with his writing style. The book has 17 chapters, and most chapters are about 35-40 pages in length. His writing style is very comfortable and easy to read. I can pick up one chapter and can burn through it within few hours or few sittings. The major problem of this book is it's mistakes. The worst one I've found so far is when the author says, java uses pass-by-reference for reference type variables. It's wrong. Java is always pass-by-value for both primitive and reference type. But there shouldn't be many mistakes like this. The only reason I'd suggest this book if you want to get a hold onto the basic concepts really quickly, and you'll willing to go to external resources without hesitation whenever a question pops in your head. I am reading the book for the last one month and I am more then halfway through.
But if you really want to dig deep and time isn't your major concern, I think Thinking in Java (4th Edition) can be a good choice. I've picked it up before I started reading Herbert Schildt. Bruce Eckel goes deep and the progression of his book is slow(compared to Herbert Schildt). It would have taken me more than 4-5 month to complete Thinking in Java.
I tried Head First Java before and didn't like it. I guess in case of learning anything new - you should pick something that goes over the fundamentals very slowly, so you mind get enough time to settle in.
Note : I am beginner in Java, but have previous experience in C and C++.
Quazi Irfan wrote:The major problem of this book is it's mistakes. The worst one I've found so far is when the author says, java uses pass-by-reference for reference type variables. It's wrong. Java is always pass-by-value for both primitive and reference type. But there shouldn't be many mistakes like this.
I was wrong!
I was reading the chapter about Threads, where the author was introducing the relation between parent thread and child thread. This is wrong as well. By default. I am not continuing reading this book. In fact, nobody should.