Job hoppers and fresh graduates must-see JAVA interview questions series (3)

Article title

I. Introduction


Man does not only rely on him to be born with everything, but on everything he gets from learning to build himself up. ----Goethe


Two: Interview Challenge

Before starting the topic of Chapter 3, we will first give Amway the "Interview Challenge": If you meet the following challenge conditions, if you do not get an offer within one month, you will provide free resume packaging suggestions and related interview questions.

If you pass the interview, you can take a screenshot to share the red envelope and let everyone witness it together. The specific conditions are as follows:

1. Computer-related majors or computer-related professional training (not less than 3 months, normally the training time of training institutions will not be less than 3 months), ready to be engaged in JAVA developers.

2. The work you are engaged in is JAVA development, and the duration is 1-3 years (Ignore what I said, you can quit directly) or you are in line with computer-related majors and are ready to work out of school.

3. Continue to study my "Interview Encyclopedia" for at least two months and have a basic grasp of the content.

4. Relevant interview evidence or interview questions need to be provided.

If you are interested in this, you can follow the [ IT Learning Diary ] and reply to the [ Interview Challenge ] to participate, and you can also give away an interview material for free if you participate now.


Three: Back-end basic knowledge (three)


One: The difference between order and disorder in JAVA


Ordered:
  the order of storage is the same as the order of addition, and can be accessed by subscripts, such as List


Disordered:
  the order of storage has nothing to do with the order of addition, and there is no subscript such as TreeSet, which is independent of the order of storage and addition. , But the objects in it have also been sorted according to specifications.


Two: IO-intensive and CPU-intensive


CPU-intensive (computation-intensive):

  Refers to the system's hard disk and memory performance is much better than the CPU, at this time, most of the system operation status is CPU Loading 100%, the CPU must read/write I/O (hard disk/memory) ), I/O can be completed in a short time, and the CPU still has many operations to be processed, and the CPU Loading is very high.


IO intensive (I/O bound)

  IO intensive refers to the system's CPU performance is much better than hard disk and memory. At this time, the system is operating, most of the situation is that the CPU is waiting for I/O (hard disk/memory) reading /Write operation, CPU Loading is not high at this time.


Three: What ROOTS objects are in garbage collection


1. Refer to all objects in the local variable table in the stack frame

2. Refer to all objects of static properties in the

method area 3. Refer to all objects of constants in the method area

4. Refer to all objects of native methods


Four: Marking (the difference between reference counting and reachability analysis)


1. Reference counting:

  There is a counter. Every time the object is called, the counter is incremented by 1, and every time it is released, the counter is decremented by 1. But it is difficult to solve the problem of several object circular references.


2. Reachability analysis:

  starting from the object of GC ROOTS, search from here, search for objects that directly or indirectly reference the relationship with the node, and combine them in the form of a chain (reference chain), GC will not be recycled The object on this chain.


Five: What are the core components of J2EE


1, JDBC
2, JNDI
3, RMI
4, JSP
5, SERVLET
6, XML
7, JMS
8, EJB
9, IDL
10, JTS
11, JTA
12, JAVA MAIL
13, JAF

Six: Servlet life cycle


1. Loading and instantiation

  When the Servlet container is started or the client initiates a request, the Servlet container looks up whether the Servlet exists in the memory, if it exists, it reads the response of the instance directly, and if it does not exist, it creates it.

2. Initialize the

  Servlet container and call the init method to initialize the model

3. Handling services

  to deal with specific business requirements in the service method

4. When the destroy

  server is shut down or restarted, execute the destroy method to destroy the container.


Seven: How to solve memory overflow when using POI technology


1. Memory overflow

  during write operation : When the amount of data is large, there is a risk of overflow in the write operation. You can use the official SXSSYWorkBook API provided by POI for write operations (it supports xlsx), which guarantees that there are only configurable rows at any time It will be stored in the memory, avoiding the problem of memory overflow to the greatest extent, but there is still a problem of memory overflow. It is recommended to use Alibaba’s easyExcel component instead.

2. Memory overflow when reading data,

  you can use csv to replace excel in the exported format.


Eight: the execution order of code blocks and constructors in JAVA


1. The parent class static code is fast

2, the sub class static code is fast

3, the parent class code is fast

4, the parent class constructor

5, the child class code is fast

6, the sub class constructor function


