星空网 > 软件开发 > Java

常见类

package CommonClassPart;import java.io.File;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class CommonClass {      public static void main(String[] args) {    CommonClass cc = new CommonClass();    cc.datePart();    cc.showDividedLine();    cc.stringBufferPart();    cc.showDividedLine();    cc.CalenderPart();    cc.showDividedLine();    cc.filePart();  }  private void filePart() {        File file = new File("f://tryFile");    if(file.exists()){      System.out.println("该资源已经存在");      if(file.isDirectory()){        System.out.println(file.getName()+"是一个目录");      }else{        System.out.println(file.getName()+"是一个文件");      }    }else{      file.mkdir();      System.out.println("创建该目录成功");    }      }  private void CalenderPart() {    Calendar calendar = Calendar.getInstance();    Date time = calendar.getTime();    System.out.println(time);    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    System.out.println(sdf.format(time));      }  private void showDividedLine(){    System.out.println("--------------------------");  }    private void stringBufferPart() {    /**     * 反正都要阐述final关键字的问题就直接在这里面说了吧。     */        final StringBuffer sb = new StringBuffer("this is a string");     sb.append(",and can be modified");    System.out.println(sb);    System.out.println("所以我们可以看到,当一个对象被final修饰以后,它的引用的地址的值是不可以被改变的,但是引用的内容的值是可以改变的。");  }  private void datePart(){        /**     * 之前做过一个东西,要求实时获取服务器端的时间,作为用户的注册时间,当时写了一个死的时间,并没有真的实现,现在利用这个Date来实现一下。     */    User user = new User();    user.setUserId(1);    user.setUserName("lifei");    user.setUserPassword("lifei");        Date date = new Date();    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");    System.out.println(sdf.format(date));    System.out.println(date);        user.setUserRegisterTime(sdf.format(date));        System.out.println(user);    /**     * 这样就可以把这个数据,以一定的格式存储在 数据库里面了。     * 日历类,StringBuffer类。还有很多。因为后面没怎么用到,或者应用的时候再说吧,前面提到了关于 StringBuffer的一个事情,其实后面用到的主要是拼接字符串用于数据库中语句的查询,以及当应用final关键字修饰以后,具体什么不可以被更改。这样的一些问题     */          }}

 

运行结果:

2016-02-06
Sat Feb 06 14:38:33 CST 2016
User [userId=1, userName=lifei, userPassword=lifei, userRegisterTime=2016-02-06]
--------------------------
this is a string,and can be modified
所以我们可以看到,当一个对象被final修饰以后,它的引用的地址的值是不可以被改变的,但是引用的内容的值是可以改变的。
--------------------------
Sat Feb 06 14:38:33 CST 2016
2016-02-06 14:38:33
--------------------------
创建该目录成功

 




原标题:常见类

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

Intermarche:https://www.goluckyvip.com/tag/21550.html
INTERMIX:https://www.goluckyvip.com/tag/21551.html
International Bridge:https://www.goluckyvip.com/tag/21552.html
International Shopping Feature 跨国购物功能 :https://www.goluckyvip.com/tag/21553.html
internethobbies:https://www.goluckyvip.com/tag/21554.html
INTEROUGE:https://www.goluckyvip.com/tag/21555.html
凌晨三点到天津西站可以去哪里? :https://www.vstour.cn/a/410229.html
Temu广告投入上千万美元, 在美知名度高达88%!:https://www.kjdsnews.com/a/1842236.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流