Java past and present
Java was originally a programming language developed by James Gosling (Gao Commander, known as the father of Java) of SUN (acquired by Oracle) in the early 1990s. It was originally named Oak and aimed at small The embedded applications of home appliances have resulted in little response from the market. Unexpectedly, the rise of the Internet gave Oak a new lease of life, so Sun transformed Oak and officially released it under the name of Java in 1995. The reason was that Oak had already been registered, so SUN registered the Java trademark. With the rapid development of the Internet, Java has gradually become the most important network programming language.
Java is between a compiled language and an interpreted language. In order to ensure that virtual machines developed by different platforms and companies can correctly execute Java bytecode, SUN has formulated a series of Java virtual machine specifications. From a practical point of view, the compatibility of the JVM is very good, and the low-version Java bytecode can run normally on the high-version JVM.
With the development of Java, SUN has divided Java into three different versions:
- Java SE:Standard Edition
- Java EE:Enterprise Edition
- Java ME:Micro Edition
What is the relationship between these three?
To put it simply, Java SE is the standard edition, including standard JVM and standard libraries, while Java EE is the enterprise edition, it just adds a large number of APIs and libraries on the basis of Java SE to facilitate the development of Web applications, databases, For messaging services, the virtual machine used by Java EE applications is exactly the same as Java SE.
There is no doubt that Java SE is the core of the entire Java platform, and Java EE is necessary for further learning of Web applications. Frameworks such as Spring that we are familiar with are all part of the Java EE open source ecosystem.
Glossary
- JDK: Java Development Kit (java development kit)
- JRE: Java Runtime Environment (Java Runtime Environment, which is mainly composed of JVM running Java bytecode files, namely Java Virtual Machine)
The relationship between the two is as follows:
Simply put, JRE is a virtual machine that runs Java bytecode. However, if you only have Java source code and you want to compile it into Java bytecode, you need JDK, because in addition to JRE, JDK also provides development tools such as compilers and debuggers.
Environment configuration
To learn any programming language, there are IDE
or official development tools recommended by the predecessors, as well as the configuration of the operating environment, which are all necessary. The editor here chooses IDEA 2021
and jdk8
.
JDK download and installation
1. Download
Official website download link: https://www.oracle.com/java/technologies/javase-downloads.html
The jdk8 version used by the editor here is the more stable version currently in use, and it is recommended. If you can’t download it, you can visit here to extract it: https://pan.baidu.com/s/1tb1AG-FBHpYRsw0Q5U9YLw
Extraction code: 3kwk
2, install
The editor takes the win10 system as an example, just download it and unzip it. The editor does not need to install the version. Note the path of decompression: Do not use the path with Chinese. In addition, it is strongly recommended that you change your computer’s drive letter name and account name to English or Pinyin to avoid some strange problems. Although these problems may not appear until the database or other software is installed later, the program’s The world does not recognize Chinese characters.
3. Configuration environment
Desktop this computer, in accordance with the following sequence of operations: right mouse button --> Properties --> Advanced System Settings --> Advanced --> Environment Variables:
After selecting environment variables, we can see the following interface. At this time, select System Variables --> New, and a dialog box for creating new system variables will pop up. Enter JAVA_HOME in the variable name and JDK installation in the variable value. Path (the jdk in the editor is the decompressed directory), click OK.
We also need to modify the system Path
variables. Add the following two paths after the variable:
%JAVA_HOME%\bin
%JAVA_HOME%\jre\bin
New/modify CLASSPATH
variable
If there is a CLASSPATH variable, select it and click Edit. If not, click New.
Enter/add after the existing variable value:
变量名:CLASSPATH
变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;
Verify that the installation is successful
Use the shortcut key Win+R
and enter cmd
call up the command line window
Enter java
, if information similar to the following figure appears, it means that the configuration is successful.
Then enter the commands javac
and java -version
. If there is no error message, it is ok. The latter command is to check your jdk version number. If you forget which version of jdk you installed at the time for a long time, you can use this command to check.
IDEA download and install
Download https://www.jetbrains.com/idea/download/#section=windows
Ultimate
version selected by the editor here is 64-bit. Generally, the current computer system will be recognized intelligently when downloading. The exe file downloaded by the editor, and the zip format, can be tried by yourself.
Installation is simple, almost all the way next
. It is recommended that you do not habitually install the software on the C drive, so that the C drive will become larger and larger, which will eventually cause the computer to get stuck.
It is recommended that you modify the font size of the editing area and the
display method dividing line. In the latter, when you have more methods, it is not easy to distinguish the beginning and the end of the method, especially when all the methods are folded.
File-->Settings, then refer to the following figure to modify:
File-->Settings, then refer to the following figure to modify:
In addition to these two most basic settings, the others can be adjusted according to personal preference to make them most comfortable to use.
Hello World in detail
Many authors on this part of the Internet put it behind to explain, because it involves a little bit more, here refers to nouns, which is difficult for novices to understand, but the editor carefully pondered it. Next, there is no problem at all when I explain it at the beginning. It is always good to listen to it. At least I feel a little bit low in my heart.
Write your first Java program
Create the first java program: File-->New-->Project (you can see the jdk we installed in this step) -->Next-->Next-->You will see the following interface:
Project name
is the name of the project we created. You can name it yourself. English or Pinyin is recommended. <br/>Project location
Where to put the project we created on the computer, it is recommended not to use the path with Chinese.
Then there is finish
, we will see the following interface:
This is the content provided by the system by default. In the early stage, our main work was in src
. The following is an example of creating the first java program:
Right-click on src
, and select new-->Java Class-->input the name of the new class to be created (the naming rules of the class name will be discussed later in this article) --> press Enter.
For example, the class name entered by the editor here is MainHello
:
public class MainHello {
}
This step is equivalent to the creation of a java file, but there is no function entry for system execution. This entry can be understood as the entry of a certain scene in real life (such as the entrance to the scenic spot), but the entry of the Java file has and There is only one, then we will create this entry function:
You can use the shortcut input main
+ Enter to quickly generate this method:
Modifying this shortcut input is actually very simple, in fact, it removes the default smart prompt restriction (by default, only the first letter in uppercase will prompt the complete system class and keywords, etc.)
The method after generation is as follows:
public class MainHello {
public static void main(String[] args) {
}
}
At this time, you will see the green run button coming out. This is the entrance that the system recognizes by default. What we will learn next will be here. The editor first uses the output sentences provided by the system here to output the familiar Hello World
.
public class MainHello {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Then click Run to see the result.
Parsing
Here is a simple analysis of the entry of the Java program, that is, the main function. First look at the rectangles marked with different colors in the figure below.
public
modified qualifier in java. In addition to the first time, there areprivate
,protected
anddefault
(this is not written by default). Its function is to limit the access rights of the class file or the method in the class text, respectively. It is clear at a glance:
class
keyword in the java language. In addition, there are many keywords and reserved words . The latter is temporarily not used by the system but reserved. Maybe it will be used later, but developers cannot use it. For example:goto
. Just understand the following:
MainHello
is the identifier we defined. In the Java language, the naming of identifiers is regular:- Strictly case sensitive
- Cannot start with a number
- Can only be combined by one or more of letters, numbers, underscores, and $
- Cannot occupy keywords and reserved words in Java
- To see the name and the meaning
- Naming method, recommended camel case nomenclature (not required, it is recommended)
Identifiers act on class names,
method names,
variables, and
statement blocks, which are the most commonly used by us.
main(String[] args)
is one of the functional forms in java: method with one parameter. The functions and methods mentioned in java actually refer to the same thing. There are two methods in Java according to the number of parameters:no parameter method and
parameter method (the number of parameters can be customized), and the type of parameters can also be customized.
The main method here takes a string array type parameter, here is a new term: array, in Java the array can be divided into different dimensions:
one-dimensional array and
multi-dimensional array.
The understanding of the array can be simply understood as the billiard balls in a box. Each ball has a number that is the characteristic of an array. This is called in the Java language and index . The index starts from 0, for example, there are 10 balls in total. Then the index is 0~9.
summary
The relevant content involved in the entry of the Java program is introduced here, and the specific content will be explained in detail later.
type of data
Data types in java language can be divided into two categories: basic data types and
reference data types. Everyone is very clear through the following map:
Base
There are four forms of representing integers in Java: decimal (which we usually use), binary, octal, and hexadecimal.
- Binary: Start with 0b or 0B, including numbers from 0 to 1.
- Decimal: Including numbers from 0 to 9.
- Octal: Start with 0 and include numbers from 0 to 7.
- Hexadecimal: starting with 0x or 0X, including numbers from 0 to 9, and letters a~f, A~F.
Base conversion
other hexadecimal to decimal
Formula: Coefficient * Add the power of the base number (the coefficient refers to each number, the base refers to the number of bases, the weight refers to starting from 0 from right to left, and the power is the power)
For example: calculate the decimal value of 0x100:
0x100 = 1*16^2 + 0 * 16^1 + 0 * 16^0
= 16*16
= 256
decimal to other hexadecimal
Formula: Divide the base (base, which is the base to be converted) and take the remainder (remainder)
For example: calculate 60 in binary:
variable
- Stored in memory
- According to the scope is divided into: local variables and global variables
- Declaration rules: variable type variable name, such as: int stuAge
- Variable assignment operator: =
- Variable usage rules: declare first, then use
- Variable default value: The basic data type has a corresponding default value. The default value of the reference type is
null
, and the default value of the Boolean type isfalse
.
constant is actually a special case of variable . The constant final
, its value will not be changed twice, and it is generally defined with capital letters.
to sum up
Yesterday I saw a video about programming which was very interesting. I recommend you to https://youtu.be/dU1xS07N-FA
.
I believe everyone who learns java knows this sentence: once and runs everywhere. So what is the principle behind it?
"The Java compiler does not compile all classes into a machine code program. Instead, it compiles each class independently, and instead of compiling into machine code, it compiles into a special intermediate code (bytecode). When the program At startup, the bytecode is compiled into machine code."
This is why Java is widely used in many industries, and more and more developers are used as one of the preferred learning languages.
The editor specially created a public : 160b45f52a4c89 recommended to learn java, will share java
, and is based on originality, welcome everyone to search and pay attention (if you follow, send the boutique video tutorial selected by the editor), and learn Java together!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。