其它常用类
来源:互联网 发布:淘宝二手单反镜头骗局 编辑:程序博客网 时间:2024/06/05 10:16
import java.util.Arrays;import java.util.Properties;/* System 系统类 主要用于获取系统的属性数据。System类常用的方法: arraycopy(Object src, int srcPos, Object dest, int destPos, int length) 一般 src - 源数组。 srcPos - 源数组中的起始位置。 dest - 目标数组。 destPos - 目标数据中的起始位置。 length - 要复制的数组元素的数量。 currentTimeMillis() 获取当前系统系统。 重点 exit(int status) 退出jvm 如果参数是0表示正常退出jvm,非0表示异常退出jvm。 一般 gc() 建议jvm赶快启动垃圾回收期回收垃圾。 getenv(String name) 根据环境变量的名字获取环境变量。 getProperty(key) finalize() 如果一个对象被垃圾回收 器回收的时候,会先调用对象的finalize()方法。 */class Person{ String name; public Person(String name) { this.name = name; } @Override public void finalize() throws Throwable { super.finalize(); System.out.println(this.name+"被回收了.."); }}public class Demo1 { public static void main(String[] args) { /* int[] srcArr = {10,12,14,16,19}; //把srcArr的数组元素拷贝 到destArr数组中。 int[] destArr = new int[4]; System.arraycopy(srcArr, 1, destArr, 0,4); //System.exit(0); //jvm退出.. 注意: 0或者非0的 数据都可以退出jvm。对于用户而言没有任何区别。 System.out.println("目标数组的元素:"+ Arrays.toString(destArr)); // 0 14 16 0 System.out.println("当前的系统时间:" + System.currentTimeMillis()); System.out.println("环境变量:"+System.getenv("JAVA_HOME")); for(int i = 0 ; i<4; i++){ new Person("狗娃"+i); System.gc(); //建议马上启动垃圾回收期 } Properties properties = System.getProperties(); //获取系统的所有属性。 properties.list(System.out); */ String value = System.getProperty("os.name");//根据系统的属性名获取对应的属性值 System.out.println("当前系统:"+value); }}
/* RunTime 该类类主要代表了应用程序运行的环境。 getRuntime() 返回当前应用程序的运行环境对象。 exec(String command) 根据指定的路径执行对应的可执行文件。 freeMemory() 返回 Java 虚拟机中的空闲内存量。。 以字节为单位 maxMemory() 返回 Java 虚拟机试图使用的最大内存量。 totalMemory() 返回 Java 虚拟机中的内存总量 */public class Demo2 { public static void main(String[] args) throws IOException, InterruptedException { Runtime runtime = Runtime.getRuntime();// Process process = runtime.exec("C:\\Windows\\notepad.exe");// Thread.sleep(3000); //让当前程序停止3秒。// process.destroy(); System.out.println(" Java虚拟机中的空闲内存量。"+runtime.freeMemory()); System.out.println("Java 虚拟机试图使用的最大内存量:"+ runtime.maxMemory()); System.out.println("返回 Java 虚拟机中的内存总量:"+ runtime.totalMemory()); }}
/*日期类 Date Calendar日期格式化类 SimpleDateFormat */public class Demo3 { public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss"); String date = sdf.format(new Date()); System.out.println("当前系统时间:"+date); String birth="1993年5月6日 12:03:05"; Date date2 = sdf.parse(birth); System.out.println(date2); }}
/* Math 数学类, 主要是提供了很多的数学公式。 abs(double a) 获取绝对值 ceil(double a) 向上取整 floor(double a) 向下取整 round(float a) 四舍五入 random() 产生一个随机数. 大于等于 0.0 且小于 1.0 的伪随机 double 值 */public class Demo4 { public static void main(String[] args) { System.out.println("绝对值:"+Math.abs(-3)); System.out.println("向上取整:"+Math.ceil(3.14)); System.out.println("向下取整:"+Math.floor(-3.14)); // System.out.println("四舍五入:"+Math.round(3.54)); System.out.println("随机数:"+Math.random()); }}
0 0
- 其它常用类
- 其它常用
- 黑马程序员----Java中其它常用类
- java基础_12_Java常用的其它类
- 其它常用流对象
- NSString其它常用方法
- 第九天集合框架与常用的其它类
- 黑马程序员_常用API_String、Stringbuffer、StringBuilder、其它类
- 黑马程序员--API中常用的其它类(日期,系统参数等等)
- 黑马程序员_java基础之正则表达式及API(StringBuffer和其它常用类)
- 黑马程序员——【学习笔记】IO技术——API中其它常用的类
- VC其它- VC常用小技巧
- VC其它- VC常用小技巧
- VC其它- VC常用小技巧
- VC其它- VC常用小技巧
- VBscript常用函数——其它函数
- 黑马程序员_java其它常用对象
- Foundation框架中的其它常用细节
- Gradle设置 Java项目classpath
- SQLite3之补充
- 欢迎使用CSDN-markdown编辑器
- linux下安装redis3.2
- 输入正整数n,按从小到大的顺序输出所有形如abcde / fghij = n的表达式,其中a~j恰好为0~9的一个排列,2
- 其它常用类
- 判断一个点是否在指定区域内
- 【记录】eLua初体验
- android xml布局文件中使用RelativeLayout,明明有这个id,却提示找不到---->解决办法
- android xml布局文件中使用RelativeLayout,明明有这个id,却提示找不到---->解决办法
- 某openstack公司面试经历
- 输入正整数k,找到所有的正整数x>=y,使得1/k=1/x + 1/y; 样例输入: 2 12 样例输出: 2 1/2 = 1/6 + 1/3 1/
- redis持久化RDB和AOF
- postgresql的一些使用技巧