2. The Differences
C++ features not supported by Java
Features unique to Java
Shared features which differ
between C++ and Java
3. What Java lacks
• Pointers
For security reasons
• Structures or unions
Class is enough
• Operator overloading
Ambiguity. Causes more troubles than benefit
• Preprocessor or preprocessor directive
It’s relevance is worth eliminating
• Automatic Type conversions
Loss of precision
4. • Concept of Global Variables/Functions
Entire code is encapsulated to classes
• Default Arguments
Not an ideal approach
• Multiple Inheritance
Is done using interfaces
• Destructors
Instead finalize() is used
• The << and >> operators
Since operator overloading is not supported in Java
• Passing objects by value
To eliminate ambiguity
+the keywords
abstract, super, typedef, unsigned int,
goto, delete
5. What Java Gains
• Threads
Multithreading allows two or more pieces of the same
program to execute concurrently and is supported by Java
language itself.
• Packages
Constructing and using a class library was not this easier yet.
• Interfaces
Used to implement multiple inheritance. no instance of Interfaces
can be created. Similar to Abstract classes in C++.
• Sophisticated memory management technique
When the last reference to an object is destroyed, the object itself
will be deleted on the very next garbage collection.
6. • API Classes
Substitutes C++ class library.API classes are completely
object oriented.
• Enhanced break and continue
Could accept labels as targets.
• Unicode
Java character set contains 16-bit wide Unicode
characters ensures code portability.
• >>> operator
Performs unsigned right shift
• The documentation comment
Delimited using /** and */
• The String data type
Helps handle strings in an easy and convenient way
+a fully object oriented platform independent
programming concept.
7. What’s in Common
• Boolean
In C++ everything except zero will be treated as TRUE, but java
won’t!
• Access Specifier
It’s impossible to assign access specifiers to a group of java
variable declarations.
• Exception Handling
In 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…
8. Eliminating Pointers
Converting Pointer parameters JC
Converting pointers that operate on arrays JC
C++ Reference parameters Vs Java Reference param JC
Converting C++ Abstract classes into Java Interfaces JC
Converting Default Arguments JC
Converting C++ Multiple inheritance hierarchies. eg
Destructors Vs Finalization JC
The Key Aspects
9. Ref er ence
Java2 Complete Reference
http://java.sun.com/
http://www.scs.carleton.ca