java 数字字符串判断
Boolean strResult
= str
.matches("-?[0-9]+.?[0-9]*");
if(strResult
== true) {
}
《Java编程思想》
构造函数实际上是static方法,只不过该static声明是隐式的。因此,构造函数不能够被override,同样,它也不具有多态private方法本质上属于final方法,因为不能被子类访问
class Glyph {
void draw() {
System
.out
.println("Glyph.draw()");
}
Glyph() {
System
.out
.println("Glyph() before draw()");
draw();
System
.out
.println("Glyph() after draw()");
}
}
class RoundGlyph extends Glyph {
private int radius
= 1;
RoundGlyph(int r
) {
radius
= r
;
System
.out
.println("RoundGlyph.RoundGlyph(). radius = " + radius
);
}
void draw() {
System
.out
.println("RoundGlyph.draw(). radius = " + radius
);
}
}
public class PolyConstructors {
public static void main(String
[] args
) {
new RoundGlyph(5);
}
}
java 编程单元(class)java 方法的动态绑定/ 通常情况下,我们不必判定是否应该进行动态绑定—它会自动发生。
class StaticSuper {
public static String
staticGet() {
return "Base staticGet()";
}
public String
dynamicGet() {
return "Base dynamicGet()";
}
}
class StaticSub extends StaticSuper {
public static String
staticGet() {
return "Derived staticGet()";
}
public String
dynamicGet() {
return "Derived dynamicGet()";
}
}
public class StaticPolymorphism {
public static void main(String
[] args
) {
StaticSuper sup
= new StaticSub();
System
.out
.println(sup
.staticGet());
System
.out
.println(sup
.dynamicGet());
}
}
Java中构造函数的调用顺序
分配内存调用基类构造函数按声明顺序调用成员的初始化方法调用子类构造函数只有非private方法才可以被覆盖父类和子类的同名属性都会分配不同的存储空间
一个spring Bean从创建到销毁
包扫描操作,并对其进行实例化操作依赖注入判断是否实现了BeanNameAware接口 封装 setter/getter判断是否实现了BeanFactoryAware接口 封装对象工厂类判断是否实现了ApplicationContextAware接口 获取上下文判断是否实现了BeanPostProcessor接口 ?判断Bean是否配置了init-method判断Bean是否实现了BeanPostProcessor接口 完成bean 初始化一般是在ApplicationContext执行close方法时会进行销毁操作。在销毁过程中,判断是否实现了DisposableBean接口,如果有则执行destroy方法。判断Bean是否配置了destroy-method,如果有,在销毁过程中会默认执行一次destroy-method方法。
spring 处理流程
BeanFactory添加事件(方法)实例化调用事件(事件监听)
springBoot 事务管理
class@EnableTransactionManagement //开启声明式事务@Configurationmethod@Transactional 事务回滚/提交@Override@Beanvar java 变量声明@Resource@Autowired
<dependency>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-starter-jdbc
</artifactId>
<scope>test
</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-starter-data-jpa
</artifactId>
<scope>test
</scope>
</dependency>
spring AOP、ORM、事务管理
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxPoolSize" value="${c3p0.pool.maxPoolSize}"/>
<property name="minPoolSize" value="${c3p0.pool.minPoolSize}" />
<property name="initialPoolSize" value="${c3p0.pool.initialPoolSize}"/>
<property name="acquireIncrement" value="${c3p0.pool.acquireIncrement}"/>
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:advice id="txAdivce" transaction-manager="txManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="find*" read-only="false"/>
<tx:method name="get*" read-only="false"/>
<tx:method name="view*" read-only="false"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(* com.*.service.*.*(..))" id="txPointcut"/>
<aop:advisor advice-ref="txAdivce" pointcut-ref="txPointcut"/>
</aop:config>