preface

There are too many directions for Java programmers. Not to mention mobile development, big data, blockchain, ARTIFICIAL intelligence, etc., most Java programmers are Java Web/ back end development.

What frameworks do you need to be familiar with as a Java Web developer?

Today, north swim to explain to you about these 15 general, must grasp the framework, learn these, do not say, get not 30K you my head hammer!

At the same time also sorted out some good information for you, if you need to directly click to get it

  • 15 framework source read and write notes
  • A line of Internet companies Java interview core knowledge points
  • 22 Classic Java Architect learning books
  • 2021 Gold three silver four interview true questions collection

Welcome to my column to dive into Java, this column will continue to update Java learning tips, looking forward to growing together!

Ok, don’t say much, sit steady and hold good, let’s go!

1. Spring Series

Needless to say, the Spring framework is now the most powerful in the Java backend framework family, with both IOC and AOP to greatly simplify the complexity of software development. Also, Spring is now integrated with all the major development frameworks, making It a universal framework that makes JAVA development easier

The Spring framework is a layered architecture consisting of seven well-defined modules. The Spring module is built on top of the core container that defines how beans are created, configured, and managed, as shown in Figure 1.

Each module (or component) that makes up the Spring framework can exist on its own or be implemented jointly with one or more other modules. The functions of each module are as follows:

Core container:

The core container provides the basic functionality of the Spring framework. The main component of the core container is the BeanFactory, which is an implementation of the factory pattern. BeanFactory uses the Inversion of Control (IOC) pattern to separate the application’s configuration and dependency specifications from the actual application code.

Spring context:

A Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, E-mail, internationalization, validation, and scheduling capabilities.

Spring AOP:

The Spring AOP module integrates aspect-oriented programming capabilities directly into the Spring framework through configuration management features. As a result, you can easily make any object managed by the Spring framework AOP enabled. The Spring AOP module provides transaction management services for objects in Spring-based applications. By using Spring AOP, you can integrate declarative transaction management into your application without relying on EJB components.

Spring DAO:

The JDBC DAO abstraction layer provides a meaningful exception hierarchy that can be used to manage exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code that needs to be written (such as opening and closing connections). The Spring DAO’s JDBC-oriented exceptions follow the common DAO exception hierarchy.

Spring ORM:

The Spring framework plugs into several ORM frameworks to provide object-relational tools for ORM, including JDO, Hibernate, and iBatis SQL Map. All of this follows Spring’s generic transaction and DAO exception hierarchies.

Spring Web module:

The Web context module builds on the application context module and provides context for web-based applications. Therefore, the Spring framework supports integration with Jakarta Struts. The Web module also simplifies handling multi-part requests and binding request parameters to domain objects.

Spring MVC framework:

The MVC framework is a full-featured MVC implementation for building Web applications. The MVC framework becomes highly configurable through the policy interface, and MVC accommodates a number of view technologies, including JSP, Velocity, Tiles, iText, and POI.

Instantiate the Spring container

Create a new Web project, spring-Demo

2.2. Import the Spring core package

Import applicationContext. XML file to SRC and create com.spring.demo

2.4, import JUnit, right-click the project properties – > Java build path — — — — > Libraries — — — — — > add library — — — — — > JUnit 4 – > next – > finish

Create a Junit Test Case class

2.6. Instantiate the container, obtain the address of the applicationContext configuration file, create the applicationContext object and pass in the obtained configuration address, and the console prints the information of the instantiated container

2.7 information is displayed on the console. The following information indicates that the container is successfully instantiated

org.springframework.context.support.ClassPathXmlApplicationContext@3c1d332b: 
startup date [Wed Nov 09 16:23:19 CST 2016]; root of context hierarchy
Copy the code

Create javaBean objects using the Spring container

1, instantiated with a constructor

<beanid="calendarObj1"class="java.util.GregorianCalendar"></bean>
Copy the code

1.2)inTestCasecallgetBeanObtaining a Configuration Filebean,createBean ** object instance

Calendar cr = ac.getBean("calendarObj1",Calendar.class);
Copy the code

The console information is successfully instantiated

calendarObj1:java.util.GregorianCalendar[time=1478679801551,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun .util.calendar.ZoneInfo[id=”Asia/Shanghai”,offset=28800000,dstSavings=0,useDaylight=false,transitions=19,lastRule=null], firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2016,MONTH=10,WEEK_OF_YEAR=46,WEEK_OF_MONTH=2,DAY_OF_MONTH=9,DAY_OF _YEAR=314,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=23,SECOND=21,MILLISECOND=551,ZONE_OF FSET=28800000,DST_OFFSET=0]

