Class System 方法学习
来源:互联网 发布:centos7 yum安装git 编辑:程序博客网 时间:2024/05/23 00:02
Static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
复制一个数组的部分到指定数组的指定位置
public class FirstJava { public static void main(String[] args) { int[] fun = {0,1,2,3,4,5,6}; System.arraycopy(fun,0,fun,3,2); for (int i=0; i < fun.length; i++) { System.out.println(fun[i]); } }}
static String clearProperty(String key)
方法将删除由指定的键指定的系统属性
public class FirstJava { public static void main(String[] args) { System.setProperty("akke","abc"); System.out.println("using getProperty: "+ System.getProperty("akke")); System.clearProperty("akke"); System.out.println("using getProperty: "+ System.getProperty("akke")); }}
static Console console()
Returns the unique Console object associated with the current Java virtual machine, if any.
java.io.Console 只能用在标准输入、输出流未被重定向的原始控制台中使用,在 Eclipse 或者其他 IDE 的控制台是用不了的。
import java.io.Console;import java.io.PrintWriter; public class NewJava { public static void main(String[] args) { Console cons = System.console(); if (cons != null) { // ------------------------- PrintWriter printWriter = cons.writer(); printWriter.write("input:"); cons.flush(); // ------------------------- String str1 = cons.readLine(); // ------------------------- cons.format("%s", str1); } } }
static long currentTimeMillis()
以毫秒返回现在的时间(自1970年1月1日0时起的毫秒数)
public class FirstJava { public static void main(String[] args) { System.out.println("currentTime: "+ System.currentTimeMillis()); }}
static void exit(int status)
结束正在运行的虚拟机
static void gc()
运行垃圾回收器
//告诉垃圾收集器打算进行垃圾收集,而垃圾收集器进不进行收集是不确定的
static Map
import java.util.Map;public class FirstJava { public static void main(String[] args) { Map<String, String> env = System.getenv(); for(String key : env.keySet()){ //只能遍历key System.out.println("Key = "+key); } for(Object value : env.values()){ //只能遍历value System.out.println("Value = "+value); } }}
输出一个Map:http://blog.csdn.net/b_h_l/article/details/7593970
static String getenv(String name)
获得指定环境变量名的值
static Properties getproperties()
确认现在的系统变量
public class FirstJava { public static void main(String[] args) { Properties pps = System.getProperties(); pps.list(System.out); }}
static String getProperty(String key)
通过指定键获得系统变量
static String getProperty(String Key, String def)
通过指定键获得系统变量,如果相应的值不存在,则用def(ault)初始化该变量
static SecurityManager getSecurityManager()
获得当前系统的安全管理者,如果该管理者不存在,则返回null
public class FirstJava { public static void main(String[] args) { SecurityManager securityManager = System.getSecurityManager(); if(securityManager!=null) System.out.print(securityManager.toString()); else System.out.println("empty"); }}
###static int identityHashCode(Object x)
根据对象返回hashCode()
public class TestSystemHashCode { public static void main(String[] args) { String a = new String("hhh"); String b = new String("hhh"); System.out.println(System.identityHashCode(a)); System.out.println(System.identityHashCode(b)); System.out.println(a.hashCode()); System.out.println(b.hashCode()); //输出不同 String string1 = "wxg"; String string2 = "wxg"; System.out.println(System.identityHashCode(string1)); System.out.println(System.identityHashCode(string2)); System.out.println(string1.hashCode()); System.out.println(string2.hashCode()); //输出相同 } }
static Channel inheritedChannel()
???
public class FirstJava { public static void main(String[] args) throws IOException { Channel channel = System.inheritedChannel(); if(channel!=null) System.out.print("not empty"); else System.out.println("empty"); }}
static String lineSeparator()
返回系统资源(换行符)
public class FirstJava { public static void main(String[] args) throws IOException { String lineseparator = System.lineSeparator(); if(lineseparator!=null) System.out.print("first line"+lineseparator+"second line"); else System.out.println("empty"); }}
static void load(String filename)
static void loadLibrary(String libname)
调用其他运行库
static String mapLobraryName(String libname)
返回一个与平台相关的本地库的名字
public class FirstJava { public static void main(String[] args) { // prints the name of the Operating System System.out.println(System.getProperty("os.name")); /* maps a library name into a platform-specific string representing a native library */ String str = System.mapLibraryName("os.name"); System.out.println(str); }}
static long nanoTime()
返回最准确的可用系统计时器的当前值,以毫微秒为单位。
这个返回值是一个从确定的值算起的,但是这个值是任意的,可能是一个未来的时间,所以返回值有可能是负数。
public class FirstJava { public static void main(String[] args) { long l = System.nanoTime(); System.out.print(l); }}
static void runFinalization()
//强制调用已经失去引用的对象的finalize方法
///(选择性的)被调用在gc之前
static void setErr(PrintStream err)
重新分配“标准”错误输出流
static void setIn(InputStraem in)
重新分配“标准”输入流
static void setOut(printStream out)
重新分配“标准”输出流
import java.lang.*;import java.io.*;public class SystemDemo { public static void main(String[] args) throws Exception { // create file FileOutputStream f = new FileOutputStream("file.txt"); System.setOut(new PrintStream(f)); // this text will get redirected to file System.out.println("This is System class!!!"); // existing file System.setIn(new FileInputStream("file.txt")); // read the first character in the file char ret = (char)System.in.read(); // returns the first character System.out.println(ret); // create a file FileOutputStream f = new FileOutputStream("file.txt"); System.setErr(new PrintStream(f)); // redirect the output System.err.println("This will get redirected to file"); } }}
static void setProperties(properties props)
static String setProperty(String key, String value)
设置系统属性的属性参数
public class SystemDemo { public static void main(String[] args) { // prints Java Runtime Version before property set System.out.print("Previous : "); System.out.println(System.getProperty("java.runtime.version")); Properties p = System.getProperties(); p.put("java.runtime.version", "Java Runtime 1.6.0"); System.setProperties(p); // prints Java Runtime Version after property set System.out.print("New : "); System.out.println(System.getProperty("java.runtime.version")); }} public class SystemDemo { public static void main(String[] args) { // prints Java Runtime Version before property set System.out.print("Previous : "); System.out.println(System.getProperty("java.runtime.version" )); System.setProperty("java.runtime.version", "Java Runtime 1.6.0"); // prints Java Runtime Version after property set System.out.print("New : "); System.out.println(System.getProperty("java.runtime.version" )); }}
static void setSecurityManager(SecurityManager s)
阅读全文
0 0
- Class System 方法学习
- Class String 方法学习
- System.setProperty和Class.forName方法获取数据库连接的异同
- System.class.getResourceAsStream分析
- extjs4: class system
- Python Class System
- System class 源码解读
- spring 源码学习-class方法创建类
- 【ExtJS 4.x学习教程】(1)类系统(Class System)
- 23.2 The System.Exception class
- Ext js 6 - Class System
- 学习笔记-- 使用System.Text.StringBuilder的方法和属性
- java学习笔记之class类实例获取方法
- scala学习-Scala class的构造方法与继承
- [ExtJS5学习笔记]第六节 Extjs的类系统Class System命名规则及定义和调试
- [ExtJS学习笔记]第六节 Extjs的类系统Class System命名规则及定义和调试
- 保证 load class from system class loader first!
- 一步一步翻译,解说extjs4-------------Class System
- oracle之 监听器无法启动的几个原因总结
- Leetcode算法学习日志-647 Palindromic Substrings
- 第3周项目2- 顺序表的基本运算
- OPENGL学习笔记之二
- Gensim源代码详解——dictionary(持续更新中)
- Class System 方法学习
- 言简意赅剖析计算机使用补码的意义
- DirectX错误号及其原因
- hdu_1711_kmp板子
- 用c++实现获取ie网页的验证码图片识别后输入到验证码框
- 数据结构第二周项目--程序的多文件组织
- hihocoder #1032 : 最长回文子串(动态规划+manacher算法)
- volatile与synchronized的区别
- win7 64位安装redis 及Redis Desktop Manager使用