Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

By email I just answered my brother who is learning computer programming that C+

ID: 654603 • Letter: B

Question

By email I just answered my brother who is learning computer programming that C++ and Java are more similar than C and C++ even though C++ is nearly a superset of C. Do you agree?

AFAIK Stanley Lippman wrote the "canonical work" (C++ Primer) on C++ and Dennis Ritchie and Brian Kernighan wrote the "canonical work" (The C Programming Language) on C but I'm no C++ expert so I ask you the question.

Here is the conversation translated to English:

---------- Forwarded message ----------
From: Niklas
Date: 1 May 2013 07:22

It is rather that one knows Java if one knows C++.

There is more difference between C and C++ than between Java and C++ example C + + features, but does not use, pointers, rather than using C + + so-called references which also are used in Java instead of pointers. In C dynamic memory is allocated with malloc and in C++, this is done with the keyword new and in C is dynamic memory is released using the keyword free which in C++ is called called delete.

Operating systems get programmed in C and assembly language, and applications such as GUI programming are done with more object-oriented languages e.g. C++, Java, Visual Basic, Flash...so it depends on what problem you want to solve, CPU scheduling or widgets. There are different paradigms.

On 1 May 2013 07:16 wrote Holger:

I'm reading a book on C++. So far it seems to be identical to java, except for a few minor syntactical variations (include instead of import, etc.), but I assume that the differences will subsequently. Is it possible to automatically C if it can C + +?

On May 1, 2013 6:45 AM, "Niklas" wrote:

Hello! Here is the pdf of programming in C. It's fine to ask me if you have any questions. Sincerely, Niklas

Explanation / Answer

This is extremely subjective (what does similar mean? What kinds of similarity matter most?) but I think very few people would agree with you that Java and C++ are more similar than C and C++. Some key points:

Your assertion that C++ is not used for low-level tasks like operating systems is incorrect.
In fact, there are several operating systems written mostly or primarily in C++.* Most of the major operating systems are written in C partly for historical reasons--they are built on an existing code base. If one were to write a brand-new OS from scratch starting today, C++ would be a likely choice.
C++ is used for many low-level programming tasks, such as embedded systems, in a similar domain to C.
Java is written in C++. But no one would think of writing a C++ compiler in Java.
C and C++ are both small, fast, and close to the hardware, while Java intentionally abstracts away from the hardware.
C and C++ compile into machine code, while Java runs on a virtual machine. This is a gigantic difference.
C++ and C have pointers and let you perform memory arithmetic, while Java doesn't give you direct access to memory.

Memory management is automated in Java. In both C and C++ you have the primary responsibility for memory management.
Java mandates object-oriented programming. In C++ it is optional. One can write C++ in the exact same style as C, or one can use a mixture of OO and other paradigms.

The reference to GUI programming is not very relevant. Yes, OO is useful for GUI programming, thus languages with object-oriented support tend to be preferred. But GUI programming can be done in C. And C++ is not tied to GUI programming. It is used for many non-graphical tasks.
The one major area of commonality between Java and C++ is that they both support object-oriented programming. However, it would be a mistake to emphasize this over other factors. OO support is really little more than some convenient syntax that allows you to organize related code in a useful way. C++'s commonality with C is far more significant in what it is like to program, in what applications it is used for, and in how the code performs.

*Note: the link does mention experiments with Java operating systems, and apparently hardware that can run Java directly has even been produced. However, these are not mainstream and are not typical uses of Java. Normally Java requires a virtual machine, which by definition must be written in some other language.