BeginnersBook

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
    • Learn jQuery
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

C++ vs Java – Difference between C++ and Java

By Chaitanya Singh | Filed Under: Learn Java

In this post, you will learn the difference between C++ and Java. There are many similarities and differences between these programming languages.

Before we see the difference between them, lets look have a look the basic details about both of these programming languages.

C++ language

C++ is the first programming language that introduced the concept of object oriented programming, it was C++ that introduced the whole idea about objects and classes. C++ initially known as “C with classes” as it was developed as an advanced version of C, with added object oriented features as an improvement.

C++ language was developed by Bjarne Stroustrup at AT & T Bell Laboratories. The first commercial C++ compiler known as Cfront, was released in 1985.

Java language

Java programming language was developed by James Gosling at Sun Microsystems in early 1990. Java was initially developed for digital devices such television, remote, set-top boxes.

Java project initially named “Greentalk” by James Gosling, it got renamed to “Oak” later. in 1995 Sun Microsystems renamed it again from Oak to java as “Oak” was a registered trademark for another organization.

Read more at: History of Java.

C++ vs Java

DescriptionC++Java
Compiler & InterpreterC++ only supports compiler. C++ program is compiled and run by the compiler, which converts the source code into machine code.Java supports both compiler and interpreter. Java Compiler converts the java code (source code) to the bytecode. Java interpreter JVM executes this bytecode at runtime and produces output. This compilation and execution can be done on different machines.
Platform-independentC++ is platform dependent.Java is platform-independent. As the bytecode can be run on any machine by JVM.
Designed ForC++ was designed as an upgraded version of C, with advanced features such Object oriented features.Java was initially developed for Digital devices, later it was widely accepted as an internet programming language.
Used forC++ is mainly used for developing system programming.Java is mainly used for application programming.
Goto statementC++ supports the goto statement.Java does not support the use of goto statements.
Multiple inheritanceC++ supports multiple inheritance.Java does not support multiple inheritance. The same functionality can be achieved by using interfaces in java.
Pointers C++ supports the use of pointers.Java does not have any concept of pointer, nor does it support similar functionality.
ReferencesIn C++, you can use both call by value and call by reference.Java only supports call by value and does not support call by reference.
MultithreadingC++ does not have its own concept of multithreading.Java supports multithreading.
Operator overloadingC++ supports the concept of operator overloading.Java doesn’t support operator overloading.
StructureC++ supports structures.Java does not support structures.
UnionsC++ supports unions.Java does not support unions.
Runtime errorIn C++, you cannot handle runtime errors.In Java, you can catch and handle runtime errors.
PortableC++ is not portable as it is platform dependent language.Java is a portable language as java is a platform independent language.

C++ Program

Let’s have a look at a very simple C++ program that prints a message “Hello World!” on the screen.

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

Output:

Hello World!

Java Program

Let’s write the same program in Java programming language.

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

Output:

Hello World!
❮ Features of JavaJDK vs JRE vs JVM ❯

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Java Tutorial

  • Java Index
  • Java Introduction
  • History of Java
  • Features of Java
  • C++ vs Java
  • JDK vs JRE vs JVM
  • JVM - Java Virtual Machine
  • First Java Program
  • Variables
  • Data Types
  • Operators

Java Control Statements

  • Java If-else
  • Java Switch-Case
  • Java For loop
  • Java while loop
  • Java do-while loop
  • Continue statement
  • break statement

OOPs Concepts

  • OOPs Concepts
  • Constructor
  • Static keyword
  • Inheritance
  • Types of inheritance
  • Aggregation
  • Association
  • Super Keyword
  • Method overloading
  • Method overriding
  • Overloading vs Overriding
  • Polymorphism
  • Types of polymorphism
  • Static and dynamic binding
  • Abstract class and methods
  • Interface
  • Abstract class vs interface
  • Encapsulation
  • Packages
  • Access modifiers
  • Garbage Collection
  • Inner classes
  • Static import
  • Static constructor
  • Java Interview Q

MORE ...

  • Java 8 Features
  • Java 9 Features
  • Java Conversion
  • Java String
  • Java Date
  • Exception handling
  • Java Multithreading
  • Java I/O
  • Java Serialization
  • Java Regex
  • Java AWT
  • Java Swing
  • Java Enum
  • Java Annotations
  • Java main method

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap