Java should be the first language THAT I got into contact with programming. I remember that WHEN I was learning Java, I didn’t understand a lot of things very well, and I kept learning along with the pace of the teacher. However, the more I learned it, I found those ignorant things suddenly realized. So by the time you’ve seen it all, your understanding of Java will be different!

I vaguely remember that at the beginning of learning the eight basic data types of Java, the teacher asked us to be sure to memorize these things. At that time, I felt like learning the multiplication table in primary school. Later, I learned the logical statements of if and for and some basic features, and then I did some logical questions. At that time feeling Columbus discovered the new continent general curiosity and joy! In fact, Learning Java is also fun. Below I will according to my understanding to sort out and summarize their knowledge, I hope these summaries can bring you some help, but also bring me some help!

1. The Object class

All classes and arrays use Object as their superclass. It has several important methods. The first is toString. It doesn’t make sense to print the address value, so many times we’ll override the toString method so that it returns the variable value of the member. The second is the equals method. The equals method of Objects is prone to throw null pointer exceptions when comparing two Objects. The Equals method of Objects optimizes this problem. In many interviews, interviewers will basically ask about the difference between “==” and “equals.”

2.Collection

Common methods like add, clear, remove, isEmpty, contains, size, and toArray come to mind when referring to this container. And iterator is an iterator interface, the way he traversal is to determine whether there are elements, if there was taken, circulation, this process until all the elements, its method hasNext and next, the former judge whether to have the next element, then return true; The latter moves down one position and returns the current element after the move. Finally, there are two very important subinterfaces: List and set. Both are inherited collections; the former is sequential, has integer indexes, and allows repeating elements. The latter does not contain duplicate elements, does not guarantee the order of the elements, and has no index.

3.Map

A Map is a two-column collection of key-value pairs of keys and values. Each key maps a value. Ensure that keys are unique. In keySet mode, all the keys are stored in the Set. The iterator traverses the Set. During the traversal, the iterator retrieves the elements of the Set, which are actually the keys in the Map. Finally, the value is obtained by the keys through get. The second type of key/value pair is entrySet(). The corresponding relation object of the key/value pair (Entry interface implementation object) is stored in the Set Set and traversed through the Set Set. During the traversing of the Set, objects of the Entry interface implementation class are retrieved. By implementing the class object, call methods getKey,getValue to get the key-value pair.

HashMap

HashMap is actually the interviewer of data structure, simple introduce here, his underlying data structure is a hash table, list ➕ array, whenever data came in, the hash algorithm can calculate the address of the key in the array, if the address of the key values of the same data, can form the list data is hanged in the array. If you want to take a closer look at this, you can check out Obin’s HashMap article, which covers hashMaps in detail.

4. Exception mechanism

When we write code, we take into account that if an abnormal condition occurs during the execution of the program, it will eventually cause the JVM to stop abnormally. Java.lang. Throwable is the parent class of all exceptions and errors in Java, with two subclasses. Error: The parent class of all errors, very serious, cannot be executed without modifying the source code, so we cannot handle this situation. Exception: represents an Exception that can be corrected by code to keep the program running. It must be handled. To resolve an exception, we use a throw to throw an exception and a try… Catch a catch and process it. In our enterprise-level projects, exceptions tend to be thrown and custom exceptions. In Spring projects, we use enumerations to define exceptions, and sections to accept and handle exceptions.

5. The thread

When I think of threads, I think of processes. Most of the time when you can’t manually close a program on your computer, you open the task manager and you can see all the processes in it. A process is the running application in the computer and a thread is how many tasks are running in the application. Threads are created in three ways: they inherit the Thread class, implement the method run(), can not throw exceptions and return no value; Runnable interface implementation, implementation method run(), can not throw exceptions and no return value; Implement Callable interface, interface to override the method is publicCall (), can throw an exception and return a value. In the project, we generally use multi-threading, the running principle of threads is actually the CPU random preemptive scheduling, and each thread has independent stack memory, and has independence. There are generally four ways to create multithreading: cache thread pool, fixed length thread pool, timing thread pool, single thread pool. Multithreading has four synchronization mechanisms: mutex, conditional variables, semaphore, asynchronous signal; Finally, threads are available in several states: New, runable, running, blocked, and dead.

