What is the difference between Java and C + +?

Source: Internet
Author: User

From (Baidu knows) to be retained from watching

For basic mastery, the two are relatively similar. Because they are object-oriented languages, most of the syntax is similar. However, Java is relatively easy to use because Java does not have a pointer concept, and it is done through a Java virtual machine, so it is easier for programmers. C + + requires programmers to master the memory of the application and release, if not mastered, it is prone to program crashes and other issues. Java language and C + + language to learn better, then third-party library is essential, such as the Java Swing, C + + ACE, etc. are very good class library, must master these skills. In terms of language rankings, the two are the top 3. Java has a slight advantage. The outlook for employment is both developing, but it is relatively difficult to learn Java and then to C + +, whereas C + + is relatively easy to transition to Java. Personal knowledge, such as self-study, it is recommended to learn Java, Overall relative C + + will be easier. The difference: —————— Java and C + + are object-oriented languages. In other words, they are capable of implementing object-oriented thinking (encapsulation, inheritance, polymorphism). And because C + + in order to take care of a large number of C-language users, and compatible with C, making itself only a band-Class C language, more or less affect the thoroughness of its object-oriented! Java is a completely object-oriented language, with a clearer syntax, smaller size, and easier learning. It is based on a thorough and detailed study of a variety of programming languages, and it abandons the shortcomings of other languages and fundamentally solves the inherent defects of C + +. There are more similarities between Java and C + +, but the main differences between the two languages make Java easier to learn and the programming environment simpler. I cannot completely list the differences here, only the more significant differences are listed: 1. The pointer Java language makes it impossible for programmers to find pointers to direct access to memory without pointers, and to add automatic memory management capabilities to effectively prevent pointer manipulation errors, such as system crashes caused by wild pointers, in the C + + language. But it is not that Java does not have pointers, the virtual machine inside or use a pointer, but outsiders are not allowed to use it. This facilitates the security of Java programs. 2. Multiple inheritance C + + supports multiple inheritance, a feature of C + + that allows a class to be derived from a multi-parent class. Although multiple inheritance is powerful, it is complex to use and can cause a lot of trouble, and it is not easy for the compiler to implement it. Java does not support multiple inheritance, but allows a class to inherit multiple interfaces (Extends+implement), realizes the function of multiple inheritance of C + +, and avoids the inconvenience caused by multiple inheritance implementations in C + +. 3. Data types and class Java are fully object-oriented languages, and all functions and variables departments must be part of the class. In addition to the basic data types, the rest are used as class objects, including arrays. Objects combine data and methodsUp and encapsulate them in a class so that each object can implement its own characteristics and behavior. C + + allows functions and variables to be defined as global. In addition, the structure and union in C + + is removed in Java, eliminating unnecessary hassles. 4. All objects in the automatic memory management Java program are built on the memory stack with the new operator, which is similar to the C + + operator. The following statement consists of an object that establishes a class Read, and then calls the work method of the object: Read R=new read (), r.work (), statement read r=new read (), and an instance of read on the stack structure. Java automates garbage collection operations without the need for a programmer to delete them. and C 20 must be released by the program Shell memory resources, increase the program designer's negative throw. In Java, when an object is not reused, the garbage collector adds a label to it to delete it. Useless memory recycling programs in Java run in the background in a threaded fashion, using idle time to work. 5. Operator overloading does not support operator overloading. Operator overloading is considered a prominent feature of C 20, although in Java the class can generally implement such a function, but the convenience of operator overloading is still missing a lot. The Java language does not support operator overloading in order to keep the Java language as simple as possible. 6. Preprocessing features Java does not support preprocessing. A pre-compilation phase, known as a pre-processor, is available during the compilation process for C/E 20. The preprocessor provides convenience for developers, but increases the complexity of the Ding compilation. The Java Virtual machine does not have a preprocessor, but it provides an introduction statement (import) similar to the functionality of the C 20 preprocessor. 7. Java does not support default function parameters, while C 20 supports C, where code is organized in functions, functions can access the program's global variables. C 20 adds the class, provides the class algorithm, the algorithm is a function connected to the class, the C 20 class method is very similar to the Java class method, however, because C 20 still supports C, so C 20 developers can not prevent the use of functions, the result of mixed use of functions and methods to make the program more chaotic. Java has no functions, and as a more pure object-oriented language than C 20, Java forces developers to include all the routines in the class, in fact, implementing routines in a way that motivates developers to better organize coding. 8 Strings C and C 20 do not support string variables, using the null terminator in C and C 20 programs to represent the end of the string, in Java strings are implemented with class objects (string and StringBuffer), which are the core of the Java language. Implementing a string with a class object has several advantages: (1) The method of establishing a string and accessing string elements is consistent throughout the system; (2) the wordThe string class is defined as part of the Java language, not as an additional extension; (3) The Java string performs run-time check-out to help troubleshoot some runtime errors, and (4) to concatenate strings with "ten". 9. "Goto" statement "terrible" goto statement is C and C + + "relic", it is the technical legal part of the language, referring to the GOTO statement caused the program structure confusion, difficult to understand, goto sentence to be used for unconditional transfer subroutine and multi-structure branch technology. Given the wide justification, Java does not provide a goto statement, which, while specifying Goto as the keyword, does not support its use, making the program simple and readable. L0. Type conversions sometimes include implicit conversions of data types in C and C 20, which involves automatic coercion of class conversions. For example, in C 20, you can assign a floating-point value to an integer variable and remove its mantissa. Java does not support automatic coercion of type conversions in C 20 and, if required, must be explicitly enforced by the program for type conversions. 11. Exception mechanisms in abnormal Java are used to capture exception events and to enhance system fault tolerance try{//code}catch (exceptiontype name) {///processing} where the exception may be generated, where exceptiontype represents the exception type. and C + + does not have such a convenient mechanism.

What is the difference between

Java and C + +?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.