Basic differences between Java and C ++

Source: Internet
Author: User
Tags define function

Preface

Java groups are expanding every day, including some of the world's largest ISVs, it also includes the company's CIOs, information technology personnel, system analysts, C/S developers, programmers, multimedia designers, marketing staff, educators, managers, Video Producers and even amateurs.. Traditionally, it is rare for such people to work effectively together. When talking about open systems, we often talk about published APIs and specifications, source code availability, or hardware, networking, and operating systems, no one is talking about people in the open sense. Java completes the closed chain of open systems. It develops human resources and, in turn, opens up the way to work together.

When talking about Java, people will immediately think of an object-oriented programming language similar to C ++ that is suitable for distributed environments, think of the features of this language, such as simplicity, stability, security, unrelated to the architecture, portability, interpretability, high performance, multithreading, and dynamic. These are the main features of Java as a programming language.

Java was developed by a technical team of Sun. In the process of implementing the Java language, the Sun Team's technical staff quickly realized that C ++ could not become a fully object-oriented and networked development language. C ++ is developed by adding object-oriented functions to the original C language. Therefore, it has inherent limitations. This is mainly reflected in the wide variety of C ++ features, a large number of redundancy, and no C ++ compiler can support all its functions. In view of this situation, Sun's technical staff decided not to expand C ++, but to develop a new computer language (Oak, the predecessor of Java ). However, C ++ has become a language that most programmers are familiar with. The Java design obviously cannot ignore this reality. If the difference between Java and C ++ is too large, it will undoubtedly take a lot of time and effort for programmers to learn the language. Therefore, Java retains as many C ++ styles as possible.

Since its birth, Java has created numerous small applications on clients for network users. This type of applications have good performance and a large number of results, so many users think of the Java programming language, an incorrect impression appears in my mind-Java is used to write small client programs. In fact, with the advancement of technology, the Java language is gradually changing its image of low execution efficiency, unable to serve as a key computing task for enterprises, and is constantly moving forward to the core of computing technology. Today's Java technology is penetrating various application fields along the network.

Enterprise computing: enterprise computing is the most important technical topic of Java. Sun has released the specification of Enterprise JavaBean (EJB, Enterprise JavaBean), and many companies began to develop Java Technology in the Enterprise application field. IBM has also developed ibm hpcj (High Performance Compiler for Java) 12.0 for Windows NT, and developed ibm jdk (JavaDevelopment Kit) for Windows NT, novell also announced a new server-side Enterprise Java platform, and Sun is actively upgrading its JDK system. This situation shows that Java is steadily moving towards enterprise high-end computing. For Java, the main programming tool competing with other programming languages for enterprise computing has the following advantages: first, when Java is engaged in Object-Oriented Programming, it is simpler than other programming languages such as C ++, so it ensures high programming efficiency and reduces programming investment. Second, the Java Virtual Machine technology provides "one-time programming, the cross-platform capability that is used everywhere is very suitable for the network environment, which provides convenience for Java's development on the network server side. Third, Java has a strong team of providers and supporters, this team includes IBM, Oracle, Novell, Sybase, Netscape, and other companies.

Speed-up operation: many enterprise application developers love the Java language features very much. However, when developing important systems, the choice between language features and execution efficiency is often confusing. In key computing, users may not care about how to compress data or how to set the running delay relationship, but pay great attention to the running speed of the program, this puts Java compilation policy development first. The current Java language does not just explain the execution method. The instant compiler (JITC, just-in-time compiler) technology and prototype compilation technology have been adopted by many manufacturers, technology providers, including Sun, IBM, Oracle, and Netscape, are using these technologies to gradually increase Java execution speed. Among them, IBM has already added the Java Virtual Machine (JVM, JavaVirtual Machine) the operating system and hardware features are organically combined to greatly improve the Java execution efficiency.

Embedded Computing: embedded Java is an application technology with great potential. It gives full play to the small and flexible features of Java. Taking HP as an example, the company manufactures compilation tools and Java virtual machines in its own way to embed Java into various devices, such as printers, medical monitors, and ATMs. Embedded devices rely on a real-time operating system to process an event that takes effect in real time. After Java is embedded into these devices, real-time extension is applied, this gives the device a certain degree of intelligence, enhances the manageability and availability of the embedded device, and greatly improves the work efficiency of the device. Each Vendor attaches great importance to this potential market. Currently, this market lacks a standard. If there is a standard, I believe that a large number of devices embedded in Java will soon be available.

