Anda di halaman 1dari 24

CSC 458 C++ Programming

Java vs. C++ - What are the similarities and differences?


Information from: * C++ for Java Programmers Weiss * Wikipedia.com
Dr. Paige H. Meeker Computer Science Presbyterian College, Clinton, SC

Lecture 2

Brief History of C++ High Level Differences Between C++ and Java Reasons to use C++

Introduction
Java and C++ look a lot alike syntactically. Many of the basic constructs in Java have only minor technical differences from C++; other Java features (such as OOP support for classes) have a similar look and feel to C++. How did we obtain these languages?

History of Programming Languages


Since we have had computers, we have needed a means of communicating with them to obtain desired results. This necessitates some sort of language that will allow communication between man and machine.

History of Programming Languages

The first forms of language were actually physical motion languages the programmer physically moved gears and/or wires to convey what they wished the computer to do. Programming was accomplished by rewiring the entire system each time a new calculation was required.

History of Programming Languages

John von Neumanns Computing Concepts


Shared-Program Technique Conditional Control Transfer

History of Programming Languages

1951: First Compiler (Grace Hopper) First High Level Languages:

FORTRAN (FORmula TRANslation) COBOL (COmon Business Oriented Language) LISP (LISt Processing language)

FORTRAN

Computer Science without FORTRAN and COBOL is like birthday cake without ketchup and mustard.

COBOL

Alternative expansions of the COBOL acronym have been suggested:


Compiles Only Because Of Luck Compiles Only By Odd Luck Completely Obsolete Business Oriented Language Completely Obsolete Boring Old Language

COBOL Hello World


IDENTIFICATION DIVISION. Program-Id. Hello-World. * ENVIRONMENT DIVISION. * DATA DIVISION. * PROCEDURE DIVISION. Para1. DISPLAY "Hello, world.". * Stop Run.

LISP
Please don't assume Lisp is only useful for Animation and Graphics, AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor applications, Expert Systems, Finance, Intelligent Agents, Knowledge Management, Mechanical CAD, Modeling and Simulation, Natural Language, Optimization, Research, Risk Analysis, Scheduling, Telecom, and Web Authoring just because these are the only things they happened to list. Kent Pitman

Algol

Led to:

Pascal C C++ Java

First language with a formal grammar (BNF)

Pascal

Developed out of necessity for a good teaching language Combined best features of COBOL, FORTRAN, and Algol Improved pointers, introduced CASE statements

Built to be fast and powerful Hard to read Many OS built in C (Unix, Windows, MacOS, and Linux)

C++

C with Classes Built to maintain speed of C (and run C programs) and be more portable Language of choice in high school AP classes

Java

Visual Basic

Perl
Depending on who you ask, Perl stands for:

Practical Extraction and Reporting Language Pathologically Eclectic Rubbish Lister.

Back to C++

C++ should be viewed as a new language, based largely on C. It includes modern constructs to support OOP and was influenced by several design issues.

C++ Design Concerns

Intended to be upward compatible with C as much as possible (i.e. legal C programs should be legal C++ programs) C++ programs should be as fast as C programs if they do the same thing.

No one wants to learn a more complicated language to produce slower code This means: no runtime bounds checks, no garbage collection

C++ Design Concerns

Has continually evolved, first supporting classes and inheritance, later adding templates, exceptions, and namespaces

Java Development

Similar to C++ cosmetically, but designers had two main goals

Allow the programmer to write the same set of programs that C++ allows, using simpler syntax Make it harder for incorrect code to run Requires compiler to detect many sets of errors when it first compiles the program and requiring the Virtual Machine to throw an exceptions when bad things happen at runtime. This also enhances security against hacking

High Level Differences between C++ and Java

Compiled vs. Interpreted Code Security and Robustness Multithreading API

Why learn C++?


C++ is still widely used Templates Operator Overloading STL Automatic Reclamation of Resources Conditional Compilation Distinctions between Accessor and Mutator Multiple Implementation Inheritance Space Efficiency Private Inheritance

Anda mungkin juga menyukai