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?

17 of 99 comments (clear)

  1. My advice, take it or leave it... by rixstep · · Score: 1, Informative

    My advice, take it or leave it...

    Switch jobs fast. You do not want to get into C++. It's a freaking mess. Remember Alan Kay, father of OO? Here's a quote:

    I invented the term 'object-oriented' and I can tell you I did not have C++ in mind.
    -- Alan Kay


    1. Re:My advice, take it or leave it... by the+eric+conspiracy · · Score: 2, Informative

      I did not have C++ in mind

      LOL. You know he won the Turning Prize for SmallTalk.

  2. 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!

  3. 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.

  4. 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.

  5. 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.

  6. Re:Ask Slashdot: where Google Morons ask questions by Webmonger · · Score: 2, Informative

    Not actually that useful. They don't mention smart pointers in the memory management section. They claim C++ has no string type. Not good.

  7. Re:Ask Slashdot: where Google Morons ask questions by InterventionOne · · Score: 2, Informative

    The link in the above post (see parent) seems to be broken for me. I don't know if this happens to be the same book as the one above...

    This is the book that my Survey of Programming Languages professor suggested for those of us who came in knowing Java but not C++.

    It's nice in that it compares and contrasts many features of both languages (including quite a bit on the STL and writing templates in C++), but I found myself wishing it would have gone into more detail several times - my one gripe is that it doesn't do much more than scratch the surface in several instances.

    (apparently, there's at least a couple of "C++ for Java Programmers" books on amazon alone...)

    A couple of reference sites I've used in the past:

    C/C++ Reference

    C++ Library Reference

    (Personally, I still shy away from C++ whenever I can...I certainly haven't gotten a comfortably firm grip on it yet.)

  8. 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.

  9. You'll Miss the API by pitfiend · · Score: 2, Informative
    First off, you're going to miss the Java API. I just spent the last semester in your predicament. I have a strong Java background, but I was forced to TA an intro to C++ class. I found that our text "C++ Effective Object Oriented Software Construction" by Kayshav Dattatri was a very good intro to C++ if you've got a Java background. He tends to make comparisions to Eiffel or Smalltalk, but Java comes into the picture often (and its pretty close to Smalltalk in a number of ways).

    Also check out www.cppreference.com. I have found it to be significantly more useful than the STL reference at SGI.

    To paraprhase Mark Twain, the rumors of the performance of C++ have been greatly exagerated. The advantage you get from cross platform compatibility and a fantastic API far outweigh a minor performance hit.

    1. Re:You'll Miss the API by E_elven · · Score: 2, Informative

      C++ is cross-platform. You just have to compile it separately for each target.

      Anyway, a few posters seemed to mention the Java API -or the SE part in J2SE, which to me seemed to be an alright compilation when I toyed around with Java. One should remember that C++ has all the libraries Java does, usually more and in various forms for one to pick and choose from. Google is one's friend for library-hunting aside from the nigh-obligatory boost.org libraries.

      --
      Marxist evolution is just N generations away!
  10. 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
  11. C++ for Java Programmers, by Razzy · · Score: 2, Informative

    by Timothy Budd, may be what you're looking for. My uni taught intro cs in Java but in our OO development class, C++ was the language of choice. They threw this book our way to ease the transition. It didn't hurt, although Stroustrup's book, Meyers' Effective C++ and STL, and Lippman and Lajoie's C++ Primer are more useful in the long run. Also pick up a nice STL reference like Josuttis.

  12. Re:You don't need a Java to C++ book by hummassa · · Score: 2, Informative

    Bruce Eckel's Thinking in C++ will help, also...

    --
    It's better to be the foot on the boot than the face on the pavement. ~~ tkx Kadin2048
  13. 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.

  14. Re:C++ THEN Java by Nicolay77 · · Score: 2, Informative

    I learned Java first, and then C++ with wxWindows (now wxWigdets).

    The change was so welcome that now I use C++ with wxWin almost exclusively, even if somethimes I have to use Java (because someone pays me to use it).

    It has not only GUI classes but several data structures and system functions that make very easy to leverage the operating system API without actually going down and using it. Try to make a nice screensaver in Java.

    There is something I miss from Java, because I have to implement similar things in C++ and is serialization. That's where the difference between C++ and Java lies to me. ODBC is also better in Java, but there are ODBC libraries for C++.

    I find almost everything else better in C++. But remember, do not use features of the language that you do not fully understand. Just because C++ has templates, it doesn't mean you have to use them just to feel like you're using C++. The same with multiple inheritance, in fact, never use it.

    And compared to Java, good C++ is fast as hell. The right tool for the right job, bla, bla, bla, etc...

    --
    We are Turing O-Machines. The Oracle is out there.
  15. Why hasn't anyone recommended Thinking in C++? by techstar25 · · Score: 2, Informative

    You can't go wrong with Eckel's Thinking In C++. You can download it for free. Or buy it. It seems to have been designed for C programmers moving to C++, but for free it makes a great reference (picked up a hardcopy of an old edition on half.com for $3, just because I like hardcopies, although I keep the current softcopy nearby).