Java overview
1. The relationship between JVM, JRE, and JDK
JVM: Java Virtual Machine, is short for Java Virtual Machine, is the running environment of Java programs, different platforms have their own Java virtual machine, is the foundation of Java programs compiled once, run everywhere.
JRE: Java Runtime Environment, which includes core libraries required by Java VMS and Java programs. The core class library is mainly the java.lang package, which contains the essential system classes for running Java programs, such as: basic data types, basic mathematical functions, string handling, threading, exception handling classes, etc. If you only need to run developed Java programs, you only need to install JRE.
JDK: Java Development Kit, provided for use by Java developers. Includes Java development tools and JRE. Development tools include: javac.exe, jar.exe and so on.
The relationship between JVM, JRE, JDK:
2. What are the features of the Java language?
- Simple (The Syntax of the Java language is close to that of C and C++)
- Object oriented (encapsulation, inheritance, polymorphism)
- Platform independence (Java Virtual machine implementation platform independence)
- Network programming support and convenience (the Java language itself was designed to simplify network programming)
- Support for multithreading (a mechanism that allows applications to execute multiple tasks in parallel at the same time)
- Robustness (Java language’s strong typing mechanism, exception handling, automatic garbage collection, etc.)
- security
3. What is platform independence (cross-platform) and how does it work?
Concept: Platform independence refers to the fact that programs written in Java can run on multiple system platforms once compiled.
Principle Java programs run on the system platform using Java virtual machines (VMS). Different systems have their own VMS. You can run Java programs by installing Java VMS of the corresponding system.
4. What is bytecode? What are the benefits of adopting bytecode?
- Byte code:The Java source code passes through the virtual machineCompiler compilationAfter the generated file (i.e
.class
It does not target any particular processor,Only VMS are available. - Advantages: Java eliminates the low execution efficiency of traditional interpreted languages to some extent through bytecode, while retaining 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.
5. What is a Java main class?
A Java program can have multiple classes, but only one main class. In Java programs, this main class refers to the class that contains the main method. The main class is the entry point for Java program execution.
6. Differences between Java and c++
- Java and c++ are both object-oriented languages that support encapsulation, inheritance, and polymorphism.
- Java does not provide Pointers to access memory directly, making program memory more secure.
- Java classes are single inheritance, c++ supports multiple inheritance, but Java interfaces support multiple inheritance.
- Java has automatic memory management mechanisms that do not require programmers to manually free unwanted memory.
Basic Java Syntax
1. What data types are available in Java
The Java language is strongly typed. It defines specific data types for each type of data and allocates different sizes of memory space in memory.
Data types in Java include basic data types and reference data types.
- The basic data types are:
- Integer types (byte,short,int,long)
- Floating point type (float,double)
- Character (char)
- The Boolean (Boolean)
2. Reference data types include:
- Class (class)
- Interface (interface)
- Array ([])