1. What language is Java? What is the difference between JDK, JRE and JVM
Java is a computer programming language, with cross-platform, object-oriented, generic programming characteristics, widely used in enterprise Web application development and mobile application development.
The JVM(Java Virtual Machine) is an abstract machine. It is called a virtual machine because it does not physically exist. It provides a runtime environment in which Java bytecode can be executed. It can also run programs written in other languages and compiled into Java bytecode.
The JVM is available for many hardware and software platforms. The JVM, JRE, and JDK are platform dependent because each OS is different from the other. However, Java is platform-agnostic. The JVM has three concepts: specification, implementation, and instance. The JVM performs the following primary tasks: Load code validation code Execution code provides the runtime environment
2. Three major versions of Java since 1.5
Java SE (J2SE, Java 2 Platform Standard Edition, Standard Edition) Java SE was formerly known as J2SE. It allows the development and deployment of Java applications for use in desktop, server, embedded, and real-time environments. Java SE contains classes that support Java Web services development and provide the foundation for Java EE and Java ME. Java EE (J2EE, Java 2 Platform Enterprise Edition, Enterprise Edition) Java EE was formerly known as J2EE. The Enterprise version helps develop and deploy portable, robust, scalable, and secure server-side Java applications. Java EE is built on Java SE and provides Web services, component models, management and communication apis that can be used to implement enterprise-level Service-oriented Architecture (SOA) and Web2.0 applications. In February 2018, Eclipse announced that it was officially changing the name of JavaEE to JakartaEE Java ME (J2ME, Java 2 Platform Micro Edition, Micro Edition). Java ME was formerly known as J2ME. Java ME provides a robust and flexible environment for applications running on mobile and embedded devices, such as cell phones, PDAs, TV set-top boxes, and printers. Java ME includes a flexible user interface, a robust security model, a number of built-in network protocols, and rich support for both networked and offline applications that can be downloaded dynamically. Applications based on the Java ME specification can be written once for many devices and can take advantage of the native capabilities of each device.
3. Java cross-platform and its principle
Cross-platform is a piece of code written in JAVA that can run on any operating system platform. How does JAVA do this? The JAVA source code we write is compiled into bytecode and then interpreted and executed by the JVM. As you can see, the JVM plays an important role in the cross-platform process by interpreting bytecode and executing it. Each platform has one JVM and only one copy of bytecode. A Windows JVM can interpret bytecode as instructions that can be executed on a Windows platform and execute it, while a Linux JVM can interpret bytecode as instructions that can be executed on a Linux platform and execute it. They all execute the same bytecode. This makes it cross-platform.
4. Features of the Java language
The Java language has the following characteristics: simplicity, cross-platform, object-oriented, security, multi-threading, distribution, portability, interpretation, high performance, and dynamic.
(1) simplicity the Java language is similar to C++, so programmers familiar with C++ can easily master Java, and it eliminates C++ prone to error, especially the Java language does not use Pointers, and provides automatic scrap collection, so programmers do not have to worry about memory management.
(2) Cross-platform
Cross-platform means that software can run well in any computer environment regardless of the constraints of computer hardware and operating system. In Java, its own virtual machine can well achieve cross-platform, it provides a bytecode to the underlying hardware platform and operating system barrier, making Java language cross-platform.
(3) Object oriented
Java is an object-oriented language, which makes the development of programs easier and easier to use. Such as code extension, code reuse and other functions.
(4) Security
Java security is guaranteed in two ways. On the one hand, in the Java language, C++ functions such as Pointers and free memory have been removed to avoid illegal memory operations. On the other hand, when Java is used to create a browser, the language capabilities combine with those provided by the browser itself to make it more secure. The Java language is tested many times before it can be executed on a machine. It goes through code validation, checking the format of code snippets, detecting pointer manipulation, object manipulation, and trying to change the type of an object.
(5) Multithreading
Multithreading refers to allowing two or more threads to exist in an application at the same time to support transaction concurrency and multitasking. In addition to the built-in multithreading technology, Java defines classes, methods, and so on to create and manage user-defined multithreading.
(6) Distribution
Java language supports the development of Internet applications. In the basic Java application programming interface, there is a network application programming interface, which provides libraries for network application programming, including URL, URLConnection, Socket, ServerSocket, etc. Java’s RMI(Remote method activation) mechanism is also an important means of developing distributed applications.
(7) portable
Java system itself has a strong portability, Java compiler is implemented in Java, Java running environment is implemented in ANSI C, and Java also strictly regulates the length of each basic data type
(8) Explain
Java interpreters can run object code instructions directly, and linked programs usually require fewer resources than compiled programs, so programmers can spend more time creating source programs.
(9) High performance
If the interpreter is not slow, Java can translate object code directly into machine instructions at run time, with speed comparable to C/C++ performance.
(10) Dynamic
One of the design goals of the Java language is to adapt to dynamically changing environments. Classes required by Java programs can be dynamically loaded into the runtime environment, or they can be loaded over the network. This also facilitates software upgrades.
What is bytecode and its benefits
Bytecode: A file generated by Java source code compiled by the virtual machine compiler (that is, a file extended to.class) that is not oriented to any particular processor, but only to the virtual machine. Bytecodes are extension.class files, which are compiled by a Java compiler to produce code that the JVM can understand. This code is called bytecodes, and it is not platform-oriented, it is JVM oriented.
Advantages of using bytecode: Java language solves the problem of low efficiency of traditional interpreted languages to a certain extent by means of bytecode, while retaining the characteristics of portability of interpreted languages. So Java programs run more efficiently, and because bytecode is not specific to a particular machine, Java programs can run on many different machines without recompiling.