- Computers & Software»
- Computer Science & Programming»
- Programming Languages
Frequently asked Questions in Java Interviews
Difference between C and C++ with Java
There are many frequently ask questions on Java Technology. I am discussing first interview question on Java Technology asked by every interviewer. The question is about Difference between Java, C & C++.
Difference between Java and C
Java is not like C but the major difference between Java and C is that Java an object Oriented language. It has a mechanism to define classes and objects. In 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 types struct and union.
- Java does support an Explicit pointer type.
- Java does not define the type modifiers keywords auto, extern, register, signed and unsigned.
- Java does not not have a preprocessor and therefore we can not use # define,
# include, #ifdef.
- Java requires function with no arguments and must be declared with no parenthesis and not with the void keywords as done in C.
- Java adds new operator such as instanceof and >>>.
- Java adds labeled break and continue statements.
- Java adds many features required for object oriented programming.
Java and C++
Java is true object oriented language while C++ is basically C with object oriented extension. That is why the increment operator ++ indicates. C++ has maintained backward compatibility with C. It is therefore possible to write old style C program and Compile and run it under C++. Java appears similar to C++ when we consider only “extension part” of C++. However some object oriented features of C++ make the C++ code extremely difficult to follow and maintain. Following are features are omitted from Java Technology.
- 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 “inheritance”.
- Java does not support global variables. Every variable and method is declared with in a class 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 superset of C, Java is neither a superset nor a subset of C or C++. Beside this Java adds its own new features. They are as follows.
- Java supports Multithreading.
- Java supports automatic Garbage collection and make lot of programming problems simply vanish.
- The destructor function is replaced with a finalize function.
- Exception handling in Java is different because there is no Destructor. A finally clause is always executed to perform necessary cleanup.
- Java has built –in support for comment documentation, so the source code file can also contain its own documentation.