Core Java (1), corejava
I. Xu
1. Software: a set of computer data and commands organized in a specific order.
Software Development: using development tools and computer languages to make software
2. Computer Language: language used for communication between people and computers
Machine language, assembly language, and advanced language
Advanced languages are divided into compiled language and interpreted language.
Compile-type language: a program that can be compiled into binary code by the source program, and then run the source code --> machine code execution speed, high efficiency, dependent compiler, and poor cross-platform performance
Explanatory language: the source program translates an execution sentence and knows the ending source code --> intermediate code (bytecode file) --> the execution speed of machine code is slow, the efficiency is low, and it depends on the interpreter, good cross-platform performance
In general, the compilation language can be directly run after compilation, while the execution of the Interpretation Language requires an interpretation environment.JavaVery special,JavaThe program also needs to be compiled, but not directly compiled as the machine language. Instead, the compilation is called bytecode and then executed in an interpreted way.
--
Common
DOS
Command
How to open the DOS Console
1. Start-Program-attachment-Command Prompt
2. Start-run-cmd-press ENTER
3. win + r-cmd-enter
Common doscommands
D: Switch the carriage return drive.
Dir (directory): list files and folders in the current directory
Md (make directory): Creates a directory.
Rd (remove directory): deletes a directory.
Cd (change directory) changes the specified directory (enter the specified directory)
Cd ..: Return to the upper-level directory
Cd \: Return to the root directory
Del (delete): delete a file and delete a bunch of files with the same suffix *. txt
Exit: exit the doscommand line.
Cls: (clear screen) clear screen
--
Java
Language Platform version
J2SE Java SE (Java 2 Platform Standard Edition) Standard Edition
It is a solution for developing common desktop and business applications. The technical system is the foundation of other two and can complete the development of some desktop applications.
Small Edition of Java 2 Platform Micro Edition
Is a solution for developing electronic consumption products and embedded devices.
J2EE (Java 2 Platform Enterprise Edition) Enterprise Edition
It is a set of solutions for developing applications in an enterprise environment. The technologies included in this technical system, such as Servlet and Jsp, are mainly used for Web application development.
-- Configure Environment Variables
My computer (right-click)-> properties-> advanced system settings-> advanced-> Environment Variables
-- JAVA_HOME
The system variable comes with the JAVA_HOME variable, and the variable value is the JDK installation path. You need to edit it as follows:
-- PATH
PATH already exists in the system variable. Enter the Bin PATH (separate other paths with semicolons) at the beginning. Edit the PATH as follows:
$ JAVA_HOME % \ bin
C: \ java \ jdk \ bin
-- CLASSPATH
The built-in variables do not have CLASSPATH and need to be added.
This is the Java environment configuration. After the configuration is complete, you can start Eclipse to write code. It will automatically complete the java environment configuration.
NOTE: If JDK 1.5 or a later version is used, you do not need to set the CLASSPATH environment variable or compile and run Java programs normally.
-- Test whether JDK is successfully installed.
1. "Start"-> "run", type "cmd ";
2. type the following commands: java-version, java, and javac. The environment variables are successfully configured;
--
Java
Main features of the language
1. cross-platform
The software runs normally in any computer environment without the constraints of computer hardware and operating systems.
In Java, Java's built-in virtual machines provide good cross-platform performance.
2. Object-oriented
3. Security (robustness)
4. Multithreading
Multithreading allows an application to have two or more threads at the same time to support concurrent transactions and multi-task processing. In addition to the built-in multithreading technology, Java also defines some classes and methods to establish and manage user-defined multithreading.
5. Easy to use
-- JRE
And
JDK
JRE (Java Runtime Environment)
Including the core class libraries required by Java Virtual Machine (JVM Java Virtual Machine) and Java programs. To run a developed Java program, you only need to install JRE on the computer.
JDK (Java Development Kit)
JDK is provided for Java developers, including java development tools and JRE. Therefore, if JDK is installed, you do not need to install JRE separately.
Development tools: Compilation tools(Javac.exe)Packaging tools(Jar.exe)And so on
Simply put: UseJDKDevelopedJavaProgram, hand overJRETo run.
--JavaCross-platform
With JVM, the same Java program can be executed in three different operating systems. In this way, Java programs are implemented across platforms. Java has good portability.
JavaThe language is cross-platform, whileJVMNot cross-platform.
-- Bytecode (Bytecode file)
A bytecode file is a type of file that has been pre-processed by the compiler. It is a JAVA execution file. It is a binary file,Cannot be directly executed by the SystemBut the virtual machine needs to explain the execution. Because it has been preprocessed, It is faster than the general interpretation code, but it is still slower than the direct execution of the system.
The machine code is completely attached to the hardware, and different hardware may have different meanings even if the same 0-1 code is different due to different embedded instruction sets ~ In other words, there is no cross-platform nature ~ For example ~ For CPUs of different models, you can give him an instruction of 10001101, which may be parsed into different results.
We know that JAVA is cross-platform. Why? Because he has a jvm, no matter what kind of hardware, as long as you have a jvm installed, then he knows this JAVA bytecode. As for the underlying machine code, we don't need to worry about it. We can do it with jvm, he will translate the bytecode into the machine code that the machine knows.
-- GCGarbage Collector
JavaMemory Management is actually the management of objects, including the allocation and release of objects.
For programmers, The new Keyword is used to allocate objects. When releasing an object, they only need to assign null values to all references of the object so that the program cannot access this object, we call this object "inaccessible", and GC will be responsible for recycling the memory space of all "inaccessible" objects.
Gc will enable the thread to clean up the memory, not to recycle it in time. Based on the memory efficiency, if the memory is insufficient, it will be recycled, or the system will be idle, therefore, gc has a low priority to improve operation efficiency. Programmers cannot control gc by using virtual machines. Therefore, we can only provide suggestions, but not necessarily accept them.
System. gc ()/Runtime. gc () // code function. It is recommended that garbage collection be performed here.
What is cross-platform?
Applications written in Java can run on different system platforms.
What is the principle?
To run a java application,
First install a Java Virtual Machine (JVM Java Virtual Machine. JVM is responsible for running Java programs in this system.
Why does JDK contain a JRE?
First, the developed program always needs to run to see the effect.
Second, and most importantly, the development tools in JDK are actually applications written in java. They are packaged into exe files for ease of use. If there is no JRE, these tools cannot run.