2. Instantiate using static factory methods

2.1) Add in the configuration file

<bean id="calendarObj2" class="java.util.GregorianCalendar" factory-method="getInstance"></bean>*
Copy the code

2.2) Add the test method in TestCase class

Calendar cr2 = ac.getBean("calendarObj2",Calendar.class);

       System.out.println("calendarObj2:"+cr2);
Copy the code

2.3** Look at the console

calendarObj2:java.util.GregorianCalendar[time=1478679801586,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun .util.calendar.ZoneInfo[id=”Asia/Shanghai”,offset=28800000,dstSavings=0,useDaylight=false,transitions=19,lastRule=null], firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2016,MONTH=10,WEEK_OF_YEAR=46,WEEK_OF_MONTH=2,DAY_OF_MONTH=9,DAY_OF _YEAR=314,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=23,SECOND=21,MILLISECOND=586,ZONE_OF FSET=28800000,DST_OFFSET=0]

Successfully instantiated

3, instance factory instantiation

3.1) In the applicationContext.xml configuration file

<! -- instantiate instances factory - > < bean id = "calendarObj3" class = "Java. Util. GregorianCalendar" > < / bean > < bean id = "dateObj" factory-bean="calendarObj3" factory-method="getTime"></bean>Copy the code

3.2) Added the test method in the test class

Date date = ac.getBean("dateObj",Date.class);

    System.out.println("calendarObj3:"+date);
Copy the code

3.3 junit test, control output

calendarObj3:Wed Nov 09 16:23:21 CST 2016

Successfully instantiated

Container’s IOC application

4.1) Set injection

Set injection is done by calling the set method of the bean after instantiating it with a no-argument constructor or no-argument static factory method

4.1.1) In the configuration file

<! - data source setter injection - > < bean id = "dataSource" class = "com. Spring. Dao. JDBCDataSource" > < property name = "driver" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/test? useUnicode=true&characterEncoding=UTF-8"></property> <property name="username" value="root"></property> <property name="password" value="">123456</property> </bean>Copy the code

4.1.2) Write the JDBCDataSource class. This class encapsulates getConnection(), a method that manages database connections. Before this method executes, it needs the database connection parameters: the database driver, the connection URL, user name, and password

package com.spring.dao; import java.io.Serializable; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class JDBCDataSource implements Serializable{ private static final long serialVersionUID = 1L; private String driver; private String url; private String username; private String password; public String getDriver() { return driver; } public void setDriver(String driver) { try{ Class.forName(driver); this.driver = driver; }catch(Exception e){ throw new RuntimeException(e); } } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public static long getSerialversionuid() { return serialVersionUID; } public Connection getConnection() throws SQLException{ Connection cn = DriverManager.getConnection(url,username,password); return cn; } public void close(Connection cn){ if(cn! =null){ try{ cn.close(); }catch(SQLException e){ e.printStackTrace(); }}}}Copy the code

4.1.3) Use spring to achieve the creation of JDBCDataSource object, and then use the set injection method to inject database parameters to the JDBCDataSource, so that you can normally call getConnection() method to get the database connection.

4.1.4) TestCase tests connection methods

@Test
    public void testJDBCDataSource() throws SQLException{
        String conf = "applicationContext.xml";
        ApplicationContext ac = new ClassPathXmlApplicationContext(conf);
        JDBCDataSource jds = ac.getBean("dataSource",JDBCDataSource.class);
        Connection cn = jds.getConnection();
        System.out.println(cn);
    }
Copy the code

4.1.5) Console output

com.mysql.jdbc.JDBC4Connection@1a7244ca

A database connection has been obtained

4.2) Use constructor parameters to achieve dependency attribute injection

Create a user table

CREATE TABLE `user` (
  `id` int(18) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `password` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
  `gender` varchar(10) CHARACTER SET utf8 DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
Copy the code

4.2.2) Create user entity class