6. Lambda expressions

Lambda is one of the new features in JDK1.8, a new idea, the idea of functional programming, which feels like a more concise way to write Lambda code, bypassing the intermediate process. For example, in the past, when we iterated through a collection, we used to use for, the basic for inside is the condition, and then here is the method you want to execute. Lamdba uses -> to point directly to the method you want to execute. Lambda must be used only if there is one and only one abstract method in the interface that needs to be overridden and context-derived.

7. The Stream flow

A Stream is a functional model of collection elements. It is not a collection, nor is it a data structure, and does not store any elements (or their address values) itself. He has several common methods: forEach, count, filter, Limit, Skip, Map, concat. A Stream does not execute a method after it has traversed all of the methods, as a for traversal does. Instead, it finishes executing the method without consuming extra memory.

8. The File types

File is an abstract representation of the path names of files and directories. Each File object needs to be associated with the path of a File or folder on a hard disk. Typically, a new File instance is created by converting a given pathname string to an abstract pathname. String getAbsolutePath(): returns the absolute pathname of the File as a String; String getPath() : Converts this File to a pathname String. (construction path); String getName() : Returns the name of the File or directory represented by this File; Long Length () : Returns the length of the File represented by this File. A path can be a real path or an absolute path. Public String[] list() : Returns an array of strings representing all subfiles or directories in the File directory; Public File[] listFiles() : Returns an array of files representing all subfiles or directories in the File directory.

9. IO streams

Each file has a unique URL in the Internet to locate resources on the Internet. What we usually do is the interaction of resources. Once the interaction occurs, a stream is formed. The flow direction is divided into input stream and output stream, and the format type is divided into byte stream and character stream. In addition to manipulating files using IO’s stream of byte characters, you’ll also use the Properties set, which can be saved in or loaded from the stream. We often store and use files as custom objects in Java. When we create a stream object, we will have a buffer stream, which will create an array of built-in buffers of default size. The conversion of files and objects is called serialization and deserialization. The conversion of characters and bytes forms a conversion stream.

10. Network programming

When resources interact with each other more, networks will be formed, so the knowledge of network programming will become particularly important. For the foundation of network programming, we can basically have a general concept of software architecture and network three elements. Software architecture is divided into C/S and B/S. C/S is the structure between the client and the server, and B/S is the structure between the browser and the server. The three elements of a network are IP address, port and protocol. The IP address is the address of each computer in the Internet, the port is the entrance of each service or process in the computer, and the protocol is the communication rule. The protocol is divided into TCP and UDP. TCP is to establish a good link before the network transmission. And then the data is transferred, so you have three handshakes or three interactions between the client and the server. UDP is a direct transmission, so data integrity cannot be guaranteed. In Java, there are two classes to implement TCP programs, one is java.net.Socket, create a Socket object, the two establish a connection to start communication. The other is java.net.ServerSocket, which creates a ServerSocket object, which is equivalent to starting a service and waiting for the client to connect.

11.Junit

When we complete a requirement with Java code, we usually use tests to test the feasibility of the code. And Junit is such a testing framework, to understand the test framework, can the basic use of words, we need to know the principle and the use of annotations, if want to know his principle, first to understand the operation of the Java code, general Java code after finish, we go to run, the source will form a class file, That’s what we call compiling and then running! Junit, on the other hand, can get member properties, member methods, and constructors from Java through reflection. Then we complete the Test with @before, @test, @after annotations!

Database of 12.

