The difference between Java and C ++

xiaoxiao2021-03-06  42

Firstly, the purpose of writing (declaration:) This article is the purpose of this article: a problem involved in the interview, there is no one must be staged, unless you start

Learning Java: Java and C Differences (1) 1. Language Background: C is a very broad C language development in the single-machine era, basically along the language elements, the excellent features of C,

Object-oriented. C is based on a intermediate language between assembly languages ​​and advanced languages, which combines the simple and easy-to-use and assembly language of advanced languages ​​and resource access.

The basic cross-platform properties of the code level are also realized. Java is implemented on the basis of researching electronic consumer product development platforms and Internet applications. Many of its language features are also from C language.

Use and develop, and make the object-oriented more natural and perfect, its natural network characteristics (such as security and code mobility). 2. Language characteristics: Definition of data type: two kinds

Language provides a very rich data type, but C language is different in different platforms, or even different compiler data types, Java is strictly defined data types.

Storage mode makes any type of byte bit number on different platforms. For example, int variables, in different platforms, different compilers are 32 bits (BIT),

For C language, Windows and UNIX may not be the same, the same as the UNIX system, 32-bit machine and 64-bit machine may not be different; pointer management: pointer is C (C )

The biggest advantage, it allows users to almost access all of the memory resources of the computer and other resources. At the same time, it is also the hardest problem with the C (C ) program, and to the system

Safety and stability have brought great difficulties. There is no concept of the pointer in Java, although there are also the concepts of array and objects, but its management is handed over to system management, which limits

The user's resources are accessed, but it also brings security and stability to the Java system. Memory Management: The management of memory management and pointer is much related, and the pointer is often used to represent a paragraph.

RAM. Memory management (developer-based) mainly includes memory distribution and memory release, in the C language allocation is basically managed between programmers, release also needs to be programmed

The person is released. And different allocation methods (new, malloc, etc.) have different release methods (delete, free, etc.) and must be consistent. This way provides users with resource access.

Ask the degree of freedom and control, but also bring many potential hazards to memory management, such as the assigned memory must be released, otherwise the memory vulnerability will cause memory vulnerabilities; there is no release before the distribution

Apply by other pointers, it may cause the system to crash. Java is assigned by the user in the array and object reference, and the specific assignment is determined by the system,

The programmer does not have to be released, and the system introduces memory automatic release and automatic recycling of memory management in memory management, which ensures the security and stability of the system, of course

The programmer restrictions on system resource access are limited. 3. Object-Oriented Characteristics C and Java provide object-oriented three major features: package, inheritance, and polymorphism. But in specific

There is the following main differences: A.c can make multiple inheritances on inheritance, ie a child object can have multiple parent objects, while Java only implements a single inherit, that is, an object only

Can be used by 0 or a parent; but Java can combine interfaces and single inheritance, implementing multiple inheritance; B.C 's concept, polymorphism of virtual objects and virtual functions It is still implemented by inheritance, so that the interim in Java introduces the concept of the interface, the child object can implement multiple interfaces, this mode

Close access to object-oriented ideas. It is also the design and implementation of the package can be completely separated. Of course, Java also provides a polymorphism mechanism for virtual objects and virtual functions; c. Introduced in Java

The concept of Package makes it more convenient to develop object-oriented and components, and there is no direct package concept in C , which needs other ways to implement. Java and C are all object-oriented

Say. That is, they all enable object-oriented ideas (packages, step by way, polymorphism). Because C is compatible with C, it is compatible with C, it is only

In order to bring a class of C language, there are fewer effects on its object-oriented thoroughness! Java is a complete object-oriented language, which is clearer, smaller, and more easy to learn. It is in a variety of procedures

Based on the preface design language, the in-depth study is based on the deficiencies of other languages, and the inherent defects of C are fundamentally solved. Similarity of Java and C is more than different

However, the two languages ​​ask a few major differences to make Java easier to learn, and the programming environment is simpler. I can't fully list the differences here, only listed a significant difference: 1

. The pointer Java language allows the programmer unable to find pointers to directly access memory without pointers, and add an automatic memory management function, effectively preventing the pointer operation in the C / C language.

