difference between c++ and java

10
Migrating from C++ to Java a path to eternity

Upload: ajmal-ak

Post on 29-Jun-2015

768 views

Category:

Technology


3 download

DESCRIPTION

Difference between C++ and Java

TRANSCRIPT

Page 1: Difference between C++ and Java

Migrating from C++ to Javaa path to eternity

Page 2: Difference between C++ and Java

The Differences

C++ features not supported by Java

Features unique to Java

Shared features which differ between C++ and Java

Page 3: Difference between C++ and Java

What Java lacks

• PointersFor security reasons

• Structures or unionsClass is enough

• Operator overloadingAmbiguity. Causes more troubles than benefit

• Preprocessor or preprocessor directiveIt’s relevance is worth eliminating

• Automatic Type conversionsLoss of precision

Page 4: Difference between C++ and Java

• Concept of Global Variables/FunctionsEntire code is encapsulated to classes

• Default ArgumentsNot an ideal approach

• Multiple InheritanceIs done using interfaces

• DestructorsInstead finalize() is used

• The << and >> operatorsSince operator overloading is not supported in Java

• Passing objects by valueTo eliminate ambiguity

+ the keywords

abstract, super, typedef, unsigned int, goto, delete

Page 5: Difference between C++ and Java

What Java Gains

• ThreadsMultithreading allows two or more pieces of the sameprogram to execute concurrently and is supported by Java language itself.

• PackagesConstructing and using a class library was not this easier yet.

• InterfacesUsed to implement multiple inheritance. no instance of Interfaces can be created. Similar to Abstract classes in C++.

• Sophisticated memory management techniqueWhen the last reference to an object is destroyed, the object itself will be deleted on the very next garbage collection.

Page 6: Difference between C++ and Java

• API ClassesSubstitutes C++ class library.API classes are completely object oriented.

• Enhanced break and continueCould accept labels as targets.

• UnicodeJava character set contains 16-bit wide Unicode characters ensures code portability.

• >>> operatorPerforms unsigned right shift

• The documentation commentDelimited using /** and */

• The String data typeHelps handle strings in an easy and convenient way

+ a fully object oriented platform independent programming concept.

Page 7: Difference between C++ and Java

What’s in Common

• BooleanIn C++ everything except zero will be treated as TRUE, but java won’t!

• Access SpecifierIt’s impossible to assign access specifiers to a group of java variable declarations.

• Exception HandlingIn java, the whole syntax part is similar to C++, but a catch block is mandatory for a thrown exception.

Let’s see in what ways these stuff are going to alter the Java counterpart of a previously written C++ program…

Page 8: Difference between C++ and Java

Eliminating PointersConverting Pointer parameters JCConverting pointers that operate on arrays JC

C++ Reference parameters Vs Java Reference param JCConverting C++ Abstract classes into Java Interfaces JCConverting Default Arguments JCConverting C++ Multiple inheritance hierarchies. egDestructors Vs Finalization JC

The Key Aspects

Page 9: Difference between C++ and Java

Reference

Java2 Complete Reference http://java.sun.com/

http://www.scs.carleton.ca

Page 10: Difference between C++ and Java

Danks!