Speaking of databases, I was reminded of an article I read online in which a man interviewed Ali and was asked how he would describe the concept of a database to his seven-year-old sister. I also thought about it, and if I understood it at the moment, I would probably say to my sister, the database is like a book, just like the books you read in kindergarten, you will see the books of animals, the books of plants, the books of stories, and the tables of the database are just like these books. The page number of each book is the foreign key of the table in the database, you can find the page you want to read the fastest, and the table of contents of the book is the index of the table in the database, you can see the introduction of the whole book here. There are many common databases, and THE one I use most is mysql. Before using mysql, we need to download, install and log in.

Database creation and table creation, add, delete, change and check

1. Run the following command to CREATE a DATABASE: CREATE DATABASE Specifies the DATABASE name. Query all DATABASES: SHOW DATABASES; DROP DATABASE: DROP DATABASE name; Switch database: USE database name; CREATE TABLE: CREATE TABLE name (field name type, field name type,…) ; To view all TABLES: SHOW TABLES; ALTER TABLE ALTER TABLE name; Alter TABLE name: REANME TABLE name TO new TABLE name; DROP TABLE name; DROP TABLE name; 3. Use SQL statements to add, modify, or delete data: Add data: INSERT INTO VALUES; Select * from table_name WHERE table_name = new; Select * FROM table_name WHERE table_name; SQL > SELECT 1, 2,… FROM the name of the table. Constraints, multi-table queries, and transactions will be introduced later!

13.JDBC

Earlier we looked at databases. What if we used Java code to access the database? This is obviously a problem. In the past, there were many ways for clients to access the database. After many ways, it would become very troublesome. MYSQL: com.mysql.jdbc.driver; DriverManager: DriverManager; Connection: Jar: com.mysql.jdbc.driver; Step 4 Use a Statement to execute an SQL Statement. Step 4 use a ResultSet or a virtual table. With Spring, you can use JdbcTemplate directly, using the template method pattern!

14.Linux Basics and deployment

In front of the introduction of some software knowledge, a computer must be hardware ➕ software can run, how to manage the connection between hardware and software? That’s where the system comes in. The system also has its development history, at present in the server system is more popular may be Linux, if you want to use Linux, first to understand its installation process, first prepare virtual machine software, prepare the Linux operating system, follow the steps to install. The next step is to understand some of the Linux commands, which are especially important since we rarely use the desktop when deploying the server. In the current project deployment, almost all use mirroring deployment, so that the project is set up on different servers.

15.java web

Earlier I introduced two software architectures, and B/S is the interaction between the browser and the server, so the question is, how can Java code make the two better? At this time, the introduction of Web, he is a javaEE technology to achieve a container, can make games, web pages, software. Web resources are divided into static resources that do not change in the server and dynamic resources that are dynamically generated data in the server. There are many Web servers out there, but I’ll briefly introduce a small, free server that I use a lot – Tomcat. Learn about his download installation and project deployment. The next step is to complete the creation and deployment of the Web project on IDEA.

16.Servlet

Before talking about the creation and deployment of web projects, let’s talk about the preparation of web project code, Servlet is a JavaWeb development in a small program. It handles the reception and response of data from the client to the server. Start by writing a plain Java class that implements the Serlet interface and overrides all the abstract methods. You then write code in the Service method to handle the business. Next, configure the Servlet in web.xml, and finally start Tomcat to access the Servlet resource through the mapped path. Because inheriting servlets requires overriding all abstract methods, GenericServlet optimizes this nicely. Implementing the GenericServlet interface saves you from overwriting all the abstract methods. As mentioned above, network interaction needs to use protocols. At present, Http is a popular protocol. The Service method in HttpServlet uniformly receives all Http requests sent by clients, which is the optimal version formed at this time. The first step is to write a plain Java class, FormServlet, that inherits HttpServlet. The second step is to override the doGet and doPost methods and process the business in the methods. Step 3 Configure the FormServlet in web.xml. Finally, start Tomcat and use the FormServlet mapping path to access the FormServlet using get or POST.

Annotations to develop

