String vs StringBuilder vs StringBuffer in Java

String vs StringBuilder vs StringBuffer in Java

---StringStringBufferStringBuilder
SyntaxString var = new String(str)StringBuffer var = new StringBuffer(str);StringBuilder var = new StringBuilder(str);
Mutabilityimmutablemutablemutable
ThreadSafeSafeNot Safe
JDK1.01.01.5
NoteConstant String Pool

JAVA 中的 StringBuilder 和 StringBuffer 适用的场景是什么?

stringbuffer固然是线程安全的,stringbuffer固然是比stringbuilder更慢,固然,在多线程的情况下,理论上是应该使用线程安全的stringbuffer的。

然而,然而,然而,有谁给我一个实际的案例来显示你需要一个线程安全的string拼接器?对不起,至少在我浅薄的十几年编程生涯中还没有遇到过,也许,仅仅是也许,这个地球上的确是存在这样的编程需求的,然而,它至少跟99.99...99%的程序员是无关的。

展开阅读

Java Annotations

Java Annotations

"Annotations are only metadata and do not contain any business logic"

"Annotations only provide information about the attribute (class/method/package/field) on which it is defined. The consumer is a piece of code that reads this information and then performs the necessary logic."

  1. @Override annotation in above code. Even if I don’t put @Override, code works properly without any issue.

  2. @Override tells the compiler that this method is an overridden method (metadata about the method), and if any such method does not exist in a parent class, then throw a compiler error (method does not override a method from its super class).

  3. if I would have made a typography mistake and used the method name as toStrring() {double r}, and if I wouldn’t have used @Override, my code would have compiled and executed successfully

    展开阅读

数据库范式

数据库范式

范式保证数据库操作的原子化,即Insert,Update,Delete,减少数据冗余

1. Define

  1. First normal form (1NF) is a property of a relation in a relational database. A relation is in first normal form if and only if the domain of each attribute contains only atomic (indivisible) values, and the value of each attribute contains only a single value from that domain

How to Design Programs - Prologue

  1. Hence any reasonably complete program consists of many building blocks: some deal with input, some create output, while some bridge the gap between those two.

1. From Problem Analysis to Data Definitions
    Identify the information that must be represented and how it is represented in the chosen programming language. Formulate data definitions and illustrate them with examples.

2. Signature, Purpose Statement, Header    
    State what kind of data the desired function consumes and produces. Formulate a concise answer to the question what the function computes. Define a stub that lives up to the signature.

3. Functional Examples
    Work through examples that illustrate the function’s purpose.
4. Function Template
    Translate the data definitions into an outline of the function.
5. Function Definition
    Fill in the gaps in the function template. Exploit the purpose statement and the examples.
6. Testing
    Articulate the examples as tests and ensure that the function passes all. Doing so discovers mistakes. Tests also supplement examples in that they help others read and understand the definition when the need arises—and it will arise for any serious program.
  1. Design Recipes apply to both complete programs and individual functions.

    展开阅读

ECMAScript 6 Meta Reflect&Proxy

ECMAScript 6 Meta Reflect&Proxy

Reflect

Reflect is a built-in object that provides methods for interceptable JavaScript operations. The methods are the same as those of proxy handlers. Reflect is not a function object, so it's not constructible.

Unlike most global objects, Reflect is not a constructor. You cannot use it with a new operator or invoke the Reflect object as a function. All properties and methods of Reflect are static (just like the Math object).

  1. Reflect.apply()

    展开阅读