The Java pit guide is drip, below is a minimum pit

There should also be 23 design patterns to master. ╮(╯▽╰)╭ notice, the first J is capital.

The characteristics of the Java cross-platform, style is close to c + + is the most important API documentation docs.oracle.com/javase/10/d…

Language features

  1. object-oriented
  2. Cross-platform, running on the JRE, which includes the JVM
  3. Mechanisms with automatic garbage collection are strongly typed, simple, object-oriented, distributed, robust, secure, portable, interpreted languages (which will be translated into bytecode and run on the JVM), high-performance, dynamic, multithreaded.

The development tools

The JDK, a toolkit for developers, includes the JVM. JRE, a Java runtime environment, is divided into server-side runtime environment and developer runtime environment. When Java is deployed on the server, JRE is required to run Java programs.

system

It is divided into three systems, respectively J2SE, J2EE, J2ME respectively for the above three systems.

Professional term

JDK Software used by programmers who write Java programs JRE software used by users who run Java programs Server software SDK software development kit DAO Interface for data access MVC A mode JSP A way to write Java in HTML, rendered by the server side, and then returned to the user (has been used very few, currently are directly packaged into THE API, its interface design needs to comply with the RESTful API design specifications, belongs to an architectural way, You can use https://swagger.io/ to design the API, JSP is similar to PHP is written directly in HTML ~) Servlet a package into HTTP interface, and then through HTTP request to access, using this Java can pay more attention to the back-end business logic, to achieve decoupling. JDBC a connection method used to connect to a database such as Mysql Tomcat a container that runs servlets. SSH frameworks running on the server include Hibernate5 framework, Struts2 framework, Spring4 framework SSM framework Spring, SpringMVC and Mybatis framework. RPC framework clients call an object that exists on a remote computer without knowing the details of the call, just as they call objects in a local application for distribution. Classic frame thrift.apache.org/ from FaceBook

OOP

A programming paradigm,

Classes and objects

A Class defines the abstract characteristics of a thing. The definition of a class contains the form of the data and the operations on the data. Object: is an instance of a class.

Dynamic configuration and messaging

Dynamic configuration by definition means that methods change dynamically with instances. Message Passing is when an object performs a function by receiving a Message, processing a Message, Passing a Message, or using methods of another class.

encapsulation

Object-oriented programming with Encapsulation hides the specific operation steps of a method and instead sends messages to it through a messaging mechanism.

inheritance

Inheritance means that, in some cases, a class has “subclasses.”

polymorphism

A Polymorphism is the generation by inheritance of different, related classes whose objects respond differently to the same message.

abstract

Abstraction is a way to simplify complex real-world problems by finding the most appropriate class definition for a specific problem and explaining the problem at the most appropriate inheritance level.

language

C→C++, C→Objective-C, BASIC→Visual BASIC→Visual BASIC.NET, Pascal→Object Pascal, Ada→Ada95

Object orientation in scripting

Python and Ruby Perl and PHP

Java and JS are very different, one is a script, the other is not a script. Java is not a script; it is compiled into bytecode and then run on the JVM.

Java language compilation process

Java code compilation is done by the Java source compiler, that is, Java code to JVM bytecodes (.class files) Java bytecodes execution is done by the JVM execution engine

Comparing the JVM to an operating system, Java simply creates another operating system-like machine, called a virtual machine, to run Java bytecode

Mechanisms for Java code compilation and execution

The source code to compile

Analyze and input to symbol table

② Annotation processing

③ Semantic analysis and generation of class files

The generated class file contains the following information: the class file format version number and the number and size of each part of the information

Metadata: information corresponding to declarations and constants in Java source code. Contains declaration information, domain and method declaration information, and constant pool for class/inherited superclass/implemented interfaces

③ Method information: corresponding Java source code statements and expressions corresponding information. Contains bytecode, exception handler table, evaluation stack and local variable area size, evaluation stack type record, debug symbol information

Class loading mechanism

The bottom layer uses C++ to load classes

Class execution mechanism

The JVM is a stack-based virtual machine that assigns a stack to each newly created thread, which in the case of Java programs is done at run time by operations on the stack. After class bytecode is executed by the JVM, a program counter and a stack are created. The program counter holds the offset to execute the next instruction. Each stack frame corresponds to each call of each method. The stack frame is composed of local variables and operand stack. Local variables store local variables and parameters, and operand stack is used to store intermediate results generated in the process of method execution

JVM memory management and garbage collection

The JVM memory is divided into methods, stacks, heap, and local method stacks (jNI calls in Java).

Heap memory

The operating system has a linked list of free memory addresses. When the system receives a program’s request, it iterates through the list to find the first heap node that has more space than the requested heap. It then removes that node from the free list and allocates that node’s space to the program.

Stack memory

A stack is a data structure that scales to a lower address. Is a contiguous memory region.

There will be stack overflows

Objects are stored in the heap, and variables and their intermediate results are stored in the stack

Garbage collection mechanism

If an object is not referenced by other objects, it will be deleted from time to time, that is, unused memory space is reclaimed.

Flow chart of class loading

The development environment

The official tutorial docs.oracle.com/javase/10/i… Install the JDK on Windows. Enter the oracle’s website, www.oracle.com/index.html, www.oracle.com/technetwork… At present the latest J2EE for selection JDK 10.0.2 https://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html for developers Since it is currently in Windows version, select Windows version. Click Next and everything will be set up for you. Open PowerShell input

PS C:\Users\mingm\Desktop> java -version
java version "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
PS C:\Users\mingm\Desktop>
Copy the code

If the preceding command is displayed, the configuration is correct. Environment variables such as path have been automatically configured

Server JRE

A Java environment running on the server side. The link https://www.oracle.com/technetwork/java/javase/downloads/index.html choose to download. Set the environment variables in win10 set www.runoob.com/w3cnote/win…

Eclipse

A Java IDE environment https://www.eclipse.org/ select Java environment file, can be completed, grey often simple. Because of some make people angry, package can’t use, then use https://www.eclipse.org/downloads/packages/

hello world

Now write your first Hello World program

Public class HelloWorld {/* HelloWorld! */ public static void main(String []args) { System.out.println("hello world"); }}Copy the code

Create a new helloWorld.java file and open powershell in the same directory to compile to class

PS C:\Users\mingm\Desktop\test> javac .\HelloWorld.java
Copy the code

There is an error

.\ helloworld.java :2: : GBK IJӳַ (0x81) /* HelloWorld? * / ^ 1Copy the code

Error encoding, save utF-8 encoding, so direct encoding for compilation.

PS C:\Users\mingm\Desktop\test> javac -encoding utf-8 .\HelloWorld.java
Copy the code

use

-encoding
Copy the code

The encoding is compiled using UTF-8 into a class file view directory

PS C:\Users\mingm\Desktop\test> ls directory: C:\Users\mingm\Desktop\test


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2018/9/18     22:14            425 HelloWorld.class
-a----        2018/9/18     22:12            135 HelloWorld.java


PS C:\Users\mingm\Desktop\test>
Copy the code

A class file appears in the directory and continues running

PS C:\Users\mingm\Desktop\test> java HelloWorld
hello world
PS C:\Users\mingm\Desktop\test>
Copy the code

A hello world

Write Hello World on Eclipse

Then write the project name

Next, create the package in the SRC directory

Create a Java source file

Write the code

package cn.xd.test;

public class Hello {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("hello world"); }}Copy the code

run

The results

Evaluation, not used to use IDE, so far do not know why. ╮ (╯ del ╰) ╭. It’s a matter of habit.

IntelliJ idea

Ps try this, if you can adapt to TJ, so much the better.

And the jre connection

To sum up, I prefer to simply apply the direct editor, submit Text is ok, and IntelliJ IDEA is ok for a slightly more complicated application.