📜  Java和C++之间的异同

📅  最后修改于: 2021-05-30 07:06:11             🧑  作者: Mango

如今, Java和C++编程语言已广泛用于竞争性编码中。由于某些强大的功能,这两种编程语言也经常在工业中使用。 C++因其高效,高速和动态内存利用率而在编程人员中广为流行。 Java在IT行业中广泛存在,就软件开发而言,它与任何其他编程语言都无法比拟。
让我们通过各个方面来比较这些流行的编码语言:

Java和C++之间的相似之处

  1. 执行:在编译时,使用Java源代码或。 Java文件将转换为字节码或.class文件。在运行时,JVM(Java虚拟机)将加载.class文件,并将在解释器的帮助下将其转换为机器代码。编译方法调用后(使用即时(JIT)编译器),JVM将执行优化的代码。因此, Java既是编译语言,也是解释语言。

    另一方面,C++仅使用编译器来执行代码。 C++编译器将源代码编译并将其转换为机器代码。这就是为什么C++比Java更快,但与平台无关的原因。

    下面是如何执行Java和C++代码的说明:

    执行Java代码

    执行C++代码

  2. 功能: C++和Java都具有几种面向对象的编程功能,这些功能提供了许多有用的编程功能。一个功能支持某些功能,而某些功能则不支持。
    下表显示了两种编程语言都支持和不支持的功能:
    Features C++ Java
    Abstraction Yes Yes
    Encapsulation Yes Yes
    Single Inheritance Yes Yes
    Multiple Inheritance Yes No
    Polymorphism Yes Yes
    Static Binding Yes Yes
    Dynamic Binding Yes Yes
    Operator Overloading Yes No
    Header Files Yes No
    Pointers Yes No
    Global Variables Yes No
    Template Class Yes No
    Interference and Packages No Yes
    API No Yes
  3. 应用程序: C++和Java都有广阔的应用领域。以下是这两种语言的应用:
    • C++编程语言的应用
      1. 适用于开发大型软件(如乘客预订系统)。
      2. MySQL是用C++编写的。
      3. 为了快速执行,C++主要用于游戏开发中。
      4. Google Chromium浏览器,文件系统,集群数据处理均使用C++编写。
      5. 这些流行的应用程序Adobe Premier,Photoshop和Illustrator用C++编写。
      6. 先进的计算和图形-实时物理模拟,高性能图像处理。
      7. C++还用于许多先进的医疗设备,例如MRI机器等。
    • Java编程语言的应用
      1. 桌面GUI应用程序开发。
      2. Android和移动应用程序开发。
      3. Java的应用是在诸如SIM卡,磁盘播放器,电视等嵌入式技术中。
      4. Java EE(企业版)提供用于运行大型企业软件的API和运行时环境。
      5. 网络应用程序和Web服务,例如Internet连接,Web App开发。
  4. 环境: C++依赖于平台,而Java是独立于平台的编程语言。我们必须在同一平台上编写和运行C++代码。 Java具有WORA(一次写入并在任何地方运行)功能,通过该功能,我们可以在一个平台上编写一次代码,并且可以在任何地方运行代码。

Java和C++之间的差异

Parameters Java C++
Founder Java was developed by James Gosling at Sun Microsystems. C++ was developed by Bjarne Stroustrup at Bell Labs since 1979 as an extension of the C language.
First Release On May 23, 1995 In October 1985
Stable Release Java SE 14 or JDK 14 was released on March 17, 2020. C++17 was released in December 2017.
Official Website oracle.com/java isocpp.org
Influenced By: Java was Influenced by Ada 83, Pascal, C++, C# etc languages. C++ was Influenced by Influenced by Ada, ALGOL 68, C, ML, Simula, Smalltalk etc language.
Influenced to: Java was influenced to develop BeanShell, C#, Clojure, Groovy, Hack, J#, Kotlin, PHP, Python, Scala etc languages. C++ was influenced to develop C99, Java, JS++, Lua, Perl, PHP, Python, Rust, Seed7 etc languages.
Platform Dependency Platform independent, Java bytecode works on any operating System. Platform dependent, should be compiled for different platform.
Portability It can run in any OS hence it is portable. C++ is platform dependent hence it is not portable.
Compilation Java is both Compiled and Interpreted Language. C++ is only Compiled Language.
Memory Management Memory Management is System Controlled. Memory Management in C++ is Manual.
Virtual Keyword It doesn’t have Virtual Keyword. It have Virtual Keyword.
Multiple Inheritance It supports only single inheritance. Multiple inheritance achieved partially using interfaces. It supports both single and multiple Inheritance.
Overloading It supports only method overloading and doesn’t allow operator overloading. It supports both methods and operators overloading.
Pointers It supports limited support for pointers. It strongly supports Pointer.
Libraries It doesn’t support direct native library call, but through only Java Native Interfaces. It supports direct system library calls, making it suitable for system-level programming.
Libraries libraries have a wide range of classes for various high-level services C++ libraries are comparatively with low level functionalities.
Documentation Comment It supports documentation comment (e.g, /**.. */) for source code. It doesn’t support documentation comment for source code.
Thread Support Java supports documentation comment (e.g, /**.. */) for source code C++ doesn’t have built-in support for threads, depends on third party threading libraries.
Type Java is only object-oriented programming language. C++ is both a procedural and object-oriented programing language.
Input-Output mechanism Java uses the (System class) System.in for input and System.out for output. C++ uses uses cin for input and cout for an Output operation.
goto Keyword Java doesn’t support goto Keyword C++ supports goto keyword.
Structures and Unions Java doesn’t support Structures and Unions. C++ supports Structures and Unions.
Parameter Passing Java supports only Pass by Value technique. C++ supports both Pass by Value and pass by reference.
Global Scope It supports no global scope. It supports both global scope and namespace scope.
Object Management Automatic object management with garbage collection. It supports manual object management using new and delete.
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”