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杂谈(九)--Struts
J2ee的开源框架很多,笔者只能介绍自己熟悉的几个,其他的目前在中国IT行业应用得不是很多。希望大家对新出的框架不要盲目的推崇,首先一定要熟悉它比旧的到底好在哪里,新的理念和特性 ......
三.优化JAVA程序设计和编码,提高JAVA程序性能的一些方法。
通过使用一些前面介绍过的辅助性工具来找到程序中的瓶颈,然后就可以对瓶颈部分的代码进行优化。一般有两种方案:即优化代码或更改设计方法。我们一般会选
择后者,因为不去调用以下代码要比调用一些优化的代码更能提 ......
Java中调用C/C++生成的DLL
一、 生成C的头文件
1. 编辑Main.java
public class Main
{
public native static int getStrNum(byte str[], int strLen);
}
2. 生成头文件
按win + r打开“运行”窗口,输入“cmd”,打开 ......
import java.io.IOException;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class DES {
private byte ......
JAVA反射机制
JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意一个方法;这种动态获取的信息以及动态调用对象的方法的功能称为java语言的反射机制。
Java反射机制主要提供了以下功能: 在运行时判断任意一个对象所属 ......