In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to compile C++ source code on a virtual machine". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1.Java runs on a virtual machine
The Java source code is not compiled into ordinary machine code. Instead, it is translated into code that the virtual machine can execute. An Java interpreter eventually executes the code. There is no linking process; explain that some classes are loaded dynamically when needed
2.Java is completely object-oriented
Java is a completely object-oriented language. This means that what you do with any Java object is done through a method. The point is that there is no such isolated thing as the main function. Instead, you have to start looking at a program, an object of a class from an object point of view. But what kind of object is this object? Most Java programs simply implement what they need by inheriting the Java base class Object, but you can save time by creating a program base class for multiple applications with similar features.
Strict object-oriented rules mean that you can't use the original source code directly without modification; the same is true of system calls. In C++, you can use the original C procedure calls, including system calls, by declaring extern "C" outside C++ 's normal namespace.
In Java, there is only one similar method of secure backtracking, but it is not very simple. You have to define a local method that aims to provide an interface for the C language, and then provide the media for the connection. The Java environment provides tools to accomplish this task, but the whole process is negligible compared to the extern provided in C++, and the process of using C++ classes is more complicated because it introduces excuses for C and questions about C functions and C++ member functions.
Fortunately, many of the commonly used system utility functions have been provided in the methods in the system classes, but these clearly do not include the classes and procedures you have created over the years. Therefore, you should delve into it when you need it.
There is no separate header file in 3.Java
In Java, everything about classes is placed in a separate file. The location of a method can only occur in one place, and the implementation of a method must be carried out at the same time as it is defined. The advantage of this is that when implementing the program, it is not easy to fail because of an asynchronous error in the file, or get a declaration that is not implemented. Class declarations can be leveraged by the Java interpreter or even obtained from a compiled unit, so there is no need for a header file, as long as there is a compiled file.
The disadvantage of doing so has to do with our programming process. Many programmers who understand C++ source code like to use header files instead of documents. To see the interface parameters of a member function, you only need to look at the declaration in the header file. You can often look at the header file to see how to use this class. There is no such summary in Java. Because the code that implements the class method must appear when the method is defined, and it often takes up a whole page or more for the code of a single function. In this way, it's hard to get a preliminary idea of how classes are used by looking at Java's code. You must prepare enough documentation for the classes you need. It goes without saying that documentation is extremely scarce when dealing with non-commercial libraries.
In the current Java environment, two tools are provided to compensate for this, javap to print class identity, and javadoc to provide HTML documents for embedded programs.
4. Decompose Java namespaces with Package
A common problem in large C++ projects is namespaces-how to ensure that some programmers in the project will not create classes with the same names as others? To make matters worse, the vendor may provide a library that contains classes with the same name as your class. There are many ways to solve this problem, but it is likely that the project has already started before the problem is discovered, and it takes a lot of pain to correct the error.
Java solves this problem with the concept of "Package", and Package effectively divides namespaces through collection classes. Two classes with the same name in different packages are still different. The key question becomes whether the class is placed in the corresponding package.
Remember, Java does not resolve naming conflicts. Extending a base class causes conflicts between derived classes. For example, if your favorite vendor provides some classes, and then you use them as the base class and derive a class with a foo method, it may appear when the supplier provides a new version of the class, if the supplier also provides a foo method in the new class.
5. Exception is an important feature of Java
Exceptions and exception handling are esoteric things in C++; much of the C++ source code never handles them or even knows what they are. Exceptions are unexpected errors that occur in the normal process, so they are not returned from the method or passed in as parameters; however, they cannot be ignored! An example here is the method of calculating the square root of a book. The normal interface form is to pass a positive number as an argument to the method, and then the method returns a positive real number as a result, which can be verified and thrown when an exception occurs. In most systems, programmers do not have to do this, so that an unconsidered exception can cause the program to exit abnormally.
In Java, exceptions have become a very mature part of the language. The description of the method contains the exception information, and the program handler also forces verification that if you use a method that can generate an exception, you must check to see if the exception occurs. Almost all Java programmers encounter exceptions because classes in many very useful libraries throw exceptions. Handling exceptions is not difficult, but there are times when you need to pay attention. The document for a method indicates the type of exception that the method throws. If you forget, never mind, the compiler will remind you.
6. A string is no longer an array of characters
Java includes an object of a string and is a constant. A string is not like a character array, although you can simply construct a string from a character array. You should replace character arrays with strings as much as possible, because they will not be overwritten by misoperation.
7.Java restricts constant objects and methods
In C++, you can formally declare a function parameter or function return value to be of type const, which can effectively prevent improper modification of the parameter or return value. In addition, you can declare a member function as const, indicating that it cannot modify any objects it operates on.
Java supports constant operators and read-only variables, which are implemented through the final keyword. However, Java does not support making a writable variable read-only when the function is passed and returned. Or define a constant method that does not manipulate the modified object.
In Java, the impact of this omission is very small compared to that in C++, largely due to the difference between string variables and character arrays, but it also creates an error risk. In particular, there is no way to verify whether a method can change the object.
This is the end of the content of "how to compile C++ source code on a virtual machine". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.