自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(25)
  • 收藏
  • 关注

原创 通用程序设计

import java.util.*;public class CommonProgram { enum Suit { CLUB, DIAMOND, HEART, SPADE } enum Rank { ACE, DEUCE, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING } pr...

2016-03-31 12:48:48 204

原创 复合优先于继承

public class CompositionOverInheritance { public static void main(String[] args) { InstrumentedSet<String> st = new InstrumentedSet<String>(new HashSet<String>()); Instrumen...

2016-03-31 12:46:30 113

原创 用私有构造器或者枚举类型enum强化singleton

public class Singleton { private static Singleton instance = new Singleton(); private Singleton() { } public static Singleton getInstance() { return instance; } public void ser...

2016-03-31 12:46:22 149

原创 static、final、private方法的区别

public class FinalAndPrivate { @SuppressWarnings("all") public static void main(String[] args) { Parent p = new Parent(); p.call(); p.call2(); p.print(); p.staticMethod(); ...

2016-03-31 12:45:38 262

原创 finally的一些特性

public class FinallyTest { public static void main(String[] args) { System.out.println("test1:" + testFinal1()); System.out.println("test2:" + testFinal2()); System.out.println("test3:" +...

2016-03-31 12:45:12 205

原创 java 泛型Generics

import java.util.*;public class Generics { //无限制的通配符类型 static int numElementsInCommon(Set<?> s1, Set<?> s2) { int result = 0; for (Object o : s1) if (s2.contains(o)) ...

2016-03-30 14:03:33 86

原创 java 内部类

public class InnerTest { public static void main(String[] args) { //必须先有外部类的对象才能生成内部类的对象,因为内部类的作用就是为了访问外部类中的成员变量 Outer.Inner in = new Outer().new Inner(); //out.new Inner() in.show...

2016-03-30 14:01:56 68

原创 java Reflection反射

import java.lang.reflect.*;public class Reflection { public static void main(String[] args) { ReflectPerson p = new ReflectPerson("chenzq", 20); Class<? extends ReflectPerson> ...

2016-03-30 14:01:45 60

原创 jdk动态代理生成的代理类模拟

import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.lang.reflect.UndeclaredThrowableException; public class Business...

2016-03-30 14:01:38 101

原创 java 多线程编程(生产者和消费者)

public class ProducerAndConsumer { public static void main(String[] args) { Storage storage = new Storage(); Thread producer1 = new Thread(new Producer(storage, "producer1")); Th...

2016-03-30 14:00:57 165

原创 java类成员初始化顺序

public class InitialOderExtends extends Parent { // 静态变量 public static String s_StaticField = "subclass--static variable"; // 变量 public String s_Field = "subclass--variable"; // 静态初...

2016-03-29 13:39:46 50

原创 用enum代替int常量

public class EnumObject { public static void main(String[] args) { double x = 1.11; double y = 2.01; for (Operation op : Operation.values()) System.out.printf("%f %s %f = %f%n",...

2016-03-29 13:39:38 125

原创 避免创建不必要的对象

public class AutoBoxing { public static void sum() { long start = new java.util.Date().getTime(); //使用基本数据类型 long sum = 0L; for(long i = 0; i < Integer.MAX_VALUE; i++) { ...

2016-03-29 13:39:18 90

原创 java Annotation注解

import java.lang.annotation.*;import java.lang.reflect.*;public class Annotation { public static void main(String[] args) { int tests = 0; int passed = 0; Class<?> testClass...

2016-03-29 13:38:59 53

原创 java for循环使用标签以及switch

public class LabeledLoop { public static void main(String[] args) { int i = 0; outer: // Can't have statements here for(; true ;) { inner: // Can't have statements here for(; i ...

2016-03-29 13:37:27 430

原创 cglib动态代理实现(使用代理类的父类作为目标对象)

import java.lang.reflect.Method;import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor;import net.sf.cglib.proxy.MethodProxy;//直接使用代理类的父类作为目标业务对象。public class Bu...

2016-03-28 00:04:07 1636

原创 Cglib动态代理(CallbackFilter)

import java.lang.reflect.Method;import net.sf.cglib.proxy.Enhancer;import net.sf.cglib.proxy.MethodInterceptor;import net.sf.cglib.proxy.MethodProxy;import net.sf.cglib.proxy.Callback;impo...

2016-03-28 00:03:23 957

原创 java普通代理模式

public interface Business { public void service(); public void execute();}public class BusinessImpl implements Business { private String id = "default"; public BusinessImpl() {} ...

2016-03-28 00:03:11 115

原创 cglib动态代理实现(持有业务类对象)

import java.lang.reflect.Method;import net.sf.cglib.proxy.Enhancer;import net.sf.cglib.proxy.MethodInterceptor;import net.sf.cglib.proxy.MethodProxy;//传入业务类实例作为目标对象。public class Business...

2016-03-28 00:03:01 220

原创 jdk动态代理

import java.lang.reflect.InvocationHandler;import java.lang.reflect.Proxy;import java.lang.reflect.Method;public class BusinessJdkProxy { public static void main(String[] args) { Bu...

2016-03-28 00:02:10 65

原创 java基本数据类型缺省值

public class DefaultInitValue { private int iValue; //0 private long lValue; //0 private boolean bValue; //false private char cValue; //(short)0 || '\u0000' private float fValue; /...

2016-03-27 16:43:26 1338

原创 java初始化陷阱

import java.util.Iterator;import java.util.NoSuchElementException;public class InitOrder { public static void main(String[] args) { //错误的初始化 new RoundGlyph(5); for (Iterator<...

2016-03-27 16:29:13 81

原创 java重载之基本类型

public class PrimitiveOverload { static void prt(String s) { System.out.println(s); } void f1(char x) { prt("f1(char)"); } void f1(byte x) { prt("f1(byte)"); } void f1(short x) { p...

2016-03-27 16:15:25 127

原创 java对象复制之Serializable

import java.io.*;@SuppressWarnings("all")public class CloneBySerializable implements Serializable { private int j; private Thing thing; public CloneBySerializable(int j) { this.j = j;...

2016-03-27 16:09:12 194

原创 java对象复制之clone

public class ObjectClone implements Cloneable { private int i; private Handler handler = new Handler(101, "chenzq"); public ObjectClone(int i) { this.i = i; } public void increase() {...

2016-03-27 16:05:09 88

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除