JAVASE----13----其他对象

来源:互联网 发布:怎么移民 知乎 编辑:程序博客网 时间:2024/05/26 12:58
System:
import java.util.Properties;public class SystemDemo {/*System 类中的方法和属性都是静态的 * out:标准输出,默认是控制台。 * in:标准输入,默认是键盘 *  * 描述系统一些信息, * 获取系统属性信息: Propertirs getPropertirs(); */public static void main(String[] args) {Properties prop=System.getProperties();//因为 Properties是Hashtable的子类,也就是Map集合的一个子类对象。//那么可以通过map的方法去除该集合中的元素。//该集合中存储的都是字符串。没有泛型定义。//如何在系统中自定义一些特有信息呢?System.setProperty("mykey", "myValue");   for(Object obj :prop.keySet())   {   String value=(String)prop.get(obj);  // System.out.println(obj+"::"+value);   }    //获取指定属性信息。String value=System.getProperty("os.name");  System.out.println(value);  //Windows XP    }}

Runtime:


import java.io.IOException;public class RuntimeDemo {/** * Runtime 对象 * 该类并没有构造函数,说明不可以new对象。那么会直接想到该类中的方法是静态的。、 * 发现该类中还有非静态方法。说明该类肯定会提供了方法获取本类对象。而且该方法是静态的,并且返回值类型是 * 本类类型。 * 由这个特点可以看出该类使用了单例设计模式完成。 * 该方法是:static Runtime getRuntimr(); * @throws InterruptedException  *  */public static void main(String[] args) throws IOException, InterruptedException {Runtime r=Runtime.getRuntime();//Process p=r.exec("D:\\应用程序\\Tencent\\QQProtect\\Bin\\QQProtect.exe");//Thread.sleep(5000);////p.destroy();r.exec("notepad.exe  SystemDemo.java");}}


Math:

import java.util.Random;public class MathDemo {/** * @param args */public static void main(String[] args) {  //ceil 返回大于指定数据的最小整数。           double d= Math.ceil(16.34);  //17           //floor 返回小于指定数据的最大整数。           double d1=Math.floor(12.34);  //12           sop("d="+d);           sop("d1="+d1);                        //四舍五入           long l=Math.round(12.54);  //13           sop("l="+l);                                   double d2=Math.pow(2,3);  //8.0           sop("d2="+d2);                        //           for(int x=0;x<10;x++)//           {//           int d5=(int)(Math.random()*10+1);//           sop(d5);//伪随机//           }           Random r=new Random();           for(int x=0;x<10;x++)           {            int d5=r.nextInt(10)+1;            sop(d5);           }           }public static void sop(Object obj){System.out.println(obj);}}


Date:

import java.text.SimpleDateFormat;import java.util.Date;public class DateDemo {/** * @param args */public static void main(String[] args) {Date d=new Date();System.out.println(d);  //Mon Apr 08 17:44:33 CST 2013//将模式封装在SimpleDateFormat对象中。SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日E"); //调用format方法,让模式格式化指定Date对象。String time =sdf.format(d);System.out.println(time); //2013年04月08日星期一}}


Calendar:

import java.util.Calendar;public class CalendarDemo {/** * @param args */public static void main(String[] args) {String []mons={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};        Calendar c=Calendar.getInstance();        System.out.println( c.get(Calendar.YEAR)+"年");//2013年        int index=c.get(Calendar.MONTH);        System.out.println(mons[index]);//四月        System.out.println( c.get(Calendar.DAY_OF_MONTH)+"日");//8日}}


原创粉丝点击