Java past life

Java was originally a programming language developed by James Gosling of SUN (which was acquired by Oracle) in the early 1990s. Originally named Oak, it was aimed at embedded applications for small home appliances, but the market did not take off. But the rise of the Internet gave Oak a new lease of life, so SUN reinvented it and officially released it as Java in 1995, because 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 falls between compiled and interpreted languages. In order to ensure that virtual machines developed by different platforms and companies can correctly execute Java bytecode, SUN has developed a series of Java virtual machine specifications. From a practical point of view, JVM compatibility is so good that lower versions of Java bytecode can run perfectly well on older JVMS.

As Java has evolved, SUN has created three different versions of Java:

  • Java SE: Standard Edition
  • Java EE: Enterprise Edition
  • Java ME: Micro Edition

What’s the relationship between these three?

Simply put, Java SE is standard edition, including standard JVM and standard library, while Java EE is enterprise edition, it is just on the basis of Java SE plus a large number of apis and libraries, so as to facilitate the development of Web applications, databases, message services, etc. Java EE applications use the same virtual machines as Java SE applications.

There is no doubt that Java SE is the core of the entire Java platform, and Java EE is necessary for further learning about Web applications. Familiar frameworks like Spring are part of the Java EE open source ecosystem.

Noun explanation

  • JDK: Java Development Kit
  • Java Runtime Environment (JRE) : a Java Runtime Environment consisting of a JVM running Java bytecode files

The relationship between the two is as follows:

Simply put, the JRE is a virtual machine running Java bytecode. However, if you only have Java source code, to compile into Java bytecode, you need the JDK, because the JDK includes the JRE as well as the compiler, debugger, and other development tools.

Environment configuration

To learn any programming language, it is necessary to have the IDE or official development tools recommended by the predecessors, as well as the configuration of the runtime environment. Xiaobian here select IDEA 2021 and JDK8.

JDK download and installation

1, download

Website download link: https://www.oracle.com/java/technologies/javase-downloads.html

Xiaobian jdK8 version used here, is currently used more stable version, recommended use. If they can’t download can visit here to extract ha: https://pan.baidu.com/s/1tb1AG-FBHpYRsw0Q5U9YLw extraction code: 3 KWK

2, installation,

Xiaobian to Win10 system as an example, download good decompression can be, xiaobian is no need to install the version. Note: Do not use a path with Chinese characters. In addition, it is strongly recommended: change the name of the drive letter and account name of your computer to English, or pinyin, so that you will avoid some strange problems, although these problems may appear after the installation of database or other software, but the program world is not to understand Chinese characters.

3. Configure the environment

Desktop This computer, in the following order: right mouse button -> Properties -> Advanced System Settings -> Advanced -> Environment Variables:

After selecting the environment variable, we can see the following interface, then choose system variable -> New, then the dialog box for creating a new system variable will pop up, enter JAVA_HOME in the variable name, enter the JDK installation path in the variable value, and click OK.

We also need to modify the system Path variable. Add the following two paths after the variable:

%JAVA_HOME%\bin
%JAVA_HOME%\jre\bin
Copy the code

Create/modify the CLASSPATH variable

If the CLASSPATH variable exists, select and click Edit. If not, click New.

Enter/add to existing variable values:

Variable name: CLASSPATH Variable value:. %JAVA_HOME%\lib\dt.jar; %JAVA_HOME%\lib\tools.jar;Copy the code

Verify that the installation is successful

Press Win+R and enter CMD to bring up the command line window

Enter Java. If information similar to the following is displayed, the configuration is successful.

If there is no error message, it is OK. The latter command is to check your JDK version number. If you forget which JDK version you installed for a long time, you can use this command to check.

IDEA download and install

Download address: https://www.jetbrains.com/idea/download/#section=windows

The Ultimate 64 – bit version is used to identify the current computer system. Exe files and zip files are available for download.

Installation is simple, almost all the way to the next. It is recommended that you do not install the software in C disk habitually, so that C disk will be bigger and bigger, and finally lead to the computer is very card.

I suggest you modify the font size and display method divider in the edit area. The latter, when you have a lot of methods, it’s not easy to tell the beginning of a method from the end of a method, especially when you’re folding all methods.

File–>Settings, then modify as shown below:

File–>Settings, then modify as shown below:

In addition to these two most basic Settings, others can be adjusted according to personal preference to use the most comfortable.

Hello World,

Many authors on this part of the network are put it in the back, because things a little bit more involved, here refers to a noun, this for beginners, it’s difficult to understand, but small make up closely studied, at the very beginning there is no problem, always listen to good, at least in the mind have a low.

Write your first Java program

Create the first Java program: File–>New–>Project (in this step you can see the JDK we installed) –>Next–>Next–> You will see the following screen:

Project name is the name of the Project we created. You can name it yourself. English or Pinyin are recommended. Project location Where the Project we created is placed on the computer, it is recommended not to use the path with Chinese.

