找回密码
 立即注册
redking20090327212blog | 企业管理 2022-09-23 94 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
本季方案
1、StringBuffer类
2、Runtime类
3、包装类与JDK1.5的新特性——泛型
4、日期的操作类
5、Math类
6、Random类
1、StringBuffer(要点)
·String类的时候说过:String类的内容一旦声明则不行改动,改动的仅仅其地址。那么假如如今非要使用循环不断的修复String内容的时候,则就可以使用StringBuffer,也是一个字符串,可是可以修复。
·String类中的字符串连接使用的是“+”,而StringBuffer中的连接使用的是append()方法。
redking.blog./200903/11/27212_1236774759dAfS.png
看下作用:
redking.blog./200903/11/27212_1236774760zqsQ.png
在内容会不断修复的时候使用StringBuffer比较适合。
redking.blog./200903/11/27212_1236774762Hk01.png
如今再看下作用哈~
redking.blog./200903/11/27212_1236774765hbiQ.png
StringBuffer是不能直接转成String类目标,有必要调用toString()方法才可以把一个StringBuffer的目标变为String类的目标。
redking.blog./200903/11/27212_1236774768mPoi.png
redking.blog./200903/11/27212_1236774770kqXw.png
2、Runtime表明运行时(理解)
在一个JVM中只要一个运行时,可以通过此类调用本机的一些程序。
此类中所有的结构方法对外部不行见,也即是说结构方法被私有化了,所以看不见。
单态--gt;在全面JVM中只能有一个运行时,所以其内部必定有一个方法可以获得Runtime目标。
publicstaticRuntimegetRuntime()
redking.blog./200903/11/27212_1236774771U7Ue.png
看下作用:
redking.blog./200903/11/27212_1236774784qaYT.png
Exec方法回来的是一个Process目标
redking.blog./200903/11/27212_12367747883i5n.png
redking.blog./200903/11/27212_1236774791pnVj.png
看下作用:记事本打开三秒后自动关闭了哈~
redking.blog./200903/11/27212_1236774792GnSE.png
3、包装类
在JAVA中提出了一种概念:全面皆目标,假如有此概念的话,则必定有个对立点:
基本数据类型是目标吗?必定不是,那么此刻假如要契合之前的理论,则有必要把基本数据类型进行包装。
redking.blog./200903/11/27212_1236774795iVnU.png
redking.blog./200903/11/27212_1236774796Omc0.png
看下作用:这即是典型包装类的使用哈~
redking.blog./200903/11/27212_1236774797s8Nb.png
实际上包装类即可以把一个基本类型包装成目标,也可以把包装类变为基本数据类型。
Integer--gt;int:publicintintValue()可以终结
redking.blog./200903/11/27212_1236774802kVdc.png
看下作用:
redking.blog./200903/11/27212_1236774802Q5Nr.png
以上的操作在JDK1.4之前都是这样做的,有必要手工进行装箱或拆箱操作,并且包装类是不能直接进行++或—操作的。
在JDK1.5以后提供了自动的装箱和拆箱操作,用户不必像之前那样有必要直接调用方法终结了。
redking.blog./200903/11/27212_1236774805W0Ts.png
看下作用:
redking.blog./200903/11/27212_1236774806YMkS.png
3、包装类与JDK1.5的新特性——泛型
思考题:
如今请求终结一个坐标的操作类,有以下三种坐标:
·整数:x=30;y=50
·小数:x=30.3;y=50.5
·字符串:东经,北纬
考虑点:
关于用户而言,必定只关怀x和y的设置,你不能说让用户自己去选择设置整数或小数等。
以上问题我通过方法的重载做?我们验证一下使用方法的重载哈~
redking.blog./200903/11/27212_12367748108vdN.png
此处就可以使用JDK1.5提供的新功能——泛型,在运行的时候由外部指定详细的操作类型。
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、日期的操作类
获得当时的日期
可以直接使用java.util.Date类终结。
redking.blog./200903/11/27212_12367748339jEM.png
redking.blog./200903/11/27212_1236774834uraZ.png
打印的时刻:TueMar1021:05:44CST2009
这样的时刻看起来很别扭,不太契合我们中G人的习气。通常直接使用此类的话,得到的时刻不是很舒畅,可以直接使用别的一个类——Calendar,此类可以把时刻准确到毫秒。
Calendar是一个抽象类,假如是抽象类,则此处必定使用其子类终结。
redking.blog./200903/11/27212_1236774855ep6C.png
redking.blog./200903/11/27212_1236774870Ca7P.png
redking.blog./200903/11/27212_1236774894HhMx.png
看下作用:
redking.blog./200903/11/27212_1236774898xqPa.png
下面我们有选择滴进行删减哈~
redking.blog./200903/11/27212_1236774917JgAg.png
redking.blog./200903/11/27212_1236774919mWa4.png
(2)日期的格式化类
例如,如今有以下一个时刻:
2009-3-1021:18:30:345
将以上的时刻格式显示为:
2009年3月10日21点18分30秒345毫秒
把之前的日期格式重新格式化了一下。
假如要终结上面的功能,则就可以使用SimpleDateFormart类,此类可以使用固定的模板把时刻扣出来。
redking.blog./200903/11/27212_12367749432xsm.png
redking.blog./200903/11/27212_12367749705OcM.png
redking.blog./200903/11/27212_1236774980GSkV.png
看下作用哈~
redking.blog./200903/11/27212_1236774985r8Qz.png
5、Math类
数学操作类,可是在面试中里边有一个方法比较常见:round()方法,这个方法首要即是四舍五入哈~~~
四舍五入的操作类
redking.blog./200903/11/27212_1236774995RnT0.png
来看下作用哈~
redking.blog./200903/11/27212_1236774997Dhdb.png
6、Random类,获得随机数
redking.blog./200903/11/27212_12367750129Isu.png
redking.blog./200903/11/27212_12367750166WFK.png
看下
[零基础学JAVA]JavaSE使用部分-34.Java常用API类库.doc

(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)

[下载]10542833549.rar




上一篇:Spring快速入门pdf下载
下一篇:java 设计模式(续)