Fortune Telling Collection - Fortune-telling birth date - What language is java?

What language is java?

Java is an object-oriented programming language, which not only absorbs the advantages of C++ language, but also abandons the concepts of multiple inheritance and pointers that are difficult to understand in C++, so Java language has two characteristics: powerful function and simple use. As the representative of static object-oriented programming language, Java language perfectly realizes the object-oriented theory and allows programmers to carry out complex programming in an elegant way of thinking.

Java is a strongly typed language, which allows the function of checking potential type mismatch to be extended at compile time. Java requires explicit method declaration and does not support implicit declaration in C style.

Java can write desktop applications, Web applications, distributed systems and embedded system applications.

Features of Java:

Java has the characteristics of simplicity, object-oriented, distributed, robustness, security, platform independence and portability, multithreading and dynamics. The following is a detailed introduction:

1, simple

Java looks a lot like C++, but in order to make the language small and familiar, designers have removed many available features in C++ language, which are rarely used by ordinary programmers. For example, Java does not support go to statements, but provides break and continue statements and exception handling. Java also eliminates the operator overloading and multiple inheritance characteristics of C++, and does not use the main file, thus eliminating the preprocessor. Because Java has no structure, arrays and strings are objects, so pointers are not needed. Java can automatically handle object references and indirect references, and realize the automatic collection of useless units, so that users don't have to worry about storage management and can spend more time and energy on research and development.

2. Object-oriented

The Java language provides object-oriented features such as classes, interfaces and inheritance. For the sake of simplicity, it only supports single inheritance between classes, multiple inheritance between interfaces, and implementation mechanism between classes and interfaces (the keyword is implements). Java language fully supports dynamic binding, while C++ language only uses dynamic binding for virtual functions. In a word, Java language is a pure object-oriented programming language.

Step 3 distribute

Java is designed to support network applications. It is a distributed language. Java not only supports various levels of network connections, but also supports reliable streaming network connections with Socket classes, so users can generate distributed clients and servers.

Network becomes the distributed carrier of software applications. Java programs can be run anywhere as long as they are written once.

4. Compilation and interpretation

The Java compiler generates bytecode instead of the usual machine code. Java bytecode provides an architecture-independent object file format, which is designed to effectively transfer programs to multiple platforms. Java programs can run on any system that implements Java interpreters and runtime systems.

In the explanatory environment, the standard "link" stage of program development has disappeared greatly. If Java still has a link stage, it is only a process of putting new classes into the environment, and it is an incremental and lightweight process. Therefore, Java supports rapid prototyping and simple testing, which will lead to rapid program development. This is a subtle development process, which is in sharp contrast to the traditional time-consuming "compile, link and test".

5. Robustness

Java was originally used as a language to write consumer electronics software, so it was designed to write highly reliable and robust software. Java eliminates some programming errors and makes it very easy to write reliable software with it.

Java's strongly typed mechanism, exception handling and automatic garbage collection are important guarantees for the robustness of Java programs. Discarding pointers is a wise choice for Java. Java's security check mechanism makes Java more robust.

6. Safety

Java's storage allocation model is one of its main methods to defend against malicious code. Java has no pointers, so programmers can't get hidden internal information and fake pointers pointing to memory. More importantly, the Java compiler doesn't handle storage scheduling decisions, so programmers can't guess the actual storage scheduling of classes by looking at the declarations. The actual storage address of the reference in the compiled Java code is determined by the Java interpreter at runtime.

The Java operating system uses bytecode verification process to ensure that the code loaded on the network does not violate any Java language restrictions. This security mechanism includes how to load classes from the Internet. For example, loaded classes are placed in a separate namespace instead of local classes to prevent malicious applets from replacing standard Java classes with their own versions.

7, portability

Java makes language declarations independent of implementation aspects. For example, Java clearly states the size of each basic data type and its operation behavior (these data types are described by Java syntax).

The Java environment itself can be ported to new hardware platforms and operating systems. The Java compiler is also written in Java, and the Java running system is written in ANSIC language.

8, high performance

Java is a language that compiles first and then interprets, so it is not as fast as a fully compiled language. However, in some cases, performance is very important. In order to support these situations, Java designers have made an "just-in-time" compiler, which can translate Java bytecode into machine code of a specific CPU (central processing unit) at runtime, that is, realize full compilation.

Java bytecode format design takes into account the needs of these "just-in-time" compilers, so the process of generating machine code is quite simple, and it can produce quite good code.

9, multithreading

In the Java language, a Thread is a special object, which must be created by the thread class or its subclasses. There are usually two ways to create threads:

1), by using a subclass constructed as Thread(Runnable) to wrap the 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 by this subclass is a thread. It is worth noting that the Thread class implements the Runnable interface, so any thread has its run method, which contains the code that the thread wants to run. The activity of a thread is controlled by a set of methods. Java language supports the simultaneous execution of multiple threads, and provides a synchronization mechanism between multiple threads (the keyword is synchronized).

10, dynamic

One of the design goals of Java language is to adapt to dynamic environment. Classes needed by Java programs can be dynamically loaded into the running environment or loaded through the network. This is also conducive to software upgrades. In addition, classes in Java have a runtime representation, and the type of runtime can be checked.

1 1, platform independence

Java programs (files with Java suffixes) are compiled into bytecode format independent of architecture (files with class suffixes) on the Java platform, and then can be run on any system that implements this Java platform. This method is suitable for heterogeneous network environment and software distribution.