(Program this season
1. StringBuffer class
2. Runtime class
3. Packaging classes and new features of JDK1.5 - Generics
4. Date operation class
5. Math class
6. Random class
1. StringBuffer (points)
When I said the String class: once the content of the String class is declared, it cannot be changed, only its address is changed. So if you have to use a loop to continuously repair the String content, you can use StringBuffer, which is also a string, but it can be repaired.
· String concatenation in the String class uses " ", while the concatenation in StringBuffer uses the append() method.
redking.blog./200903/11/27212_1236774759dAfS.png
Take a look at the effect:
redking.blog./200903/11/27212_1236774760zqsQ.png
StringBuffer is suitable when the content is constantly being repaired.
redking.blog./200903/11/27212_1236774762Hk01.png
Now let's see how it works~
redking.blog./200903/11/27212_1236774765hbiQ.png
StringBuffer cannot be directly converted into a String class target, it is necessary to call the toString() method to change a StringBuffer target into a String class target.
redking.blog./200903/11/27212_1236774768mPoi.png
redking.blog./200903/11/27212_1236774770kqXw.png
2. Runtime indicates runtime (understanding)
Only one runtime in a JVM can call some native programs through this class.
All structural methods in this class are not visible to the outside world, that is to say, the structural methods are privatized, so they are invisible.
Monomorphic --> There can only be one runtime in a full-scale JVM, so there must be a method inside it to get the Runtime target.
publicstaticRuntimegetRuntime()
redking.blog./200903/11/27212_1236774771U7Ue.png
Take a look at the effect:
redking.blog./200903/11/27212_1236774784qaYT.png
The Exec method returns a Process target
redking.blog./200903/11/27212_12367747883i5n.png
redking.blog./200903/11/27212_1236774791pnVj.png
Look at the effect: Notepad will automatically close after three seconds of opening~
redking.blog./200903/11/27212_1236774792GnSE.png
3. Packaging
A concept is proposed in JAVA: comprehensive goals, if there is such a concept, there must be an opposite:
Is the basic data type the goal? It must not be, then if you want to conform to the previous theory, it is necessary to wrap the basic data type.
redking.blog./200903/11/27212_1236774795iVnU.png
redking.blog./200903/11/27212_1236774796Omc0.png
Look at the effect: this is the use of a typical packaging class~
redking.blog./200903/11/27212_1236774797s8Nb.png
In fact, the wrapper class can wrap a basic type into a target, and it can also turn the wrapper class into a basic data type.
Integer--gt;int:publicintintValue() can be terminated
redking.blog./200903/11/27212_1236774802kVdc.png
Take a look at the effect:
redking.blog./200903/11/27212_1236774802Q5Nr.png
The above operations are done before JDK1.4, it is necessary to manually perform boxing or unboxing operations, and the packaging class cannot directly perform or - operations.
After JDK1.5, automatic boxing and unboxing operations are provided, and users do not have to call the method directly as before.
redking.blog./200903/11/27212_1236774805W0Ts.png
Take a look at the effect:
redking.blog./200903/11/27212_1236774806YMkS.png
3. Packaging classes and new features of JDK1.5 - Generics
Thinking questions:
Now the operation class that requests to terminate a coordinate has the following three coordinates:
·Integer: x=30; y=50
·Decimal: x=30.3; y=50.5
String: east longitude, north latitude
Points to consider:
For the user, you must only care about the settings of x and y. You can't say that the user can choose to set integers or decimals.
I do the above problem by overloading the method? Let's verify the overloading of the use method~
redking.blog./200903/11/27212_12367748108vdN.png
Here you can use the new function provided by JDK1.5 - generic type, which specifies the detailed operation type externally at runtime.
redking.blog./200903/11/27212_1236774815UHxw.png
redking.blog./200903/11/27212_1236774817ibBO.png
redking.blog./200903/11/27212_1236774824jLmw.png
redking.blog./200903/11/27212_1236774825uwga.png
redking.blog./200903/11/27212_1236774830Bv8A.png
redking.blog./200903/11/27212_12367748316xJc.png
4. Date operation class
get the current date
Can be terminated directly using the java.util.Date class.
redking.blog./200903/11/27212_12367748339jEM.png
redking.blog./200903/11/27212_1236774834uraZ.png
Printed Moment: TueMar1021:05:44CST2009
Such a moment looks awkward and doesn't quite fit our Chinese habits. Usually, if you use this class directly, the time you get is not very comfortable. You can directly use another class, Calendar, which can accurately measure the time to milliseconds.
Calendar is an abstract class, if it is an abstract class, it must be terminated by its subclass.
redking.blog./200903/11/27212_1236774855ep6C.png
redking.blog./200903/11/27212_1236774870Ca7P.png
redking.blog./200903/11/27212_1236774894HhMx.png
Take a look at the effect:
redking.blog./200903/11/27212_1236774898xqPa.png
Below we have a choice to delete it~
redking.blog./200903/11/27212_1236774917JgAg.png
redking.blog./200903/11/27212_1236774919mWa4.png
(2) Formatting class for date
For example, today there is one of the following moments:
2009-3-10 21:18:30:345
Display the above moment format as:
Mar 10, 2009 21:18:30 345 ms
Reformat the previous date format.
If you want to end the above functions, you can use the SimpleDateFormart class, which can use a fixed template to deduct the time.
redking.blog./200903/11/27212_12367749432xsm.png
redking.blog./200903/11/27212_12367749705OcM.png
redking.blog./200903/11/27212_1236774980GSkV.png
Let's see how it works~
redking.blog./200903/11/27212_1236774985r8Qz.png
5. Math class
Mathematical operations, but there is a method that is more common in interviews: round() method, this method is first and foremost rounding ha~~~
Rounding operation class
redking.blog./200903/11/27212_1236774995RnT0.png
Let's see how it works~
redking.blog./200903/11/27212_1236774997Dhdb.png
6, Random class, get random numbers
redking.blog./200903/11/27212_12367750129Isu.png
redking.blog./200903/11/27212_12367750166WFK.png
take a look
[Zero Basic Learning JAVA] JavaSE usage part - 34. Java common API class library.doc)