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.
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.
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).
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).
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.
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) 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.
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.
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.
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.
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.
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...
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.
Correction: if you read, understand, and write code based on that book you may legitimately claim to know Java.
Reading books about programming languages teaches you about as much about programming as reading sheet music does about composing. It's a key prerequisite, but not the same thing.
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?
Totally off topic, but this reminded me of the scene in Office Space where Samir reacts to Tom's 'Jump To Conclusions Mat' product idea: 'Yes, this is horrible, this idea'.
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.
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.
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.
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.
While slightly off topic, albertcardona may have a point here. This deserves some clarification. It may be that they specifically need Java if they're going to have some in house programmers maintain the application later, but if all they're really interested in is the JVM then you've got some options you may want to consider. I don't want to stray too far here, but one thing I've noticed about many Java people is that they have very narrow views of what's good. (Don't flame me. I'm a Java developer myself.) Maybe they're just playing it safe. It seems to be a common theme with Java. Basically, for several years now the prevailing attitude has been that Struts is the only game in town, but there is a world of other good options for the JVM.
Anyway, back on topic... If you must go the Struts route do yourself a favor and use Struts 2. It's been a little while since I've been in the Java web development world, but when I was keeping up with it a lot of developers still hadn't moved on yet. It's light years ahead of Struts 1 and really not so bad to work with as far as Java web development is concerned.
Some others have mentioned 'Thinking in Java'. It's a great book for those new to Java and especially object oriented programming. A seasoned programmer may find it a little verbose. Either way it's free to read online so it's probably worth checking out. If you're looking for something a little smaller to digest you might want to check out Sun's tutorials, and the Java API docs are invaluable. The language itself is simple; it's knowledge of the standard libraries that separates a good Java developer from a mediocre one.
'Effective Java' and 'Hardcore Java' (specifically the chapter on the Collections API) should be mandatory reading for Java developers as well so you may want to check those out once you get up to speed with the language.
For learning Struts, I'd check out the online docs first. Last time I checked they were pretty good. If you still want a book, I've found the 'In Action' series from Manning Press to be good.
> 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.
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."
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.