

Ask YC: Best book for Java - kashif

I am working on a project that the client wants in Java, specifically using Struts. Any recommendations on a good book for learning Java for an existing programmer? time as always is a scarce quantity.<p>EDIT: Web Programming in Java
======
rcoder
If you haven't done web development with Java/Struts before, you actually may
want to reconsider whether taking this project on with a tight deadline is in
your best interest. The tool ecosystem is very different for the Java web
developer, and I'm afraid you may find yourself spending more time reading API
docs and puzzling through XML configuration files than actually writing code.

If the client wants Java/Struts code for a _good_ reason (like they have in-
house programmers who can maintain Java webapps) your first Java project may
not be up to the standards they expect. If they want it for a _bad_ reason
(say, because the CIO read about it in an in-flight magazine) then you should
be able to push back on the decision and choose a framework with which you're
more comfortable.

~~~
delano
You will be able to pull it off if you learn well under pressure. Java is
consistent so it's easy to learn the basics quickly. There are some things
that are good to know upfront, like j2d2's comments. I'll also add:

6) It's easy to be verbose in Java and verbosity can quickly tie you into a
certain design. Either plan for more learning/design time early or spend that
time learning Eclipse (fwiw, I personally don't enjoy using Eclipse, but many
people do and it does make refactoring a lot easier).

7) Choosing between similar datatypes can have unexpected impacts. This is re-
wording of j2d2's #3. See also:
<http://www.google.com/search?q=java+vector+vs+arraylist>

re: Struts 2 specifically, I like it. It's a reasonable and well-designed Java
framework. I've used WebWork (which became the codebase for Struts 2) and
Struts 2 for several successful projects. (Success in terms of delivering on
time and the hand-off to internal developers).

~~~
rcoder
Learning the basics of the Java language is indeed pretty easy. The syntax is
fairly consistent (assuming you ignore generics and annotations to start with)
and the core class libraries are useful (if a bit eclectic).

Regardless, the original poster didn't ask about learning "Hello, World!" He
asked about ways to learn both the Java language and the Struts stack on a
tight schedule in order to deliver a project to a paying client.

That's a tall order, and one I don't think most people can pull off without
expert mentoring. There's just too much material to absorb, and having so many
unknowns going in to a project will make cost estimation very difficult
indeed.

The original poster might be able to reasonably offer a discounted billing
rate and/or more relaxed delivery schedule in order to manage expectations,
but I personally haven't encountered many people doing hired-gun J2EE
consulting on the cheap.

------
richesh
I'm assuming you are looking for Struts 2, if this is the case there are only
few good books out there. I own all these books below and they are useful, but
they are not as updated as the latest release. My suggestion to you is to keep
an eye on the struts 2 wiki and join the mailing list to get the latest
information.

1\. Practical Apache Struts 2 Web 2.0 Projects (Practical Projects) by Ian
Roughley - [http://www.amazon.com/Practical-Apache-Struts-Web-
Projects/d...](http://www.amazon.com/Practical-Apache-Struts-Web-
Projects/dp/1590599039/)

2\. Starting Struts 2 by Ian Roughley - [http://www.amazon.com/Starting-
Struts-2-Ian-Roughley/dp/1430...](http://www.amazon.com/Starting-Struts-2-Ian-
Roughley/dp/1430320338/)

3\. Struts 2 in Action (In Action) by Don Brown, Chad Davis, and Scott
Stanlick - [http://www.amazon.com/Struts-2-Action-Don-
Brown/dp/193398807...](http://www.amazon.com/Struts-2-Action-Don-
Brown/dp/193398807X)

------
coglethorpe
I'm developing a webapp in Java/Struts for a client now and have found the
internet (a variety of sites, via search engines) to be my best resource. I
don't think I've used a book in years now.

Here's a few I've run across:

<http://www.theserverside.com/>

<http://www.developer.com/>

<http://www.javaworld.com/>

There's a ton more.

And the sources, of course:

<http://struts.apache.org/>

<http://java.sun.com/>

I use MyEclipse to develop and it's pretty helpful and has Struts support:

<http://www.myeclipseide.com/>

~~~
delano
This also:

<http://www.infoq.com/books/starting-struts2>

------
j2d2
A few things to remember when programming java:

1) It's _not_ pass-by-reference. Java is pass-by-value, but it is passing
pointer values, not variable values. This sometimes behaves like pass-by-
reference but if pass a from foo() to bar() and call new on a inside bar, a
will get it's old value once bar() returns to foo().

2) Eclipse has a tremendously useful debugger and, as an emacs guy, I can
vouch for Eclipse being well worth learning. You can change code in running
programs, but beware it reruns whatever method you're in. Sometimes (possibly
all times) without resetting values changed in that method.

3) Use interfaces when you can. Map instead of HashMap, etc.

4) Leverage the classpath for testing bugfixes easily. Create a jar with your
_fixed_ class, put it in front in the classpath. Keeps things simple and let's
you build upon anything you shipped to a client.

5) If you have to use RMI, understand why readExternal() must reflect the
order of things from writeExternal() and how this can break easily. This
specific case may not be useful to you right now, but it will help you
understand what RMI, and serialization in general, is actually doing.

I'm sure there are other good lessons but it's been a while since I worked
with someone new to java.

------
strlen
Bruce Eckel's _Thinking in Java_ (available free online, just as are his C++,
Design Patterns and .NET books) is excellent, combined with just API
references.

