Java Interview Advanced Parts Collection

Source: Internet
Author: User
Tags aop version control system

Framework Basics

Reflection: Reflection is a kind of dynamic correlation mechanism of Java development. Because the Java language itself is not a dynamic language, if we want to get the dynamic effect of the program, we introduce the concept of reflection mechanism.

How do you express reflection?

What can I do with reflection?

PS: An interview question: What are the ways to create an instantiated object in Java?

① the most common method of creating objects, use the new statement to create an object.

② returns an object through a factory method, for example: String s =string.valueof (). (factory method involves framework)

③ uses the reflection mechanism to create instantiated objects, three methods of class classes, or Newinstance () instance methods of class types.

④ invokes the object's clone () method. (commonly known as the Cloning method)

⑤ invokes the ReadObject () method of the ObjectInputStream object by means of an I/O-left deserialization.

Note: In daily development, the use of annotations simplifies a lot of code, while also reducing the programmer's daily workload.

Java annotations can be subdivided into JDK annotations and third-party annotations. Its specific use, the next opportunity to say.

Orm

Before you know hibernate and MyBatis, you must first understand what is ORM?

ORM is a three-word abbreviation: object/relationship Mapping. The translation is "object/relationship mapping".

Why do you have an ORM?

When writing an application with object-oriented thinking, the object's information is ultimately stored in a relational database, so we need to write many SQL statements related to the underlying database. Obviously this is not convenient, ORM framework technology can solve these tedious problems.

The meaning of ORM existence?

Completely abandon the idea of writing SQL statements, fully using object-oriented thinking development.

Why abandon the idea of writing SQL statements in a program?

① different databases use different SQL syntax, for example: A SQL script that runs in T-SQL, but not necessarily guaranteed to run in Pl-sql.

② the same functionality in different databases have different implementations, for example: Paged SQL.

The ③ program relies too much on SQL, which brings a lot of trouble to the porting, extension and maintenance of the program.

Hibernate framework

Hibernate is an open-source ORM Framework technology in the Java world.

Hibernate's mechanism principle:

The ①hibernate is a very lightweight package for JDBC.

(Essentially, the final hibernate still operates on the database through JDBC, but in a certain package based on JDBC)

Unlike EBJ (which is itself a Java EE specification, heavyweight ORM Framework Technology), Hibernate is a lightweight ORM Framework Technology (②).

③hibernate is between the database layer and the business logic Layer and acts as a persistence layer.

HQL Data Query Basics

Retrieving an Object--from clause

Select the--select clause

Restricting--where clauses

Sort--order By clause

HQL and SQL statements are different, the FROM clause in HQL is mandatory, and there can be no SELECT clause.

Common Properties of Hibernate:

Cascade: Sets a cascading relationship.

Inverse: Sets which party maintains the association relationship.

Example: The following code sets the common properties and the many-to-one-to-many relationships between tables.

<class name= "" table= "" >

<id name= "id" type= "java.lang.Long" >

<column name= "ID"/>

<generator class= "Increment"/>

</id>

<many-to-one name= "" class= ""

Fetch= "" >

<column name= ""/>

</many-to-one>

......

<set name= "" inverse= "true" cascade= "All" lazy= "false" >

<key>

<column name= ""/>

</key>

<one-to-many class= ""/>

</set>

</class>

Struts2 Frame

Struts is a popular and mature Web application framework based on the MVC design pattern.

http://www.jianshu.com/p/46f870043522

Struts2 the invocation of the dynamic method:

Cases:

① methods that specify the method property.

<action name= "" method= "" class= "" >

<result>/index.jsp</result>

</action>

② the exclamation point way.

<action name= "" class= "" >

<result>/index.jsp</result>

</action>

<constant name= "Structs.enable.DynamicMethodInvocation" value= "true" ></constant>

The way to ③ wildcard characters.

<action name= "_*" method= "{1}" class= "" >

<result>/index.jsp</result>

<result>/{1}.jsp</result>

</action>

When using a wildcard, if you want to use multiple methods, you can add it in method= "{1}{2} ..." and need to modify the Name= "" name + suffix _*_* ... and configure the required <result>/{ }.jsp</result> Label

STRUTS2 Accessing the Servlet API:

How Struts2 interceptors work:

Ideas:

When struts executes an action, it executes some interceptors before the action executes, if more than one interceptor executes in turn.

① first executes the interceptor one, executes the interceptor one processing method and does some processing operation.

② If there are other interceptors, the Interceptor II will be executed, interceptor three ... To intercept.

③ when all interceptors are executed, the action action is executed and the business processing method in action is invoked to handle the business.

After the ④ is called, a string result is returned, which is the result set. The view is then matched.

The ⑤ then executes the previously executed interceptor again in reverse, eventually responding to the client.


Spring Framework

Spring is a lightweight control inversion (IOC) and facet-oriented (AOP) container framework and open source framework.

Benefits of the Spring framework:

① Spring is lightweight from two aspects of size and overhead.

