Files
knowledge/categories/java.md
T
2018-06-13 13:12:06 +10:00

3.8 KiB
Raw Blame History

Java GC

  • GC types
    • Serial GC
    • Parallel GC
    • CMS GC
    • G1 GC
  • Object type
    • Young generation minor GC
    • Old generation full GC
  • System.gc()

JVM

  • Method Area
    • Class name, Constant, static Constant, Class object
  • Heap
    • Object instance, array

    • young generation

    • Old generation

  • VM stack
    • local variable
    • dynamic links
    • operation stacks
  • Native method stack
  • program counter

JVM insight

jvm insight

Spring

  • Spring boot
    • Rest controller
    • Jpa template
    • Spring scheduler
    • Annotation bean
  • Spring cloud
    • Consol
    • Zuul
    • Cloud config
    • Spring cloud zookeeper( discovery and configuration)
  • Spring ecurity

ORM

  • Hibernate
    • validation
  • JPA
    • Sprint jpa tempalte
  • Mybatis

Build

Useful tips

  • Iterate map
    • for (Map.Entry<String, String> entry : map.entrySet()) { }
  • List to array
  • Object
    • immutable
    • object that cant be modified after its created
      • Dont allow subclass override methods, class to be final
      • Dont provide setter method
      • Make all field private and final
    • mutable
  • Default Timezone
    • TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"))
  • generics
    • Why we need?

    • e.g we have sort method, and different type(n) of objects. then you have to write n kind of search methods.

  • event listener

JAVA SE

modifier

* public
* no modifier
* protected
* priivate

Java modifier diagram

Java modifier diagram

NIO

- Channels
- A channel is a kind of stream, from the channel data can be read into a buffer.
- channel implementations
	- FileChannel
		- reads data from and to files
	- DatagramChannel
		- read and write data over the network via UDP
	- SocketChannel
		- read and write data over the network visa TCP
	- ServerSocketChannel
		- allows you to listen for incoming TCP connections, like a web server. For each incoming connection a SocketChannel is created.
- Buffer

- code sample
        RandomAccessFile aFile = new RandomAccessFile("data/nio-data.txt", "rw");
            FileChannel inChannel = aFile.getChannel();

            //create buffer with capacity of 48 bytes
            ByteBuffer buf = ByteBuffer.allocate(48);

            **int bytesRead = inChannel.read(buf**); //read into buffer.
            while (bytesRead != -1) {

            **buf.flip**();  //make buffer ready for read

            while(buf.hasRemaining()){
                System.out.print((char) **buf.get**()); // read 1 byte at a time
            }

            **buf.clear**(); //make buffer ready for writing
            bytesRead = inChannel.read(buf);
            }
            aFile.close();
- properties
	- capacity
	- position
	- limit

- Steps for buffer to read and write data.
	- write data into buffer
	- call buffer.flip()
	- read data out of the buffer
	- call buffer.clear() or buffer.compact()
- Non-blocking IO
- Selectors

- A selector allows a single thread to handle multiple Channels
- [http://tutorials.jenkov.com/java-nio/index.html](http://tutorials.jenkov.com/java-nio/index.html)