c++ to java
DESCRIPTION
Difference between C++ and JavaTRANSCRIPT
Migrating from C++ to Javaa path to eternity
The Differences
C++ features not supported by Java
Features unique to Java
Shared features which differ 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
• 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
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.
• 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.
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…
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
Reference
Java2 Complete Reference http://java.sun.com/
http://www.scs.carleton.ca
Danks!