What Java Has Removed from C++

By: Tamil Selvan Emailed: 1728 times Printed: 2338 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

There are a number of C++ features that Java does not support. In some cases, a specific C++ feature simply didn't relate to the Java environment. In other cases, the designers of Java eliminated some of the duplication of features that exists in C++. In still other instances, a feature of C++ is not supported by Java because it was deemed too dangerous for Internet applets.

Perhaps the single biggest difference between Java and C++ is that Java does not support pointers. As a C++ programmer you know that the pointer is one of C++'s most powerful and important language features. It is also one of its most dangerous when used improperly. Pointers don't exist in Java for two reasons:

  • Pointers are inherently insecure. For example, using a C++-style pointer, it is possible
    to gain access to memory addresses outside a program's code and data. A malicious
    program could make use of this fact to damage the system, perform unauthorized
    accesses (such as obtaining passwords), or otherwise violate security restrictions.
  • Even if pointers could be restricted to the confines of the Java run-time system (which
    is theoretically possible, since Java programs are interpreted), the designers of Java
    believed that they were inherently troublesome.

    Since pointers don't exist in Java, neither does the -> operator.

Here are a few more of the most important "omissions":

  • Java does not include structures or unions. These were felt to be redundant since the
    class encompasses them.
  • Java does not support operator overloading. Operator overloading is sometimes a
    source of ambiguity in a C++ program, and the Java design team felt that it causes
    more trouble than benefit.
  • Java does not include a preprocessor nor does it support the preprocessor directives.
    The preprocessor plays a less important role in C++ than it does in C. The designers
    of Java felt that it was time to eliminate it entirely.
  • Java does not perform any automatic type conversions that result in a loss of
    precision. For example, a conversion from long integer to integer must be explicitly
  • All the code in a Java program is encapsulated within one or more classes. Therefore,
    Java does not have what you normally think of as global variables or global functions.
  • Java does not allow default arguments. In C++, you may specify a value that a
    parameter will have when there is no argument corresponding to that parameter when
    the function is invoked. This is not allowed in Java.
  • Java does not support the inheritance of multiple superclasses by a subclass.
  • Although Java supports constructors, it does not have destructors. It does, however,
    add the finalize( ) function.
  • Java does not support typedef.
  • It is not possible to declare unsigned integers in Java.
  • Java does not allow the goto.
  • Java does not have the delete operator.
  • The << and >> in Java are not overloaded for I/O operations.
  • In Java, objects are passed by reference only. In C++, objects may be passed by
    value or by reference.

Java Home | All Java Tutorials | Latest Java Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


1. View Comment

Sometimes java do support operator overloading as for example (+) operator.In case of String it is used for concatenation but for addition of two integers it is used for adding 2 nos.

View Tutorial          By: Gunjan Srivastava at 2011-07-06 09:14:00
2. View Comment

I don't like Java for not supporting pointers.

View Tutorial          By: Yannbane at 2012-10-14 12:16:27
3. View Comment

I've been learning C++/C for the past year or so, and like the idea behind a lot of Java functionality. Passing by reference, automatic garbage handling and no GOTO are all nice! Might have to start looking into the language soon.

View Tutorial          By: William Semple at 2013-01-05 17:53:30

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by Tamil Selvan
Inner Class Example in Java
PreparedStatement Example in Java
UNIX read and write system calls sample program in C
Pointer Arrays and Pointers to Pointers in C
Relational and Logical Operators in C
Arithmetic Operators in C
strlen() sample program in C++
Sample program to draw a arc in J2ME
What Java Has Removed from C++
FileReader and FileWriter example program in Java

More Tutorials in Java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Java File
Java String
Count number of vowels, consonants and digits in a String in Java
Reverse a number in Java
Student marks calculation program in Java
Handling Fractions in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Multiple Inheritance sample in Java
Java program using Method Overriding
Java program to check if user input is an even number

More Latest News
Most Viewed Articles (in Java )
How to Send SMS using Java Program (full code sample included)
Method Overriding in Java
XML and Java - Parsing XML using Java Tutorial
wait(), notify() and notifyAll() in Java - A tutorial
What is Java?
InetAddress Example program in Java
How to use ArrayList in Java
Vector example in Java
Student marks calculation program in Java
Method Overloading (function overloading) in Java
Execute system commands in a Java Program
Stack example in Java - push(), pop(), empty(), search()
The Basic Structure of a Simple Java program
Recursion in java
Read from a COM port using Java program
Most Emailed Articles (in Java)
Vector in Java - Sample Program
Use of return statement in Java
Taking the size of an Array at runtime & generate random numbers to populate the Array
instanceof operator example in Java
3-D Secure Payment or 3DS - (3-Domain Secure Payment)
What is a Java Package and how to use it?
How to use Iterator in Java
J2EE Components
The modulus Operators
The java Buzzwords
The Basic Structure of a Simple Java program
Java Chat Client Sample Applet
Reverse a number in Java
MultiLevel Inheritance sample in Java
Type Casting in Java