After finishing, we should see the following screen:

This is the default system to provide content, the previous main work is in the SRC directory, the following to create the first Java program for example: SRC right-click, choose new- >Java Class- > enter the name of the new Class (Class name naming rules will be described later in this article) -> enter.

For example, the class name is MainHello:

public class MainHello {}Copy the code

This step is equivalent to creating a Java file, but there is no system to execute the function entrance, this entrance can be temporarily understood as the entrance of a scene in real life (such as: scenic spots entrance entrance), but the Java file entrance has and only one, next we create this entrance function:

This method can be quickly generated by typing main+ Enter:

Change this shortcut input is also very simple, in fact, is to remove the default intelligent prompt limit (default only uppercase initial, will prompt the entire system class and keyword, etc.)

The generated method is as follows:

public class MainHello {

    public static void main(String[] args) {}}Copy the code

This is where the green run button comes out, and this is the default entry that the system recognizes, and that’s where we’re going to do the rest of the work. Xiaobian first here to use the output statement provided by the system, output we are familiar with Hello World.

public class MainHello {

    public static void main(String[] args) {
        System.out.println("Hello World"); }}Copy the code

Then click Run to see the result.

parsing

Here is a simple analysis of Java program entry, that is, the main function, first look at the rectangles in different colors below

  • publicThis is called in JavaModifier qualifierThere is more than the first timeprivate,protectedanddefault(default is not to write this), it is used to restrict access to the class file or the method in the class, as shown in the following figure:

  • classIs in the Java languageThe keywordIn addition, there are many keywords as wellReserved wordsThe latter is the system is not used for the time being but reserved, maybe later use, but the developer can not use it. For example:goto. Just know the following:

  • MainHelloThat’s what we definedidentifierIn the Java language, identifiers are named in a regular way:

    • Strictly case sensitive
    • You can’t start with a number
    • The value can be a combination of letters, digits, underscores (_), and $($)
    • Do not occupy Java keywords and reserved words
    • Be known by name
    • Nomenclature, hump nomenclature recommended (not required, recommended)

Identifiers for class names, method names, variables, and statement blocks are the most common.

  • main(String[] args)It’s one of those functions in Java that takes one argumentmethods. When we talk about functions and methods in Java, we mean the same thing. There are two methods in Java, depending on the number of arguments:Parameterless methodandThere are parameter methods (the number of parameters can be customized), the type of the parameter can also be customized.

The main method takes a string array as an argument, and a new term appears: array. In Java, arrays can be divided into one-dimensional arrays and multidimensional arrays according to their dimensions.

The understanding of array can be simply understood as billiard balls in a box. The number on each ball is the characteristic of array, which is called index in Java language. The index starts from 0, for example, there are 10 balls, then the index is 0~9.

Summary of Java program entry involved in the relevant content is introduced here, the specific content will be explained in detail later.

The data type

Data types in the Java language can be divided into two broad categories: basic data types and reference data types. This is clear from the following map:

Into the system

There are four ways to represent integers in Java: decimal (which we usually use), binary, octal, and hexadecimal.

  • Binary: starts with 0B or 0B and contains 0 to 1 digits.
  • Decimal: a number ranging from 0 to 9.
  • Octal: digits starting with 0 and including 0 to 7.
  • Hexadecimal: starts with 0x or 0x and includes 0The number nine, and the letter AF, A ~ f.

Hexadecimal conversion

Convert other bases to decimal

Formula: Coefficient * sum of the powers of the base (coefficient refers to each number, base refers to how many bases, weight refers to zero from right to left, 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
Copy the code

Transfer from decimal to other base systems

Formula: Divide the base (base, that is, the base to be changed) and reverse the remainder (remainder)

For example: compute the binary of 60:

variable

  • Stored in memory
  • According to scope, it is divided into local variables and global variables
  • Declaration rule: Variable type Variable name, for example, int stuAge
  • Variable assignment: =
  • Rules for using variables: Declare them first, then use them
  • Variable defaults: There are default values for base data types and default values for reference typesnull, the Boolean default value isfalse.

A constant is a special case of a variable. Constants are final, their value cannot be changed twice, and are usually defined in uppercase letters.

conclusion

Yesterday saw a video about programming fun, recommend you to look at the https://youtu.be/dU1xS07N-FA.

I believe that learning Java all know such a sentence: compile once, run everywhere. So what’s the theory behind it?

“The Java compiler does not compile all classes into a machine code program. Instead, it compiles each class independently, and not into machine code, but into special intermediate code (bytecode). When the program starts, the bytecode is compiled into machine code.”

This is why Java is widely used in many industries and is becoming one of the preferred learning languages for more and more developers.

Xiaobian specially created a public number: recommend learning Java, will share Java related content, and the original, welcome to search attention (attention is to send xiaobian selection of high-quality video tutorial), learn Java together!