Core knowledge iii

Describe the difference between forwards and redirects

①: request forwarding is to hop to the server and redirect is to hop to the browser

②: The address bar of the browser forwarding browser has not changed, and the redirect to the address bar will be changed

③: Query replication can carry and share data, redirect common data that cannot be transferred

④: The request forwarding path is / resource path, and the redirect path is / project name / resource path


1. Use object:

Reset Direction: Answer

Request redirect: request

2. Writing path:

Reset direction: customer path

Request Forwarding: Server Destination Path

3. Can you jump outside the network:

Flush Direction: Absolute path with HTTP protocol

Request Forwarding: No, visit the area

4. Amount of response time:

Flush Direction: Redirect n+1 Redirect Time n+1 Time

Request forward: repost request n times, reply 1 time

5. Address change or not:

Reset direction: change, path is the path of the last redirect

Request forwarding: no change.

6. Safety features:

Program path impact: some procedures, key procedures, do not want the outside world to know the program access path

Reconstruction: it will expose the program path not safe

Request redirect: the program will not be exposed.

Software update, re-update: Some programs are not allowed to get twice.

Reset Direction: Because the address bar is changed to prevent re-updating

Request redirect: Path has not changed, which may cause users to refresh repeatedly

Later: This is an unperturbed check on the server.

7. Network speed and efficiency:

Reset direction: heavy dependence on network speed, slow network speed, poor jump efficiency

Request Forwarding: It does not rely on network speed, and hopping efficiency is extremely high.

8. Action action request:

Reset direction: can’t use it

Request forwarding: can be used

9. Access to the protection directory resource

Flush Direction: Unable to access protection directory

Transfer request: yes

When will the request be promoted?

① Requires security and does not expose program paths

② Efficiency required

③ Use query

④ Visit protection directory resources

When to use a redirect?

① Jumping external network resources

② Change the address bar path

Is it possible to access a web project directly through a browser? How to access

According to Web-Info, the protected directory is accessible directly through the browser and cannot be accessed. You can access it by forwarding the request

When a method is notified of a proxy, there is still a notification to act as an agent, so the agency method of them must be the same (proxy agent or CGLIB agent)

For example, the service layer method is notified by the transaction notification agent and permission notification proxy Shiro. Currently.

The result of this program



Java Class

Can a “.java” source file include multiple classes (not inner classes)? What are the restrictions?

There are multiple classes, but only one public class can be accessed, and the public category name must match the file name.

The outer class cannot be changed with a private, protected one, but the inner class can be default without a modifier. Rune is a modified default class).

Which keywords can be changed

Public, Defaultt


Is there a length() method on an array? Is there a length() method?

An array has a length method and a string has a length() method.

Please write about the meaning and scope of the four modifiers

Private body (private)

Private can change data members, construct methods, and method members. The class cannot be changed (here is the outer class, no inner class). Members modified by private can only be used in their class definition and cannot be called in other classes.

Default permissions (default)

The class, data members, struct methods, and method members can use default permissions, that is, not to write any keywords. The default permissions are the same package permissions, and members of the same package permissions can only be invoked in the definition of their classes and the class of the same package.

Security Permissions

Protected can change data members, constructed methods, methods, and members, and cannot change the class (refers to outer class here, no inner class). Members modified by protected can be called in a class that can be defined in a class that is in the same package.

If there are different packages they name, then that class must be a subclass that defines them.

Public permissions (public)

The public can change the class, data members, constructive methods, method members. Members modified by the public can be called in any class, regardless of the same package or different packages, is the most authoritative modifier.

Inside This package Subclass Outer bag
public  √  √  √  √
protected  √  √  √  ×
default  √  √  ×  ×
 private  √  ×  ×  ×

Can I create objects without building a function? (Maybe)

Several ways to create objects in Java (important):

(1) Create objects with the new operator, which is the most common method for creating objects.

(2) Use reflector methods to call java.lang.class or java.lang.reflect.constructor.

(3) Clone() Method to call an object.

