There are many differences and similarities between the C ++ and Java programming language. Below is a list of the main differences between C ++ and Java.
Property | C++ | Java |
---|---|---|
Platform-independent | It is platform-dependent. | It is platform-independent. |
Mainly used for | It is mainly used for system programming. | It is mainly used for application programming. It is manly used in window, web-based, enterprise and mobile applications. |
Design Purpose | It was designed for systems and applications programming. | It was designed with a goal of being easy to use and develop Web application that can be accessed from everywhere |
Goto & Const | It supports the Goto & Const Keyword | It doesn’t support the Goto & Const Keyword.However, in Java, final keyword is used instead Const. |
Multiple inheritance | It supports both single and multiple inheritance | It doesn’t support multiple inheritance through class. Multiple inheritance is partially done through interfaces |
Operator Overloading | It supports operator overloading. | It doesn’t support operator overloading. |
Pointers | It supports pointer. You can write pointer program in C++. | However, you can’t write the pointer program in java but It supports pointer internally. |
Compiler and Interpreter | It uses compiler only which converts source code into machine code | It uses compiler and interpreter both. At compilation time , java source code is converted into bytecode and interpreter executes this bytecode at runtime and produces output. |
Call by Value and Call by reference | It supports both call by value and call by reference. | It supports call by value only. |
Structure and Union | It supports structures and unions. | It doesn’t support structures and unions. |
Thread Support | There is no built-in thread support. We can achieve using third party libraries. | It has built-in thread support. |
Documentation comment | It doesn’t support documentation comment. | It supports documentation comment (/** … */) to create documentation for java source code. |
Libraries | Comparatively available with low level functionalities | Java Platform provides a comprehensive set of standard class libraries |
Memory Allocation | It allows memory allocation for primitive data types at compile time and it is called as Static programming language | It allows memory allocation for primitive data types at runtime and it is called as Dynamic programming language |
C++ Example
File: main.cpp
#include<iostream> using namespace std; //This is where the execution of program begins with main method int main() { cout<<"Hello World using C++ !"; return 0; }
Output
Hello World using C++ !
Java Example
File: Test.java
class Test{ public static void main(String args[]){ System.out.println("Hello World using Java !"); } }
Output
Hello World using Java !