Package Pack;import Java.text.simpledateformat;import Java.util.calendar;import java.util.date;import Java.util.properties;import Java.util.random;public class Main {public static void main (string[] args) throws Exceptio n {//method1 (); Systemy object//method2 (); Runtime Object//method3 (); Data class//METHOD4 (); Method5 (); Method6 (); Math class} public static void Sys (Object obj) {System.out.println (obj); } public static void Method1 () {Properties prop = System.getproperties ();//properties is a subclass of Hashtable, key value fo R (Object Obj:prop.keySet ()) {sys (obj+ ":" +prop.get (obj)); Read System Properties} system.setproperty ("MyKey", "myvalue"); Set the property itself String OS = System.getproperty ("Os.name"); SYS (OS); Output WINDOW7 sys (System.currenttimemillis ()); Current time} public static void Method2 () throws Exception {Runtime RT = Runtime.getruntime (); Rt.exec ("F:\\1.txt"); Process p = rt.exec ("notepad.exe"); Open file Thread.Sleep (4000); Pause 4 seconds P.destroy (); Close process} public static void Method3 () {Date d = new Date (); SYS (d); SYS (D.gettime ()); SimpleDateFormat SDF = new SimpleDateFormat ("Y years mm D Day E hh:mm:ss"); Format SYS (Sdf.format (d)); } public static void Method4 () {Calendar c = calendar.getinstance (); SYS (C.gettime ()); SYS (C.get (calendar.year) + "-" +c.get (Calendar.month)); Gets the key to get the value C.add (Calendar.day_of_month, 4);//Current date plus 4 days} public static void Method5 () {Calendar c = Calen Dar.getinstance (); C.set (2014,3,1); Setting time is C.add (Calendar.day_of_month,-1); 3.1 Before the number, that is, how many days C.add (calendar.year,5) was calculated for the year February; Added 5 sys (C.get (calendar.year)); Gets the key to get the value of sys (C.get (calendar.day_of_month)); } public static void Method6 () {sys (math.e+ "---" +math.pi); Double d = Math.ceil (12.46); Take the smallest integer greater than the specified dataDouble D1 = Math.floor (12.46);//Take the maximum integer less than the specified data double d2 = Math.Round (12.45);//Rounding Sys (MATH.POW (2,3)); Power Operation SYS (D1); for (int i=0;i<10;i++) {Double d3 = Math.random () *10; SYS (D3); } Random R = new Random (); for (int i=0;i<10;i++) {int d4 = R.nextint (8); Range 0~8 sys (d4); } }}
Java Common classes