Курс Java-2016. Занятие 07. Логи, фасады, библиотеки и коллекции

  • View
    379

  • Download
    0

Embed Size (px)

Transcript

  • Java, 2016

    , ,

    slf4j, maven repo, collections framework

    annie.tarasenko@7bits.it, denis.nelubin@7bits.it

    mailto:annie.tarasenko@7bits.itmailto:denis.nelubin@7bits.itmailto:annie.tarasenko@7bits.it

  • Java, 2016

    System.out.println("Hello");System.err.println("World");new Exception("stack").printStackTrace();

    HelloWorldjava.lang.Exception: stack

    at it.sevenbits.example.logs.OutPrint.main(OutPrint.java:8)

    !

  • Java, 2016

    SLF4J

    org.slf4j slf4j-api 1.7.21

    http://www.slf4j.org/

    http://www.slf4j.org/http://www.slf4j.org/

  • Java, 2016

    SLF4J (Simple Logging Facade for Java)import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class SLF4JLogSample { final static Logger logger =

    LoggerFactory.getLogger(SLF4JLogSample.class); public static void main(String[] args) { logger.info("Hello"); logger.warn("World"); logger.error("error", new Exception("exception")); }}

  • Java, 2016

    SLF4JSLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to no-operation (NOP) logger implementationSLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

  • Java, 2016

    SLF4J

  • Java, 2016

    SLF4J SimpleLogger

    org.slf4j slf4j-simple 1.7.21

  • Java, 2016

    SLF4J SimpleLogger[main] INFO it.sevenbits.example.logs.SLF4JLogSample - Hello[main] WARN it.sevenbits.example.logs.SLF4JLogSample - World[main] ERROR it.sevenbits.example.logs.SLF4JLogSample - errorjava.lang.Exception: exception

    at it.sevenbits.example.logs.SLF4JLogSample.main(SLF4JLogSample.java:13)

  • Java, 2016

    Logback

    ch.qos.logback logback-classic 1.1.7

  • Java, 2016

    Logback12:13:58.659 [main] INFO it.sevenbits.example.logs.SLF4JLogSample - Hello12:13:58.670 [main] WARN it.sevenbits.example.logs.SLF4JLogSample - World12:13:58.696 [main] ERROR it.sevenbits.example.logs.SLF4JLogSample - errorjava.lang.Exception: exception

    at it.sevenbits.example.logs.SLF4JLogSample.main(SLF4JLogSample.java:13)

  • Java, 2016

    Logback configuration (logback.xml)

    %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n

  • Java, 2016

    Logback configured13:32:20.330 [main] WARN i.s.example.logs.SLF4JLogSample - World13:32:20.343 [main] ERROR i.s.example.logs.SLF4JLogSample - errorjava.lang.Exception: exception

    at it.sevenbits.example.logs.SLF4JLogSample.main(SLF4JLogSample.java:13)

  • Java, 2016

    Log levellogger.trace("");logger.debug("");logger.info("");logger.warn("");logger.error("");

  • Java, 2016

    String name = "World";

    if (logger.isDebugEnabled()) { logger.debug("Hello, {}!", name);}

  • Java, 2016

  • Java, 2016

    Maven Central http://search.maven.org/

    http://search.maven.org/http://search.maven.org/

  • Java, 2016

  • Java, 2016

    Collection Framework java.util

    Java 1.2

    Generic Java 1.5

  • Java, 2016

    java.util.ListList listOfStrings;

    listOfStrings.add("abc"); // listOfStrings.size(); // listOfStrings.contains("abc"); // listOfStrings.get(0); // for (String item : listOfStrings) { // }

  • Java, 2016

    ListList arrayList = new ArrayList();

    List linkedList = new LinkedList();

  • Java, 2016

    java.util.MapMap map;map.put(5, "five"); // map.size(); // map.containsKey(5); // map.containsValue("five"); // map.get(5); // for (Map.Entry entry : map.entrySet()) { // entry.getKey(); // entry.getValue(); // }

  • Java, 2016

    MapMap hashMap =

    new HashMap();

    Map treeMap = new TreeMap();

  • Java, 2016

    Hashtable

  • Java, 2016

    Red-black tree

  • Java, 2016

    hashCode() equals()public class Entry { public Integer key; public String value; @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Entry entry = (Entry) o; if (key != null ? !key.equals(entry.key) : entry.key != null) return false; return value != null ? value.equals(entry.value) : entry.value == null; } @Override public int hashCode() { int result = key != null ? key.hashCode() : 0; result = 31 * result + (value != null ? value.hashCode() : 0); return result; }}

  • Java, 2016

    Formatter:

    , ,

    Logger (SLF4J) , unit-

    , 22:00 , 28 2016 .

    5 12 !

    : https://habrahabr.ru/post/113145/

    https://habrahabr.ru/post/113145/