JavaNote-Overview and Installation

1. Java language overview

1.1 Java Overview

  • It is a high-level programming language launched by (Stanford University Network Company) in 1995 SUN.Stanford University Network

  • It is a 面向Internetprogramming language. Java was initially attractive because Java programs could be run in a Web browser. These Java programs are called Java applets (Applets) and are embedded in HTML code.

  • With the rapid development of the Internet and the continuous maturity of Java technology in the web, it has become the preferred development language for web applications.

1.2 A brief history of Java language

Starting stage:

In 1991, a team of Sun engineers wanted to design a language that could be used in the control and communication of home appliances. Since these devices have limited processing power and memory, and different manufacturers choose different central processing units (CPUs), the key to this language is: 代码短小、紧凑且与平台无关.

The Gosling team took the lead in creating this language and named it "Oak". Later, because the market demand for smart home appliances was not as high as expected, Sun gave up the plan.

With the development of the Internet in the 1990s, Sun discovered the prospects of using the language on the Internet, so it transformed Oak and officially released it under the name Java in May 1995.

development stage:

Release version publish time Remark
Java 1.0 1996.01.23 Sun releases first development kit for Java
Java 1.1 1997.02.19 The JavaOne conference was held, creating the largest conference of its kind in the world at that time.
Java 1.2 1998.12.08 Java is split into: J2SE (Standard Edition), J2EE (Enterprise Edition), J2ME (Small Edition)
Java 1.3 2000.05.08
Java1.4 2004.02.06
Java 5.0 2004.09.30 ①The version number is directly updated from 1.4 to 5.0; ②The platform is renamed JavaSE, JavaEE, and JavaME
Java 6.0 2006.12.11 2009.04.20 Oracle announced the acquisition of SUN
2009.04.20 Oracle acquired SUN, the transaction price 74亿was US dollars.
Java 7.0 2011.07.02
Java 8.0 2014.03.18 This version is the biggest change since Java 5.0. Is a long-term support release (LTS)
Java 9.0 2017.09.22 ① Starting from this version, it will be updated every six months ; ② Java 9.0 will no longer support Windows 32-bit systems.
Java 10.0 2018.03.21
Java 11.0 2018.09.25 The JDK installation package cancels the independent JRE installation package and is a long-term support version (LTS)
Java 12.0 2019.03.19
... ...
Java17.0 2021.09 Java 17.0 is released, version number also known as 21.9, which is a long-term support version.
... ...
Java19.0 2022.09 Java 19.0 is released, the version number is also called 22.9.
... ...

Supplement: Father of Java-James Gosling

image

Mr. James Gosling is world-famous as the "Father of Java Technology". He is the founder of Java technology. He personally designed the Java language and developed the Java compiler and Java virtual machine, making Java the most popular development language in the world.

James Gosling joined Sun in 1984 and continued to serve Sun until around 2010, when Sun was acquired by Oracle and joined Oracle as the chief technology officer of the client software group; he resigned from Oracle in April 2010.

1.3 Java technology system platform

  • Java SE (Java Standard Edition) Standard Edition
    • Supports the Java platform for desktop-level applications (such as applications under Windows), that is 定位个人计算机的应用开发.
    • Including user interface interfaces AWT and Swing, network functions and internationalization, image processing capabilities, input and output support, etc.
    • This version was formerly known as J2SE
  • Java EE (Java Enterprise Edition) Enterprise Edition
    • A set of solutions provided for developing applications in an enterprise environment, ie 定位在服务器端的Web应用开发.
    • JavaEE is an extension of JavaSE that adds class libraries for server development. For example: Servlet can extend the functions of the server and handle client requests through the request-response model; JSP is a technology that can embed Java program code in a web page.
    • version formerly known as J2EE
  • Java ME (Java Micro Edition) small version
    • A platform that supports Java programs running on mobile terminals (mobile phones, set-top boxes), that is 定位在消费性电子产品的应用开发.
    • JavaME is an extension of JavaSE, which streamlines the core class library of JavaSE and also provides its own extension classes. Added class libraries suitable for micro devices: javax.microedition.io.*, etc.
    • This version was formerly known as J2ME

image

Note: Android development is not equivalent to Java ME development.

2. Java development environment setup

