difference padding/margin

To me the biggest difference between padding and margin is that margins auto-collapse, and padding doesn’t. Consider two elements next to each other each with padding of 1em. This padding is considered to be part of the element, and is always preserved. So you will end up with the content of the first element, followed by the padding of the first element, followed by the padding of the second, followed by the content of the second element. Thus content of the two elements will end up being 2em apart.

Now replace that padding with 1em margin. Margins are considered to be outside of the element, and margins of adjacent items will overlap. So in this example you will end up with the content of the first element followed by 1em of combined margin followed by the content of the second element. So the content of the two elements is only 1em apart.

This can be really useful when you know that you want say 1em of spacing around an element, regardless of what element it is next to.

The other two big differences is that padding is included in the click region and background color/image, but not the margin.

By default I use margin everywhere, except when I have a border or background and want to increase the space inside that visible box.


封装 if else

public interface Handler {
boolean isSatisfied(Input input);
void handle();

public class Condition1Handler implements Handler {
public boolean isSatisfied(Input input) {
return (input.isStatus1 && input.isStatus2) || input.isStatus3;

public void handle() {



for (Handler h : registeredHandlers) {
if (h.isSatisfied(input)) {



bounded type parameters

 public <U extends Number> void inspect(U u){
        System.out.println("T: " + t.getClass().getName());
        System.out.println("U: " + u.getClass().getName());

    public static void main(String[] args) {
        Box<Integer> integerBox = new Box<Integer>();
        integerBox.set(new Integer(10));
        integerBox.inspect("some text"); // error: this is still String!

generic methods

public class Util {
    // Generic static method
    public static <K, V> boolean compare(Pair<K, V> p1, Pair<K, V> p2) {
        return p1.getKey().equals(p2.getKey()) &&
boolean same = Util.<Integer, String>compare(p1, p2);

generic type example?

Box<Integer> integerBox;
public class Box<T> {
    // T stands for "Type"
    private T t;

    public void set(T t) { this.t = t; }
    public T get() { return t; }

The Diamond

In Java SE 7 and later, you can replace the type arguments required to invoke the constructor of a generic class with an empty set of type arguments (<>) as long as the compiler can determine, or infer, the type arguments from the context. This pair of angle brackets, <>, is informally called the diamond. For example, you can create an instance of Box<Integer> with the following statement:

Box<Integer> integerBox = new Box<>();


  • Type as parameters

why use?

  • Stronger type checks at compile time.
  • Enabling programmers to implement generic algorithms.
  • Elimination of casts.The following code snippet without generics requires casting:
    List list = new ArrayList();
    String s = (String) list.get(0);

    When re-written to use generics, the code does not require casting:

    List<String> list = new ArrayList<String>();
    String s = list.get(0);   // no cast

replication implmentation (Mysql)


Replication is based on the master serhttps://myrubylearning.wordpress.com/wp-admin/post-new.php?post_type=postver keeping track of all changes to its databases (updates, deletes, and so on) in its binary log.

Each slave that connects to the master requests a copy of the binary log.

Because each slave is independent, the replaying of the changes from the master’s binary log occurs independently on each slave that is connected to the master.

Replication Solutions: