Dark Horse programmer ---------- other java-based classes, dark horse ---------- java

Source: Internet
Author: User

Dark Horse programmer ---------- other java-based classes, dark horse ---------- java
------- Android training, java training, and hope to communicate with you! ----------

I,System

Usage of the System class:

/* System: the methods and Properties in the class are static out: standard output. The default value is console in: standard input. The default value is the keyboard to obtain the System property information: Properties getProperties (); */import java. util. *; class SystemDemo {public static void main (String [] args) {Properties prop = System. getProperties (); // customize some special information in the System. setProperty ("mykey", "myvalue"); // obtain the specified property information String value = System. getProperty ("OS. name "); System. out. println ("value =" + value); // obtain all attribute information for (Object obj: prop. keySet () {String value = (String) prop. get (obj); System. out. println (obj + ":" + value) ;}// other objects in the Java Foundation: System // usage of the System class :}

Ii. Runtime

Runtime object
This class does not provide constructor, indicating that new objects cannot be created. The method in this class is static.
It is found that there are non-static methods in this class, indicating that this class will certainly provide methods to obtain the class objects, and this method is static, and the return value type is the class type.
From this feature, we can see that this class is completed using the singleton design mode.

The following code practices:

class RuntimeDemo{public static void main(String[] args)throws Exception{Runtime r = Runtime.getRuntime();Process p=r.exec("notepad.exe SystemDemo.java");Thread.sleep(4000);p.destroy();}}
Iii. Date and Calender

In our daily life, date is very important, so a large part of programming is also related to date, such as querying, deleting, and adding by date. Therefore, date operations are very important. Accurate to milliseconds.

SimpleDateFormat sdf = new SimpleDateFormat ("yyyy MM dd e hh: mm: ss"); // SimpleDateFormat is in the java. text package
You can use SimpleDateFormat to format a date, or use this class to obtain a single attribute of a date. For example, SimpleDateFormat ("yyyy") only obtains the year.
Note: E indicates the day of the week. You do not need to write it as week E. Because E has been localized, E will get "Monday" directly"

Date:

Public static void main (String [] args) {Date d = new Date (); System. out. println (d); // The printed time does not conform to our habits, so we have the following formats // encapsulate the pattern into SimpleDateformat objects. SimpleDateFormat sdf = new SimpleDateFormat ("MM dd, yyyy"); // call the format method to format the specified Date object in the format. String time = sdf. format (d); System. out. println ("time =" + time );}
Calender:
<Span style = "font-size: 14px;"> class CalendarDemo {public static void sop (Object obj) {System. out. println (obj);} public static void main (String [] args) {Calendar c = Calendar ar. getInstance (); String [] mons = ", "August", "August"}; String [] weeks = {"", "Sunday", "Monday ", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; int index = c. get (Calendar. MONTH); int index1 = c. get (Calendar. DAY_OF_WEEK); sop (c. get (Calendar. YEAR) + "YEAR"); // sop ("Week" + c. get (Calendar. DAY_OF_WEEK); sop (weeks [index1]); sop (pattern (c); // display today's date and current time c. add (Calendar. YEAR, 3); // sop (pattern (c) after the YEAR is changed to 3 years; // display the specified date and time }}</span>

4. Math's method for providing numbers

Knowledge learned from videos:

Class MathDemo {public static void sop (Object obj) {System. out. println (obj);} public static void main (String [] args) {for (int x = 0; x <10; x ++) {int d = (int) (Math. random () * 10 + 1); // generate a random number from 1 to 10 sop (d);} public static void show () {double d = Math. ceil (16.56); // ceil returns the smallest integer greater than the specified data, double d1 = Math. floor (13.45) // floor returns the maximum integer long l = Math. round (12.415); // rounding sop ("d =" + d); sop ("d1 =" + d1); sop ("l =" + l ); double d2 = Math. pow (2, 3); // returns the 2's power-3 sop ("d2 =" + d2 );}}

------ Android training, java training, and hope to communicate with you! ----------

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.