The first system and runtime class
Overview:
1. System is a class that describes some of the information in the systems, and the properties and methods in the class are static. cannot be instantiated, no constructors are provided
2.
Out: Standard output stream, default screen
In: Standard input stream, default is keyboard
Method:
1. Get the property information of the system
Propertiesgetproperties ();
Description
1) The method returns the double column set, the key and the value, because the properties is a subclass of Hashtablee, so it can get the set elements by the map method;
2) The collection stores all the strings. No definition of generics
2. Get the specified attribute information
Stringgetproperty (Key)
3. Define unique information within the system
Stringsetproperty (Key,value)
4, how to load the property information when the JVM starts
Java-d "Name" = "Value" program to set specific system property information
Runtime class
Overview:
1. Each Java application has a runtime instance that uses the application to connect to the environment in which it is running.
An application cannot create its own instance of the runtime class, which is created by itself at the bottom of the system;
2. No constructors are provided in this class. The description cannot be a new object, but not all static. So there must be a static
method to obtain this type of object.
3, this is also a single case design pattern of a
Method:
1) Static Runtime GetRuntime ()
2) Process exec (String Command)
3) void Destroy ();//Note You can only end Java-enabled programs
Give me a chestnut:
PackageSystem;ImportJava.util.*; Public classSystemdemo { Public Static voidMain (string[] args)throwsexception{//Properties p=system.getproperties ();//Obtaining System Information for the system//System.out.println (p); //String value=system.getproperty ("Os.name");//gets the key value for the OS. Name value, which is the system-specified//System.out.println (value);// //System.setproperty ("I Cloud", "water tone");//System.out.println (p);//runtime class //String s=system.getproperty ("I Cloud");//System.out.println (s);Runtime r=runtime.getruntime ();//using the static method to obtain this class of object process P=r.exec ("Uedit32.exe Systemdemo.java");//Execute Notepad program Thread.Sleep (40000);//wait 40000 milliseconds p.destroy ();//program P end}}
Second Lecture time class
Date class
1, Overview: The date class represents the characteristics of the instant Java specific format such as: Mon June 20:35:21 CST2014
2. Custom Format
The default format is not practical, and we need to do this with the Format method in DateFormat
Calendar class
1, Overview: Calendar is an abstract class, more useful than date
2, Basic access methods:
1) Year: Calendar.year
2) Month: Calendar.month
3) Date: Calendar.day_of_month
4) Week: Calendar.day_of_week
5) Hours: Calendar.hour_of_day
6) Minutes: Calendar.minute
7) Seconds: Calendar.second
Set the time
1) void set (Year,month,day)
2) int Add (calendat.day_of_month,-1); push him up a day
3) void set (calendat.day_of_month,3); Set this day to 3;
4) int get (int field)//Get some data
Raise some chestnuts:
Package System;import Java.util.*;import java.text.*;p ublic class Timedemo {public static void main (string[] args) {Date d =new date ();//Gets the time object, which is to get the present time System.out.println (d);//Take a look at its format SimpleDateFormat sdf=new SimpleDateFormat ("yyyy year" + " MM month DD Day e HH:mm:ss ");//variable format string Time=sdf.format (d);//sdf format is used for D, and then to the String class TimeSystem.out.println (time);// Take a look at another method Calendar c=calendar.getinstance ();//also obtain the present time, note is the static method Getinstancec.set (2015,1,1);// Set time February 1, 2015 System.out.println (pattern (c));//show Current time C.add (calendar.year,3);//Add three years System.out.println (pattern (c) );///Custom pattern method}//Gets the specified date and time private static string pattern (Calendar c) {//Get time string S=nian (c) +yue (c) +ri (c) + "" +time ( c); return s;} private static String time (Calendar c) {String time=c.get (calendar.hour_of_day) + ":" +c.get (Calendar.minute) + ":" +c.get (Calendar.second); return time;} private static String ri (Calendar c) {String s=c.get (calendar.day_of_month) + "Day"; return s;} private static String Yue (Calendar c) {//tabular method, available for the week, can be used for lowercase capitalization string[] yue={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};return Yue[c.get (Calendar.month)]; private static string Nian (Calendar c) {//Get year String s = C.get (calendar.year) + "year"; return s;}}
Do 3 little exercises.
1 /*Practice:2 * 1, how many years to obtain any year3 * C.set (yue,2,1)//March 14 * C.add (calenar.day_of_month,-1);5 * C.get (calendar.day_of_month);6 * 2, get the day before the present moment7 * C.add (calenar.day_of_month,-1);8 * 9 * 3, calculate the number of days of classTen * Ideas: 1) Set two time classes such as: C1.set (2013,5,5); C2.set (2144,4,4); One 2) Cycle in C1.get (calendar.day_of_month)!=c2.get (calendar.day_of_month) A and C1.add (calendar.day_of_month,1) to traverse the non-weekend days, counted in the Int type count - 3) returns the Count - * the */ - Public classTestdemo { - Public Static voidMain (string[] args) { -Eryue (2015);
Lastime ();
Howday (2013,5,5,2014,5,4);//From May 5, 2013 to May 4, 2014 + } - + Public Static intEryue (intYear) {//Get February days ACalendar c=calendar.getinstance (); atC.set (year,2,1); -C.add (calendar.day_of_month,-1); - returnC.get (calendar.day_of_month); - } - //get the day before - Public StaticString Lasttime () { inCalendar c=calendar.getinstance (); -C.add (calendar.day_of_month,-1); to returnpattern (c); + } - the //Calculate effective Days * Public Static inthowday (int y,int m,int d,int y2,int m2,int D2) { $Calendar c1=calendar.getinstance ();Panax NotoginsengCalendar c2=calendar.getinstance (); -C1.set (y,m,d); theC2.set (y2,m2,d2); + intCount=0; A the for(; C1.get (calendar.day_of_month)! =c2.get (calendar.day_of_month) +; C1.add (calendar.day_of_month,1)){ - if(C1.get (Calendar.day_of_week)!=1&&c1.get (Calendar.day_of_week)!=7) $count++; $ } - - returncount; the } - Private StaticString pattern (Calendar c) {//Get TimeWuyiString S=nian (c) +yue (c) +ri (c) + "" +Time (c); the returns; - } Wu Private StaticString Time (Calendar c) { -String Time=c.get (Calendar.hour_of_day) + ":" +c.get (Calendar.minute) + ":" + About C.get (calendar.second); $ returnTime ; - } - Private StaticString ri (Calendar c) { -String S=c.get (Calendar.day_of_month) + "Day"; A returns; + } the Private StaticString Yue (Calendar c) {//Get month -String[] yue={"January", "February", "March", "April", "May", "June", "July", "August", $"September", "October", "November", "December"}; the returnYue[c.get (Calendar.month)]; the } the Private StaticString Nian (Calendar c) {//Get year theString s = c.get (calendar.year) + "year"; - returns; in } the}
The third lecture is the math class
I. Overview
The math class is the most basic execution of the property Run method
Second, the method
1, double ceil (double d); Returns the smallest shape greater than the specified data, such as 1.6 returns -1,1.6 returns 2.0
2. Double floor (double d);//returns the maximum positive number that is less than the specified data
3. Double Pow (double a,double b);//a B-square
4, long round (double b); rounding
5, double random (), greater than 0 is less than 1.0 of the stochastic number;
1 PackageSystem;
Do exercises2 /*given a decimal, keep the last n bits of the decimal point3 * 1, first multiplied by 10 of the N-square, and then rounded;4 * 2, divide this by 10 of the n-th square;5 */6 Public classXiaos {7 Public Static voidMain (string[] args) {8 //double D=baoniu (12.1564,2);9 //System.out.println (d);Ten // } One // A //private static Double Baoniu (double d, int i) { - //Double D1=d*math.pow (d, 2); - //long L=math.round (D1); the //return L/math.pow (d, 2); -System.out.println (Math.ceil (1.6)); -System.out.println (Math.Round (2.4) + "--" +math.round (2.6)); -System.out.println (Math.floor (2.4) + "-=-" +math.pow (2.6,4)); + for(inti=0;i<10;i++) -System.out.println (Math.random () *10); + //Rounding Exercises ASYSTEM.OUT.PRINTLN (Retention (13.654,2)); at } - - Private Static DoubleRetentionDoubleDinti) { - DoubleD1=d*math.pow (ten, I);//move the decimal point forward I bit - LongL=math.round (D1);//rounding after decimal point - returnL/math.pow (ten, I);// in } -}
Dark Horse Programmer--java Basics--Other streams