The difference between object – oriented and process – oriented
Process oriented
Advantages: Higher performance than object-oriented, because class invocation needs to be instantiated, the overhead is relatively large, more consumption of resources; For example, SCM, embedded development, Linux/Unix and so on generally adopt process-oriented development, performance is the most important factor.
Disadvantages: No object-oriented easy maintenance, easy reuse, easy to expand
object-oriented
Advantages: easy to maintain, easy to reuse, easy to expand, because of the characteristics of object-oriented encapsulation, inheritance, polymorphism, can design a low coupling system, make the system more flexible, more easy to maintain
Disadvantages: Lower performance than process-oriented
Ii. What are the features of Java language?
Simple and easy to learn; Object-oriented (encapsulation, inheritance, polymorphism); Platform independence (Java virtual machine implementation platform independence); Reliability; Security; Support multithreading; Support network programming and very convenient; Compilation and interpretation coexist;
JVM JDK (JDK) and JRE (JRE
JVM
A Java Virtual machine (JVM) is a virtual machine that runs Java bytecode. The JVM has specific implementations for different systems (Windows, Linux, macOS) that aim to use the same bytecode, and they all give the same results.
What is bytecode? What are the benefits of adopting bytecode?
In Java, code that can be understood by the JVM is called bytecodes (files with a.class extension) that are not oriented to any particular processor, just to the virtual machine. Java solves the problem of low efficiency of traditional interpreted languages by means of bytecode to some extent, and at the same time retains the 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.
Java programs from source to run generally have the following three steps:
We need to pay special attention to the.class-> machine code step. In this step, the JVM classloader loads the bytecode file and then executes it line by line through the interpreter, which is relatively slow. In addition, some methods and code blocks need to be called frequently, which is called hot code, so the JIT compiler was introduced later. JIT is runtime compilation. When the JIT compiler completes the first compilation, it saves the machine code corresponding to the bytecode for direct use next time. And we know that machine code is certainly more efficient than Java interpreters. This explains why we often talk about Java as a compilation and interpretation language.
HotSpot adopts Lazy Evaluation, where, according to the 80/20 rule, only a small portion of code (hot code) consumes most of the system’s resources, and that is what the JIT needs to compile. The JVM collects information based on each time the code is executed and makes some optimizations accordingly, so the more times it executes, the faster it gets. JDK 9 introduces a new Compilation mode, AOT(Ahead of Time Compilation), which compiles bytecode directly to machine code, thus avoiding overhead such as JIT warm-up. The JDK supports hierarchical compilation and AOT collaboration. However, AOT compilers are certainly not as good as JIT compilers.
Summary: A Java Virtual machine (JVM) is a virtual machine that runs Java bytecode. The JVM is available for different systems
Unified specific implementations (Windows, Linux, macOS) aim to use the same bytecode as them
They all give you the same answer. Bytecode and JVM implementations for different systems are Java language “coditions”
It works everywhere.
The JDK and JRE
The JDK is the Java Development Kit, which is a full-featured Java SDK. It has everything the JRE has, as well as a compiler (Javac) and tools (such as Javadoc and JDB). It can create and compile programs.
JRE is the Java runtime environment. It is the collection of everything you need to run a compiled Java program, including the Java Virtual Machine (JVM), Java class libraries, Java commands, and other basic artifacts. However, it cannot be used to create new programs.
If you just want to run a Java program, you just need to install the JRE. If you need to do some Java programming, you’ll need to install the JDK. However, this is not absolute. Sometimes, even if you don’t plan on doing any Java development on your computer, you still need to install the JDK. For example, if you deploy a Web application using JSPS, you are technically just running Java programs in the application server. So why do you need the JDK? Because the application server converts JSPS into Java servlets, you need to use JDK to compile the servlets.
Oracle JDK and OpenJDK
There are probably a lot of people like me who haven’t touched or used OpenJDK before looking at this question. So are there any major differences between Oracle and OpenJDK? Here are some information I collected to answer this question that many people ignore.
For Java 7, there is nothing critical. The OpenJDK project is based on HotSpot source code donated by Sun. In addition, OpenJDK was selected as the reference implementation for Java 7, maintained by Oracle engineers. An Oracle blog post from 2012 has a more detailed answer about the differences between the JVM, JDK, JRE and OpenJDK:
Q: What is the difference between the source code in the OpenJDK repository and the code used to build the Oracle JDK?
A: Very close – Our Oracle JDK version build process is based on OpenJDK 7, adding only a few parts, such as deployment code, which includes Oracle’s Java plug-in and implementation of Java WebStart, as well as some closed source party components, Like graphics rasterizers, some open source third-party components like Rhino, and bits and pieces like attached documentation or third-party fonts. Going forward, our goal is to open source all parts of the Oracle JDK, except the parts where we consider commercial functionality.
Conclusion:
1. Oracle JDK releases will be released every three years, while OpenJDK releases will be released every three months;
2. OpenJDK is a reference model and is fully open source, while Oracle JDK is an implementation of OpenJDK and is not fully open source;
3. Oracle JDK is more stable than OpenJDK. The OpenJDK and Oracle JDK have nearly the same code, but the Oracle JDK has more classes and some bug fixes. Therefore, if you want to develop enterprise/business software, I recommend you choose the Oracle JDK because it is thoroughly tested and stable. In some cases, some people have mentioned that they may encounter many application crashes while using OpenJDK, but simply switch to the Oracle JDK to solve the problem;
4. Top companies are using Oracle JDK, such as Android Studio, Minecraft and IntelliJ IDEA development tools, where Open JDK is less popular;
5. Oracle JDK provides better performance than OpenJDK in terms of responsiveness and JVM performance;
6. The Oracle JDK does not provide long-term support for upcoming releases. Users must update to the latest version each time to get support.
7. Oracle JDK is licensed under the binary code License, while OpenJDK is licensed under the GPLv2 license.
The difference between Java and C++
I know many people have never learned C++, but the interviewer likes to compare Java with C++. No way!! Even if you haven’t learned C++, write it down!
Both are object-oriented languages, and both support encapsulation, inheritance, and polymorphism
Java does not provide Pointers to access memory. Program memory is safer
Java classes are single-inherited, and C++ supports multiple inheritance. Although Java classes cannot be multiinherited, interfaces can.
Java has automatic memory management, so you don’t need to manually free unwanted memory
What is the difference between the main class of a Java application and the main class of a small program
A program can have more than one class, but only one class can be the main class. In A Java application, this main class is the class that contains the main () method. In Java applets, the main class is a subclass that descends from the system class JApplet or Applet. The main class of the application is not required to be public, but the main class of the applet must be public. The main class is the entry point for Java program execution.
What are the differences between Java applications and applets
Simply put, the application starts from the main thread (the main() method). Applets do not have a main method, but instead run embedded in a browser page (init() or run() is invoked), similar to flash mini-games.
Character constants and string constants
1. Form: A character constant is a single character caused by a single quotation mark. A string constant is several characters caused by a double quotation mark
2. Meaning: character constant is equivalent to an integer value (ASCII value), can participate in expression operation string constant represents an address value (the location of the string in memory)
A string constant takes up several bytes (at least one end-of-character flag).
Whether the Constructor can be override
When we talk about inheritance we know that the private attributes and constructors of the parent class cannot be inherited, so Constructor cannot be overridden, but can overload, so you can see multiple constructors in a class.