You are on page 1of 7

3/9/22, 6:19 PM C++ vs Java - Javatpoint

Home Java Programs OOPs String Exception Multithreading Collections JavaFX


⇧ SCROLL TO TOP

https://www.javatpoint.com/cpp-vs-java 1/7
3/9/22, 6:19 PM C++ vs Java - Javatpoint

C++ vs Java
There are many differences and similarities between the C++ programming language and Java. A list of top
differences between C++ and Java are given below:

Comparison C++ Java


Index

Platform- C++ is platform-dependent. Java is platform-independent.


independent

Mainly used C++ is mainly used for system Java is mainly used for application programming. It is
for programming. widely used in Windows-based, web-based, enterprise,
and mobile applications.

Design Goal C++ was designed for systems and Java was designed and created as an interpreter for
applications programming. It was printing systems but later extended as a support network
an extension of the C programming computing. It was designed to be easy to use and
language. accessible to a broader audience.

Goto C++ supports the goto statement. Java doesn't support the goto statement.

Multiple C++ supports multiple inheritance. Java doesn't support multiple inheritance through class. It
inheritance can be achieved by using interfaces in java.

Operator C++ supports operator Java doesn't support operator overloading.


Overloading overloading.

Pointers C++ supports pointers. You can Java supports pointer internally. However, you can't write
write a pointer program in C++. the pointer program in java. It means java has restricted
pointer support in java.

Compiler and C++ uses compiler only. C++ is Java uses both compiler and interpreter. Java source code
Interpreter compiled and run using the is converted into bytecode at compilation time. The
compiler which converts source interpreter executes this bytecode at runtime and
code into machine code so, C++ is produces output. Java is interpreted that is why it is
platform dependent. platform-independent.

Call by Value C++ supports both call by value Java supports call by value only. There is no call by
and Call by and call by reference. reference in java.
reference

Structure and C++ supports structures and Java doesn't support structures and unions.
Union unions.  

Thread C++ doesn't have built-in support Java has built-in thread support.
Support for threads. It relies on third-party
libraries for thread support.
2

Documentation C++ doesn't support Java supports documentation comment (/** ... */) to
⇧ SCROLL TO TOP
comment documentation comments. create documentation for java source code.

https://www.javatpoint.com/cpp-vs-java 2/7
3/9/22, 6:19 PM C++ vs Java - Javatpoint

Virtual C++ supports virtual keyword so Java has no virtual keyword. We can override all non-
Keyword that we can decide whether or not static methods by default. In other words, non-static
to override a function. methods are virtual by default.

unsigned right C++ doesn't support >>> Java supports unsigned right shift >>> operator that fills
shift >>> operator. zero at the top for the negative numbers. For positive
numbers, it works same like >> operator.

Inheritance C++ always creates a new Java always uses a single inheritance tree because all
Tree inheritance tree. classes are the child of the Object class in Java. The
Object class is the root of the inheritance tree in java.

Hardware C++ is nearer to hardware. Java is not so interactive with hardware.

Object- C++ is an object-oriented Java is also an object-oriented language. However,


oriented language. However, in the C everything (except fundamental types) is an object in
language, a single root hierarchy is Java. It is a single root hierarchy as everything gets
not possible. derived from java.lang.Object.

Note

Java doesn't support default arguments like C++.

Java does not support header files like C++. Java uses the import keyword to include different classes and
methods.

C++ Program Example


File: main.cpp

#include <iostream>  
using namespace std;  
int main() {  
   cout << "Hello C++ Programming";  
   return 0;  
}  

Output:

⇧ SCROLL TO TOP

https://www.javatpoint.com/cpp-vs-java 3/7
3/9/22, 6:19 PM C++ vs Java - Javatpoint

Hello C++ Programming

Java Program Example


File: Simple.java

class Simple{  
    public static void main(String args[]){  
     System.out.println("Hello Java");  
    }  
}  

Output:

Hello Java

← Prev
Next →

Want to get paid for Sign Up 10 Eye-Catching Ikat Looks


sharing your For A True Textile Lover
opinions? ZeeZest.Com
Lifepoints
Sponsored Sponsored


For Videos Join Our Youtube Channel: Join Now

Feedback

Send your Feedback to feedback@javatpoint.com

Help Others, Please Share

⇧ SCROLL TO TOP

https://www.javatpoint.com/cpp-vs-java 4/7
3/9/22, 6:19 PM C++ vs Java - Javatpoint

Learn Latest Tutorials

Splunk tutorial SPSS tutorial Swagger T-SQL tutorial Tumblr tutorial


tutorial
Splunk SPSS Transact-SQL Tumblr
Swagger

React tutorial Regex tutorial Reinforcement R Programming RxJS tutorial


learning tutorial tutorial
ReactJS Regex RxJS
Reinforcement R Programming
Learning

React Native Python Design Python Pillow Python Turtle Keras tutorial
tutorial Patterns tutorial tutorial
Keras
React Native Python Design Python Pillow Python Turtle
Patterns

Preparation

Aptitude Logical Verbal Ability Interview Company


Reasoning Questions Interview
Aptitude Verbal Ability
Questions
Reasoning Interview Questions
Company Questions

Trending Technologies  

Artificial AWS Tutorial Selenium Cloud Hadoop tutorial


Intelligence tutorial Computing
AWS Hadoop
Tutorial tutorial
Selenium
Artificial Cloud Computing 2
Intelligence

⇧ SCROLL TO TOP

https://www.javatpoint.com/cpp-vs-java 5/7
3/9/22, 6:19 PM C++ vs Java - Javatpoint

ReactJS Data Science Angular 7 Blockchain Git Tutorial


Tutorial Tutorial Tutorial Tutorial
Git
ReactJS Data Science Angular 7 Blockchain

Machine DevOps
Learning Tutorial Tutorial
Machine Learning DevOps

Sponsored

Want to get paid for taking Sign Up


online surveys?
Lifepoints
Recommended by

B.Tech / MCA

DBMS tutorial Data Structures DAA tutorial Operating Computer


tutorial System tutorial Network tutorial
DBMS DAA
Data Structures Operating System Computer Network

Compiler Computer Discrete Ethical Hacking Computer


Design tutorial Organization and Mathematics Tutorial Graphics Tutorial
Architecture Tutorial
Compiler Design Ethical Hacking Computer Graphics
Computer Discrete
Organization Mathematics

Software html tutorial Cyber Security Automata C Language


Engineering tutorial Tutorial tutorial
Web Technology
Tutorial
Cyber Security Automata C Programming
Software
Engineering

C++ tutorial Java tutorial .Net Python tutorial List of


Framework Programs
C++ Java Python
tutorial
Programs  
.Net

Control Data Mining Data


Systems tutorial Tutorial Warehouse
Tutorial 2
Control System Data Mining
Data Warehouse
⇧ SCROLL TO TOP

https://www.javatpoint.com/cpp-vs-java 6/7
3/9/22, 6:19 PM C++ vs Java - Javatpoint

Sponsored
Oil Blends You Can Make at Home for All Your
Hair Concerns
Zee Zest
Recommended by

⇧ SCROLL TO TOP

https://www.javatpoint.com/cpp-vs-java 7/7

You might also like