I'm an experienced C / C++ programmer who now has to learn Java. Is reading The Java Language Specification a useful and efficient way to get up to speed or is there some better resource, say something similar to the wonderful Accelerated C++ by Koenig? Currently I'm reading Java Software Solutions and am finding it quite slow and mind numbing.
Coming from the C++ side, I learnt Java by using three things:
- The Java Language Specification
- The Java Pocket Guide
- Collections of Java source code of reasonable quality. In my case I flipped through a lot of the Apache Project's source code.
I'd say you can learn Java as language from the JLS in the same way you can learn mathematics by reading books; it won't do you any good until you actually sit down and start applying the theoretical skills you have accumulated.
In general, I think best way to learn languages is to learn their idioms and work from there. For example, language can be object oriented, procedural, functional or any combination of these, may be built on automatic or manual resource handling, uses actual syntax to denote importance of certain elements (for example several languages nowadays equal \n
to ;
and others use whitespace as block identifiers).
I would recommend Head First Java first. Then, Effective java. Generics FAQ of Java, which is available as downloadable PDF too.
C++ syntax is pretty close to Java. The semantics are, however, somewhat different especially in terms of the object hierarchy tree.
If you are an experienced C++ coder, I would consider having a look at one of the many "Java for C/C++ programmers" cheat sheets to get the important points and then work my way through the Learning Java part of the Java Tutorial. You need to get it in through the fingers, and the exercises for the Java Tutorial are okay for this purpose.
Then you have your drivers license, and can dive into learning the Java Runtime Library because it is just huge and it will take some time to learn.
Reading the language specification is not an efficient way to get started learning the language. It is a document written for a very different purpose. It is well suited to getting the details and nuances right. Java is a less complex language than c++, and I found the need to refer to the specification comes up less often.
From a practical point of view, what kind of java do you need to learn? Do you need to fit into an existing project using lots of old style java, do you need to get up to date with the latests enterprise frameworks and tools, do you need to do some JSR work?
One of the key features of current-day Java is the huge, active open source community and the many tools/libraries/frameworks available for anytyhing you'd ever need to do. Learning just the Java language (which you might be able to do as you describe) is usually not enough to be productive in any serious Java project. Besides learning the language, take a look at the frameworks you are likely to need. In a typical J2EE environment you might encouter:
- Build management: Maven, Ant
- Dependency injection: Spring, Guice
- Persistence: Hibernate, iBatis, JPA, JTA
- Application container: Websphere/Weblogic/Glassfish/Tomcat/Jetty
- Logging: Log4j, Commons logging, SLF
- Web framework: Struts 2, Tapestry, Spring Web MVC, JSF, GWT, Wicket
There is a lot more where that came from... Check which stuff you are likely to need and start with that.
Why not give The Art and Science Of Java a try? It scores in its content.