易截截图软件、单文件、免安装、纯绿色、仅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调用SQL Server的存储过程详解

1使用不带参数的存储过程
  使用 JDBC 驱动程序调用不带参数的存储过程时,必须使用 call SQL 转义序列。不带参数的 call 转义序列的语法如下所示:
  
以下是引用片段:
{call procedure-name}
  作为实例,在 SQL Server 2005 AdventureWorks 示例数据库中创建以下存储过程:
  
以下是引用片段: ......

Java调用系统命令学习(三)

学习了两篇的Runtime类,现在对它有了更深一层的了解,那么我们来看看下面的代码:
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader ;
import java.io.BufferedReader;
public class Exec_Output{
public static void main(String []args)throws IOException,Int ......

web service:java 和 .net之间互操作

通过Web Service混合.NET和Java技术往往很容易,但Web Service并非是.NET和Java互操作的万灵丹。Web Service在集成独立的跨网络通信的组件时非常有用,在简单的调用/返回情景中,涉及的数据类型数量非常有限,且Web Service是基于标准的,混合.NET和Java技术通常显得很简单,因此有人认为Web Serv ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号