------
pbnaidu
I would also read Effective Java along with Struts related text book. Here's
the link to the book [http://www.amazon.com/Effective-Java-2nd-Joshua-
Bloch/dp/032...](http://www.amazon.com/Effective-Java-2nd-Joshua-
Bloch/dp/0321356683/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1213823747&sr=8-1)

------
hello_moto
Kashif:

1) Head First Java 5 1) Effective Java

The strategy here is to study both interchange; once you learned a topic from
HF Java 5, check the best practice in Effective Java.

2) Head First JSP/Servlet 2) Any Struts 2 book

You can start with the basic few chapters from HF JSP/Servlet and move on to
Struts 2. If you found alien concepts in Struts 2, check back HF JSP/Servlet.

------
dedalus
Just Java by Peter Van der Linden is an exceptional introduction thats
comprehensive and well thought out (may be not just for complete newbiee)

<http://www.amazon.com/exec/obidos/ASIN/0131482114>

------
jsmcgd
If you read this book you will _know_ Java.

<http://www.deitel.com/Default.aspx?tabid=1191>

Highly recommend.

~~~
silencio
I had one introductory Java class that used that book and I didn't find it
very helpful. I ended up using it literally as a doorstop after the prof
suggested we do so as a joke, only kept it to do the assignments from the
book, and went with Eckel's Thinking in Java instead.

That was a few years ago and a couple editions back..but I think some of it
was personal preference/frustration. It's been a while so I forgot what my
particular gripes were..I thought the introductory stuff was okay but (iirc)
what ended up happening was that the book didn't cover anything particularly
advanced that I wanted to know more about, which at that point was probably
things like JDBC and JavaServer...things...I guess back then it was JSP and
servlets, it looks like they dropped that for JSF in the newer editions.
Obviously I can't expect a book to cover everything, but I mean I was
expecting at least a gloss-over of the more advanced topics.

Plus, if I remember correctly, a new edition of Thinking in Java was less than
half the price and an older edition is available online for free. Sooo...

~~~
jsmcgd
I initially hated the book. I though its attention to detail was anal at best.
But if you took the time to read it all, it really did cover a lot and I felt
that I had a solid and complete understanding of the concepts (not a feeling I
get when reading most other books).

True it didn't cover the advanced stuff which is why I bought 'Advanced Java
How to Program' as well.

------
huhtenberg
Go over "How to Win Friends and _Influence People_ " by Dale Carnegie and then
convince them to stay away from Java.

You will benefit not only yourself, but the humanity as whole :)

~~~
dgabriel
Replies like this are incredibly unhelpful. I suppose google uses Java because
it's such a destructive force.

I recommend starting here -
<http://en.wikibooks.org/wiki/Java_Programming/Struts>

~~~
gaika
Google has different cost structure, most companies pay a lot more for
programmers' time than they would pay for hosting an app. Developing in web
frameworks like rails and django is 5-10x more effective and is totally worth
time switching. Also you can host rails app on java app servers today with
jruby.

------
Tichy
I started with the Java tutorial. Back then I really liked it. Not sure if it
is still as good (feature creep), but might be worth a look.

------
xlnt
SICP

~~~
RyanGWU82
This is an absolutely terrible response. Did you even read his question? The
original poster is already an experienced and proficient programmer. He just
needs to understand the syntax and concepts of a new language.

SICP uses Scheme, not Java. SICP does not teach Java's syntax, nor object-
oriented fundamentals, nor web development with Struts. What possible
rationale makes this a good suggestion?

~~~
xlnt
Why so harsh? I think he'd be better off reading SICP than a java book,
despite the _short term_ reasons to do otherwise. And so what if it's in
scheme? if he can't understand scheme then he's not a proficient programmer.

~~~
silencio
I'd have to disagree, because the short term reason is a pretty big one.

Not saying SICP sucks, I think the original poster would benefit from reading
it..but at this point if he/she/it is working on said project NOW and needs a
good Java/Struts book NOW, SICP isn't going to be that helpful.

Only in the long run.

~~~
xlnt
I understand that some people will disagree. I might be wrong. That's no
reason for him to be harsh. It's good for the poster to get a variety of
advice.

------
albertcardona
Please save yourself from the limitations in java syntax and use
clojure/jython/scala. Clojure is my favorite -native java speed but lisp
syntax, and awesome lock-free multithreading.

What your client really wants is the JVM and its libraries, not java the
language.

~~~
icey
I don't know anything about Jython or Scala, but I do know that Clojure does
NOT have native Java speed.

Clojure objects are Java Objects, so they must be boxed & unboxed by the JVM.

Clojure is decently fast, but well-written Java will continue to smoke it for
some time to come.

~~~
richhickey
> Clojure objects are Java Objects, so they must be boxed & unboxed by the
> JVM.

I presume you meant Clojure numbers, because there is no notion of 'boxing'
for reference types. For all non-numeric objects, the Clojure representation
is the same as the Java representation. Type-hinted calls to methods of said
objects generate the same bytecode as Java, with the same performance.

As far as numbers, recent enhancements (
<http://clojure.org/java_interop#primitives> ) allow Clojure to produce
primitive arithmetic with the same speed as Java, but with a more-powerful,
macro-amenable syntax.

While Clojure offers higher-order constructs with an attendant, but not
prohibitive, cost, performance-oriented Clojure code can match the speed of
Java.

~~~
icey
Rich, you're seriously some kind of linguistic superhero. Or maybe like the
Monty Python version of the Spanish Inquisition. Either way, it's impressive.

This:

    
    
        As far as numbers, recent enhancements allow Clojure to 
        produce primitive arithmetic with the same speed as Java, 
        but with a more-powerful, macro-amenable syntax."
    

Just blows me away.

