Slashdot Mirror


Learning C++ for Java Programmers?

The Real Joe Faith asks: "The O'Reilly book 'Java in a Nutshell' used to include a really handy introduction to Java specifically aimed at C++ programmers. It meant an experienced programmer could re-use their knowledge and get up to speed quickly. But what about going the other way? I know a fair amount of Java but, for my sins, have always avoided C++. Now I need to learn it. Fast. Not just the syntax, but also about the various standard libraries out there. Now that Java is the standard language on most computer science courses I guess there will be a few people in the same boat. Can anyone recommend a good book (or any other information source)?" For those Java programmers among us who have gone this route, what books did you use to assist you in the transition to C++? How well did these books work for you?

7 of 99 comments (clear)

  1. STL is important by magefile · · Score: 4, Informative

    This is probably the best tutorial I've come across for the Standard Template Library.

    Good luck!

  2. no API by baylorhawk · · Score: 3, Informative

    Well, I can't recommend a book, since I learned C++ first, but I have a warning...there is no definitive API. I imagine that would be a stumbling block for Java-to-C++ converts.
    However, might I recommend this for the STL?
    I think that in searching for a book, you should probably look for one that highlights the differences between the languages. That helped me when I was learning Java, and it's probably the quickest way you can pick it up. Have a look at Amazon and just search under books for "java c++". The first few entries are aimed at this. I can't vouch for these books, but hey, that's what I found.

  3. book we use for 15-113 by viperstyx · · Score: 4, Informative

    heres a book that was suggested by my professor here at CMU for our intro to C class: "C for Java Programmers" by Thomasz Muldner" ISBN: 0-201-70279-7 not exactly c++ but may be you can find something like it. in anycase, should help others.

  4. Re:Do us all a favor by baylorhawk · · Score: 4, Informative

    The parent post has a point. C++ is a difficult language to pick up quickly. My college has 3 C++ courses that are prereqs to just about all the other cs courses, and I still didn't learn it well until my senior year when I had to use it again.
    Learning C++ for any practical use will take time and practice to learn all of the nuances, especially the copy constructors, operator overloading, and all of that junk.

  5. Re:Ask Slashdot: where Google Morons ask questions by boneshintai · · Score: 3, Informative

    Ok, now having actually read the link, here is a list of things that are either actively wrong or totally unhelpful:

    • No mention of std::vector in the discussion of arrays
    • Deprecated pre-standard headers such as
      #include <pair.h>
      instead of
      #include <pair>
    • Introduces C-style IO (printf et al) before stream IO, even though Java provides workable streams and C-style IO is completely nonestensible in ways a Java programmer may be accustomed to
    • To declare a constant in C++, you use #define (not final) as in:

      #define MAX_SIZE 10

      No. Please use const instances. They're typechecked but the compiler is free to translate them into inline constants similar to what the preprocessor produces:

      const int MAX_SIZE = 10;
    • Macros (#define min(x,y) (((x)
    • void main (...) is totally wrong. Main is not permitted to be void in C++. Some compilers will allow it, but it is not a feature of the langugae.
    • C-style typedef struct {...} typename; is unnecessary in C++; structs essentially are handled as classes that default to public and as such the struct name is a type.
    • Unions.
    • "In C++, all parameters are passed by value." Unless they're passed by reference, anyways.
    • You do not need to use std::malloc to allocate a structure or a builtin type. The 'new' operator works just fine.

    Christ. This is from 1998. No wonder it's got so many issues.

  6. zerg by Lord+Omlette · · Score: 3, Informative

    My favorite book is Accelerated C++ by Koenig n Moo. It's C++ taught as a language w/ a library. It's not taught as C w/ classes tacked on as an afterthought. Check it out.

    You will spend the rest of your life learning C++, anyone who says they "know" the language is either lying or deluding yourself. After you're done w/ Accelerated C++, pick up Modern C++ Design by Alexandrescu. Also get a subscription to C/C++ Users Journal.

    --
    [o]_O
  7. The three needs of Java2C++ programmers by SilentJ_PDX · · Score: 4, Informative

    I was in the same boat a year ago. I think (good) Java developers needs are unique when approaching C++ because we already know about 80% of the syntax and concepts, but we need a quick way to get into the STL, tips on how NOT to hang yourself (far too easy in C++), and some sense of how C++ programmers organize code.

    For getting into the STL, I chose Accelerated C++ by Koenig and Moo. It is very basic at the beginning. However, it's not a 700-page behemoth (a Good Thing), it approaches C++ as OOP from the outset, and it starts using the STL from chapter 1. I'm sure you'll need a full STL reference after this book, but it serves as a decent starter. (I also have "The C++ Programming language" by Stroustrup and it's a bit too close to a language definition... good reference, bad primer)

    For the tips, Scott Myers books can't be beat. Enough people have heaped praise on them that I won't bother with it here.

    That leaves the last part of my education: "how do C++ programmers organize code". Unfortunately, the C++ world doesn't seem nearly as unified as the Java world. I started out doing things very Java-like, but decided that probably wasn't going to work if I eventually start coding with other people. Accelerated C++ has some tips. The C++ Programming Language also has a lengthy discussion on how to organize your code. Being the completely anal guy I am, I wanted to get it right the first time. Unfortunately, that's not possible. My style is still changing frequently as I see elements I like. I'm sure it will calm down if I ever get a job in a C++ shop.