(4) Using the Deeflowing method, call objects in ReadObject().

(1) and (2) will explicitly call the constructor explicitly; (3) is a photocopy of existing objects in memory, so the constructor will not be called; constructor is not called.

Definition and advantages and disadvantages of generics

Java Generic Type is a new feature in Java SE 1.5. The essence of a generic type is a parameterized type, which means that the type of data being exploited is defined as a parameter. This parameter type can be used when creating a class, interfaces, and methods. Called genetic, generic interfaces, and generic methods respectively.

Only during the compilation period is effective. Delete after compilation.

Generic Type Definition: The definition of generics can be predefined in a class.

The generic type applies flexibly to different categories, methods, and interfaces. Pass the data type as a parameter.

Take Advantage of Generics

①: ClasscastException during the work period has been moved to the compilation period in compilation failure.

②: Avoid strong rotation type problem.

③: program security enhancement

1. Variable and immutable

The string class uses a character array to store a string. Next, since there are “final” modifiers, you can know that the string object is immutable.

private final char value[];

Both StringBuilder and StringBuffer are derived from the AbstractStringBuilder class. The AbstractStringBuilder also uses a character array to store a character string. As we know, these two objects are a variable.

char[] value;

2. is it safe

Objects in a string are immutable, which can be understood as a constant, obviously thread safe.

AbstractStringBuilder is a public parent class of StringBuilder and StringBuffer that defines the basic operations of some string, such as expand, add, insert, index, and other public methods.

StringBuffer adds a synchronous lock, or a call method is added to a method, so it’s safe.

StringBuilder doesn’t have a synchronous lock on the method, so it’s uncleaned safety.

3. StringBuilder и StringBuffer

StringBuilder and StringBuffer have a public parent, the AbstractStringBuileder class.

One difference between abstract classes and interfaces is that some sub-category public methods can be defined in abstract classes. The subclass only needs to add new functionality, and it doesn’t need to repeat an existing method; while the graph is found only for method assertion and constant method constant. Definition.

The StringBuilder and StringBuffer methods all call public methods on the AbstractStringBuilder such as Super.Appending(…). Simply StringBuffer will add the synchronized keyword to the method for synchronization.

Finally, if the program is not multi-threaded, StringBuilder is more efficient than StringBuffer.

Difference between static variables and instance variables?

Difference in grammatical definition: add static keywords before static variables, not added before instance variables.

The difference between the program is the run time: an instance variable belongs to an attribute of a certain object, and an instance object must be created and the space will be assigned to the instance variables to use that instance variable. Static variables do not belong to a specific instance object, but belong to a class, which is why it is also called a class variable. While the program is loading the class’s class bytecode, no instance object is created, and the static variable will be assigned space. Used. In short, an instance variable must be created after an object can be created before it can be used through that object, and a static variable can be used directly for quoting.

For example, for the following procedures, no matter how many instance objects are created, only the StaticVar variable is allocated, and each instance object is created, this StaticVar will add 1; that is, multiple instances can be assigned, and the value of each instance is added only once.


Result of work:


Final, final, final result (for details, click on the address below)

The final is used to declare attributes, methods, and classes, respectively, indicating that the attributes cannot be converted, the method cannot be covered, and the class cannot be inherited.

Finally, it is part of the structure of the anomalous processing statement, which means that it is always executed.

Infintize is an object class method. This is the method that is recycled when the garbage collector is executed to recycle other resources during garbage collection, such as closing files.

Please describe the anomalous processing mechanism in Java

When an anomaly is thrown in a program, the program exits the code from the program that causes the anomalies in the program. Code after TRY blocks will not be executed again. If you find it, you pass the code to the code in the hoist block, and then continue with the program.

If there is a final keyword, after the anomaly is added to the program, regardless of whether the exception is caught, it guarantees the code in the block finally. Use the return keyword to exit a function call in Try and Catch blocks. It will also execute the block code first and then exit. That is, the code in blocks, finally, always guarantees execution. Because of the characteristics of blocks, finally blocks are finally used to do clean work such as releasing resources.

