简体   繁体   中英

Best approach for learning Java after C++?

I've been using C++ for about 6 or 7 years now, and I consider myself fluent in it. I've never bothered with Java until now, but I find myself out of the job (company went under) and I need to expand my skill set. Someone recommended Java, so I am wondering if there is any advice for where somebody like me might start. I am also interested to know what the key aspects of Java are that are most likely to come up in an interview.

There are some popular areas that I think of when we talk about Java

  • Concepts of OOP : I'm sure this will not be much different from C++: Class, Abstract Class, Interface, Polymorphism, Overriding, Overloading, Inheritance, Static member, ... Interface will likely be area that you might want to focus. Since this is not directly available in C++, I don't know.
  • Core Java : Such as the basic syntax and the common classes such as Math, String, System.out, Scanner, Basic file I/O, Stream. Know the concept of Garbage Collection, Reference Type (since pointers are not available here.) Know the Java platform/technologies, J2SE, J2EE. Basic GUI with Swing and its layout managers. Web Applications with Servlet/JSP.
  • Popular tools, frameworks, and libraries : This may not as important as above bullets. But maybe you should know what Eclipse, Netbeans, Spring, Struts, Hibernate, EJB, Ant, JUnit, JavaDoc, are for.

You can always search for "C++ to Java" in Google. I'm sure there will plenty of good start points. Don't forget not to put * in front of var name next time you code Java :)

I recommend you read the book Effective Java cover to cover. Not only will you learn lots of good programming practices, but you will also learn more about Java than you otherwise would. Highly recommended. :-)

As a simple example, in Java, rather than rolling bitfields by hand (which is rather painful to do in Java, and for good reason), you use an EnumSet instead. This is documented in Item 32.

BTW, if you don't mind reading a PDF (no DRM) version, it's cheaper than hardcopy too: http://www.informit.com/title/0132345285

There are a number of great "in depth" Java books that will teach you not only Java, but also best programming practices.

If you're just interested in syntax and an introduction to the Class Hierarchy, Java in 24 hours is pretty good. From there, you will know enough to go and explore more on your own.

I highly recommend thinking of a small project to help you learn. In fact, think of a teeny tiny project -- it will turn out much bigger than you think! ;) Maybe a simple shoot-em-up or a Daleks - or Asteroids -alike, or some such.

The main thing being: for an expert-level programmer, don't try to learn Java from a book. You can get introduced to Java via a book, but then you have to go learn on your own (or from another.) It's like learning to drive a car -- you can get the basics from a book, but you need to explore & try stuff, and someone who knows how can be very helpful.

Some things that will help:

  • Download and bookmark the HTML Java docs. You will reference them often.
  • Have a small project, a simple game or utility app that you estimate will take a couple of days to write. Spend a couple of weeks writing it ;)
  • Note that "Java" is 3 things:
    • Java the programming language. Like C++ or Lisp or Perl.
    • Java the Class Hierarchy. Like STL or Cocoa.
    • Java the run-time virtual machine, the JVM.

People use the word "Java" to mean all 3 things, and slip between them without much notice, so pay attention to that, when you start talking Java to people.

Good luck!

(And let us know when your game is available :)

The biggest issue with the C++ to Java conversion is that they're so similar -- you'll find yourself doing C++-isms for a while. But it's no big deal: as suggested, read Josh Bloch's book, and run through the tutorials on java.sun.com and you'll do fine.

In my opinion, Java sets itself apart from C++ in three ways:

  1. Automated memory management
  2. Simplified syntax (and no preprocessor)
  3. The Java standard libraries

As a former C++ guy, the first two shouldn't be a problem. (In fact, I would wager they will strike you as rather refreshing.) To get used to the libraries, I recommend Bruce Eckel's Thinking in Java - the 3rd edition is free to download. Though the beginning chapters will probably be a little too basic, the sections about GUI programming, concurrency, and the various container classes will be very helpful.

Beyond that, the best way to learn any language is to read good code.

I started by reading the Java Language Specification, version 2 at the time (2001). In my view it is quite readable as specifications go.

Effective Java is good advice.

Java Puzzlers is good to learn corner cases and possible pitfalls.

Peter Norton的Java编程指南, “从C / C ++过渡到Java”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM