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:
C++编程语言与Java之间有许多异同点。下面列举了C++和Java的主要区别:
Comparison Index 比较项目 | C++ | Java |
---|---|---|
Platform-independent平台独立性 | C++ is platform-dependent.平台独立的 | Java is platform-independent.不是独立平台的 |
Mainly used for主要用途 | C++ is mainly used for system programming.主要用于C++主要用于系统编程。 | Java is mainly used for application programming. It is widely used in window, web-based, enterprise and mobile applications. Java主要用于应用程序设计。广泛应用于窗口、网络、企业和移动应用中。 |
Design Goal设计目的 | C++ was designed for systems and applications programming. It was an extension of C programming language. C++是为系统和应用程序设计的。它是C编程语言的扩展。 | Java was designed and created as an interpreter for printing systems but later extended as a support network computing. It was designed with a goal of being easy to use and accessible to a broader audience. Java是作为打印系统的解释器而设计和创建的,但后来扩展为支持网络计算。它的设计目标是简单易用,让更多的人能够使用。 |
Goto | C++ supports the goto statement. C++支持goto语句。 | Java doesn‘t support the goto statement. Java不支持goto语句。 |
Multiple inheritance多重继承 | C++ supports multiple inheritance. C++支持多重继承。 | Java doesn‘t support multiple inheritance through class. It can be achieved by interfaces in java. Java不支持通过类来实现多重继承。在java中可以通过接口来实现。 |
Operator Overloading操作符重载 | C++ supports operator overloading. C++支持操作符重载。 | Java doesn‘t support operator overloading. Java不支持运算符重载。 |
Pointers指针 | C++ supports pointers. You can write pointer program in C++. C++支持指针。你可以在C++中编写指针程序。 | Java supports pointer internally. However, you can‘t write the pointer program in java. It means java has restricted pointer support in java. Java内部支持指针。但是,你不能在java中写指针程序。这意味着java中对指针的支持受到了限制。 |
Compiler and Interpreter编译器和解释器 | C++ uses compiler only. C++ is compiled and run using the compiler which converts source code into machine code so, C++ is platform dependent. C++只使用编译器。C++是使用编译器编译和运行的,编译器将源代码转换成机器代码,所以,C++是依赖于平台的。 | Java uses compiler and interpreter both. Java source code is converted into bytecode at compilation time. The interpreter executes this bytecode at runtime and produces output. Java is interpreted that is why it is platform independent. Java同时使用编译器和解释器。Java源代码在编译时被转换为字节码。解释器在运行时执行这个字节码并产生输出。Java是被解释的,这就是为什么它是独立于平台的。 |
Call by Value and Call by reference按值调用和按引用调用 | C++ supports both call by value and call by reference. C++支持按值调用和按引用调用 | Java supports call by value only. There is no call by reference in java. Java只支持按值调用。 |
Structure and Union结构和集合 | C++ supports structures and unions. 支持 | Java doesn‘t support structures and unions. 不支持 |
Thread Support线程支持 | C++ doesn‘t have built-in support for threads. It relies on third-party libraries for thread support. C++没有对线程的内置支持。它依靠第三方库来支持线程。 | Java has built-in thread support. Java有内置的线程支持。 |
Documentation comment文档注释 | C++ doesn‘t support documentation comment. C++不支持文档注释 | Java supports documentation comment (/** ... */) to create documentation for java source code. Java支持文档注释来创建java源代码的文档。 |
Virtual Keyword虚拟关键字 | C++ supports virtual keyword so that we can decide whether or not override a function. C++支持虚拟关键字,这样我们可以决定是否覆盖一个函数。 | Java has no virtual keyword. We can override all non-static methods by default. In other words, non-static methods are virtual by default. Java没有虚拟关键字。我们可以默认覆盖所有非静态方法。换句话说,非静态方法默认是虚拟的。 |
unsigned right shift >>>无符号右移>>> | C++ doesn‘t support >>> operator. 不支持 | Java supports unsigned right shift >>> operator that fills zero at the top for the negative numbers. For positive numbers, it works same like >> operator. Java支持无符号右移>>>运算符,对于负数,在顶部填入0。对于正数,它的工作原理和>>运算符一样。 |
Inheritance Tree继承树 | C++ creates a new inheritance tree always. C++总是创建一个新的继承树。 | Java uses a single inheritance tree always because all classes are the child of Object class in java. The object class is the root of the inheritance tree in java. Java总是使用单一的继承树,因为在java中所有的类都是Object类的子类。在java中,对象类是继承树的基类。 |
Hardware硬件 | C++ is nearer to hardware. C++更接近硬件。 | Java is not so interactive with hardware. Java与硬件的交互性不强。 |
Object-oriented面向对象 | C++ is an object-oriented language. However, in C language, single root hierarchy is not possible. C++是一种面向对象的语言。但是,在C语言中,单根层次结构是不可能的。 | Java is also an object-oriented language. However, everything (except fundamental types) is an object in Java. It is a single root hierarchy as everything gets derived from java.lang.Object. Java也是一种面向对象的语言,然而,在Java中,所有的东西(除了基本类型)都是对象。它是一个单一的根层次结构,因为所有的东西都是从java.lang.Object.派生出来的。 |
File: main.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello C++ Programming";
return 0;
}
File: Simple.java
class Simple{
public static void main(String args[]){
System.out.println("Hello Java");
}
}
原文:https://www.cnblogs.com/saisesai/p/13089574.html