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
Description | C++ | Java |
---|---|---|
Compiler & Interpreter | C++ 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-independent | C++ is platform dependent. | Java is platform-independent. As the bytecode can be run on any machine by JVM. |
Designed For | C++ 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 for | C++ is mainly used for developing system programming. | Java is mainly used for application programming. |
Goto statement | C++ supports the goto statement. | Java does not support the use of goto statements. |
Multiple inheritance | C++ 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. |
References | In 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. |
Multithreading | C++ does not have its own concept of multithreading. | Java supports multithreading. |
Operator overloading | C++ supports the concept of operator overloading. | Java doesn’t support operator overloading. |
Structure | C++ supports structures. | Java does not support structures. |
Unions | C++ supports unions. | Java does not support unions. |
Runtime error | In C++, you cannot handle runtime errors. | In Java, you can catch and handle runtime errors. |
Portable | C++ is not portable as it is platform dependent language. | Java is a portable language as java is a platform independent language. |
Summary | C++ is perfect for programs that need to run really fast and need detailed control over the computer’s hardware and memory. | Java is great where ease to develop application matters, and have access to a lot of built-in tools and features. |
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!
Leave a Reply