Since the designers of the Java language are very familiar with the C++ language, they drew lessons from the C++ language when designing. It can be said that the Java language is a programming language that is "more orientedobject" than the C++ language. Let's talk about the characteristics and advantages of Java through this article.
Characteristics of Java
The Java language is an excellent programming language. Its biggest advantage is that it has nothing to do with the platform. The same code can be used on Windows 9x, Windows NT, Solaris, Linux, MacOS and other platforms. The "write once, run anywhere" feature makes it widely adopted on the Internet.
Because the designers of the Java language are very familiar with the C++ language, they drew lessons from the C++ language when designing. It can be said that the Java language is a programming language that is "more object-oriented" than the C++ language. The grammatical structure of the Java language is very similar to the grammatical structure of the C++ language, which makes it easier for C++ programmers to learn the Java language.
Of course, if it were just a facelift to C++, there would be no Java craze today. Some useful new features provided by the Java language make it easier to write "error-free code" using the Java language than the C++ language.
These new features include:
1) Provides automatic management of memory, and programmers do not need to allocate and release memory in the program , those terrible memory allocation errors will no longer bother you;
2) Remove the confusing and error-prone "pointers" in the C++ language and use other methods to make up for it;
3) Avoids confusion between assignment statements (such as a = 3) and logical operation statements (such as a = = 3);
4) Cancels the complex problem of multiple inheritance facility.
Some notes:
"Multiple inheritance" is an "object-oriented" term, which we will describe in detail in Chapter 2. These advantages are the background of Java craze. With its powerful portability, multi-threading processing and networking capabilities, Java has become popular around the world and has gradually become a standard for handheld devices, the Internet, and in-car computers.
Some tips:
The Java language specification is public. You can find it on Oracle's official website and read the Java language specification. It's a great way to improve your skills.
The key features of the Java language
The Java language has many effective features that attract programmers, the most important ones are the following A few:
1. Simple and effective
The Java language is a fairly concise "object-oriented" programming language. The Java language omits all the difficult-to-understand and confusing features of the C++ language, such as header files, pointers, structures, units, operator overloading, virtual base classes, etc. It is more rigorous and concise.
Note:
Some readers who are familiar with Visual Basic language will think that Java language is more complicated than VB , indeed using Java programming is more laborious than using VB. But everyone must know that VB is an integrated development tool. It has become an artifact for developing GUI programs with its visual tools, but it cannot be regarded as a language. Its basis is Basic language, which is the simplest language, but its functions are not as complete as C, C++, and Java.
Java language uses special software construction method, which can run independently on a very small machine. Only 40K can accommodate a most basic interpreter. Even with the basic standard library and thread support, only 175K is enough. This is also a secret to the success of the Java language.
2. High portability
For a programmer, the program written can be used on Windows, MacOS, LINUX and other platforms at the same time without modification. Running on it is simply a dream come true! The Java language makes this originally unreachable thing closer and closer to us. Programs written in the Java language can run on different platforms with only a few modifications, or sometimes no modifications at all. Java is definitely a cross-platform programming language.
For example, different platforms have different regulations on the size of data types. On some platforms, the integer type (int) is represented by a 16-bit binary number, while on other platforms it is represented by a 32-bit binary number. The C/C++ language does not shield this difference caused by different platforms. In this way, if a C language source program developed on a platform that uses 16-bit binary numbers to represent integers has to run on a platform that uses 32-bit binary numbers to represent integers, it is simply bad news.
In the Java language, this difference caused by the platform is shielded. Integer numbers in Java must be represented by 32-bit binary, and the Java virtual machine digests this difference. When we want to transplant a Java language source program developed on a platform that uses 16-bit binary numbers to represent integers to run on a platform that uses 32-bit binary numbers to represent integers, there is no need to modify it.
It is inevitable that the Java language has such high portability, because its design concept is "write once, run anywhere".
3. "Object-oriented"
It can be said that "object-oriented" is a revolution in software engineering, which has greatly improved human software development capabilities. A great progress and a major milestone in software development.
In the past 30 years, "object-oriented" has made great progress and fully reflected its value. Up to now, it has formed "object-oriented system analysis", "object-oriented system design", "object-oriented system design", Object-oriented programming" a system. Therefore, as a modern programming language, it cannot deviate from this direction, and the Java language is no exception.
Note:
The Java language is hailed as a more "object-oriented" programming language than C++. It is difficult to use the Java language well with the idea of "object".
4. Interpretation type
Do you still remember the Basic language? When we use Basic language for programming, we must first enter the Basic language environment, then enter the source program, and then run it. The Basic language environment interprets and runs sentence by sentence, and directly obtains the results. This language is an interpreted language.
This is not the case with languages like C/C++. We first use editing software or an integrated development environment (IDE) to write the source program, and then compile it to generate an executable file. Then we execute this executable file through the operating system to get the result. This language is a compiled language.
Interpreted languages have low efficiency and slow speed; compiled languages have high efficiency and fast speed.
The Java language is an interpreted language. Yes, you read that right, it is an interpreted language, that is to say, compared to C/C++ language, programs written in Java language are inefficient and slow in execution. But it achieves the grand goal of "write once, run anywhere" by running Java interpreters on different platforms and interpreting Java code. In order to achieve the goal, it is worth sacrificing efficiency. Besides, computer technology is changing with each passing day, and computing speeds are getting faster and faster. Users will not feel too slow.
Some tips:
In fact, Java language is not completely interpretable like Basic language. It is an interpreted and compiled language. compromise. To write a program using the Java language, first use editing software or an integrated development environment (IDE) to write the source program, and then use a Java compiler to perform a pseudo-compilation and compile it into intermediate code (also called bytecode). Then use the Java interpreter to interpret it.
5. Suitable for distributed computing
The Java language has powerful, easy-to-use networking capabilities and is very suitable for developing distributed computing programs. Java applications can access remote objects through URLs just like accessing local file systems .
It is very simple to write a Socket communication program using Java language. Using it is easier than using any other language. And it is also very suitable for the development of public gateway interface (CGI) scripts. In addition, you can also use Java applet (Applet), Java Server Page (Java Server Page, referred to as JSP), Servlet and other means to build richer web pages.
6. Has better performance
As mentioned earlier, since Java is an interpreted language, its execution efficiency will be relatively slower. However, because the Java language uses two methods, its performance is still good.
1) After the Java language source program is written, first use a Java pseudo-compiler to perform pseudo-compilation, convert it into intermediate code (also called bytecode), and then interpret it;
2) Provides a "Just-in-Time" (JIT) compiler. When faster speed is needed, the JIT compiler can be used to convert the bytecode into machine code and then buffer it. This will make it faster.
Some tips:
7. Robust and prevent problems before they happen
The Java language does many early checks for potential problems during pseudo compilation, and does a lot of things during runtime. The corresponding check can be said to be the most stringent "compiler". Its method of "preventing problems before they occur" eliminates errors in many programs before they happen. Often there are many errors that would only be exposed at runtime in other languages, but are discovered at the compilation stage. In addition, the Java language also provides many features to ensure program stability and robustness, effectively reducing errors and making Java applications more robust.8. With multi-thread processing capabilities
Note:
It should be noted that the implementation of threads on various mainstream platforms varies greatly, so the Java language cannot be used in this regard for the time being. To be "platform independent", Java implements a set of multi-threading mechanisms for different operating systems. And for programmers, the code that calls the multi-threading mechanism is still the same on different machines. Since the Java language was designed, security was carefully considered and a lot of work was done. Exploration makes the Java language the most secure programming language currently. Although Sun once promised: "An anti-virus and anti-hacker system can be easily built through Java," the truth that "there is no absolute security in the world" will not be ineffective just because of someone's promise. Shortly after the release of JDK (Java Development Kit) 1.0, a group of security experts from Princeton University in the United States discovered the first error in the security features of Java 1.0. Since then, Java security issues have begun to receive attention. However, the security risks discovered so far are very trivial, and the Java development team also claims that they take system security bugs very seriously and will immediately fix those discovered. And because Sun has opened up the details of the Java interpreter, it helps all walks of life to jointly discover, prevent, and stop these security risks.10. Is a dynamic language
Java is a dynamic language, which means in the following two aspects:1) In In the Java language, you canquery runtime information simply and intuitively;
2) New code can be added to a running program.11. Neutral object language
"The Java compiler generates a neutral object file format." In other words, the Java compiler passes After pseudo-compilation, a "neutral" bytecode independent of any computer system will be generated. This neutral structure is not actually the first of its kind in Java. Before the advent of Java, the UCSD Pascal system had already done this in a commercial product. In addition, there was a precedent for this method before UCSD Pascal, which was implemented by Niklaus Wirth. This method of reducing some performance in exchange for better portability and versatility is adopted in the Pascal language. Java's bytecode has undergone many careful designs, making it well compatible with most popular computer systems today, can be easily interpreted on any machine, and can be easily translated into machine code dynamically.The above is the detailed content of Detailed explanation of the characteristics and advantages of Java (power node arrangement). For more information, please follow other related articles on the PHP Chinese website!