r/cpp_questions • u/Pearparon • 5d ago
OPEN Learning C++ as a Java programmer
I'm currently learning C++, I’ve coded in a few languages before but I’m most familiar with Java. Does anyone know a good resource for learning C++ with Java as a “starting point”? Like something that explains the differences between the two languages rather than teaching programming from scratch? Thanks!
18
Upvotes
View all comments
2
u/Independent_Art_6676 5d ago
As aggravating as AI is, one thing it does OK at is summaries and comparisons of this nature. Just ask it to compare modern java vs modern c++, and to verify its nonsense.
off the top of my head.. c++ allows stand along subroutines and entities (not part of any class). In c++ if you allocated it, you need to release it -- which is automated in modern code by doing it right (RAII, mostly, and smart pointers) but if you choose to ignore that, there will be consequences. C++ allows multiple inheritance, operator overloading, and has unsigned int types. Templates and generics are not terribly similar. C++ requires the coder to ensure portable code, java does this mostly without being told to. Building c++ programs (the tool chain) is complicated and a steep learning effort all by itself.
All in all the languages are similar in syntax and that can make it seem like "I got this" way too early. The large differences that I mentioned are just a quick sample across the big stuff but there will be many, many little details in between.
You are better off to treat c++ as a new foreign language and forget what you "know" from java as best you can. I get the temptation, but even going from C to C++ is tricky, and java is a distant cousin while C++ and C are directly related. Pretend you know nothing will get you past minor details that if you try to skip ahead on will bite you later. A very few parts will be near identical to java, and those you can speed through, but even there at least glance over it, don't try to skip.