What does the transaction acid refer to?

Atomicity: Emphasize an inseparable division of affairs.

Consistency: Emphasize before and after the execution of transactions, the data must be consistent.

Ø: Transaction execution must not be disturbed by other transactions.

SUCTIVE: Once a transaction has ended (sent/rolled up) data, it lasts for the database.

What is the difference between assertion and prepared stat? Which performance is better?

Compared to the statement

① The interface of the prepared indicator presents pre-linked statements. Its main advantage is that it can reduce SQL compilation error and improve SQL security (reduce the possibility of SQL injection attack);

② SQL statement in prepared enterprise can bring parameters;

③ When SQL is processed in batches or the same queries are executed frequently, prepared enterprise has obvious performance benefits. Because the database can cache the compiled and optimized SQL statement, the same statement will be faster next time.

When a thread enters an object’s synchronized method A, can other threads enter that object’s synchronized method?

can not. Other threads can only access this object’s non-sync method, while sync methods cannot enter

1. Have other methods been added with the synchronized keyword. If not added, it may.

2. If this method is called wait internally, you can introduce other synchronized methods.

3. If other methods are added with the synchronized keyword and the wait is not called internally, it cannot.

4. If the other methods are static, the synchronous lock uses the class’s current byte code, which cannot be synchronized with non-static methods because non-static methods use that.

Please tell me the method to sync with threads.

WAIT(): Make the thread in the wait (blocking) state and release the lock of the object being held;

Sleep(): Make the thread running in the sleep state is a static method. Call this method to catch an interrupted ectrieception exception;

Notify(): Wake up a thread in a waiting state. Of course, when this method is called, it cannot exactly wake up the waiting state thread.

Notityall(): Wake up all threads that are waiting for the wait state. Note that this is not to give all thread locks on trail, but to have them compete;

There are several ways to implement multi-industry implementation

There are two ways to implement multithreading before Java 5: One is to inherit the thread class; the other is to implement a startup interface. Both methods must be defined by overriding the run() method to define the thread’s behavior. It is recommended to use the latter because inheritance in Java is the only inheritance. One class has a parent class. If the thread class is Inherited, it will no longer inherit other categories, this is obviously more flexible using a runable interface.

Addendum: After Java 5 there is still a third way to create threads: implement a parsed interface

What is the difference between Sleep() and Wait()?

Sleep() from Thread class, Wait() from Object class

When using the sleep method, the current thread releases the execution right, does not release the lock, other threads cannot execute

When using the wait method, the current thread releases the execution right and the lock is released at the same time. Other threads can be executed

The Sleep() method is a static method of the thread class (thread) that causes that thread to suspend execution for the specified time and allow other threads to execute, but the monitoring state is still preserved.) Because calling Sleep does not release the object’s lock. Wate() is an object class method. The method calls the wait() method on that object causes that thread to relinquish the lock on the object (pausing the thread) and enter the wait pool while waiting on that object. Only this thread enters the pool object’s lock to acquire the object’s lock to enter the ready state

Start a thread with the run() or start() method?, start the thread with the start() method.

Start the thread to call the start() method, so that the virtual processor represented by the thread is in the running state, which means it can be scheduled and executed by the JVM, which does not mean the thread will run immediately. The run() method is a callback method after the thread has started.

1. Starting a thread – the start () method.

2. After the thread is started, the start() method will call the contents of the execute method.

Difference: Start is about creating and running a thread, while start is about code on a thread.

What is the lifecycle of a server

Servlet is single case in memory — single instance object

Servlet class has max object

Servlet lifecycle:

Servlet Creation: The servlet was polled first. When the service is created, the server calls the init() method of the service.

Servlet destruction: when the server is closed normally. When the service is destroyed, the server calls the Dissome() method of the service.

Work for Servlet: Servlet is called once, and Service() method will be executed once, and Service() calls Doget() and DoPost() methods according to request method.

Leave a Comment