I was quickly going through this book "JAVA for everyone" (only two last chapters left), when I started to have a question: seems that JAVA is much easier than C++, then what is the difference between these two programming languages? and why did college teach us C++ instead of JAVA?
I guess Wikipedia is the most convenient source to find the answer for the first question, here is some summation I made. So far, I still cannot understand everything they explained, but anyway, let me write down what I can understand first:
Design aims: C++ was designed for systems and application programming, extending C language which means it added support for statically-typed object-oriented programming, exception handling, scoped resource management and generic programming. JAVA was created initially as an interpreter for printing systems but grew to support network computing. It is a statically-typed object-oriented language too that used syntax similar with C++, but is not compatible with it.
Compilation: C++ source code is written to be platform independent, and then is compiled into native machine code while JAVA code is first compiled into byte-code for the JVM(Java virtual machine), so JAVA code is dependent on the JAVA platform and not dependent on OS.
Struct and Union: JAVA only supports class, does not support struct or union.
"." operator: In C++, it takes an object as the left operand and access a member of the object. In JAVA, it takes a reference to an object as the left operand and access a member of that object (the equivalent operator in C++ is "->", which takes a pointer as the left operand).
Pointer v.s. reference: In C++, pointers can point directly to memory address. In java, similar thing is called references, but references can only refer to objects and arrays. Java references do not allow direct access to memory address or allow memory addresses to be manipulated with pointer arithmetic. In C++, on can construct pointers to pointers, pointers to ints and doubles and pointers to arbitrary memory locations. Java references can only access objects and arrays, never primitives, other references, or memory locations.
So far, this is what I can understand best for the first question, maybe I will add something more as I know more about the comparison.
As for the second one, I turned to Baidu.com since I first learned C++ in college in China. The answer is C++ is a foundation of learning other programming languages, it is much easier to learn JAVA after you have already known something about C++ (I agree).
No comments:
Post a Comment