Lecture 1: System Classes
I. overview
1. System is a class describing some information of the system. The attributes and methods in the class are static. Cannot be instantiated, no constructor is provided.
2. Field Summary
out: Standard output stream. The default is the console.
in: Standard input stream. The default is the keyboard.
Two, method
1. Obtain the attribute information of the system:
PropertiesgetProperties();
Explain:
1) The double-column set returned by this method is the key-value pair; since Properties is a subclass of Hahstable, that is, a subclass object of the Map set, the elements in the set are extracted by the Map method.
(2) The collection stores strings without generic definitions
2. Get the specified attribute information:
String getProperty(Stringkey);
3. Define specific information within the system:
String setProperty(Stringkey,String value);
4. How to load some attribute information when the jvm starts up:
Command: java-D<name>=<value> can set unique system attribute information
Example:
Lecture 2: Runtime classes
I. overview
1. Every java application has an instance of Runtime class, which can be connected with the environment in which it runs. The application can not create its own instance of Runtime class, which is created by the bottom of the system.
2. Constructors are not provided in this class. Explain that new objects are not allowed. Then it comes to mind that the methods in this class are static. Looking at the API documentation, we found that there are also non-static methods in this class. It shows that this kind of method will certainly provide a way to get the original object. Moreover, the method is static and the return value type is the original type.
3. It can be seen from the above characteristics that this kind of design is accomplished by using the singleton design pattern.
Two, method
1. Get this class of objects
static RuntimegetRuntime();
2. Executing the specified string command in a separate process
Processexec(String command);
3. In Process, there is a way to kill the child process, which can end the process opened by the exec method.
void destroy();
Example:
Lecture 3 Time Class
I. Date class
1. Overview
The Date class represents a specific instant, accurate to milliseconds.
The default display format in java is: Mon Jun 1022:35:21 CST 21013
2. Custom Format
The default format does not necessarily meet everyone's needs, so you need to customize the formatting mode. Because most of the methods in the Date class are out of date, only its subclasses can be found to implement them. The format method can be implemented in the subclass DateFormat, but DateFormat is an abstract class and cannot be instantiated. But there's a SimpleDateFormat subclass below, which defines the time pattern.
Specific steps:
Create Date objects
2) Encapsulate time patterns into SimpleDateFormat objects
3) Call format method to let format mode specify Date object
The code is as follows:
II. Carendar Classes
1. Overview:
Calendar is an abstract class that provides some methods for the conversion of a particular instant to a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH.
2) Calendar can acquire the time of year, month, day and so on. The corresponding subsection values are also provided. Refer to the API documentation.
2. Methods:
2.1. Basic acquisition time
1) Year of acquisition: Calendar.YEAR
2) Access month: Calendar.MONTH
3) Get date: Calendar.DAY_OF_MONTH
4) Access Week: Calendar.DAY_OF_WEEK
5) Get hours: Calendar.HOUR_OF_DAY
6) Get minutes: Calendar.MINUTE
7) Get seconds: Calendar.SECOND
2.2. Setting time:
1) According to calendar rules, add or subtract the specified amount of time for a given calendar field:
void add(int field,int amount);
2) Get the corresponding time value for the specified calendar field:
int get(int field);
3) Set the time value corresponding to a given calendar field to a given value:
void set(int field,int value);
Set the values of the calendar fields YEAR, MONTH and DAY_OF_MONTH:
void set(int year,int month,int date);
Example:
Little exercise:
Lecture 4. Math Class
I. overview
Math classes contain methods for performing basic mathematical operations, such as elementary exponents, logarithms, square roots, and triangular functions. This class is all static methods.
Two, method
1. doubleceil(double d); //Returns the smallest integer greater than the specified data
2. Double floor (double d); //Returns the largest integer less than the specified data
3. Double pow (double a, double b); //Return the b-th power of a
4. long round(doubleb); //Returns the value rounded by b.
5. doublerandom(); // returns a positive double value, which is a random number greater than or equal to 0.0 and less than 1.0
III. Random Classes
This is a separate class in java.util that is used to get random numbers. The random method in Math is the same, but this class has its own method, which can strongly convert the corresponding random number to the specified basic data type.
For example: intnextInt(int n); / / Returns a pseudo-random number, which is an int value evenly distributed between 0 (including) and specified value (excluding) from this random number generator sequence.
Little exercise: