1. 下面是一到Java笔试题: public class Test2 { public void add(Byte b) { b = b++; } public void test() { Byte a = 127; Byte b = 127; add(++a); System.out.print(a + " "); add(b); System.out.print(b + ""); } } 2. 为方便分析起见,将打印的语句去掉,如下: public void…
先看代码: package com.roocon.thread.t3; public class Sequence { private int value; public int getNext(){ return value++; } public static void main(String[] args) { Sequence sequence = new Sequence(); new Thread(new Runnable() { @Override public void run(…
++/-- 是一种特殊的算术运算符,在算术运算符中需要两个操作数来进行运算,而自增自减运算符是一个操作数 前缀自增(++a):先进行自增运算,再进行表达式运算: 后缀自增(a++):先进行表达式运算,再进行自增运算. int x = 5, y=5; int a = 2*++x; int b = 2*y++; System.out.println(a+"=="+b); 输出结果:a = 12, b =10; 前缀++,先自增运算,=> a=2*6 后缀++,先表达式运算,=>…
一.MyBatis 完整示例 这里,我将以一个入门级的示例来演示 MyBatis 是如何工作的. 注:本文后面章节中的原理.源码部分也将基于这个示例来进行讲解.完整示例源码地址 1.1. 数据库准备 在本示例中,需要针对一张用户表进行 CRUD 操作.其数据模型如下: CREATE TABLE IF NOT EXISTS user ( id BIGINT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Id', name VARCHAR(10) NOT…
ι 版权声明:本文为博主原创文章,未经博主允许不得转载. 先看Android源码(API24)中对ThreadLocal的定义: public class ThreadLocal<T> 即ThreadLoca是一个泛型类,再看对该类的注释: /** * This class provides thread-local variables. These variables differ from * their normal counterparts in that each thread th…
ι 版权声明:本文为博主原创文章,未经博主允许不得转载. 先看Handler的定义: /** * A Handler allows you to send and process {@link Message} and Runnable * objects associated with a thread's {@link MessageQueue}. Each Handler * instance is associated with a single thread and that thre…
之前看了一篇关于"Java finally语句到底是在return之前还是之后执行?"这样的博客,看到兴致处,突然博客里的一个测试用例让我产生了疑惑. 测试用例如下: public class FinallyTest { public static void main(String[] args) { System.out.println(getMap().get("key")); } public static Map<String,String> g…
类加载与字节码技术 1.类文件结构 根据 JVM 规范,类文件结构如下 ClassFile { u4 magic; //魔数 u2 minor_version; //小版本号 u2 major_version; //java 主版本号 u2 constant_pool_count; //常量池 cp_info constant_pool[constant_pool_count-1]; u2 access_flags; //访问标识与继承信息 u2 this_class; u2 super_cla…