Java features
VSimple and simple
VPlatform independence
VObject-oriented
VMultithreading
VDistribution
VHigh Performance (compared with other interpreted languages)
VRobustness
Concepts related to Java virtual machines
VWhat is JVM?
JVM is short for Java Virtual Machine (JVM). It is a fictitious computer that simulates various computer functions on an actual computer. The Java Virtual Machine has its own complete hardware architecture, such as the processor, stack, and register, as well as corresponding command systems.
VWhy use JVM?
The most important feature of Java is that it can run in any operating system. Java Virtual Machine (VM) is used to support operating system-independent operations and can run in any system.
VBasic JVM principles
The Java Virtual Machine shields information related to the specific operating system platform, so that the Java language compiler only needs to generate the target code (bytecode) that runs on the Java Virtual Machine ), it can be run on multiple platforms without modification. When executing bytecode, the Java Virtual Machine finally interprets the bytecode as a machine instruction execution on a specific platform.
Environment Variable description
VPath
§ Windows operating system is used to find the path of executable files.
VClasspath
§ The Java Virtual Machine (JVM) uses the class loader to load the classes used by the application. The classes to be loaded are determined based on the current needs.
§ The classpath environment variables tell the Class Loader where to find the classes and user-defined classes provided by the third party. In addition, you can use the JVM command line parameter-classpath to specify the class path for the application, and the class path specified in-classpath overwrites the value specified in the classpath environment variable.
Javac-classpath path Java File
Java-classpath path Java class
VNote:
§ The javac command is followed by the full name of the source program file (including the extension. Java );
§ The Java command is followed by the main class name (excluding the extension. Class );
Naming principles for source program files
VA source program file can contain multiple classes, but only one class can be modified with public; or all classes do not need public modification.
VIf the source program file has a public modified class, the source program file name must be the same as the public modified class name; otherwise, the source program name can be any legal identifier.
Common Java Development commands
VJava development tools include:
§ Javac: a Java compiler used to compile a Java program into bytecode.
§ Java: Java interpreter. Execute a Java application that has been converted to bytecode.
§ Javadoc: Document builder that creates HTML files.
§ Javap: decompile and restore class files back to methods and variables
Key points:
Note the following when setting environment variables:
A: The environment variable must be a system variable.
B: %: call another environment variable in one environment variable.
% Java_home % \ bin
Path: used to search for executable files.
Classpath: used to search for class files.
Character Set:
Char is a character type. The Java language uses UNICODE character encoding for characters,
Since a computer can only store binary data, it must encode the characters.
Character encoding: a string of binary data to indicate specific characters.
ASCII code: Express modern English and other Western European languages, 1 byte, 7-bit, 128 characters.
ISO-8859-1 (Latin-1): The International Standard Organization is coded for characters in the western European language, 1 byte 8-bit, ASCII compatible
Gb2312 (gbk21866): It is a simplified Chinese character encoding, including 7445,21866, which is compatible with ASCII.
Unicode Character Set: contains cross-platform characters in all languages around the world.
UTF-8 (transmission speed is faster than UTF-16 in the network .) : Some systems do not support Unicode.
UTF-16
In the Unicode Character Set, a character occupies 2 bytes (16 bits ).
A single byte occupies 8 bits and can occupy up to 4 bytes.
In Java, data can be stored in six different places:
1. Register (register ). This is the fastest storage zone, because it is located in a different place from other storage areas-inside the processor. However, the number of registers is extremely limited, so the registers are allocated by the compiler as needed. You cannot directly control it or feel any signs of register in the program.
2. Stack ). It is located in generic Ram, but its "Stack pointer" can be used to obtain support from the processor. If the stack pointer moves down, new memory is allocated. If the stack pointer moves up, the memory is released. This is a fast and effective distribution storage method, second only to registers. When creating a program, the Java compiler must know the exact size and lifecycle of all data stored in the stack, because it must generate code to move the stack pointer up and down. This constraint limits the flexibility of the program, so although some java data is stored in the stack-especially object reference, Java objects are not stored in it.
3. Heap ). A universal memory pool (also exists in Ram) used to store Java objects. The benefit of heap is that the compiler does not need to know how many storage areas are allocated from the heap or how long the stored data remains in the heap. Therefore, it is flexible to allocate storage in the heap. When you need to create an object, you only need to write a new line of simple code. When you execute this line of code, the storage is automatically allocated in the heap. Of course, you must pay the appropriate code for this flexibility. It takes more time to store data by heap and stack.
4. static storage ). Here "static" refers to "at a fixed position ". Static storage stores the data that persists when the program is running. You can use the keyword static to identify the specific elements of an object as static, but Java objects are never stored in static buckets.
5. Constant storage ). Constant values are usually directly stored in the program code. This is safe because they will never be changed. Sometimes, in an embedded system, constants are separated from other parts, so in this case, you can choose to put them in the Rom.
6. Non-ram storage. If the data exists completely outside of the program, it can exist without any control of the program.
1. static storage zone: allocated when a program exists in it during compilation, such as static variables;
2. Stack zone: local variables of various original data types are created on the stack. When the program exits from the scope of the variable, the memory of the variable will be automatically released.
3. Heap area: objects (including arrays) are created in the heap. When the program is running, the new keyword is used to create the object. When the object is created, the memory is allocated to it in the heap.