JAVA豆知识

--java知识点---

2017/06/08 Java_从指定的目录下拷贝所有指定类型文件到output目录

2017/04/20

===导入的包的源码加入方法===============================

 导入的包的源码加入方法(如mybatis的源码):

properties->Java Build Path->Libraries->mybatis包-Source attachment ...-edit-下载的源码的根目录层mybatis-3-mybatis-3.4.4-OK

===LOG4J===========================

Log4j:日志输出 。Jar包和配置文件(log4j.properties放入src根目录下,(指定其他路径时,需要配置))

MyBatistsjar包的logging.LogFactory.class源码,定义了各种LOG的接口,其中包含Log4j,所以配置好Log4j 之后就可以打印LOG了

 

 properties文件 key=value

//级别

logger log;
//级别由低到高
log.debug("adf");
log.info(message);
log.warn(message);
log.error(message);

//大于等于DEBUG级别的都输出

log4j.rootLogger=DEBUG,Console//整个工程的级别//Console,输出位置是控制台。DEBUG级别的原因:参照jar包的logging.jdbc下的类的源码,比如ConnectionLogger.class的源码里,是用debug()出力的,所以不能高于这个级别,否则不会打印Log。
log4j.appender.Console=org.apache.log4j.ConsoleAppender//配置此类才会输出到控制台(log4j.rootLogger=DEBUG,A
log4j.appender.A)
log4j.appender.Console.layout=org.apache.log4j.PatternLayout//布局
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n//布局自定义

(%d [%t] %-5p [%c] - %m%n,%开头的有特殊含义,[]空格-等都是原样输出。%d产生时间 %t所处线程名称,%-5p:%p输出的级别,-5表示输出的字符至少占5位,不足用空格补齐,“-”表示补齐的空格在右边,没有“-”的话,空格就在左边。%c输出日志时的类全名+包名 %n换行%m输出时附加的信息)
log4j.logger.org.apache=INFO//org.apache为包名,为org.apache包下配置为INFO级别

 导入的包的源码加入方法(如mybatis的源码):

properties->Java Build Path->Libraries->mybatis包-Source attachment ...-edit-下载的源码的根目录层mybatis-3-mybatis-3.4.4-OK

===LOG4J==============================

---日期格式-------------------------------------------------------

package spring.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Set;

import org.junit.Test;

public class TestJ1 {
    @Test
    public void te1() {
        int[] xArry = new int[4];
        xArry[3] = 1;
        System.out.println(xArry[3] + ":: " + xArry.length);
        ArrayList<Object> sl = new ArrayList<Object>();
        sl.add("hello");
        HashMap x = new HashMap();
        x.put(1, "X");
        Set m = x.entrySet();
        m.getClass();
        System.out.println(m.getClass());
       
    }
    @Test
public void te2() throws ParseException { Date dd = new Date(); String x = "2015年12月11日"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日"); dd = sdf.parse(x); System.out.println(dd); System.out.println(sdf.format(dd));
        Date dd2 = new Date();
        System.out.println(sdf.format(dd2)); } }

console print:

1:: 4
class java.util.HashMap$EntrySet
Fri Dec 11 00:00:00 CST 2015
2015年12月11日
2017年04月18日

 

----------------------------------------------------------

2017/04/12

浅析Java中的final关键字 http://www.cnblogs.com/dolphin0520/p/3736238.html

Java内部类详解 http://www.cnblogs.com/dolphin0520/p/3736238.html

public class BouncingBall {
    public static void main(String[] args) {
        MyClass myClass = new MyClass();
        StringBuffer buffer = new StringBuffer("Hello");
        myClass.changeValue(buffer);
        MyClass mc2 = new MyClass();
        StringBuffer buffer2 = new StringBuffer("Hello");
        mc2.changeValue(buffer2);
        System.out.println(buffer.toString() + ":" + buffer.hashCode());
    }
}

class MyClass {
    static String x;
    
    // public void changeValue(final StringBuffer buffer) {
    public void changeValue(StringBuffer buffer) {
        buffer.append(" world");
        x += buffer.toString();
        // buffer = new StringBuffer("Hello");
        System.out.println(x);
    }
}

 

nullHello world
nullHello worldHello world
Hello world:780173189

 

---Eclipse-------------------------------------------------------------------------------

20170414

Eclipse:重写superClass的方法 source-override/Implement Method 

      select method you want to override

----------------------------------------------------------------------------------

 

1. Set Map HashMap Tree ArrayList LinkedList List collection
2. iterator

 Collection(I)                                                    Map(I)
            |                                                              |
    ----------------------------                              ---------
    |                    |             |                              |          |
  List(I)          Queue(I) Set(I)               HashMap    SortedMap
    |                    |              |                             |           |
 --------------      |          --------------     HashTable    TreeMap
 |                |      |          |                |
ArrayList LinkedList HashSet  SortedSet

0.尽量返回接口而非实际的类型,如返回List而非ArrayList,这样如果以后需要将ArrayList换成LinkedList时,客户端代码不用改变。这就是针对抽象编程。

1. 对象只有一种创建方式
  String s = new String();

2. 所有数值类型都有正负号,没有无符号类型

3. 对象数组:String s[] 每个引用为null
   基本类型数组: int a[] 每个0

4. 永远不要释放对象

