1 / 11

C++ for Java Programmers

C++ for Java Programmers. Chapter 1 Basic Philosophical Differences. 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

gosgood
Download Presentation

C++ for Java Programmers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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 C++ for Java Programmers

  3. 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 C++ for Java Programmers

  4. 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 C++ for Java Programmers

  5. 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()); C++ for Java Programmers

  6. 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 C++ for Java Programmers

  7. 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++ C++ for Java Programmers

  8. 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 C++ for Java Programmers

  9. And new features • C++ added a number of new features to C • Classes, inheritance • Virtual functions • Templates • Exception Handing C++ for Java Programmers

  10. 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 C++ for Java Programmers

  11. 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 C++ for Java Programmers

More Related