Mistakes, the system caused by the wild pointer crashes. But not saying that Java does not have a pointer, the virtual machine still uses a pointer, but the outsiders are not allowed. This is conducive to the safety of the Java program

. 2. Multiple inheritance C supports multiple inheritance, this is a feature of C , which allows multiple parent classes to derive a class. Although multiple inheritance functions is strong, it is complicated, and it will cause many numbers.

It's not easy to have it to achieve it. It is also very difficult to achieve it. Java does not support multiple inheritance, but allows a class to inherit multiple interfaces (Extends Implement), implement C multiple inheritance functions, and avoid

There are many inconveniences from multiple inheritance implementations in C . 3. Data types and class Java are the language of fully object-to-object, all functions and variables must be part of the class. apart from

Outside the basic data type, the rest is used as class objects, including arrays. The object combines data and methods to encaps them in the class so that each object can realize its own characteristics and

behavior. C allows the function and variables to be defined as global. In addition, the structure and joints in C / C are canceled in Java, eliminating unnecessary trouble. 4. Automatic memory management JAVA

All objects in the order are built on the memory stack with the New operator, which is similar to the NEW operator of C . The following statement is built by a class of a class read, then

Use the object's Work method: read r = new read (); r.work (); statement read r = new read (); an instance of a READ is created on the stack structure. Java automatically performs a useless memory recycling operation, does not require programmers to delete. And c19 must release memory resources by the program, increase the negative throw of program designers. Java is not used when an object is not used

The useless memory recovery will give it a label to delete. The Used Memory Recycling Program in Java is run in the thread mode, using free time. 5. Operator overloading Java

Operators are not supported. Operator overload is considered to be a highlighted feature of C. Although the class can be substantially achieved in Java, the convenience of the operator is still lost.

less. The Java language does not support operator overloading to keep Java languages ​​as simple as possible. 6. Pre-processing functions Java does not support pre-processing. C / C 10 has a pre-compilation process

The comparative stage, that is, a well-known preprocessor. The preprocessor provides developers to provide convenience, but increases the complexity of Ding compilation. Java virtual machine does not have a preprocessor, but it provides the introduction language

IMPORT is similar to the functionality of the C 10 tether. 7. Java does not support the default function parameters, and C is supported in C, the code organization is in the function, the function can access the program's global

variable. C 10 Ten has added a class, providing a class algorithm, which is a function connected to the class, and the C10 type method is very similar to the Java class method, however, because C is still supporting C, so

It can prevent C10 developers from using functions, resulting functions, and method mixing make programs confusing. Java has no functions, as a more pure-oriented object-oriented language than C, Java

Forced developers include all routines, in fact, using methods to implement routine can incentive developers better organize encoding. 8 string C and C 10 do not support strings

Variables, using NULL terminator in the C and C ten tripes, the end of the string represents the character string, and the string in Java is implemented with the Strinr and StringBuffer, these objects are

The core of the Java language, the use of class objects have the following advantages: (1) Raising a string in the entire system and accessing a string element is consistent; (2) J3 yang string class

It is defined as part of the Java language, rather than as an additional extension; (3) Java string executes runtime empty, can help eliminate errors that occur when running; (4)

Connect the "10" to the character string. 9 "GOTO statement" terrible "GOTO statement is C and C " relics ", it is a legal part of the language technology, reference the goto statement

The chaos of the program structure is not easy to understand, and the GOTO sentence is used for unconditional transfer subroutines and multi-structure branch technology. In view of the broad ground, Java does not provide a goto statement, which is specified

Goto is used as a keyword, but does not support it, making the program simple and easy to read. L0. Type conversion Sometimes the implicit conversion of data types in C and C is involved, which involves automatic mandatory classes.

Type conversion problem. For example, a floating point value can be given to the integer variable in C19 and the mantissa is removed. Java does not support automatic mandatory type conversion in C19, if needed, must be

Explicitly mandatory type conversion. 11. Abnormal mechanisms in exception Java are used to capture exceptions, enhance system fault tolerance capabilities try {// may generate exceptions} catch

转载请注明原文地址:https://www.9cbs.com/read-77872.html

New Post(0)