易截截图软件、单文件、免安装、纯绿色、仅160KB

JAVA规范学习——static成员初始化

class Super { static int taxi = 1729; }
class Sub extends Super {
static { System.out.print("Sub "); }
}
class Test {
public static void main(String[] args) {
System.out.println(Sub.taxi);
}
}
输出:1729
知识要点:
A reference to a class field causes initialization of only the class or interface
that actually declares it, even though it might be referred to through the name of a
subclass, a subinterface, or a class that implements an interface.
也就是说只有使用该类或者接口直接定义的类变量,才会激发该类的初始化;如果使用的是其父类定义的类变量,则子类不会被初始化
interface I {
int i = 1, ii = Test.out("ii", 2);
}
interface J extends I {
int j = Test.out("j", 3), jj = Test.out("jj", 4);
}
interface K extends J {
int k = Test.out("k", 5);
}
class Test {
public static void main(String[] args) {
System.out.println(J.i);
System.out.println(K.j);
}
static int out(String s, int i) {
System.out.println(s + "=" + i);
return i;
}
}
输出:
1
j=3
jj=4
3
 知识要点:
Initialization of an interface does not, of itself, cause initialization of any of its
superinterfaces.
The reference to J.i is to a field that is a compile-time constant; therefore, it
does not cause I to be initialized. The reference to K.j is a reference to a field
actually declared in interface J that is not a compile-time constant; this causes initialization
of the fields of interface J, but not those of its superinterface I, nor
those of interface K. Despite the fact that the name K is used to refer to field j of
interface J, interface K is not initialized.


相关文档:

java性能的优化(二)

    三.优化JAVA程序设计和编码,提高JAVA程序性能的一些方法。
   
通过使用一些前面介绍过的辅助性工具来找到程序中的瓶颈,然后就可以对瓶颈部分的代码进行优化。一般有两种方案:即优化代码或更改设计方法。我们一般会选
择后者,因为不去调用以下代码要比调用一些优化的代码更能提 ......

Java Annotation使用大全 (ZT)


一、Annotation究竟是什么?
    Annotation 提供了一条与程序元素关联任何信息或者任何元数据(metadata)的途径。从某些方面看,annotation就像修饰符一样被使用,并应用于包、类型、构造方法、方法、成员变量、参数、本地变量的声明中。这些信息被存储在annotation的“name=value”结构对中 ......

Java线程讲解

一 线程的基本概念
线程是一个程序内部的顺序控制流.一个进程相当于一个任务,一个线程相当于一个任务中的一条执行路径.
多进程:在操作系统中能同时运行多个任务(程序)
多线程:在同一个应用程序中有多个顺序流同时执行
Java的线程是通过java.lang.Thread类来实现的
JVM启动时会有一个由主方法(public static void main( ......

java面试题及答案(基础题122道,代码题19道)

JAVA相关基础知识
1、面向对象的特征有哪些方面
1.抽象:
抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面。抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用部分细节。抽象包括两个方面,一是过程抽象,二是数据抽象。
2.继承:
继承是一种联结类的层次模型,并 ......

gson(JSON字符串转换成一个相等的Java对象)

  目前大多数使用gson的还要求在java类中使用java annotation,不完全支持POJO。
Gson这个Java类库可以把Java对象转换成JSON,也可以把JSON字符串转换成一个相等的Java对象。Gson支持任意复杂Java对象包括没有源代码的对象。
代码例子
/*
* To change this template, choose Tools | Templates
* and open the ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号