Difference between CC ++ and Java

xiaoxiao2021-03-06  42

Difference between C / C and Java Difference Between Java and C / C Original Review: http://docs.rinet.ru/jintra/appe.htmi.a_7

Preprocessor: All C / C compilers have a phase in the compilation process, called the pre-processor .c preparations are mainly search and replacement, # define, # typedef and other indicators. The declared identifier. Although most C advocates do not advocate the use of this feature that is inherited by C language, this usage is also widely used in C programmers. C definition It is stored in the header file used to supplement the actual code file.

The problem with the method of using the preprocessor is that the programmer is easy to add a complexity of the program inadvertently. One example is in a project, many programmers use the # define, # typedef and other indicators to indicate themselves. A series of nouns created, which directly leads to the other programmers to find the appropriate information in order to understand the procedures, so that the maintenance and reuse of the code are almost impossible. Another The problem with the pre-processor method is to lack sufficient stability when performing type inspection or validity check.

There is no preprocessor in Java. It provides a similar function function with the C preprocessor, and has deepened the control. Use the regular data member to replace the #define indicator, use the class definition to replace the #typedef used. Just make Java source code more coherent and readable than C . In addition, Java programs do not use header files, Java's compiler creates class definitions directly from the source code that simultaneously contains the definitions and methods implemented.

Most developers of the pointer agree that when using C / C programming, the misunderstanding of the pointer is the main reason for the program error. In short, when you have a pointer, you have the ability to destroy memory. C Programmers typically use complex pointer operations to create and maintain dynamic data structures, the result is that the C programmer spends a lot of time to solve the thousands of mysterious problems caused by the complex pointer operation.

Java language does not support pointers. Java implements a large number of references to implement similar to pointers. Java, all arrays and objects are passed by reference. This method avoids the error management due to pointers Common mistakes. This makes programming in many ways to simplify, because in addition to those experienced programmers, the average person is easily confusing the correct pointer usage.

You may think that because there is no pointer, many data structures such as dynamic arrays are not possible in Java. In fact, any tasks that can be completed can be more reliable with objects and array objects. You can also benefit from Java's Runtime System provides security guarantees, such as the index of all arrays to the boundary check.

Structures and UNINIONS has three complex data types in C : class, structure, and joint. Java only implements one of these three types: class .java will force users to use classes to replace the use of structures or Union to achieve the features required. Although the programmer needs to pay more work, in fact, because the class can simulate the structure and joint, this makes the code more coordinated .java designer sincere hope The simplicity of the language is maintained, so the repeated part of the language feature is eliminated.

Functions: In the C language, the code is based on the functions of the functions of the functions constructed by each subroutine, which is the method of the class, which is related to the class-related function .c It is very similar to Java. However, due to the support of C to C, there is no way to make C programmers do not use functions in the class. The mixing of the function and method directly leads to the confusion of the program understanding. .

There is no function in Java. As a pure-oriented language than C , the Java enforcement programmer integrates all the programs to the method. Forced usage, instead of other limits. The result is that method is The form is implemented to encourage programmers to better organize code structure. Remember this: Use the function and there is no error on any program path. It is just not compliant with object-oriented essences in the Java paradigm.

Multiple Inheritance Multiple inheritance is a feature of C , which allows you to derive subclasses from different parent class. Although multiple inheritations are sometimes a powerful inheritance, the error is used due to complexity, It is often caused. From the perspective of the compiler, multiple inheritors are also very complex and difficult to achieve. Java selection other ways without direct support. You can achieve and multiple inheritance through the Java interface (Interfaces) Similar functions. The interface of Java provides an object method description without incorporating the implementation.

Strings (strings) C and C do not add text strings to its built-in type. One standard technology used in C is to mark strings in an array in an empty end.

In Java, the string is implemented as the first class object (String and StringBuffer), which means that Java provides kernel-based support. Java uses objects to implement strings have the following advantages:. Cross Platforms and languages ​​create strings and management of elemental access. Because the strings in Java are defined as part of the language rather than a part of the extension, this makes the Java string function with predicata .. Java executes Extensive Runtime Checking, which helps eliminate some tricky runtime errors.

Even in C and C , the GOTO statement is also controversial, but from the technical statement, the GOTO statement is part of the language legal. The criticism of the goto statement has come from It will cause confusion and unreadable code structure, sometimes even cause a so-called "pasta", non-predictable. Goto statement generally applies to places where do not need to be jumped, more structured branch technology .

For such a reason, Java does not support GOTO statement. Java language specifies that Goto is a keyword, but does not support it. I think Java designers even want to eliminate "goto" as an identifier. Possibility. Java language does not contain a goto statement makes language simplification and avoids writing code.

Operator overloading operator overload, as a significant feature of C , while Java does not support. Although Java provides similar functions through some implementations of classes, it is still lacking some conveniences brought by operator overload. However, From the perspective of protecting Java, operator overload may sometimes become tits. There is no doubt that Java's developers make language does not support operator overload making Java simplified as possible.

Automatic Coercions automatically reduces the implicit conversion associated with data types that appear in C / C . For example: You can assign a FLOAT value to an int variable in C , which will result in a loss of some information. .Java does not support the automatic reduction of C style. In Java, if some reduction can cause data loss, you must explicitly specify the data type to be converted.

Variable Arguments C / C Allows you to declare a function using variable parameters, such as Printf. Although this is a convenient feature, but also makes the compiler unable to check the parameter type, this means There will be some questions you don't know when running. Java does not support variable parameters.

Command line parameters (Command-line arguments) system pass to the Java program command line parameter command line parameters passing to the C program is a very different. Different, passing to the number of parameters passing to both languages. In C / C , the system passes two parameters: argc and argv, the former specifies the number of parameters stored in Argv, the latter is a character pointer to the stored argument group address. In Java, the system passes to The program is a separate value: args.args is a string array containing the command line argument.

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

New Post(0)