java常用类(Runtime类与System类)-小白学习中

Runtime类

Runtime描述的是运行时状态,在每一个JVM进程中都会提供唯一的一个Runtime类实例化对象,所以想要获取Runtime类的实例化对象就必须使用Runtime类中提供的getRuntime()方法。

方法:
public static Runtime getRuntime();
获取Runtime类的实例化对象。

Runtime runtime=Runtime.getRuntime();

public int availableProcessors();
获取可用的CPU处理器数量。

int cpu=runtime.availableProcessors();
System.out.println(“cpu:”+cpu);

public long maxMemory();
获取最大可用内存量。以字节为单位。

long max=runtime.maxMemory();

public long totalMemory();
获取总共可用内存量。

long total=runtime.totalMemory();

public long freeMemory();
获取空闲内存量。

long free=runtime.freeMemory();

public void gc();
运行垃圾收集器,释放垃圾空间。

runtime.gc();

System类

System是一个系统类,主要功能是进行信息的输入和输出。
输入:System.in

Scanner scanner=new Scanner(System.in);

输出:System.out或System.err

System.out.println(“hello”);//黑字
System.err.println(“hello”);//红字

其他常用方法:

public static void arraycopy(Object a,int a1,Object b,int b1,int length);
数组复制。(原数组名称,原数组开始点,目标数组名称,目标数组开始点,需要复制的长度)。

String string=“hello word”;
char[] a=string.toCharArray();//字符串转换为字符数组
char[] b = new char[4];
System.arraycopy(a,6,b,0,4);

public static long currentTimeMillis();
获取当前时间。返回毫秒数。

long l=System.currentTimeMillis();

public static void gc();
释放垃圾空间。

System.gc();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值