2.1 What are JDK and JRE

  • JDK (Java Development Kit): It is a Java program development toolkit that contains JRE tools used by developers.
  • JRE (Java Runtime Environment): It is the runtime environment of Java programs, including JVM and what is needed for runtime 核心类库.

The following is Java 8.0 Platform:

image

image

2.2 JDK version selection

  • Ba Ye Party : Stick to the position of Java. Although Java has now entered the 20s, it is still the main position of some development environments.
  • Revolutionary Party : Adapt to accept the new stable version. Bringing developers a more convenient and efficient experience. For example:
    • G1收集器: The most popular GC algorithm. The G1 collector in Java 11 and above is the default GC, but it is not in Java 8.
    • 框架反推着开发人员使用更高的版本. Before the official release of Java 17, the Java development framework Spring first announced on its official blog that Spring Framework 6 and Spring Boot 3 plan to achieve a high-end baseline of overall availability in the fourth quarter of 2022. This means that springboot3.0 needs to be based on java17 and spring6.0. If you choose the latest springboot3.0 as an architecture from an enterprise, it must be standard with jdk17.

2.3 Download of JDK

  • Download URL (Oracle official website): www.oracle.com
  • Download steps: As shown in the picture, select Developers at the bottom of the official website

image

(1) In the technical classification section in the middle of the Developers page, select Javaand click to enter, as shown in the figure:

image

(2) What is shown here is the latest Java version, such as Java20. Scroll down to the Java SE column. Click Download Oracle JDKand select a specific version to download.

image

image

(3) After selecting the Download Oracle JDK button, enter the Download Java interface. Select the corresponding version and click the download link to download.

image

(4) If you want to install the Java 8 version, you can continue to scroll down to the following location on the current page:

image

(5) Select Accept License Agreement and click Download.

image

(6) Download after registering or logging in:

(7) If you need to install other historical versions, you can choose  Java archive:

image

Then choose to download.

2.4 JDK installation

  • Installation Notes
    • Foolproof installation, just take the next step.
    • Recommendation: The installation path should not contain special symbols such as Chinese characters or spaces.
    • Take the JDK17 version as an example.
  • installation steps:

(1) Double-click jdk-17_windows-x64_bin.exethe file and click Next, as shown in the figure:

image

(2) Modify the installation path and click Change, as shown in the figure:

image

(3) Modify the installation path to D:\develop_tools\jdk\jdk-17.0.2\and click Next, as shown in the figure:

image

(4) After a few seconds, the installation is completed, as shown in the figure:

image

image

2.5 Configure the path environment variable

Why configure path?

  • The path environment variable is the path that the window operating system searches when executing a command.
  • It is hoped that when using javac.exeother tools on the command line, the directory where the tool is located can be found in any directory.

JDK8 configuration plan: configure JAVA_HOME+path (recommended)

  • step:

(1) Open the computer on the desktop, find it on the left after entering 计算机, click the mouse 右键, and select 属性, as shown in the figure:

image

(2) Select 高级系统设置, as shown in the figure:

image

(3) 高级Click on the tab 环境变量, as shown in the figure:

image

(4) In 系统变量, click 新建 to create a new environment variable, as shown in the figure:

image

(5) Enter the variable name JAVA_HOME, enter the variable value  D:\develop_tools\jdk\jdk1.8.0_271 , and click 确定, as shown in the figure:

image

(6) Select Path the environment variable, 双击or 点击编辑 , as shown in the figure:

image

(7) Type at the front of the variable value %JAVA_HOME%\bin. as the picture shows:

image

Note: It is strongly recommended to %JAVA_HOME%\bindeclare it at the front of all variables in the path environment variable !

(8) After the environment variable configuration is completed, restartjavac the DOS command line, enter the  or javacommand or in any directory java -version, and the operation will be successful.

Configure classpath, which is used to specify the path for class file recognition. In fact, it is not necessary.

The summary is as follows:

image

JDK17 configuration solution: automatic configuration

After we install JDK17, we should configure the path environment variable in the same way as JDK8. However, we found that after installing JDK17 and before configuring environment variables, execute the CMD command:

image

It worked! And it is version 17.0.2. Because JDK17 automatically configures environment variables after installation. as follows:

image

It is recommended here to set the path of JDK17 installation to JAVA_HOMEand %JAVA_HOME%\binmove it up to the first place.

image

image

