Presentation is loading. Please wait.

Presentation is loading. Please wait.

C++ for Java Programmers Chapter 1 Basic Philosophical Differences.

Similar presentations


Presentation on theme: "C++ for Java Programmers Chapter 1 Basic Philosophical Differences."— Presentation transcript:

1 C++ for Java Programmers Chapter 1 Basic Philosophical Differences

2 Chapter 1C++ for Java Programmers2 Similar Roots, different paths Both C++ and Java (and C# and PHP and many other languages) grew out of one tradition of languages So it is not surprizing they have similarities But also many differences that can trap the unwary

3 Chapter 1C++ for Java Programmers3 Common Ancestor - C Designed by Dennis Ritchie in 1970’s Intended for System Programming (specifically, unix) Economy of expression Easy for compiler to generate code Both high level and low level features

4 Chapter 1C++ for Java Programmers4 Some Features of C Explicit use of pointers Close match between pointers and arrays Variety of bit-level operations Fast execution time Minimal memory requirements Simple memory model Portable assembly language

5 Chapter 1C++ for Java Programmers5 Criticisms of C “Too concise for human understanding” while (*p++ = *q++) Lack of run-time checks makes programs error prone (array index checking, parameter matching, etc.) Opens door or malicious use gets(s) a[i++] = i++; func1(func2(), func3(),func4());

6 Chapter 1C++ for Java Programmers6 Development of C++ Inspired by earlier language Simula Started as collection of macros and library routines for C Intended to be backward compatible with C Inherited C mind-set (pointers, lax checking, memory model) Uncompromising emphasis on efficiency

7 Chapter 1C++ for Java Programmers7 Examples of Emphasis on Efficiency Few run-time checks (if you want checks, you write them yourself) Many operations ill-defined, so can match machine dependency Stack memory model instead of heap Many decisions left to compiler writer a[i++] = i++

8 Chapter 1C++ for Java Programmers8 Legacy Problem - old C code The C++ programmer must know about Old C libraries Old techniques (use of preprocessor, etc) Old types (char * for strings, etc) Old styles (use if integers for booleans) Use of global variables, functions, other features not found in Java

9 Chapter 1C++ for Java Programmers9 And new features C++ added a number of new features to C Classes, inheritance Virtual functions Templates Exception Handing

10 Chapter 1C++ for Java Programmers10 The Language Java Designed by James Gosling Add simplicity and security to syntax of C++ Trade off between simplicity and efficiency Preserve consistent behavior on all platforms Add run-time checks for safety Heap based memory model, garbage collection Simpler OO model

11 Chapter 1C++ for Java Programmers11 Comparisons are dangerous Can you say one is better than the other? No. Each has slightly different use, different outlook Given right situation, either can be made to look better than the other


Download ppt "C++ for Java Programmers Chapter 1 Basic Philosophical Differences."

Similar presentations


Ads by Google