5. 每个类都必须存放在包中
  com.mycompany.xxx

6. 不要引用对引用赋值(除了参数传递),修改一个影响另一个

7. clone() 定义在Object中的protected方法,其它类要使用它,要重写Clone()并且定义为public. 返回值是Object类型,所以要强制转换下
  编写可克隆类:(1)implements Cloneable  (2)重写clone,调用super.clone() (3)clone声明为public (4)捕获CloneNotSupportedException异常

8. ArrayList的clone只能做到外面拷贝,内部对象还是同一个的对象

9. Random rand = new Random()
rand.newInt(100); //生产0 - 99的随机数

10. 对象的== 比较的是引用
    对象的equal() 比较的是实际内容相同
    自定义类equal() 比较的是对象的引用,所以要重载

11. 不能把非布尔值当成布尔值使用(与CC++不同)

12. >>>移位运算符,高位填0

13. 字符串与非字符串使用+连接,则必须以字符串开始

14. 0x 0

15. char byte short 做算术运算,会转成ini

16. this(...) 调用构造器, 构造器中只能使用一个,并且放在第一句

17. finalize()并不一定被调用,可用来检测错误,所以只能手动代替析构函数

18. ini[] a = new int[10] 尽量使用这种方式, 数组间可以赋值,是复制引用
   a.length()

19. 在子类中重新方法不会屏蔽基类的同名方法(C++会屏蔽)

20. 只有非private方法才能被重写

21.

[22]---20171207 str.split("\\s+")   str..split("[,\\s]+")

“\\s“ 可不是什么空格,它就是一个字符串,由 \ 和 s 组成。'\0' 才是空格。
这个字符串是一个正则表达式,表示一个空白字符,也就是空格、\t、\n等字符。
之所以要写成 \\s 是因为 \是转义字符,它要把它和它后面的一个字符转义成另外一个特殊的字符,像 \0 ,就不再是 \ 和 0 了,
而是 它俩一起表示空格这个字符了。那既然 \ 是转义字符,它要和它后面的一个字符一起表示另外一个字符了,那要表示它自己怎么办呢?
按规定,\\ 就表示 \ 这个字符了。第一个 \ 是转义字符,第二个 \ 还是转义字符,只不过它被第一个 \ 转义了
正则表达式,
\\d表示 0-9 的数字,
\\s表示 空格,回车,换行等空白符,
\\w表示单词字符(数字字母下划线)
+号表示一个或多个的意思

[22]---20171207正则表达式 regular expression

 

正则表达式,
\\d表示 0-9 的数字,
\\s表示 空格,回车,换行等空白符,
\\w表示单词字符(数字字母下划线)
+号表示一个或多个的意思

core java volume 1:


c
 The character c
 
\unnnn, \xnn, \0n, \0nn, \0nnn
 The code unit with the given hex or octal value
 
\t, \n, \r, \f, \a, \e
 The control characters tab, newline, return, form feed, alert, and escape
 
\cc
 The control character corresponding to the character c
 
Character Classes
 
[C1C2. . .]
 Any of the characters represented by C1, C2, . . . The Ci are characters, character ranges (c1-c2), or character classes
 
[^. . .]
 Complement of character class
 
[ . . . && . . .] 
 Intersection of two character classes
 
Predefined Character Classes
 
.
 Any character except line terminators (or any character if the DOTALL flag is set)
 
\d
 A digit [0-9]
 
\D
 A nondigit [^0-9]
 
\s
 A whitespace character [ \t\n\r\f\x0B]
 
\S
 A non-whitespace character
 
\w
 A word character [a-zA-Z0-9_]
 
\W
 A nonword character
 
\p{name}
 A named character class—see Table 12-9
 
\P{name}
 The complement of a named character class
 
Boundary Matchers
 
^ $
 Beginning, end of input (or beginning, end of line in multiline mode)
 
\b
 A word boundary
 
\B
 A nonword boundary
 
Syntax
 Explanation
 
\A
 Beginning of input
 
\z
 End of input
 
\Z
 End of input except final line terminator
 
\G
 End of previous match
 
Quantifiers
 
X?
 Optional X
 
X*
 X, 0 or more times
 
X+
 X, 1 or more times
 
X{n} X{n,} X{n,m}
 X n times, at least n times, between n and m times
 
Quantifier Suffixes
 
?
 Turn default (greedy) match into reluctant match
 
+
 Turn default (greedy) match into possessive match
 
Set Operations
 
XY
 Any string from X, followed by any string from Y
 
X|Y
 Any string from X or Y
 
Grouping
 
(X)
 Capture the string matching X as a group
 
\n
 The match of the nth group
 
Escapes
 
\c
 The character c (must not be an alphabetic character)
 
\Q . . . \E 
 Quote . . . verbatim
 
(? . . . ) 
 Special construct—see API notes of Pattern class

 

 

 

 

 

 

--java知识点---

浅析Java中的final关键字 http://www.cnblogs.com/dolphin0520/p/3736238.html

Java内部类详解 http://www.cnblogs.com/dolphin0520/p/3736238.html


css篇
1. 选择器  p 代表 段落标签     #p 代表 id="p" 的标签   .p  代表 class="p" 的标签  三者可以嵌套  #nav .li {...}

posted @ 2017-04-12 16:44  charles999  阅读(294)  评论(0编辑  收藏  举报