The first chapter Java language characteristics (1.3)
1.3, Java language characteristics
1.3.1. Simplicity
Java seems to be designed like C++ , but in order to make the language small and easy to be familiar with, designers have C++
removed many of the features available in the language, which are rarely used by ordinary programmers.
E.g:
Java
not supportgo toSentence, instead providebreakwithcontinueStatement and exception handling.Java
C++
Operator overloads that have also been eliminated (overload)withMultiple inheritanceFeatures, and does not use the main file, eliminating the need for pre-processing procedures.Java
Nostructure,ArraywithstringThey are all objects, so there is no needpointer。Java
It can automatically handle object references and indirect references, and realize automatic collection of useless units, so that users don't have to worry about storage management issues, and can spend more time and energy on research and development.
1.3.2, object-oriented
Java
It is an object-oriented language. For programmers, this means paying attention to the data in the application and the methods of manipulating data ( method
), rather than thinking strictly in terms of process. In an object-oriented system,class( class
) Is the method of data and manipulation of dataset. Data and methods are described togetherObject( object
)'S status and behavior. Each object is an encapsulation of its state and behavior. Classes are arranged according to a certain system and hierarchy, so that subclasses can inherit behavior from superclasses. There is a root class in this class hierarchy, which is a class with general behavior. Java
The program is organized by classes.
Java also includes a classExtended collection, Respectively form variousPackage( Package
), users can use it in their own programs. For example, Java provides classes ( java.awt
packages) for generating graphical user interface components , here awt
is abstract windowing toolkit
the abbreviation of abstract window tool set ( ), classes ( java.io
packages) that handle input and output, and classes ( packages) that support network functions java.net
.
1.3.3, distribution
Java
Designed to support applications on the web, it isDistributed language. Java
It not only supports various levels of network connections, but alsoSocket classSupport reliableflow( stream
) Network connection, so users can generate distributed clients and servers .
The network becomes a distributed vehicle for software applications. Java
The program can be run everywhere as long as it is written once.
1.3.4. Compilation and Interpretation
Java
Compiler generationBytecode( byte-code
) Instead of the usualMachine code. Java
Bytecode provides an explanatory object file format in the architecture, and the code is designed to effectively transfer programs to multiple platforms. Java
The program can be implemented in anyJava interpreterwithOperating system( run-time system
) Runs on the system.
In an explanatory environment, the standard of program development"link"The stage has disappeared greatly. If Java
there is a linking stage, it is just a process of loading new classes into the environment. It is an incremental and lightweight process. Therefore, Java
support for rapid prototyping and easy experimentation will lead to Rapid program development. This is a time-consuming process that is different from the traditionalCompile, link and test"A sophisticated development process in sharp contrast.
1.3.5, robustness
Java
It was originally used as a language for writing consumer home electronic product software, so it was designed to writeHigh reliabilitywithsteadySoftware. Java
Eliminates certain programming errors, making it easy to write reliable software.
Java is aStrongly typed language, Which allows to extend the ability to check for potential type mismatches at compile time. Java requirementsExplicitThe method statement, it does not support C- styleImplicitstatement. These strict requirements ensure that the compiler can catch call errors, which leads to a more reliable program.
One of the most important enhancements in reliability isJava's storage model. Java
Does not support pointers, it eliminatesRewrite storagewithCorrupted dataThe possibility. Similarly, the Java
automatic "Garbage collection"Prevent storage leaks and other harmful errors related to dynamic storage allocation and deallocation. The Java
interpreter also performs many runtime checks, such as verifying that all array and string accesses are within bounds.
Exception handlingIt is Java
another feature that makes the program more robust. An exception is a signal that an abnormal condition similar to an error occurs. usetry/catch/finallyStatement, the programmer can find the error handling code, which simplifies the task of error handling and recovery.
1.3.6, security
Java
ofStorage allocation modelIt is one of the main methods to defend against malicious code . Java
There are no pointers, so programmers cannot get concealed inside information and fake pointers to point to memory. More importantly, the Java
compiler does not handleStorage scheduling decision, So the programmer cannot guess the actual storage arrangement of the class by looking at the declaration. Java
The storage reference in the compiled code is determined by the Java interpreter at runtime to determine the actual storage address .
Java operating system useBytecodeThe verification process ensures that the code loaded on the network does not violate any Java
language restrictions. This part of the security mechanism includes how the class is loaded from the Internet. For example, the loaded class is placed in a separate name space instead of a local class to prevent malicious applets from replacing the standard Java
class with its own version .
1.3.7, portability
Java makes language declarations independent of implementation aspects.
E.g
- Java explicitly states the size of each basic data type and its arithmetic behavior (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;
- The Java operating system is written in ANSI C language. (It
ANSIC
is a standardC
published by the American National Standards Institute (ANSI) for languages. Software developers using C are encouraged to follow theANSI C
documentation requirements because it encourages the use of cross-platform code.)
1.3.8 High performance
Java is aCompile first and then explainLanguage, so it’s not as good asFully compileabilityThe language is fast. But in some cases performance is very important. In order to support these situations, Java designers have produced "timely"Compile the program, it can putJava bytecodeTranslated into specific CPU
(central processing unit)Machine code, Which is to achieve full compilation.
The Java bytecode format is designed to take 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.
1.3.9, multithreading
Java isMultithreaded language, It provides support for multi-threaded execution (also known as a lightweight process), can handle different tasks, and makes it easy to program with clues. The Java lang package provides a Thread class, which supports methods for starting a thread, running a thread, stopping a thread, and checking the thread status.
Java's clue support also includes a setSynchronization primitive. These primitives are a widely used synchronization scheme developed by CARHaore based on the supervision procedure and condition variable style . With keywords synchronized
, programmers can explain that certain methods cannot run concurrently in a class. These methods are under the control of the supervisory program to ensure that the variables are maintained in a consistent state.
1.3.10, dynamic
The Java language is designed to adapt to changing environments. It is aDynamic language.
For example, classes in Java are loaded on demand, and some are even obtained through the network.