Introduction to Java language
Java language is an object-oriented high-level language, which is owned by Sun company (now acquired by Oracle company). It was jointly developed by James Gosling and his colleagues and was officially launched in 1995. According to Oracle's official data index, there are currently hundreds of millions of systems developed using Java in the world. Java is an object-oriented programming language. It not only absorbs the various advantages of C++ language, but also abandons concepts such as multiple inheritance and pointers that are difficult to understand in C++. Therefore, Java language has two characteristics: powerful and easy to use.
What can the Java language do?
Java language is mainly used in the field of Internet program development. Common Internet programs such as Tmall, JD.com, logistics systems, online banking systems, etc., as well as the storage, query, and data mining of big data in the server background, also have many applications.
Computer basics
Binary: The data in the computer is different from the data in people's lives. People use decimal numbers in their lives, while all computers in the computer use binary numbers. It only contains two numbers, 0 and 1, and they enter one every two.
- Convert decimal data to binary data: use the method of dividing by 2 to find the remainder
- Convert binary data to decimal data: use 8421 encoding
In the binary number system, each 0 or 1 is a bit, called a bit.
Byte: A byte is the smallest storage unit in a computer. Any data stored on the computer is stored in bytes. Right-click on the file properties, and we can view the size of the file in bytes.
8 bits (binary bits) are represented as 1 byte.
1B = 8bit
1KB = 1024B
1MB = 1024KB
1GB = 1024MB
1TB = 1024GB
Commonly used DOS commands
As a beginner in the Java language, learning some DOS commands will be very helpful. DOS is an early operating system, which has now been replaced by Windows. For our developers, we currently need to accomplish some things in DOS, so we need to master some necessary commands.
command | effect |
---|---|
to you | List files and folders in the current directory |
md | Create a directory |
rd | Delete directory |
cd | Enter the specified directory |
cd… | Return to the previous directory |
cd\ | Back to the root directory |
of the | Delete Files |
cls | Clear screen |
exit | Exit the DOS command line |
Java language development environment construction
Right-click this computer, click Properties, enter the system dialog box, and then click Advanced System Settings. The
system properties dialog box will pop up, select Advanced -> Environment Variables.
Click the New button under System Variables to
pop up the New System Variable dialog box. Set the JAVA_HOME environment variable, click OK button After
confirming, click the new system variable button to set the CLASSPATH environment variable, click the OK button
, select the path system variable after confirming, click Edit, New -> configure path environment variable, and
finally enter javac in the DOS window cmd command to display the content, then Indicates that the CLASSPATH environment variable is successfully configured.
Enter java in the cmd command in the DOS window and display the following content to indicate that the path environment variable is successfully configured.
The difference between JVM, JRE and JDK
JVM (Java Virtual Machine): Java virtual machine, used to ensure the cross-platform characteristics of Java. The Java language is cross-platform, and the JVM is not cross-platform.
JRE (Java Runtime Environment): Java runtime environment, including the core class library of JVM+Java.
JDK (Java Development Kit): Java development tools, including JRM+ development tools.
JDK contains JRE and JVM, JRE contains JVM
Three technical architectures of Java language
Java2SE: Standard Edition
is a solution for the development of common desktop and business applications. This technical system is the foundation of the other two and can complete the development of some desktop applications.
Java2EE: Enterprise Edition
is a set of solutions for developing applications in an enterprise environment. The technologies included in the technical system, such as Servlet, JSP, etc., are mainly aimed at the development of Web applications.
Java2ME: Small Edition
is a solution for the development of electronic consumer products and embedded devices. This technology system is mainly used in small electronic consumer products, such as applications in mobile phones.
My first java program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Instructions for getting started
①Compiling and running are two different things.
Compilation refers to translating the Java source files we have written into class files recognized by the JVM. During this process, the javac compiler will check whether the program we have written has errors, and will prompt if there are errors , If there are no errors, it will compile successfully.
Run: refers to the class file to the JVM to run, at this time the JVM will execute the program we wrote.
②About the main method
main method: called the main method. The writing method is a fixed format and cannot be changed. The main method is the entry point or starting point of the program. No matter how many programs we write, when the JVM is running, it will start execution from the main method.
③Add comments
Comment: It is the explanation and description of the code. Its purpose is to make it easier for people to understand the code. Adding comments to the code is very necessary, it does not affect the compilation and running of the program, there are single-line comments and multi-line comments in Java.
Single line comment//Comment content
Multi-line comment/* Comment content*/
④Keywords Keyword
: refers to the words that Java has defined in the program, which have special meanings. In the HelloWorld case, the keywords that appear are public, class, static, void, etc. These words have been defined by Java and are all lowercase letters.
⑥Identifier Identifier
: refers to the content defined by ourselves in the program. Such as the name of the class, the name of the method, the name of the variable, and so on.
Identifier naming rules
①It is composed of numbers, uppercase and lowercase English letters, _ and $.
②Cannot start with a number. ③Cannot
use keywords to customize the name
constant
Constants refer to fixed data in Java programs.
classification:
variable
The amount that can be changed in the program is called a variable. Java requires that a variable can only store one data at a time, and the data type to be saved must be clear.
Variable definition:
The format of variable definition includes three elements: data type, variable name, and data value.
数据类型 变量名 = 数据值;
int i = 1;
Note: Variable names cannot be the same within the same curly brackets
Basic data type
Four types and eight basic data types:
The default type in Java: integer type is int, floating point type is double
Memory method: 12484812
byte short int long float double boolean char