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 实现的选择排序法,先在Netbeans里调试运行了一下,然后又在Eclipse了运行了一下。
public class ArraySort {
public static void main(String[] args) {
int Arrays[]={50,45,2,678,90,40,};
int i,j,temp,min;
int len=Array ......
来源:http://bbs.hackline.net/thread-3620-1-1.html
隐藏具体实现是Java语言的主要特点之一。正是因为这个原因,所以Java语言的移植性就特别好。如有个程序员编写了一个实现随机数的程序库,那么其他
程序开发人员只需要知道这个程序库需要传入那些参数,就可以使用这个类。现在无论是网上还是平时的工作中,有很多现成 ......
Java Class Attribute Type Hibernate Type Possible SQL Type-Vendor Specific
Integer, int, long short &n ......
import java.util.regex.*;
public final class RegExpValidator
{
/**
* 验证邮箱
* @param 待验证的字符串
* @return 如果是符合的字符串,返回 <b>true </b>,否则为 <b>false </b>
*/
public static boolean isEmail(String str)
{ ......
有时,我们在写一个构造函数时,经常因为它包含众多的参数而苦恼,这时可以考虑用Builder模式来创建对象。
如,我们要设计一个营养成份的类,包含能量,蛋白质,脂肪,钙,铁,锌,维生素A, 维生素B1 ... 等,但在构造的时候,不一定每次都需要这些参数,如钙,铁,锌和维生素等是可选的,为了适应多种可能的搭配,比 ......