When more and more requests are made, web.xml is too heavily configured with servlets to be easy to manage, making it prone to errors. Annotation development at this time makes development more agile and efficient. Step 1: Create a generic class that inherits HttpServlet and overrides the doGet and doPost methods; Step 2: Add an annotation @webServlet to the class; Step 3: Configure the value of the annotation @webServlet (mapping path); When there are too many annotations, use template annotations for development!

17.http&request

HTTP is a network protocol that consists of request packets and response packets. A request packet is a format of request data sent by a browser to a server, including the request line, request header, and request body. The request line contains the request method, access path and protocol version, while the request header and request body contain parameters such as the server, network connection, and data survival. The response message is the data format of the response sent by the server to the client (browser), including the response line, response header, and response body. Request has several common apis to get the type of request, complete URL, and IP address. Request has a life cycle. Each request creates a new Request object that only lasts for the duration of a single request. With domain object and function request, he is a container, it is mainly used for data transmission, with built-in map collections and a setAttribute, getAttribute and removeAttribute method.

Request forward redirection and asynchronous synchronization

Request forwarding is to transfer the request to another Servlet or HTML inside the server to realize the jump of business logic. This is possible because the data in the request domain can be shared between different servlets. Redirection is when the server responds by setting the browser to re-send the request to the specified URL. Redirect resources. When the server receives the first request, it responds to the browser and the browser asks another server to handle the request. Basically a lot of login is achieved by using redirection! In asynchronous synchronization, the client sends a request and waits for a response before sending the next request. If the request does not receive a response, the next request cannot be sent, and the client is kept waiting. Asynchrony is sending a request without waiting for a response. It can send the next request at any time without waiting.

18.HttpServletResponse

The HTTP response packet refers to the data format of the response sent by the server to the client (browser). It consists of the response line, response header, and response body. The first line of the response line usually contains the protocol/version number and status code. The response header sends the response parameters to the client (browser) in the form of key:value, and the response body is the specific data of the response. Basically, a request corresponds to a response. In the interview may ask more may be the difference between get request and POST request, generally divided into three latitude explain, get request data length is limited and POST request does not; The GET request does not contain the request body while the POST does; Get request data is exposed in the data column while POST request data is not. So normally we submit forms using post requests!

19.cookie&session

Before we get to cookies and sessions, let’s talk about sessions. A session is an activity on a network that consists of multiple requests and responses. Because it can be shared across multiple requests and responses, it solves the data storage problem. Cookies and sessions are session technologies. First, let’s talk about cookie, which is the technology that the server stores data in the client (browser). If the maximum lifetime is not manually set, the default lifetime is a session time, and the browser will disappear after closing. If the maximum lifetime is set, the closed browser will not disappear. It provides a basis for the server to identify users and relieves the pressure of data storage on the server. Session is a container created by the server for each client user accessing the server. The data stored in this container can be shared among multiple requests. The server creates a container for each client user accessing the server. Because the session is the server, persistence becomes much more important. First, manually create the session ID in the Servlet, then manually set the lifetime of the session ID, and finally give the session ID to the browser.

20.jsp

Because of the idea of encapsulation, at this time some people want to be able to encapsulate HTML and Java together, can write together, the previous introduction of Java web Servlet, and focus on the Servlet encapsulation can solve this problem. This is where JSP comes in. It is a dynamic web technology, its essence is a Servlet. The page field refers to the current JSP page, where the stored data is only valid on the current page, while the application field refers to the ServletContext field corresponding to the entire project after the service is started. And then we’re just going to get really good at summing in the domain. JSTL solves this problem because of the redundancy of the code and the different tag libraries from different Web vendors. It consists of four custom tag libraries (core, Format, XML, and SQL) and a pair of common tag library validators (ScriptFreeTLV and PermittedTaglibsTLV). Put the JSTL JAR package into the Lib folder in the Web-INF directory of the Web project, then import it into the project, and then import the JSTL resource with the taglib tag.

21. The Filter Filter

