Java is a high-level object-oriented, class-based, concurrent, safe and general-purpose computer programming language. It is a powerful technology that is widely used.
What language is java?
Java is an object-oriented programming language. It not only absorbs the various advantages of the C language, but also abandons the concepts such as multiple inheritance and pointers that are difficult to understand in C. Therefore, the Java language has Powerful and easy to use. As a representative of static object-oriented programming languages, Java language perfectly implements object-oriented theory and allows programmers to perform complex programming with an elegant way of thinking.
Java is a strongly typed language, which allows extended compile-time checking for potential type mismatch issues. Java requires explicit method declarations and does not support C-style implicit declarations.
Java can write desktop applications, Web applications, distributed systems and embedded system applications, etc.
Characteristics of Java:
Java is simple, object-oriented, distributed, robust, secure, platform independent and portable , multi-threading, dynamics and other characteristics; let’s introduce it in detail below:
1. Simplicity
Java seems to be designed very much like C, but for To make the language small and familiar, the designers removed many of the features available in C that the average programmer rarely uses. For example, Java does not support the go to statement and instead provides break and continue statements as well as exception handling. Java also eliminates C's operator overload (overload) and multiple inheritance features, and does not use the main file, eliminating the need for preprocessors. Because Java has no structures, arrays and strings are objects, so no pointers are needed. Java can automatically handle object references and indirect references and realize automatic collection of useless units, so that users do not have to worry about storage management issues and can spend more time and energy on research and development.
2. Object-oriented
Java language provides object-oriented features such as classes, interfaces and inheritance. For simplicity, it only supports single inheritance between classes, but Supports multiple inheritance between interfaces, and supports the implementation mechanism between classes and interfaces (the keyword is implements). The Java language fully supports dynamic binding, while the C language only uses dynamic binding for virtual functions. In short, the Java language is a pure object-oriented programming language.
3. Distribution
Java is designed to support applications on the network. It is a distributed language. Java not only supports various levels of network connections, but also supports reliable stream network connections with the Socket class, so users can generate distributed clients and servers.
The network becomes a distribution vehicle for software applications. Java programs only need to be written once and run anywhere.
4. Compilation and Interpretability
The Java compiler generates byte-code instead of the usual machine code. Java bytecode provides an architecture-neutral object file format, and the code is designed to efficiently deliver programs to multiple platforms. Java programs can run on any system that implements a Java interpreter and run-time system.
In an interpreted environment, the standard "linking" phase of program development largely disappears. If Java still has a linking stage, it is just the process of loading new classes into the environment. It is an incremental and lightweight process. Therefore, Java supports rapid prototyping and easy experimentation, which will lead to rapid program development. This is an elegant development process that contrasts with the traditional, time-consuming "compile, link, and test."
5. Robustness
Java was originally used as a language for writing software for consumer home electronics products, so it is designed to write highly reliable and robust software. . Java eliminates certain programming errors, making it fairly easy to write reliable software in it.
Java's strong typing mechanism, exception handling, automatic garbage collection, etc. are important guarantees for the robustness of Java programs. Discarding pointers is a smart choice for Java. Java's security checking mechanism makes Java more robust.
6. Security
Java's storage allocation model is one of its main ways to defend against malicious code. Java has no pointers, so programmers cannot get behind the scenes and fake pointers to memory. More importantly, the Java compiler does not handle storage arrangement decisions, so the programmer cannot guess the actual storage arrangement of the class by looking at the declaration. Storage references in compiled Java code determine the actual storage address at runtime by the Java interpreter.
The Java runtime system uses a bytecode verification process to ensure that code loaded onto the network does not violate any Java language restrictions. Part of this security mechanism includes how classes are loaded from the Internet. For example, loaded classes are placed in separate namespaces rather than local classes, preventing a malicious applet from replacing standard Java classes with its own versions.
7. Portability
Java makes language declarations independent of implementation aspects. For example, Java explicitly states the size and operation behavior of each basic data type (these data types are described by Java syntax).
The Java environment itself is portable to new hardware platforms and operating systems. The Java compiler is also written in Java, while the Java runtime system is written in ANSIC language.
8. High performance
Java is a language that is compiled first and then interpreted, so it is not as fast as a fully compiled language. But there are situations where performance is critical. To support these situations, Java designers created a "just-in-time" compiler, which translates Java bytecode into machine code for a specific CPU (central processing unit) at runtime, as well. That is to achieve full compilation.
The Java bytecode format was designed with the needs of these "just-in-time" compilers in mind, so the process of generating machine code is fairly simple, and it produces pretty good code.
9. Multi-threading
In the Java language, a thread is a special object that must be created by the Thread class or its descendants (grandchildren). There are usually two ways to create a thread:
1), use a constructor subclass with the type Thread(Runnable) to wrap an object that implements the Runnable interface into a thread,
2 ), derive a subclass from the Thread class and override the run method. The object created using this subclass is a thread. It is worth noting that the Thread class has implemented the Runnable interface, so any thread has its run method, and the run method contains the code to be run by the thread. The activity of a thread is controlled by a set of methods. The Java language supports the simultaneous execution of multiple threads and provides a synchronization mechanism between multiple threads (the keyword is synchronized).
10. Dynamics
One of the design goals of the Java language is to adapt to dynamically changing environments. The classes required by Java programs can be dynamically loaded into the running environment, or the required classes can be loaded through the network. This also facilitates software upgrades. In addition, classes in Java have a run-time representation and can perform run-time type checking.
11. Platform independence
Java programs (files with the suffix java) are compiled into an architecture-neutral bytecode format (files with the suffix java) on the Java platform class file) and can then run on any system that implements this Java platform. This approach is suitable for heterogeneous network environments and software distribution.
Related video tutorial recommendations: "Java Tutorial"
The above is the detailed content of What language is java?. For more information, please follow other related articles on the PHP Chinese website!