You are on page 1of 9

5/18/22, 2:35 PM C++ vs Java - Javatpoint

Home Java Programs OOPs String Exception Multithreading


https://www.javatpoint.com/cpp-vs-java 1/9
5/18/22, 2:35 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 Java is mainly used for application
for system programming. programming. It is widely used in Windows-
based, web-based, enterprise, and mobile
applications.

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

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

Multiple C++ supports multiple Java doesn't support multiple inheritance


inheritance inheritance. through class. It 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 Java supports pointer internally. However, you
can write a pointer program can't write the pointer program in java. It
in C++. means java has restricted pointer support in
java.

https://www.javatpoint.com/cpp-vs-java 2/9
5/18/22, 2:35 PM C++ vs Java - Javatpoint

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

Call by Value C++ supports both call by Java supports call by value only. There is no
and Call by value and call by reference. call by 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 Java has built-in thread support.
Support support for threads. It relies
on third-party libraries for
thread support.

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

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

unsigned right C++ doesn't support >>> Java supports unsigned right shift >>>
shift >>> operator. operator that fills 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
Tree inheritance tree. because all 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.


https://www.javatpoint.com/cpp-vs-java 3/9
5/18/22, 2:35 PM C++ vs Java - Javatpoint

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


oriented language. However, in the C However, everything (except fundamental
language, a single root types) is an object in Java. It is a single root
hierarchy is not possible. hierarchy as everything gets 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:

https://www.javatpoint.com/cpp-vs-java 4/9
5/18/22, 2:35 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 →

Youtube
For Videos Join Our Youtube Channel: Join Now

https://www.javatpoint.com/cpp-vs-java 5/9
5/18/22, 2:35 PM C++ vs Java - Javatpoint

Feedback

Send your Feedback to feedback@javatpoint.com

Help Others, Please Share

Learn Latest Tutorials

Splunk tutorial SPSS tutorial Swagger T-SQL tutorial


tutorial
Splunk SPSS Transact-SQL
Swagger

Tumblr tutorial React tutorial Regex tutorial Reinforcement


learning tutorial
Tumblr ReactJS Regex
Reinforcement
Learning

R Programming RxJS tutorial React Native Python Design


tutorial tutorial Patterns
RxJS
R Programming React Native Python Design
Patterns

https://www.javatpoint.com/cpp-vs-java 6/9
5/18/22, 2:35 PM C++ vs Java - Javatpoint

Python Pillow Python Turtle Keras tutorial


tutorial tutorial
Keras
Python Pillow Python Turtle

Preparation

Aptitude Logical Verbal Ability Interview


Reasoning Questions
Aptitude Verbal Ability
Reasoning Interview Questions

Company
Interview
Questions
Company Questions

Trending Technologies

Artificial AWS Tutorial Selenium Cloud


Intelligence tutorial Computing
AWS
Tutorial tutorial
Selenium
Artificial Cloud Computing
Intelligence

Hadoop tutorial ReactJS Data Science Angular 7


Tutorial Tutorial Tutorial
Hadoop
ReactJS Data Science Angular 7

Blockchain Git Tutorial Machine DevOps


Tutorial Learning Tutorial Tutorial
Git
Blockchain Machine Learning DevOps

https://www.javatpoint.com/cpp-vs-java 7/9
5/18/22, 2:35 PM C++ vs Java - Javatpoint

B.Tech / MCA

DBMS tutorial Data Structures DAA tutorial Operating


tutorial System tutorial
DBMS DAA
Data Structures Operating System

Computer Compiler Computer Discrete


Network tutorial Design tutorial Organization and Mathematics
Architecture Tutorial
Computer Network Compiler Design
Computer Discrete
Organization Mathematics

Ethical Hacking Computer Software html tutorial


Tutorial Graphics Tutorial Engineering
Web Technology
Tutorial
Ethical Hacking Computer Graphics
Software
Engineering

Cyber Security Automata C Language C++ tutorial


tutorial Tutorial tutorial
C++
Cyber Security Automata C Programming

Java tutorial
Java
https://www.javatpoint.com/cpp-vs-java 8/9
5/18/22, 2:35 PM C++ vs Java - Javatpoint

.Net Python tutorial List of


Framework Programs
Python
tutorial
Programs
.Net

Control Data Mining Data


Systems tutorial Tutorial Warehouse
Tutorial
Control System Data Mining
Data Warehouse

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

You might also like