package com.spring.entity; public class User { private String id; private String name; private String phone; private String password; private String gender; public User(String id, String name, String phone, String password, String gender) { super(); this.id = id; this.name = name; this.phone = phone; this.password = password; this.gender = gender; } public User() { } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } @Override public String toString() { return "User [id=" + id + ", name=" + name + ", phone=" + phone + ", password=" + password + ", gender=" + gender + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((gender == null) ? 0 : gender.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((password == null) ? 0 : password.hashCode()); result = prime * result + ((phone == null) ? 0 : phone.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() ! = obj.getClass()) return false; User other = (User) obj; if (gender == null) { if (other.gender ! = null) return false; } else if (! gender.equals(other.gender)) return false; if (id == null) { if (other.id ! = null) return false; } else if (! id.equals(other.id)) return false; if (name == null) { if (other.name ! = null) return false; } else if (! name.equals(other.name)) return false; if (password == null) { if (other.password ! = null) return false; } else if (! password.equals(other.password)) return false; if (phone == null) { if (other.phone ! = null) return false; } else if (! phone.equals(other.phone)) return false; return true; }}Copy the code

4.2.3) Create interface UserDao and write a method findUserByName(String name)

package com.spring.dao;

import com.spring.entity.User;

public interface UserDao {
    public User findUserByName(String name);
}
Copy the code

MySqlUserDao = MySqlUserDao;

package com.spring.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import com.spring.entity.User; public class MysqlUserDao implements UserDao{ private JDBCDataSource dataSource; public JDBCDataSource getDataSource() { return dataSource; } public void setDataSource(JDBCDataSource dataSource) { this.dataSource = dataSource; } public MysqlUserDao(JDBCDataSource dataSource) { super(); this.dataSource = dataSource; } @Override public User findUserByName(String name) { // TODO Auto-generated method stub System. The out. Println (" -- -- -- -- -- -- -- -- -- -- - queries the user information -- -- -- -- -- -- -- -- -- -- -- -- -- "); String sql = "select * from user where name = ?" ; Connection con = null; try{ String url = dataSource.getUrl(); System.out.println(url); con = dataSource.getConnection(); PreparedStatement ps = con.prepareStatement(sql); ps.setString(1, name); ResultSet rs = ps.executeQuery(); User user = null; while(rs.next()){ user = new User(); user.setId(rs.getString("id")); user.setName(rs.getString("name")); user.setGender(rs.getString("gender")); user.setPassword(rs.getString("password")); user.setPhone(rs.getString("phone")); } rs.close(); ps.close(); return user; }catch(Exception e){ e.printStackTrace(); throw new RuntimeException(e); }finally{ dataSource.close(con); }}}Copy the code

Spring supports constructor-injected bean instantiation. Whenever you add constructor parameter constructor-arg to the configuration file,Spring automatically calls constructor-arg to create bean instances.

<bean id="userDao" class="com.spring.dao.MysqlUserDao">
            <constructor-arg index="0" ref="dataSource"></constructor-arg>
        </bean>
Copy the code

4.2.6) Write a testFindUserByName method on the test class

@Test
    public void testFindUserByName(){
        String con = "applicationContext.xml";
        ApplicationContext ac = new  ClassPathXmlApplicationContext(con);
        UserDao userDao = ac.getBean("userDao",UserDao.class);
        User user = userDao.findUserByName("lisi");
        System.out.println(user);
        
    }
Copy the code

4.2.7 If user information is correctly displayed on the console, constructor injection is successful

User [id=2, name=lisi, phone=110, password=321654, gender=1]

4.2.8) Failed to add parameter constructor to mysqlUserDAO

4.3. Automatic attribute injection is realized by automatic assembly

4.3.1) Create a UserLoginService class and write a login method login() that relies on the finfUserByName() method

package com.spring.service; import com.spring.dao.UserDao; import com.spring.entity.User; public class UserLoginService { private UserDao userDao; public UserDao getUserDao() { return userDao; } public void setUserDao(UserDao userDao) { this.userDao = userDao; } public User login(String name,String password){ try{ User user = userDao.findUserByName(name); if(user.getPassword().equals(password)){ return user; } return null; }catch(Exception e){ e.printStackTrace(); return null; }}}Copy the code

4.3.2) There are four ways for the Autowire property to default to no, (1).byName (2) byType, (3) Constuctor, (4) AutoDetect,

4.3.3) Modify the configuration file and add the configuration

<! - automatic assembly - > < bean id = "userLoginService" class = "com. Spring. Service. UserLoginService autowire" = "byName" > < / bean >Copy the code

4.3.4) Write test method testUserLogin()

