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

JAVA规范学习——String字面常量

package testPackage;
class Test {
public static void main(String[] args) {
String hello = "Hello", lo = "lo";
System.out.print((hello == "Hello") + " ");
System.out.print((Other.hello == hello) + " ");
System.out.print((other.Other.hello == hello) + " ");
System.out.print((hello == ("Hel"+"lo")) + " "); //(1)
System.out.print((hello == ("Hel"+lo)) + " "); //(2)
System.out.println(hello == ("Hel"+lo).intern());
}
}
class Other { static String hello = "Hello"; }
package other;
public class Other { static String hello = "Hello"; }
运行结果如下:
true true true true false true 
结果解释:
1. 所有String字面量,不管其所在的class和package,都是同一个String对象的引用
2. 对于常量表达式计算的String,都是在编译期间计算的,被当作String字面量看待。例如(1)行所在的代码
3. 对于在运行期连接的String,都是新创建的,因此不相同。例如(2)行所在的代码


相关文档:

Java equals

boolean java.lang.Object.equals(Object obj)
Indicates whether some other
object is "equal to" this one.
The equals method implements an
equivalence relation on non-null object references:
It is reflexive: for
any non-null reference value x, x.equals(x) should return true.
It ......

用Java程序实现解压缩文件

package com.huawei.globe;
import java.util.zip.*;
import java.io.*;
public class Compress {
 public Compress() {
 }
 // 压缩目录下的文件
 public void compress(String zipFileName, String inputFile) throws Exception {
  compress(zipFileName, new File(inputFile)); ......

JAVA程序全局键盘监听事件


// 注册应用程序全局键盘事件, 所有的键盘事件都会被此事件监听器处理.
Toolkit tk = Toolkit.getDefaultToolkit();
tk.addAWTEventListener(new MyAWTEventListener(), AWTEvent.KEY_EVENT_MASK);
class MyAWTEventListener implements AWTEventListener {
    private boolean controlPressed = fal ......

Java Type VS Hibernate Type

Java Class Attribute Type         Hibernate Type               Possible SQL Type-Vendor Specific
Integer, int, long short &n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号