A simple transition from C + + to Java

Source: Internet
Author: User
Tags arithmetic operators goto multiple inheritance in c

For people with C + + experience, learning Java Sense and C + + is not much different

The main core content of C + + is the use of classes and objects, involves inheritance of objects, but for Java it simplifies the more cumbersome parts of C + +, in C + + construction Dynamic Data allocation, and the pointer, it can be said that the pointer is very disgusting, often cause the system burst, the distribution of data is not clear , Java is all classes, all are in the class programming mechanism, except for the memory of the system Cahe these things, you can say that Java is God, God said there is nothing.

Java has no functions, but Java classes and methods can implement any of the tasks that C + + uses with functions. C language programmers want to find in the standard library of functions, Java with various classes of static methods to implement. For example, trigonometric functions are implemented as static methods of the math class, and as a static method, users do not necessarily have to create a math object to use them.
Although multiple inheritance is an effective way for a C or C + + language to derive a class from multiple parent classes, this derivation is very complex and therefore prone to problems. It is for this reason that Java developers do not use multiple inheritance, Java similar to the Objective C protocol interface to achieve multiple inheritance in C + + can do all the tasks.
In Java, the Goto statement in the C + + language is not used for simplicity, so Java may not care about the rules associated with goto statements. Multiple break and continue in Java can realize the function of Goto statement in C + + language.
There are three complex data types in the C + + language: Unions, structs, and classes, while in Java, only classes are used, and in C + + the work of combining and structuring is implemented in Java with classes.
In Java, programmers no longer overload the standard arithmetic operators, and operator overloading is an important feature of the C + + language, while in Java the creation of parallel functionality (parallel funtionality) is achieved through classes.
Java source code is simple, it does not require #define statements, preprocessor or typedef. The Java language removes the TypeDef and define, but requires a header file. In addition, the Java language derives the definition of other classes and their methods from the source file. In contrast to C + + +, information about a Java class must be contained in a file, while the information about classes in C and C + + may be dispersed between a header file and multiple code files.
The Java language does not allow automatic casts of data types. Programmers in C + + can assign a value to a variable, but the value assigned to the variable may be lost because of the variable application environment. Forcing a type of data element in Java into a less precise data type requires programmers to use predictive methods.
The Java runtime system allows the delivery of command-line variables. This syntax is somewhat similar to the syntax of the C language, but the program name is not in the list of variables because its name is the same as its class.


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.