3. Java API documentation

  • API (Application Programming Interface, application programming interface) is the basic programming interface provided by Java.

  • The Java language provides a large number of basic classes, so Oracle also provides corresponding documentation for these basic classes to tell developers how to use these classes and the methods contained in these classes. The introduction of classes in most Java books must be completed with reference to it. It is a resource that programmers often consult.

  • Java API documentation is the JDK instruction manual and help documentation. Similar to a dictionary.

  • Download API documentation:

4. Java core mechanism: JVM

4.1 Advantages and disadvantages of Java language

4.1.1 Advantages

  • Cross-platform: This is the core advantage of Java. Java was originally designed with great emphasis on portability and cross-platform functionality. For example: Java's int is always 32 bits. Unlike C++, which may be 16 or 32, it may change according to the compiler manufacturer's regulations.

    • Applications written in the Java language can run on different system platforms. " Write once , Run Anywhere".
    • Principle: Just install a Java Virtual Machine (JVM, Java Virtual Machine) on the operating system that needs to run Java applications. The JVM is responsible for running Java programs in the system.
  • Object-oriented: Object-oriented is a programming technology, very 适合大型软件的设计和开发. Object-oriented programming supports features such as encapsulation, inheritance, and polymorphism, allowing programs to better meet 高内聚standards 低耦合.

  • Robustness: It absorbs the advantages of the C/C++ language, but removes the parts that affect the robustness of the program (such as pointers, memory application and release, etc.), and provides a relatively safe memory management and access mechanism.

  • High security: Java is suitable for network/distributed environments and needs to provide a security mechanism to prevent malicious code attacks. For example: 安全防范机制(ClassLoader class loader), different namespaces can be allocated to prevent replacement of local classes with the same name and byte code inspection.

  • Simplicity: Java is C++ syntax 简化版, we can also call Java " C++--". For example: header files, pointer arithmetic, structures, unions, operator overloading, virtual base classes, etc.

  • high performance:

    • In its initial development stage, Java was always criticized for " 性能低"; objectively, the operating efficiency of high-level languages ​​is always lower than that of low-level languages, and this is unavoidable. The development of the Java language itself has been improved through the optimization of virtual machines 几十倍运行效率. For example, JIT (JUST IN TIME) just-in-time compilation technology improves operating efficiency.

    • Java低性能的短腿,已经被完全解决了. In terms of industry development, we have also seen that many C++ applications have been transferred to Java development, and many C++ programmers have transformed into Java programmers.

4.1.2 Disadvantages

  • 语法过于复杂、严谨, there are many constraints on programmers, and it is more difficult to get started than python, php, etc. But once you learn it, jobs are in high demand, and 薪资待遇节节攀升.
  • It is generally suitable for large-scale website development. 整个架构会比较重For start-up companies, the cost of development and maintenance personnel is relatively high (that is, high salaries). Choosing to use Java language to develop websites or application systems requires a certain amount of financial strength.
  • 并非适用于所有领域. For example, Objective C and Swift have an irreplaceable position on iOS devices. Processing in the browser is almost entirely controlled by JavaScript. Windows programs are usually written in C++ or C#. Java has advantages in server-side programming and cross-platform client applications.

4.2 JVM function description

JVM ( Javailable  achine, Java virtual machine): It is a virtual computer and the running environment for Java programs VMJVM has an instruction set and uses different storage areas, responsible for executing instructions and managing data, memory, and registers.

 

image

4.2.1 Function 1: Realize the cross-platform nature of Java programs

The Java code we write all runs on the JVM  . It is precisely because of the JVM that Java programs are cross-platform.

image

Comparison before and after using JVM:

image

4.2.2 Function 2: Automatic memory management (memory allocation, memory recycling)
  • During the running process of the Java program, all operations related to calculations 数据的分配, 存储etc. are completed by the JVM.
  • Java eliminates the programmer's responsibility to reclaim unused memory space. Provides a system-level thread to track the allocation of storage space. When the memory space reaches the corresponding threshold, it checks and releases the memory space that can be released.
  • The automatic recycling of GC improves the utilization efficiency of memory space and also improves the efficiency of programmers. This is largely 减少了caused by the failure to release space 内存泄漏.

Even if GCthere is an automatic recycling function, Java programs will still have memory overflow and memory leak problems!

Guess you like

Origin blog.csdn.net/2301_78834737/article/details/131990547