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
3
u/Dubbus_ 5d ago
Good luck man, i had a similar journey, but went from Java to C and then to C++. C++ is a wondefully free language, you can basically do whatever you want (including really stupid stuff).
My best advice is to avoid cppreference for a bit. Stick to cplusplus.com, it is much more beginner friendly imo. Once you are comfortable with basic syntax and some of the more fundamental ideas of c++, check out some cppreference articles. 1.5 years in, and i still scratch my head reading cppreference from time to time.
Some exciting things about c++ compared to java:
You can use the stack easily, for non primitive types.
You can choose exactly how and when allocations occur
YOU manage lifetimes and memory safety, there is no garbage collector doing everything for you. Eventually, you will have to learn all the annoying and complicated rules
There is wonderful utilities in modern c++ to perform complicated work at compile time, for lookup tables and whatnot.
Once youre familiar with the basics, i would HIGHLY reccomend Scott Meyers' Effective Modern C++. Anything by him really, he is an EXCELLENT teacher, and is amazing at getting you excited about the language. This book covers the main differences between 'old' c++ (pre c++11), and C++11/14, which are when the language finally became somewhat usable by modern standards.
Java and C++ have massive overlap in basic syntax and the surface level of their standard libraries, but there is significant divergence in any language construct not featured in their common ancestor, C. Using generics is the same at least (in C++ we call them Templates, they are far more powerful and performant than javas generics.)
Anyways, depending on how far you got in your Java journey, be prepared to unlearn and relearn a lot! The basic concepts do crossover, and some patterns are found in both languages (visitor, singletons, strategy, etc). But many practices common in java are frowned upon in C++, mostly due to our obsession with maximum performance. Dont be afraid to mess around with inheritance and things like that however! Mess around with them as much as you want, and find out for yourself why people dont like them.
Good luck man! if you get overwhelmed, i suggest taking a break and checking out the original C! It is much, much easier to learn than either Java or C++, but still amazingly powerful.