2017.03.07

1.写api接口时,注意返回值定义问题。比如delete接口,就要返回Boolean类型。类似还有canRead(),canWrite(),canExecute()
2.写api注意定义合适的方法返回值,file.getName();返回值就是string
3.simpledateformat format(date)的返回值是string。返回日期类型的字符串。
String finalDateString = sdFormat.format(date);返回值string类型
4.simpledateformat的format参数是date类型,日期类型
5.那怎么创建date日期类型呢?通过long构造函数的参数,long代表了从格林威治时间到现在的毫秒数。
Date date = new Date(System.currentTimeMillis());


6.综上获取当前的代码,就几行。为:
long nowMillSeconds = System.currentTimeMillis();
Date date = new Date(nowMillSeconds);
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
String finalDateString = sdFormat.format(date);
System.out.println("final time is" + finalDateString);

7.获取当前时间,就要用到四个类:long,date,simpledateformat,string。
8.java 的string里包含了数据和html换行/空格等标签,怎么将这些html标签删除呢?
答:用string的replaceAll("a","b")方法。
另外提醒一点哦,string的replaceAll()方法,spilt()方法,操控完字符串后,都生成了一个新的string。
string是final的,不可修改的。
public String subStringHTML(String con,int length,String end) {
String content = "";
if(param!=null){
content=con.replaceAll("</?[^>]+>","");//剔出了<html>的标签
content=content.replace("&nbsp;","");
content=content.replace(".","");
content=content.replace(""","‘");
content=content.replace("'","‘");
if(content.length()>length){
content=content.substring(0,length)+end;
}
}

9.创建自定义异常的关键和用处在于,catch语句捕获异常时,能根据具体的异常,捕获自己的异常,按自己的异常流程处理,而不是全都显示jdk异常。
很生硬的catch语句走jdk异常。
编写自定义异常类实际上是继承一个API标准异常类,用新定义的异常处理信息覆盖原有信息的过程。
10.自定义异常,自己抛出。单独的类,和异常不相干的类或者方法,异常和任何类和方法都不相干。是单独的,孤立的。只有你再自己的业务类中,涉及到哪些业务异常了,再
随时抛出引入你这个自定义异常。

11.在方法里,如果你自定义throw抛出一个异常了。那么你就要用thows在方法上,声明这个方法是会抛出哪个类的。
如下:
public List<String> listFiles(File file) throws FileNotDirectoryException
{
if (!file.isDirectory())
{
logger.info("destination file" + file.getName() + "is not a directory");
throw new FileNotDirectoryException();
}
return null;
}

10.代码中不要用for原始循环,要用for each循环。for each循环的方便之处在于,你能用每个each对象的方法,去获得每个each的属性。
11.突然才醒悟,为什么有file类的存在了,file类,封装了io流啊,file类是可以读取部分file信息的,比如name之类的,但是不能读取file里的文字内容,这就需要
fileinputstream了。
file类有点类似于properties类。

原文地址:https://www.cnblogs.com/panxuejun/p/6516126.html