Nine: JAVA is an object-oriented language, what are the characteristics


1. It is easy to understand and has better readability

2. Platform independence, compile once, run everywhere

3. Many libraries are provided to facilitate the work of developers and reduce development time

4. Provides support for the web

5. It has good security and robustness (such as garbage collection)

6. Removed the incomprehensible and confusing features in C++


Ten: What is the MVC model, its advantages and disadvantages


1. Definition: The

  full name is: Model, View, Controller. It is a mode that organizes code by separating business logic, data and interface display.

Typical case: JSP + Servlet + JavaBean.

As a model, JavaBean is used as a data model to encapsulate business data, JSP is used as a View for interface display, and a Servlet is used as a Controller to control the flow between the interface View and Model.

2. Advantages:

  1. Low coupling: View and Model are separated, allowing modification of view layer code without recompiling the code of Model and Controller layer.

2. High reusability: Allow different views to use the same server code

3. High maintainability: Separation of View and Model makes web applications easier to maintain and modify

3. Disadvantages:

  1. It is more complicated to fully understand the MVC mode

2. Debugging is more troublesome than the original

3. It increases the complexity of the system structure and implementation


Eleven: Comparison of the memory size occupied by Int and Integer


Integer occupies more memory because it is an object and needs to store the metadata of the object. Int is a primitive data type, there is no data in this part.


Twelve: the difference between JSP and Servlet


1. JSP is essentially a Servlet, but it is better at interface display, Servlet is better at logical control

2. There are no built-in objects

in Servlet 3. The application logic of Servlet is in the java file, completely separated from the HTML code of the presentation layer It came out

4. JSP is a file with an extension file composed of java and html as .jsp


Thirteen: What is Shell


Definition:

  It is a command interpretation tool that converts the commands entered by the user into a language that the kernel can understand.

Extended knowledge: Allocate system resources for programs, and the software that handles the internal details of the computer is called operating system or kernel

It itself is a program written in C language, and it is a bridge using unix/linux. Simply put, it is a command language and a programming language.

It calls most of the functions in the system to execute programs, establishes files, and coordinates the operation of various programs in a parallel manner.

Execution mode:

  1. Interactive: Interpret and execute user commands, the user enters one, and the shell interprets and executes one.

2. Batch processing: First write the shell script (script), and then let the shell execute it at one time. It is interpreted and executed and compiled out of order.


Fourteen: What is Restful


Because there is a lot of knowledge about Restful style, it is not easy to expand here. If you want to know more detailed knowledge about Restful style, you can check the previous article. Before this, there is a special article that describes the problem of Restful style very much .


Fifteen: Tomcat deployment method


Method 1. Pack the web project of the compilation number into a war package and place it in the webapps directory of tomcat

Method 2. Modify the tomcat server.xml file, add the Context tag to the Host tag, and the attributes are as follows:

Path: The path when the browser is accessed (relative to the project name), such as: /webproject

docBace: The path where the webroot of the web project is located , Is the compiled project, such as: "D:/web"

Reloadable: The value is true/false, indicating whether tomcat reloads the project when the project is changed

Method 3 : Create an xml file in the conf/Catalina/localhost directory of tomcat, add the Context tag, and the attributes are the same as the second deployment method, such as:


Sixteen: Byte size occupied by basic data types


Byte(1), Short(2), int(4), long(7), char(2), float(4), double(8), boolean(unknown)


Seventeen: Why do serialization in JAVA implement the Serializable interface


Because when calling the serialization interface write method (writeObject), the type judgment will be performed. If the object is an object of type String, Array, Enum, Serializable, it can be serialized normally, otherwise a NotSerializableException will be thrown. The code is as follows:

Why does serialization in JAVA implement the Serializable interface


Eighteen: the role of the object's Finalize method


Function:

  Before the object is recycled (after being marked), the method of the object will be called, which can be rewritten to release the associated object space or re-reference the object to prevent it from being recycled by the GC.

Steps: The

  object is marked once, and the finalize method in the object is executed before the next GC. When executing, it is judged whether the object has rewritten the method. If not, it is directly recycled. If it is rewritten, it is placed first. In a queue, a low-priority thread is opened by the virtual machine to execute it, and then a second small-scale mark will be performed, and the marked object will be actually recycled this time.


Nineteen: The difference between pom, war, and jar projects in Maven projects


