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?
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.
That's probably because C++ isn't object-oriented. It's object capable, and probably better programmed in a generic style.
Anyway, if you want to learn C++ fast, I suggest getting a couple good books, a lot of coffee, and a compiler. It'll take a short year or so, but it's completely worth it.
This is not a flame - I'm a C++ fan. It's my favorite language. But if you think you can learn it well in less than a year, you're kidding yourself.
Fascism trolls keeping me up every night. When I starts a preachin', he HITS ME WITH HIS REICH!
I did not have C++ in mind
LOL. You know he won the Turning Prize for SmallTalk.
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.
Please don't code anything in C++ after learning it "fast." It's not that kind of language.
C++ is an excellent language, but it gives you enough rope to hang yourself, your immediate family, and maybe a few pets. Learn it fast, and you'll learn it wrong.
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.
My learning went from assembly ==> C ==> C++ ==> Java, and my advice to you is to not go from Java to C++. If you remember venn diagrams, imagine one circle as Java, Then draw circle next to it without intersection and call that one C. Now draw a circle that intersects Java and C, but also has its own distinct characteristics, and that circle would be C++. There is no way to learn C++ without learning C. If I were you, I'd learn C. Then once you learn C, your OO knowledge will make you question some things. Then C++ will make sense to bridge that gap. Learning C++, or C for that matter, is not going to be fast. And anyone who does learn it fast will be in trouble unless they're really talented. One thing is for sure, once you learn C/C++ you will REALLY appreciate Java. Good Luck.
mp3's are only for those with bad memories
Just be confident knowing that most of your basic skills will transfer, and get a normal C++ book. Personally, I recommend Stroustroup's book, and Dietel and Dietel is an oft used text. Most of those "Learn C++ in 24 Hours!" types of books are a waste of trees. Like others have said, it's crucial that you get something that covers STL (both the ones I mentioned will). It's C++'s version of a class library. You'll find it a little thin after working in Java, and that's where platform specific stuff enters the picture. You'll find most of your time is learning a new widget set (presuming you need GUI programming), or socket APIs (if you need 'em), or platform specific threading/synchronization etc.
Overall, coming from Java, you won't expect or know how to use fancy language features. That's Ok. Write C++ like you would Java (mmm, careful about that memory leak though). This assumes you're doing app development where you can afford to make every function virtual, every object a reference, and have accessor functions for every member variable. If that's not what you're up to and you need write tight C++, well, forget Java while you learn C++. Make sure you get your memory models straight--stack vs heap, by value and by reference, pointers vs reference, iterators vs pointers, reference counted, and on and on. You have to get the now classic "Effective C++" books by Scott Meyers. That's the best way to avoid classic stupid C++ mistakes. You'll find it a bit heavy going at first, but until it makes sense to you, you're probably writing bad C++. Good luck.
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.
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 am sorry, I am a bit confused by your argument. Move away from C++ to what exactly. The only other languages you mentioned where Perl, Python, Ruby, or Scheme. I have yet to use Ruby or Scheme, but I did look up some things on them.
Most of those languages are scripting lanugages and aren't really what you'd program a major application in. I know I user perl for sys admin tasks and quick hacks to just 'get things done'
If you're going to beat up on C++ tell them to move away give a decent language to move to. And you never explained what Java had that C++ doesn't.
Please tell me why I want to move away from a language such a C++ or even its predecessor C. Those languages are solid, and fast. You can do most anything with them. And the cleanliness of the program is left to the programmer, so if you develope bad practices you'll write bad code. If done propertly I see nothing wrong with using C++.
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.
Here's (on the top of head) what comes to mind when I think ab out moving from Java to C++:
In C++ you can place objects on the stack with no need to allocate an object on the heap.
The book my Koeing and Barbara Moo, Accelerated C++, is an excellent starting point in my oppinion. If you have previous programming experience, i suggest you pick this up, rather than a 500 page primer. It goes through a lot of stuff and a suprising rate. It also teaches you some basic algo's and uses STL right from the start, not the sort of backward teaching some other books use. It's very good, and i suggest you pick it up. You might also try Bruce Ekels Thinking In C++, they can be found for free (both volumes) on his site. Simply google the title and it will take you 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).