Introduction to Java

1.1 Java overview

From the beginning, Java attracted programmers with its friendly syntax, object orientation, memory management, and best cross-platform portability.

The write-once/run-anywhere feature is awesome.

1.2 Origin of Java name

Java is the English name of the Indonesian island of Java, famous for its coffee. There are many library class names in the Java language, most of which refer to coffee, such as JavaBeans(coffee beans), NetBeans(network beans), and ObjectBeans (ObjectBeans). The SUN and JAVA logo is a steaming cup of coffee. Java has a history of more than 20 years since its birth in 1995.

1.3 Development history of Java

Since the release of version 1.0 in 1995, the latest version of Java to date is Java 15

time version
1995 1.0
1998 1.2
2000 1.3
2002 1.4
2004 1.5/5.0 Major update
2005 1.6/6.0
2009 Oracle acquisition
2011 1.7/7.0
2014 1.8/8.0 Common version
2017/9 1.9/9.0
2018/3 10
2018/9 11
2019/3 12
2019/9 13
2020/3 14
2020/9 15

1.4 Java working Mode

The goal of Java is to be able to write a program that runs on all devices.

All we need to do is write the source code and compile it using the Javac compilation tool. The compiled bytecode file is then executed on a Java virtual machine

The working mode is as follows:

Java environment variables

2.1 What are the JDK and JRE

  • Java Development Kit (JDK) : The JDK is provided for Java developers to use, which contains Java Development tools, including JRE. So if you install the JDK, you don’t need to install the JRE separately
  • Java Runtime Environment (JRE) : includes Java VIRTUAL machine (JVM). Java Virtual Machine) and Java program required core class libraries, if you want to run a developed Java program, the computer only need to install JRE.
  • The JDK contains the JRE, and the JRE contains the JVM.

In short, use the development tools provided by JDK to complete the development of Java programs, and use JRE to run the developed Java applications.

2.2 Downloading and installing the JDK

Download:

The official website: www.oracle.com/technetwork…

The JDK installation:

– Foolproof installation, next step.

– Suggestion: The installation path must not contain Chinese characters or special characters.

– If you are prompted to install JRE, do not install it.

Default installation path: C:\Program Files\Java

2.3 JDK Directory Introduction

The JDK directory JDK directory functions
bin Executable files for JDK development tools, includingjava.exe,javac.exeEtc.
include Contains C language header files that support Java native interface and Java virtual machine debugger interface native programming technology
jre The root directory of the Java runtime environment, which contains the Java virtual machine, the runtime class package, and the Java application launcher,

Development tools in the development environment are not included
lib Archive files used by development tools

2.4 Configuring Environment Variables

  1. Step 1: Open – Computer – Properties – Advanced System Settings – Environment Variables – System Variables

  2. Step 2: Configure (JAVA_HOME,PATH,CLASSPATH)

    1. JAVA_HOME: Another alias for the entire JDK. Then use the alias directly
    2. PATH: Use PATH to find the corresponding command in the DOS command line. java javac
    3. CLASSPATH: Optional installation is recommended after JDK1.5. Be sure to configure one at the front.(dot)
  3. The specific configuration is as follows

    JAVA_HOME = C: Program Files\Java\jdk1.8.0_73 PATH = %JAVA_HOME%\bin; %JAVA_HOME%\jre\bin; CLASSPATH = .; %JAVA_HOME%\lib\dt.jar; %JAVA_HOME%\lib\tools.jar;Copy the code

  4. Check whether the installation is successful

    When installing, note whether the path is growing, whether there are extra semicolons, etc. You can use the following two commands to check whether the JDK was installed successfully

    • java -version

    • javac

2.5 Java Program Structure

1. Basic concepts

Before we understand the structure of the program, let’s look at the following concepts:

2. Main method

When the Java virtual machine starts execution, it looks for the class specified in the command column. Then find the main method.

Every Java program has at least one class and main method.

There is only one main method per application

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

3. Complete code

public class MyFirstApp {
    public static void main (String[] args) {
        System.out.println("I Rule!");
        System.out.println("The World"); }}Copy the code

Java operation mechanism

The Java runtime mechanism is largely dependent on the JVM

3.1 the JVM

Concept: THE JVM is a virtual computer with an instruction set and different storage areas. Responsible for executing instructions, managing data, memory, registers

Java is a cross-platform language (Windows, Linux, MAC): How to achieve cross-platform: because different operating systems (platforms) have different virtual machines. The Java virtual machine (JVM) mechanism shields underlying platform differences and implements "compile once, run anywhere".Copy the code

IDEA tool

IDEA, short for IntelliJ IDEA, is an integrated environment for Java programming language development. IntelliJ is recognized as the best Java development tool in the industry, especially in intelligent code assistant, automatic prompt code, refactoring, JavaEE support, various version tools (git, SVN, etc.), JUnit, CVS integration, code analysis, innovative GUI design and other aspects of the function can be said to be extraordinary. IDEA is the product of JetBrains, a company based in Prague, the Capital of the Czech Republic, which is dominated by rigorous Eastern European programmers. Its flagship version also supports HTML, CSS, PHP, MySQL, Python, and more. The free version only supports Java,Kotlin and a few other languages. — Baidu Encyclopedia

4.1 Download Address

The idea to download address: www.jetbrains.com/idea/downlo…

Idea is available in two versions:

  • Enterprise edition
    • 1. Fully functional
    • 2. You need to purchase legitimate copies or you need to be activated. Free trial for 30 days
  • Community edition
    • 1, free
    • 2. Some functions are not available

4.2 installation

Foolproof next installation

Activation Tutorial:

Network backup link: link: https://pan.baidu.com/s/1Yhq_7dP0MOayyEJ-g4_27A password: ute8 spare links: link: https://pan.baidu.com/s/1qFTDOEZJaVDh2CMipDReLA password: SBRWCopy the code

4.3 Basic Configuration

The IDEA version used this time is 2020.3.2

1. Go to the Setting configuration center

2. Set the global encoding

Set the global encoding to UTF-8

4.4 Creating a Java Project