标签:style blog color java io ar div 代码
/* *System的identityHashCode方法 * */ public class CodeTest { //一个对象的hashCode方法被重写后,hashCode不能唯一的表示对象 // 但是identifyHashCode方法返回的hashCode值依然是根据该对象的 // 地址得到的hashCode值 public static void main(String[] args) { String s1=new String("HELLO"); String s2=new String("HELLO"); // S1和s2不是同一个对象,但是因为String的HashCode值是根据字符序列来计算的 // 所以,s1和s2的hashCode值相同 System.out.println(s1.hashCode()+"------"+s2.hashCode()); // 但是identityHashCode返回的值不同 System.out.println(System.identityHashCode(s1)+"----------"+System.identityHashCode(s2)); } }
System提供了getenv()来获得环境变量和getProperties()来获得系统属性;
Runtime类提供了availableProcessors()来获得处理器个数,以及获得内存数的方法
public class RuntimeTest { public static void main(String[] args) throws IOException { // Runtime类不能通过new创建实例,但是可以通过get方法得到 Runtime rt=Runtime.getRuntime(); System.out.println("处理器数量 "+rt.availableProcessors()); System.out.println("空闲内存数 " +rt.freeMemory()); System.out.println("总内存" +rt.totalMemory()); System.out.println("可用最大内存数 "+rt.maxMemory()); // Runtime还可以直接启动一条进程来运行操作系统的命令 // 下面的代码启动记事本程序 rt.exec("notepad.exe");
// java常用类Object,方法getClass()返回运行时类
System.out.println(new RuntimeTest().getClass());
// equals用于比较两个对象,比较两个对象是否是同一个对象
System.out.println(new RuntimeTest().equals(new RuntimeTest()));
}
}
标签:style blog color java io ar div 代码
原文地址:http://www.cnblogs.com/twobrothers/p/3898041.html