System类
System.out 标准输出
System.err 错误输出
System.inz 标准输入(很少用)
Scanner scanner=new Scanner(System.in);
while (scanner.hasNext()) {
String str=scanner.next();
byte[]bs=str.getBytes(Charset.forName("GBK"));
String str1=new String(bs,Charset.forName("UTF-8"));
System.out.println(str1);
if (str1.endsWith(";")) {
break;
}
}
输入什么就输出什么,要进行GBK UTF-8转换,如果没有转换那么输出的就是乱码,这里有个判断就是如果输入“;”那么就终止代码运行

System.out.println("------------------------");
//getenv 获取系统所有的环境变量
Map<String, String>map=System.getenv();
Set<String>keSet=map.keySet();
for (String key : keSet) {
System.out.println(key+"--->"+map.get(key));
}

//getenv() 获取详细的环境变量
System.out.println("---------------------");
System.out.println(System.getenv("JAVA_HOME"));

//获取系统属性getProperties
System.out.println("---------------------");
System.out.println(System.getProperties());
//getProperty 获取详细的
System.out.println(System.getProperty("user.name"));

gc() 垃圾回收(只是通知Java虚拟机,并不会马上回收)
函数的作用只是提醒虚拟机:希望进行一次垃圾回收。但是它不能保证垃圾回收一定会进行,而且具体什么时候进行是取决于具体的虚拟机的,不同的虚拟机有不同的对策。
currentTimeMillis和nanoTime
// 返回当前时间与UTC 1970年1月1日午夜的时间差
System.out.println(System.currentTimeMillis());

// nanoTime 纳秒1毫秒(ms)=1000000纳秒(ns) 部分电脑不支持
System.out.println(System.nanoTime());
identityHashCode
// identityHashCode 返回指定对象的精确hashCode值,
// 下面程序中str1和str2是两个不同对象
String str1 = new String("Hello,World");
String str2 = new String("Hello,World");
// String 重写了hashCode()方法一改为根据字体序列计算hashCode值,
// 因为str1和str2的字符序列相同,所以它们的hashCode方法返回值相同
System.out.println(str1.hashCode() + "\t" + str2.hashCode());
// str1和str2是不同的字符串对象,所有它们的identityHashCode值不同
System.out.println(System.identityHashCode(str1) + "\t"+ System.identityHashCode(str2));

String str3="Java";//字符串常量池
String str4="Java";//字符串常量池
为什么相同,因为这种字符串常量,在Java运行之前会把它们放到字符串常量池, 所有可以看做同一样东西
//str3和str4是相同的字符串对象,所以它们的identityHashCode值相同
System.out.println(System.identityHashCode(str3)+"\t"+System.identityHashCode(str4));

//exit 停止正在运行的虚拟机 ,退出程序
System.exit(0);//异常退出传个负数
System.out.println("这一句将不会打印出来,因为没有执行");
2524




被折叠的 条评论
为什么被折叠?