@Test
    public void testUserLogin(){
        String con = "applicationContext.xml";
        ApplicationContext ac = new ClassPathXmlApplicationContext(con);
        UserLoginService us = ac.getBean("userLoginService",UserLoginService.class);
        User user = us.login("lisi", "321654");
        System.out.println(user);
    }
Copy the code

4.3.5) Console output

 User [id=2, name=lisi, phone=110, password=321654, gender=1]

Automatic assembly is successful


Due to the limitation of space behind some of the framework MENTIONED I will not be one to spread out, to everyone posted the official website address and source address, they do not understand the friends can enter the group to get the corresponding framework study notes.

Second, the Mybatis/iBatis

IBatis used to be a lightweight object relational mapping persistence layer (ORM) framework launched by The open source software group Apache. With the development team transferred to Google Code, iBatis 3.x officially changed its name to Mybatis, namely: IBatis 2.x, MyBatis 3.x.

Website:

www.mybatis.org/mybatis-3/

Source:

github.com/mybatis

Third, Hibernate

Hibernate is an open source object-relational mapping framework. It encapsulates JDBC objects in a very lightweight way. It maps POJOs to database tables and is a fully automatic ORM framework. Hibernate automatically generates SQL statements and automatically executes them, allowing Java programmers to use object programming thinking to manipulate databases at will.

Website:

hibernate.org/

Source:

github.com/hibernate

Fourth, the Dubbo

Dubbo is alibaba’s open source Java based high-performance RPC distributed service framework, which is now an Apache Foundation incubation project. With Dubbo, core businesses can be extracted as independent services, gradually forming a stable service center, which can be used to improve business reuse and flexible expansion, so that front-end applications can respond to changing market demands more quickly.

Website:

dubbo.apache.org

Source:

Github.com/apache/incu…

Fifth, Netty

Netty is an open source, asynchronous, event-driven network communication framework provided by JBOSS, with Netty can quickly develop high-performance, high reliability network server and client program, Netty simplifies the network application programming development process, so that the development of network programming becomes very simple.

Website:

netty.io/

Source:

github.com/netty/netty

Six, Shiro

Apache Shiro is a powerful and flexible open source security framework that cleanly handles authentication, authorization, enterprise session management, and encryption.

Website:

shiro.apache.org/

Source:

Github.com/apache/shir…

Seven, Ehcache

EhCache is a pure Java in-process caching framework that is fast and lean. EhCache is Hibernate’s default CacheProvider. It uses the JVM’s heap memory, which can be set to cache to disk, and the enterprise version can use physical memory outside the JVM heap.

Website:

www.ehcache.org/

Source:

Github.com/ehcache/ehc…

Eight, Quartz

Quartz is a widely used java-based, open source task scheduling framework. Anyone who has done scheduled tasks has never used this framework.

Website:

www.quartz-scheduler.org/

Source:

Github.com/quartz-sche…

Nine, Velocity

Velocity is a Java-based templatemaking engine, a simple but powerful templatemaking language that provides templatemaking services for various Web frameworks to fit the MVC model.

Website:

velocity.apache.org/

Source:

Github.com/apache/velo…

Ten, jQuery

JQuery is a fast, concise JavaScript framework, it encapsulates JavaScript commonly used functional code, provides a simple JavaScript design pattern, greatly simplifies JavaScript programming.

Although I haven’t done Web development for a long time, BUT I never forget, also remember some commonly used writing methods, such as:

$("#wx").html("javastack");
Copy the code

Website:

jquery.com/

Source:

jquery.com/download/

Eleven, JUnit

JUnit is a Java language unit testing framework. Most Java development environments have integrated JUnit as their unit testing tool.

Website:

junit.org

Source:

github.com/junit-team/

Twelve, Log4j

Log4j is an open source logging framework for Apache. Using Log4j, you can output logging information from your program to a console, file, etc. As one of the oldest logging frameworks, its current mainstream version is Log4j2. Log4j2 is a re-architected logging framework that eliminates the shortcomings of Log4j and draws on the design of Logback, an excellent logging framework.

Website:

logging.apache.org/log4j/2.x/

Source:

Logging.apache.org/log4j/2.x/s…


Ok, that’s about it. Do you use all of these frames?

Not really, all see here also don’t point a like add a concern you see the official master?

Previous hot article:

  • Java basic knowledge summary
  • Performance Tuning series (JVM, MySQL, Nginx, and Tomcat)
  • From being kicked out to 5 30K+ offers, all the way through the rough, sink your heart, it is not the future
  • 100 Java project parses with source code and learning documentation!

end