Because Java is
• Simple
• Object-oriented
• Robust
• Secure
• Interpreted
• Platform-independent
• Multithreading
• Dynamic Language
Simple
Java was originally designed to implement integrated control over household appliances, so it must be simple and clear. The simplicity of the Java language is embodied in three aspects:
1. the Java style is similar to C ++. Therefore, C ++ programmers are familiar with the Java language for the first time. In a sense, Java is a variant of C and C ++. Therefore, C ++ programmers can quickly master Java programming technology.
2. Java abandons some features that are easy to cause program errors in C ++, such as pointers, structures, enumeration, and memory management.
3. Java provides a variety of class libraries, which can help us easily develop Java programs.
Object-oriented
Object-oriented is the most important feature of Java, so it supports inheritance, overload, polymorphism and other object-oriented features. Java is designed to be completely object-oriented. It does not support process-oriented programming techniques similar to C.
Robust
Java is committed to checking program compilation and runtime errors. Java is also a strongly typed language, and its type check is stricter than C ++. The type check helps us to check many early development errors. Java is responsible for memory management and provides a garbage collection mechanism to effectively avoid Memory leakage problems in C ++.
Secure
Java security can be guaranteed in two aspects. On the one hand, C ++ functions such as pointers and memory release are deleted in Java to avoid illegal memory operations. On the other hand, Java security architecture is used to ensure the security of Java code. When we download Java code from the Internet and execute it locally, the Java security architecture ensures that malicious code cannot access resources on our local computer at will, for example, deleting files, access to local network resources is forbidden.
Interpreted
Java code is interpreted and executed. We use the Java compiler to compile the Java code into bytecode, which is an intermediate code and then interpreted and executed by the Java interpreter. While C ++ programs are compiled and executed, C ++ program code is compiled into local machine commands and then executed.
Platform-independent
As a network language, Java's source code is compiled into a structure-neutral intermediate file format. This intermediate code can be executed on any machine running the system in Java. The Java source program is compiled into a machine-independent bytecode format and runs on the Java Virtual Machine.
Multithreading
An important feature of Java is programming that supports multithreading at the language level. Multithreading is like building a table. If you finish this table by yourself-it's like a single thread, you need to do the desktop first, and then do the four legs after the desktop is finished, if there are five people working on the table now-five threads are opened in the program, one of them is working on the desktop, and the other four are working on four legs, the efficiency of the two methods is high and low, I believe everyone can tell the difference.
Dynamic
The dynamic feature of Java is the extension of its object-oriented design method. It allows programs to dynamically load the classes required during the running process, which is not implemented by Object-Oriented Programming Using C ++. During the C ++ program design process, every time an instance variable or a member function is added to the class, all subclasses that reference the class must be re-compiled; otherwise, the program will crash. Java takes measures to solve this problem from the following aspects. The Java compiler does not compile the reference to instance variables and member functions as a numerical reference, but saves the symbolic reference information in the bytecode and passes it to the interpreter, after the interpreter completes the dynamic connection class, it converts the symbolic reference information into a numerical offset. An object generated in the memory is not determined during the compilation process, but is delayed until the runtime is determined by the interpreter. In this way, the existing code will not be affected when the variables and methods in the class are updated. When interpreting and executing bytecode, the search and conversion process of such symbolic information is only performed once when a new name appears, and then the code can be executed at full speed. The advantage of determining reference during runtime is that you can use updated classes without worrying about affecting the original code. If a program is connected to a class in another system in the network, the owner of the class can update the class without causing any program that references the class to crash. Java also simplifies the use of an upgraded or new protocol. If your system runs a program that does not know how to handle the Java program, Java can automatically download the functional program you need.