package lesson12;
import java.util.*;
import java.io.*;
class Test
{
public static void main(String[] args) throws Exception
{
//System.out.println("Hello World!");
//中文註釋
/*for(String arg : args)
{
System.out.println(arg);
}
Scanner sc = new Scanner(new File("lesson12.java"));
//sc = sc.useDelimiter("\n");
while(sc.hasNextLine())
{
System.out.println(sc.nextLine());
}
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String mybuf = null;
while((mybuf = buf.readLine())!=null)
{
System.out.println("in輸入的是:"+mybuf);
}*/
/*System.out.println(System.getenv("java_home"));
Map<String,String> env = System.getenv();
for(String key : env.keySet())
{
System.out.println(key+"="+env.get(key));
}
System.out.println("*******系統屬性Properties******");
Properties prop = System.getProperties();
for(Object o : prop.keySet())
{
System.out.println( o + "="+prop.get(o));
}
prop.store(new FileOutputStream("test.properties"),"test comment 測試屬性");
prop.storeToXML(new FileOutputStream("test.xml"),"系統屬性","gb2312");
System.out.println("您的操作系統是:"+prop.getProperty("os.name"));
*/
//由於重寫了hashCode()故兩個對象的哈希地址有可能相等。
String str1 = new String("你好");
String str2 = new String("你好");
System.out.println(str1.hashCode()+"--"+str2.hashCode());//2個不同對象的哈希代碼相等
//但System.identityHashCode(object o )返回對象精確的哈希地址(因爲他是根據對象內存地址計算的)
System.out.println(System.identityHashCode(str1)+"--"+System.identityHashCode(str2));//2個不同對象的標識哈希代碼永遠不相等
String str3 = "你好";
String str4 = "你好";
//str3和str4引用同一個內存對象,故他們的標識哈希代碼必然相等
System.out.println(System.identityHashCode(str3)+"--"+System.identityHashCode(str4));//相等
//獲取程序相關聯的Java運行時對象
Runtime rt = Runtime.getRuntime();
final long mb = 1024*1024;
System.out.println("處理器數量:"+rt.availableProcessors());
System.out.println("Java VM 空閒內存:"+rt.freeMemory() / mb+"MB");
System.out.println("Java VM 總內存大小:"+rt.totalMemory() / mb +"MB");
System.out.println("Java VM 可用最大內存:"+rt.maxMemory()/mb+"MB");
}
}