Jump to content

Welcome to NulledBlog
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!

How Java differs from C and C++ ( Short Explanation )

  • Please log in to reply
No replies to this topic


  • Offline
  • PHP/MySQL Dev

  • PipPip
  • Posts:
    08 Jul, 2015

Although Java was modeled after C and C++ languages, it differs from C and C++ in many ways. Java does not i a number of features available in C and C++. For the benefit of C and C++ programmers, we point out here a few major differences between C/C++ and Java language

How Java Differs From C:

Java and C

Java is not lot like C but the major difference between Java and C is that Java is an object-oriented language and has mechanism to define classes and objects. In an effort to build a simple and safe language, the Java team did not include some of the C features in Java.

  • Java does not include the C unique statement keywords sizeof, and typedef.
  • Java does not contain the data type struct and union.
  • Java does not define the type modifiers keywords auto,extern,register,signed, and unsigned.
  • Java does not support an explicit pointer type.
  • Java does not have a preprocessor and therefore we cannot use # define, # include, and # ifdef statements.
  • Java requires that the functions with no arguments must be declared with empty parenthesis and not with the void keyword as done in C.
  • Java adds new operators such as instanceof and >>>.
  • Java adds labelled break and continue statements.
  • Java adds many features required for object-oriented programming.

How Java Differs From C++ :

Java and C++

Java is a true object-oriented language while C++ is basically C with object-oriented extension. That is what exactly the increment operator ++ indicates. C++ has maintained backward compatibility with C. Is is therefore possible to write an old style C program and run it successfully under C++. Java appears to be similar to C++ when we consider only the “extensions” part of C++. However, some object -oriented features of C++ make the C++ code extremely difficult to follow and maintain.

Listed below are some major C++ features that were intentionally omitted from java or significantly modified.

  • Java does not support operator overloading.
  • Java does not have template classes as in C++.
  • Java does not support multiple inheritance of classes. This is accomplished using a new feature called “Interface”.
  • Java does not support global variables. Every variable and method is declared within classes and forms part of that class.
  • Java does not use pointers.
  • Java has replaced the destructor function with a finalize() function.
  • There are no header files in Java.

Java also adds some new features. While C++ is a superset of C, Java is neither a superset nor a subset of C or C++. Java may be considered as a first cousin of C++ and a second cousin of C

As a personal note, the reason why Java is slower than C/C++ is because it runs on java virtual machine hence portability of apps whilst the latter run on machine directly hence not portable. However, running on some virtual machine means more processing time because the machine has now to communicate with the hardware unlike a c/c++ program which deals with h/w directly.


  • 0

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users