② is designed to achieve loose coupling by controlling the reversal technique.

③ provides rich support for aspect-oriented programming, allowing for the development of cohesion through the separation of application business logic and system-level services.

④ contains and manages the configuration and lifecycle of an Application object, which in this sense is a container.

⑤ is a framework in which simple components are configured and combined into complex applications.

What is Spring's IOC?

Ideas:

① when the object of the business enters the container of spring.

(Your business Objects) → (The Spring Container)

② then uses the configured raw data to produce objects that meet the needs of the system.

(Configuration Metadata) → (the Spring Container) → (Fully configured system)

③ when you want to use these objects, go to the spring container and take them out directly.

What is Spring's AOP?

AOP: A technology that implements unified maintenance of program functions through precompilation and run-time dynamic proxies.

The main functions are: Logging, performance statistics, security control, transaction processing, exception handling and so on.

Note:

Precompiled method: AspectJ.

Dynamic Proxy mode: JDK dynamic agent and Cglib dynamic agent. (i.e. SPRINGAOP and JBOSSAOP)

The AOP uses of spring:

① provides declarative enterprise services, specifically the declaration of alternative services for EJBS.

② allows users to define their own methods to accomplish the complementary use of OOP and AOP.

Spring's transaction management

Spring's top-level abstraction for transaction management consists of 3 interfaces:

Transactiondefinition defines transaction propagation behavior (7):

Spring MVC Framework

Spring MVC is a kind of implementation form of front-end controller, its basic concept is divided into static concept and dynamic concept.

static concept: shown below. Dispatcherservlet is the front controller of Spring MVC.

Ideas:

① when a browser-side user's request is distributed through Dispatcherservlet, it reaches the Cotroller layer.

When ② arrives at the Cotroller level, it produces the business data model that we need.

③ then the model layer is then passed through the Dispatcherservlet to our view layer.

④ finally completed the final page rendering.

Summary: MVC separates the business logic from the page, and its core is implemented through Dispatcherservlet.

Dynamic concept: shown below.

Ideas:

① when the browser requests the request to arrive at Dispatcherservlet. (Because Dispatcherservlet is also a servlet, all request can be intercepted by it)

② then Dispatcherservlet will search for a mapping, which is handlermaping, and delegate its functionality to handlermaping.

③ then handlermaping according to its own configuration, to find the controller and handlerinterceptor need to use.

④ then the controller and the Handlerinterceptor are made into an executable chain, the Handler/handleradapter adapter.

The ⑤handler/handleradapter adapter returns the information to Dispatcherservlet,dispatcherservlet and starts calling this generalized processor Handler/handleradapter.

The purpose of ⑥controller is to generate a Modelandview model and return it to Dispatcherservlet.

⑦dispatcherservlet does not manage the view display, so it invokes the Viewresolver view parser and returns it to the View object using this method. (Viewresolver's role is to tell Dispatcherservlet which view is used to parse the current scene)

⑧ then modelandview the model data to view, completing the page rendering.

Spring MVC Interceptor Workflow:

MyBatis Frame

Like Hibernate, MyBatis is an open-source ORM framework technology.

Mechanism principle of MyBatis:

①mybatis supports the persistence layer framework for common SQL queries, stored procedures, and advanced mappings.

②mybatis a large number of SQL statements out of the program, configured in the configuration file, the implementation of SQL flexible configuration.

OGNL expression:

MyBatis Framework and Hibernate framework comparison:

① "Fully Automated" Hibernate provides a complete package and a full set of mapping mechanisms for the database structure.

② "semi-automated" MyBatis provides an ORM mechanism for business logic executives to face with purely Java objects.

③hibernate automatically generates SQL statements, and MyBatis does not automatically generate SQL statement execution during run time.

Four, the tool article

JUnit Unit Test

JUnit is a test-driven development-based testing framework.

Note:

JUNIT4 does not need to inherit the Junit.framework.TestCase class.

All methods in JUNIT3 must use @test annotations and need to prefix the method name with test, inheriting the Junit.framework.TestCase class.

Version management tool SVN

SVN is an open source version control system.

As an example:

① Personal code → pocket money

Code in the ② version control tool → Cary's money

③ client → card in version control tool

Service side → swipe card machine in ④ version control tool

Note: In the actual version management, you write the code, you need to submit to the server, and then others to modify your code, will be updated from the server to the current directory code, and then modify and submit. Therefore, "Cary's money" can be understood as the team's public code system.

Project management tools Maven

MAVEN is a software project management tool that enables you to manage project builds, reports, and documents through a small section of information that is based on the Project object Model (POM).

Note:

MAVEN is also a powerful set of automated management tools that cover the cycle of compiling, testing, running, cleaning, packaging, and deploying the entire project.

It also provides a concept of a warehouse, which helps developers manage the third-party package that the project relies on, and the most likely to avoid problems with different environment configurations (running on your computer and not running on my computer).

Java Interview Advanced Parts Collection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.