Filter is a Web component that intercepts requests and responses from clients and servers. It intercepts requests before they reach the Web resources to be accessed by clients. It can solve some problems such as illegal characters, login permissions, and Chinese garbled characters. First configure the classpath for the Filter in the web.xml file, and then the mapping path for the intercepted servlets. Its lifecycle is when the filter is initialized when the server is started, the init method of the filter is executed, and then the filter method is executed once when a requested path is a configured path that satisfies the filter. Finally, when the server stops, the filter is destroyed, executing the filter’s destory method. For annotation development, add WebFilter annotations to the interface you want to intercept. Later we will learn about Spring, which uses Filter to intercept facets.

22.jQuery

Jquery is actually a JSP framework, which has a lot of plug-ins and corresponding solutions. To understand his words, first understand his three core grammars, five selectors, five operations and events. The three core syntax are $(” selector “), $(callback), and $(HTML). Five major selectors: basic selectors made up of some elements, ids and classes; A hierarchical selector for hierarchical relationships between tags; Filter the selector according to the attribute filter of the tag attribute; Basic filter selector for filtering according to the position and characteristics of the label; Form object property filter selector that filters selected labels based on the properties of the form object. Get the value of the tag attribute or set the value of the tag attribute using jquery. The action of getting the content between two labels; Use jquery to operate label attributes. Dynamically controls the operation of the corresponding style by manipulating the Class attribute. The operation of adding or deleting a style attribute to a tag. Finally, there are events: there are many, many events, each triggering a different context. The first thing we do is we bind the event, the first way is to register the event as an attribute of the tag, and the second way is to get the tag object and bind the event to that object. Then you can write the method you want in the event.

23.AJAX

Ajax is simply asynchronous JavaScript and XML operations that can update parts of a web page without reloading the entire page. JSP native Ajax first creates the Ajax engine object, then listens for the Ajax engine object binding, then binds the submission address, and finally sends the request response data. Jquery.get ([Settings]) includes the request address, asynchronous or synchronous request, request data, data type, and callback function if successful or failed. The second type of POST request, jquery.post ([Settings]), contains the same information as above. The third type of AJAX request, jquery.Ajax ([Settings]), has the request type in addition to the above, which defaults to “GET”.

24.JSON

JSON is a data interchange format that stores and represents data independently of the text format of a programming language, so it is now the dominant data interchange language. Json objects have three data formats: {name: value} of the first object type; The second array/collection type {value}; The third hybrid type of [{},{}] or {name:[]… }. He has four common tools: First, Jsonlib, the Java class library needs to import a lot of JAR packages; The second is Gson, a simple JSON conversion tool provided by Google. The third and currently the most commonly used Fastjson, a high-performance JSON conversion tool provided by Alibaba technical team, I heard that there were many problems with the source code leakage recently, and some people began to abandon it. The fourth Jackson, the open source free JSON conversion tool, is used by default for SpringMVC transformation.

25.Redis

The previous introduction of the database, strictly speaking, he is a relational database, the use of table structure, only support basic types, can only be applied to the hard disk. NOSQL, a non-relational database, is not strictly a database, but a collection of structured data storage methods, either document or key-value equivalence. Flexible use, can use hard disk or memory as the carrier. There are four types of mainstream NOSQL. The first type is key-value storage database, including ️TokyoCabinet/Tyrant, Redis, Voldemort and BerkeleyDB, which are used for content caching and are mainly used to handle high-access loads of massive data. The second column stores databases, including Cassandra,HBase, and Riak, which are applied to distributed file systems. The third kind of document database, CouchDB, MongoDB application in Web applications; The fourth Graph database, Neo4J, InfoGrid, InfiniteGraph applied to social networks. Let’s take a quick look at one of these redis, which generally supports five data types: String, Hash, List, set, and sortedSet. For basic use, the first step is to set the IP address and port number. The second step is to set the data; The third step is to obtain data; Finally, release resources. Because redis creation and destruction are performance-intensive, we have redis connection pooling. First configure his connection pool information, then write the connection pool tool, and finally use it to use Redis.