Home > Java > javaTutorial > What is the difference between C++ and Java

What is the difference between C++ and Java

青灯夜游
Release: 2019-03-11 09:15:50
Original
5536 people have browsed it

C and Java are the most commonly used programming languages. Java has a strong C influence as it was developed after C and both support the object-oriented programming (OOP) paradigm. So what's the difference between the two? The following article will introduce to you some differences between C and Java. I hope it will be helpful to you.

What is the difference between C++ and Java

A brief introduction to C

C language syntax is a super version of C Set; C was developed to extend the procedural C language to include OO functionality. In C, some units are object types and some are traditional primitive types, so it's a mixed language. Due to its origin, it is sometimes inconsistent with pure OO programming (e.g. standalone functions). However, the syntax and semantics remain stable between native and object data types. [Video tutorial recommendation: C Tutorial]

Memory Management in C

C exposes its memory management to programmers, which is beneficial Customizable memory allocation strategy. Objects (primitive or class types) declared at compile time have static storage allocated by the compiler. The new operation is used to obtain dynamic storage from the heap at runtime and should be explicitly deleted using the delete operation when not in use. The memory address remains fixed for the lifetime of the object. It does not provide runtime error detection.

A brief introduction to java

What is the difference between C++ and Java

Java is an object-oriented programming language. Every java Programs are defined as a class. It is a portable, device-independent language. Java's popularity comes from its large associated class library and its portability. [Video tutorial recommendation: java tutorial]

Java has unique primitive and object types and is a strongly typed language. It has no syntax for referencing primitives, but provides facilities for converting primitives and corresponding object types, such as int and integer.

Memory management in Java

Memory management is the category of JVM. Java code (data and methods) remains within the context of the class. The garbage collector is used for object release, where the system returns object memory to its pool when the object is no longer useful. Java also provides runtime memory error detection and throws appropriate exceptions when detected.

The difference between C and Java

What is the difference between C++ and Java

1. Platform dependency

When compiling, Java source code is converted into bytecode; at runtime, the interpreter executes this bytecode and provides output. Java is primarily an interpreted language and therefore platform-independent.

And C uses a compiler to compile and run source code. It converts source code into machine-level language; therefore C is platform dependent.

2. Memory management

In C, objects are located at fixed addresses and memory is managed by the programmer. Java has system-controlled memory management, and objects can be relocated in memory.

3. Inheritance model

C supports single inheritance and multiple inheritance; while Java supports single inheritance, but does not support multiple inheritance, but uses abstract interfaces.

4. Polymorphism

Java provides automatic polymorphism; in C, polymorphism is explicit for each specific method.

5. Universal base class

There is no universal base class in C; while in Java, there are universal object ancestors.

6. Portability

Java code is portable; C does not provide portability.

7. Typing semantics

The semantics in C are consistent between primitive types and object types. In Java, there are differences in the semantics of primitive types and object types.

8, All functions and data exist in classes in Java. C allows functions and data to be outside any class.

9, The Java library provides a large number of classes for advanced services and system integration; while the C library provides low-level functions, but provides a rich set of general (template) containers (data structures) and algorithm.

The above is the detailed content of What is the difference between C++ and Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template