Java language features
1. Simplicity
The real memory manipulation in the Java language: the JVM (Java Virtual Machine)
All Java programs run in a Java virtual machine.
The Java virtual machine operates on memory during execution.
For C or C++ programmers can manipulate memory directly through Pointers.
C or C++ is more flexible and allows the programmer to manipulate memory directly, but requires a skilled programmer.
C or C++ is more manipulative.
The Java language hides the concept of Pointers, and programmers cannot manipulate Pointers directly, or in other words, memory directly. This approach has advantages and disadvantages:
- Advantages: Less likely to cause memory leaks. (Easy.)
- Cons: Efficiency issues, including poor steering.
Aircraft navigation:
If the language is C, the programmer is the pilot of the plane.
If it’s Java, the programmer is a passenger on the plane.
The underlying Java language is C++, so the JVM is a virtual computer written in C++.
Where is the JVM?
When you install the JDK, the JVM is ready.
What is memory?
What are the most important components of a computer?
CPU:
The CPU, the human equivalent of the brain, sends and executes instructions.
Is the commander of the entire computer.
The CPU is responsible for computing, responsible for computing.
10 plus 20 is 30
The CPU is responsible for calculating 30.
However, during the calculation, there are three data that need to be stored in a temporary space:
The three numbers are: 10, 20, 30
Memory:
Temporary data storage space during the execution of a program.
Data in memory disappears after a power failure or shutdown.
Hard disk:
Persistent devices where data on hard disks is not lost due to power outages.
The main board:
Equivalent to the human torso, it is a carrier:
CPU, memory, hard disk and other major components are placed on the motherboard,
There are many wires on the motherboard to connect the above parts.
.
Java is completely object-oriented.
Object orientation is easier to understand, and humans generally perceive the world as objects.
Adopting an object-oriented approach can simplify complex problems.
3. Robustness
Mainly because there is a mechanism in Java that:
Automatic garbage collection mechanism (GC mechanism).
The Java language is robust, and C is not as robust as Java.
Java is not prone to memory leaks.
Using C++ or C incorrectly can easily lead to memory leaks.
The JVM is responsible for scheduling the GC mechanism. Programmers don’t need to interfere.
These terms are described in the explanation above:
JVM (a virtual computer written in C++), GC (garbage collection mechanism)
Java fully/perfectly supports multi-threaded concurrency.
5. Portability/cross-platform
The Java language can be written once and run anywhere.
For example, after Java programs are written, they can run on Windows, Linux and MaC OS without any changes.
Write it once, run it anywhere. (The platform changes, but the program doesn’t.)
(1) What are the advantages and disadvantages of this mechanism?
- Advantages: Write once and run anywhere, cross-platform.
- Cons: Trouble. To run Java programs, you must have a JVM.
In the same way that you have to install flash to watch videos on the web.
(2) Can the Java language write viruses?
Yes, no problem. But it’s hard to poison users.
It’s usually Java programmers who get poisoned. So few people write Java virus scripts.
(3) The relationship between JDK, JRE and JVM?
- DK:Java development toolkit
- JRE: Indicates the Java runtime environment
- The JVM, the Java virtual machine
The JDK includes the JRE and the JRE includes the JVM.
JVMS cannot be installed independently.
Both JRE and JDK can be installed independently.
There is a separate JDK installation package.
There is also a separate JRE installation package.
There is no separate JVM installation package.
When you install the JDK: the JRE is automatically installed, and the JVM inside the JRE is automatically installed.
When installing the JRE: The JVM is automatically installed.
Question:
Let’s say you’ve developed a new piece of software at a software company, and now you need to go to a customer’s office to deploy the project to get it up and running. Do you need to install the JDK?
You just need to install the JRE.
The JRE is small in size and easy to install.
Question:
Why does JDK installation come with a JRE?
Because after a Java programmer develops a program, to test the program and make it run, he needs a JRE. So JDK installation comes with an internal JRE.
To summarize the key terms we’ve touched on so far:
The technology of the Java architecture is divided into three major chunks:
- JavaSE: Standard edition
- JavaEE: enterprise edition
- JavaME: miniature version
After installing the JDK:
- JDK: Java development toolkit
- JRE: Indicates the Java runtime environment
- JVM: Java VIRTUAL machine
(4) Understanding of Java loading and execution (theory is important)
Java program from writing to the final run through the process ????
Two very important phases of a Java program:
- Compilation phase
- Operation phase
Note: Java code written directly by a Java programmer (plain text) cannot execute as recognized by the JVM. Java code written by Java programmers as plain text must go through a compilation that turns “plain text code” into “bytecode,” which the JVM can recognize.
The process by which Java code becomes bytecode from plain text is called compilation.
Java code this plain text is called Java source code. (The code you write is source code.) Source code cannot be executed directly. It needs to be compiled to generate the corresponding “bytecode” of the source code.
What the JVM recognizes is bytecode.
Can compile phase and run phase be done on different operating systems?
You compile it on Windows, you generate bytecode, and you can run bytecode on Linux because Java is cross-platform.
You can write it all at once.
Can the Java source code be deleted once compiled? Can only bytecode be executed?
Completely executable, because the source code does not participate in the program’s execution process.
What is involved in the execution of a program is bytecode.
But it’s best not to delete the source code. Because it is possible that the execution result is not what you need, when the execution result is not what you need, you can reopen the source code to make changes, then recompile to generate new bytecode, and then execute again. This will have a new execution effect.
The file extension for the source code must be xxx.java
Note also that the bytecode file extension generated by compilation is xxx.class
Without why, rote !!!!
The.java file is the source file in which the source code is written.
The.class files are bytecode files, which are compiled from source code.
Another thing to note:
A single Java source file can be compiled to generate multiple class files.
The final thing to run is the class file.
Question:
Are bytecode files binary?
Bytecode files are not binaries.
If it’s binary, you don’t need a JVM.
Because the operating system can execute binary directly.
How does a Java program go from development to final execution?
Compile time :(available on Windows)
Step 1: Create a new xxx.java file somewhere on your hard drive (optional)
Step 2: Use Notepad or another text editor such as EditPlus to open the xxx.java file
Step 3: Write “Java syntactic” source code in xxx. Java.
Step 4: Save (be sure to save the XXX.java file)
Step 5: Use a compiler (javac) to compile the xxx. Java file.
Step 6: If the source code written in the xxx. Java file is syntactically correct, the compilation will pass. If the source code written in the xxx. Java file violates the syntax, the compiler will report an error. After the compiler reports an error, the class file will not be generated.
And a Java source file can generate multiple class files. (Compilation is essentially syntax checking.)
Runtime (JRE in action) : (Can run on Windows or other OS.)
Step 7: If you are running on Linux, you need to copy the class file generated on Windows. You do not need to copy the source code, but really run bytecode. (But do not delete the source code, useful)
Step 8: Use one of the JDK’s built-in commands/tools: Java (the command/tool that runs it) to execute the bytecode
Step 9: The next steps are left to the JVM without programmer intervention.
The JVM loads the bytecode file in, and the JVM interprets the bytecode (the interpreter takes care of the bytecode)
The explanation is 1010101010.. Binary of etc.)
Step 10: The JVM hands the generated binaries to the OS, which executes the binaries to interact with the hardware.
Note: There are two very important commands that need to be used in this process.
- Javac command, responsible for compilation
- Java command, responsible for running
Episode:
Java source files are compiled to generate a.class, B.class, c. class, etc., so we call A A class, B A class, C A class. Where A, B, and C are the class names.
No reason, memorization, that’s what SUN’s Java syntax dictates.
A/B/C is the name of the class. Class A, B and C.
The code written in the source file is called source code.
That’s a complicated process, so what’s a programmer supposed to do?
- Creating a Java File
- Open a Java file
- Writing Java source code
- save
- Javac command to compile
- Java Command Execution
- Write, compile, run
(5) write the first Java program in Java: HelloWorld (HelloWorld: born)
You don’t have to understand this program, you just have to copy it, because I’m not going to explain why it’s written that way.
Mainly in order to build Java development environment, test whether the Java environment can be used.
Step 1: Install the Text Editor
Step 2: Install JDK (download JDK first)
Install JDK13 and go to the next step.
JDK13 is installed with a built-in JRE, and a JRE independent of the JDK is not generated.
For java13, you need to execute special commands if you want to generate a JRE independent of the JDK.
I won’t talk about it here, but I’ll talk about it later when I use it.
Note that:
When JDK8 is installed, not only does the JDK come with a BUILT-IN JRE, but it also generates a separate JRE outside the JDK directory. (In earlier versions, there were actually two JRE versions.)
One is built into the JDK and one is independent of the JDK.
The bin directory of the JDK contains:
- Javac.exe is responsible for compilation
- Java.exe is responsible for running it
Step 3: Write code
Let’s write our first program, HelloWorld.
This code emphasizes here:
File name copy
The file content code is strictly copied
Copy case
Copy every link
Copy the punctuation
Don’t ask why.
This will be explained later. Parentheses:
[]
(a)
{}
Write them all in pairs.
Step 4: Compile
Step 5: Run
The last
Many friends hope I recommend a more detailed Java zero basic tutorial, the following is I think quite good, worth watching the collection.
To share it with you, click here
www.bilibili.com/video/BV1Rx…
If it helps you, thank you for your support