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?
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
This is probably the best tutorial I've come across for the Standard Template Library.
Good luck!
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.
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.
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.
Not actually that useful. They don't mention smart pointers in the memory management section. They claim C++ has no string type. Not good.
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.)
Ok, now having actually read the link, here is a list of things that are either actively wrong or totally unhelpful:
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:
Christ. This is from 1998. No wonder it's got so many issues.
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.
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
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.
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
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.
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.
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).