Microsoft's just-released Windows XP gave up its support for Java, but Java can run independently on many operating platforms, including Linux, in addition, it is better to use some features than on Windows. We have reason to abandon Windows and choose Linux for Java development. Now, you can hold Linux in your left hand, Java in your right hand, and then say to Bill Gates with Windows XP in your smile: "Let's hell with your XP! "

For software developers, no programming language can be perfect. If you want to better understand the Java language, the best way is to compare the language with the same type of language. Since Java is similar to C ++, comparing it with C ++ is also a matter of course. Every developer has their own opinions on which one is good and which one is not good. I personally think Java Development is better than C ++. Of course, everyone's views and preferences are different. Later articles will introduce the differences between Java and C ++ and their improvements. Strong or weak, you will naturally understand.

We know that Java uses the C ++ syntax format at the beginning, basically to allow programmers to quickly familiarize themselves with the Java syntax format and shorten the learning time of Java, after all, C and C ++ are still the most common programming languages. However, if we carefully examine the detailed design of the Java program language, we can find that Java removes many C ++ features and adds some new features. These differences with C ++ include:

1. Preprocessor functions such as # define and # include are no longer available

An important feature of C ++ is its Preprocessing Program. Some other programming languages also include the # include function, but still lack the ability to process macros (Macro. # The define function can be replaced by the constant method in Java, but # include is not required in Java, because during Java program execution, the data type is recorded in the object. We do not need to rely on some header files to know the Data Type of the object or value we are using.

If you only use the # include and # define functions of the Preprocessing Program when using the C ++ language, you probably won't feel any troubles caused by the design like Java, however, if you are a master of macro functions in the C ++ Preprocessing Program, you may find it inconvenient and doubt the significance of such a design in Java.

Although preprocessing programs can easily achieve many functions, the maintenance of the entire software is unfavorable from the perspective of software engineering. Since the Preprocessing Program in C ++ is too powerful, a powerful programming Expert often develops a set of macro languages that can only be understood by himself, once the entire software is handed over to others for maintenance, it is difficult for the successor to understand the macro functions written by the previous person in a short period of time, increasing the difficulty of team work and maintenance in the future during software development.

Another point is the program code seen by the C ++ compiler, which is actually different from the program code seen by the program designer. The program designer sees the program code that has not been processed by the Preprocessing Program, and the compiler sees the program code that has been processed by the Preprocessing Program. Once the macro content handed over to the Preprocessing Program for processing is incorrect, the error message generated by the compiler will not be expected by the programmer. This also increases the difficulty of the program in troubleshooting.

The existence of the Preprocessing Program also causes inconvenience in reading the program. If you want to use a C ++ language program that has been completed by someone else, you should not only read the file written by others, but also check the file together to get a full picture of the program. For a Java program, you only need to check the java program file.

2. structure, union, and typedef are no longer available

In fact, as early as C ++, we can remove structure and union in C language and other custom structure types for complex data, because the Class definition method can fully implement this function. Typedef is not necessary. You can use all classes. Although C ++ is designed to be compatible with C, it is not only unnecessary to use redundant language features, but also easy to confuse the program.

3. No more functions

In Java programming language, the most important unit in the language of the program wizard-Function is removed ). If we look at the function as an object wizard, we can understand the concept of the function in the object wizard, it is not necessary. In the program concept of object wizard, object data is the real subject, and the method for processing object data must be attached to the object to make sense. Therefore, removing a function does not mean that there is no module-based procedures such as subprograms. On the contrary, the function is replaced by methods in the object, and the development strategy of the Wizard is strengthened again.

4. Multiplelnheritance)

In C ++, multi-inheritance is a strong function, but it is also difficult for general people to control. Removing multiple inheritance reduces Java functions, but also greatly simplifies the difficulty of writing programs. Although the multi-inheritance function is removed, Java provides the interface method to achieve some multi-inheritance functions. The so-called interface basically defines the prototype of the method for external communication of a class, and the constant number inside the class. Unlike the multi-inheritance, the interface does not define the content of the class method, and variable data in the class.

5. No more Goto

In the history of programming language development, Goto has always been a function of mixed reputation. In many cases, the use of Goto can greatly reduce unnecessary program code, but also because Goto can freely change the process of the program, if you use it rashly, it is more likely to cause program structure confusion. In general, examples of correct use of Goto appear inside the loop and want to end a loop early. In the C language, we can use break or contine to change the process of a certain layer of loop. However, if we want to change the process of two or more layers of loop execution, we can use a boolean instead of a Goto) variable, combined with the previous string if-then

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.