Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Teaching C++ to students that know Java

Course Queries Syllabus Queries

Max. 2000 characters
Replies

usr_profile.png

User

( 4 months ago )


I am now teaching an OOP course to 2nd year undergrads. This is actually a course in advanced programming in Java. In the next semester, I am going to teach the same students, a C++ course. From what I know, C++ and Java are quite similar - there are differences, but they can be covered in 2-3 hours, which are one week of teaching. This leaves me 12 more weeks, and I wonder what else to teach.

I looked at the syllabus from previous year and it looks quite similar to my current Java course: OOP, overloading, generics, unit-testing, software design, etc. I don't want to teach the same course twice in different languages...

One idea that I had is to focus, not on teaching the language itself but on teaching specific practical applications in which C++ has a clear competitive advantage. For example, if game-programming is usually done in C++, then I can focus on game-programming. So my first question is: what kind of applications are written in C++ substantially more than in Java?

And my second question: what other new topics can I include in this C++ course?

[NOTE: in case this is relevant, the same students currently take a course in C].

usr_profile.png

User

( 4 months ago )

Actually, the similarities between C++ and Java are fairly shallow and the differences are very deep. The syntax of both is derived from C, but the underlying ideas are very different.

The biggest difference is that an "object" in C++ is built on the stack, like a struct, not on the heap. It takes additional work and a lot of understanding to become comfortable with the differences. If you do create objects on the heap (with new) you need to understand the differences between pointers and references and these can be the source of hard to debug errors. And you need to be absolutely pure with deallocation. Every object needs a known lifetime to the programmer, whereas Java handles all of that automatically.

C++ has no garbage collector for heap objects, so the memory management problem needs to be solved for every application, unlike Java where it is solved once by the run-time system automatically. Smart pointers in C++ can help a bit with this but are not a complete solution. Memory leakage for non-trivial applications is a serious issue.

The visibility of things is also fundamentally different, with "friend" classes complicating the mental models of complex systems.

Don't underestimate the difficulties. You will likely have a lot of work to do to get the students comfortable with quite different mental models and with practices and idioms that keep them safe.

James Gosling once described Java as C++ without the guns, knives and clubs. You will be trying to program with all of those pitfalls, when the students, coming from Java, have little experience with them.

Their experience with C, if deep enough, will help with the memory management issue, but not with the complex (i.e. dual) object model of C++. You should become familiar with good memory management tools and practices if you want to do non-trivial things in C++.

I was once stopped dead in a C++ project by a deallocation error for 24 hours. The solution required a 1 character change in a file. One character of progress per day is very bad, though I was an experienced programmer and actually knew why it was failing.

Your own experience with C++ seems shallow from the statement of your question. I'd suggest that you work hard on that before you attempt to teach such a course. Especially, build something that requires sophisticated memory management and test everything as you go. You can't think of C++ as just mis-spelled Java, nor Java as just mis-spelled C++. The conceptual differences are many and deep.

My own experience as a programmer (and author)` is that Java helps me program correctly, but C++ fights me constantly for every inch of ground. I could build some beautiful things, but the fight was constant and brutal.

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif