You can definitely learn online but books aren't so bad.
This one seems good for online.
for books, just get the book that has the highest rating in Java.
I have to say Java is Easy to Learn but Hard to Master. Just learning Java itself will not get you very far in career. Here are the top Java frameworks that the industry are looking for.
Spring Web Service
Hibernate / JPA