1. POM project: used for parent project or aggregation project, used for version control of jar package

2. War project: The project can be packaged into war and published on the server

3. JAR project: The project can be packaged into a jar, one is a project that needs to be provided by a third party or run separately


Twenty: What are the "three highs" of the Internet?


Three highs: high concurrency, high availability, high performance (3H)

High concurrency: Simply put, it is the maximum number of requests that the software can withstand per unit time.

High availability: service clustering, when a service is down, there can be alternate replacements, which will not cause the service to be unavailable, such as: Redis sentinel mode

High performance: The number of tasks that can be processed per unit of time. Improved performance is mainly divided into the following two aspects.

1. Software: such as correct coding, SQL solves slow queries, introduces cache, and uses multithreading

2. Hardware: Improve server configuration (memory, CPUT), etc.


21: The difference between concurrency and parallelism


Concurrency: The

  maximum number of requests that can be processed in a period of time.

Parallel Amount: The

  maximum number of requests that can be processed at the same time.

Difference:

  Parallel refers to the number of requests processed at the same time, and concurrency refers to the number of requests that can be processed in a period of time. Concurrency is a cpu (core) alternately executes multiple tasks, and parallel is the number of tasks executed by different cpus at the same time.


Twenty-two: some common indicators to measure high concurrency


1. Response time:

  The time it takes for this process to start when the client initiates a request and ends when the client receives the response time returned by the server. In performance testing, the time from the pressure initiation stage to the processing result returned by the pressure measurement server is generally measured, and the unit is generally seconds or milliseconds.

2. Average response time:

  The average time of the same transaction during the stable operation of the system. Generally speaking, the transaction response time refers to the average response time. The standard value should be set separately according to different transactions. Generally, it is divided into complex transaction response time, simple transaction response time, and special transaction response time. Among them, the setting of the response time of a special transaction must clarify the particularity of the transaction in terms of response time.

3. Throughput

  the number of requests processed per unit time.

4. QPS (Query Per Second) The

  number of queries per second (similar to the meaning of throughput)

5. The number of concurrent users

  simultaneously carries the number of users who normally use the system functions.


Twenty-three: Measures to improve system concurrency


To improve the concurrency capability of the system, theoretically speaking, it can be through: vertical expansion (Scale UP) and horizontal expansion (Scale OUT) two ways.


One: vertical expansion

Method 1: You can improve the hardware performance of the machine, such as quad-core cpu to 8-core cpu, add solid state drive, etc.

Method 2: Improve the architecture performance of the system, such as introducing cache to reduce the number of IOs, using thread pools and asynchronous to improve the throughput of the system, etc.

Two: horizontal expansion

Reason :

No matter which method of vertical expansion is carried out, when the business volume and data volume reach a certain level, the bottleneck of the single machine will still appear. At this time, the use of vertical expansion will not have much effect on the performance of the system. Need to expand the level and introduce new machines to solve the system performance bottleneck problem.

Solution:

  When a single machine performance bottleneck appears in the vertical expansion, only new machines need to be introduced to linearly expand the system performance, but the horizontal expansion also has requirements for the system architecture.

Four: Interview Question Outline


Note: The questions and interview materials will be continuously updated.

Outline of the first stage of the interview


Five: Summary


Due to the limitation of the length of the article, the third chapter of the Interview Complete will come to an end for the time being . If you have any comments or suggestions, you can leave a message below or in a private message. If you see it, you will reply in time. You are also welcome to participate in the interview challenge and interview questions. I hope you will get your favorite offer as soon as possible. If you feel that the text is helpful to you, please pay attention and points. Great .

The interview series of articles will maintain a stable update rate, about two to three updates a week, interested and can pay attention to me.


If you want to participate in the interview challenge, you can reply [ Interview Challenge ] by private message . If you want to submit an interview question, you can reply [ Interview Question Submission ] by private message . If you want to get more interview questions and information, check the latest interview question update For progress, you can follow me, private message [ interview information ], thank you for your reading and attention.

Insert picture description here


Six: Hot Recommendation


1. A must-see JAVA interview question series for job-changers and fresh graduates (1 )

2. A must-see JAVA interview question series for job-changers and fresh graduates (2)

3. Interview Collection (1)-Let you no longer miss the resume packaging of the "Golden Nine Silver Ten" job hunting wave

4. Easily write an elegant Restful style API