美文网首页用力学习
读:java编程思想 英文版

读:java编程思想 英文版

作者: holysu | 来源:发表于2017-03-21 23:53 被阅读0次

what is object?

an object has state,behaviors and identity

cleanup: finalization and garbage collection

  1. Your objects might not get garbage collected.
  2. Garbage collection is not destruction.
  3. Garbage collection is only about memory.

how a garbage collector works

  1. reference counting
  2. adaptive garbage-collection scheme
  3. stop-and-copy
  4. mark and sweep
  5. initialization order: static(static block) -> field -> constructor
  6. array & enum

access control: access specifiers

class defines what an object is, interface defines what an object can do ,access specifiers make boundaries

two benefits
1. keep users' hands off portions that they shouldn't touch.
2. allow the library designer to change the internal workings of the class without worrying about how it will affect the client programmer.
  1. default : package access
  2. protected: inheritance access (package + descendent)
  3. public : interface access (everyone)
  4. private : self;
  5. private & protected cannot used on class(excepted inner class)

reusing classes

  1. how to implement lazy load?
  2. composition vs inheritance
  3. final
    • claim it is final version ,cannnot be modified
    • can be used upon data(primitive/reference) , methods, classes; take attention the different effect on each target
    • static final primitives are compile-constants ,named with capitals and separated with underscores.
    • how about constant memory allocation?

polymorphism

separate the things that change from the things that stay the same.
General guide: use inheritance to express differences in behavior, and fields to express variations in state.
  1. late binding, how java implement, mechanism?
  2. late binding save you lots of overloads
  3. cannot override parent's private and static methods
  4. not work at direct-accessed field
  5. RTTI: runtime type information
  6. auto upcast, force downcast(ways?)

interfaces

decoupling!!!
decoupling interface from implementation allows an interface to be applied to muliple different implementations, and thus your code is more reusable.
abstract class defined what it is like, interface say what it can do 
any abstraction should be motivated by a real need. when necessary
  1. abstract class
  2. interface
  3. method works with interface instead of class, loosen the limit of forceing params be subclasses
  4. you should always prefer interfaces to abstract classes
    releated design patterns: strategy, adatper, factory

inner classes

  1. closure , callbacks
  2. .this .new
  3. prevent any type-codeing dependency and completely hide details about implementation
  4. anonymous class
  5. nested class (static inner class)

holding your objects

task:

  • get familiar with common containers
  • java.util.collection source code
  • java.util.Collections, java.util.Arrays
  • 数据结构的实现
  • interface:collection,list, iterator
  • org.springframework.util.collections

exception

task:

  • take use of exception mechanism to complete a general api call process dealing with different
  • common types of exception
  • try/catch , if no exception occurs there is little cost
  • checked exception vs. unchecked exception
  1. Error, Exception, RuntimeException
  2. exception specification interface for a particular method may narrow during inheritance and overriding, but it may not widen

Strings

string is immutable!!!

questions:

  1. why string is immutable? and how
  2. formatter classes
  3. code structure

RTTI(runtime type information)

  1. class loader, mechanism
  2. 基于反射实现java版本重试
  3. java.lang.reflect Proxy.newProxyInstance动态代理
  4. Null Objects

Generics

by knowing what you can't do, you can make better use of what you can do
the generic types are present only during static type checking, after which every generic type in the program is erased by replacing it with none-generic upper bound
  1. 实现.net的Tuple功能
  2. generic class, inteface, method
  3. type inference: only work when assignment
    erasure
  4. migration compatability
  5. problem with erasure:
    • cannot use as specific type,
    • type information is lost
    • ensure type consistent during compile time
  6. ? extends vs ? super
  7. wildcards , bound and unbound
  8. design pattern: decorator/adatper/strategy

reference:

  1. Java 泛型总结(一):基本用法与类型擦除
  2. Java泛型中extends和super的理解

arrays

  1. initialization
  2. Arrays.xx
  3. java.lang.Comparable

containers in depth

  1. design pattern: flyweight

  2. Map : HashMap/LinkedMap/TreeMap(red-black)/WeakHashMap/ConcurrentHashMap/IdentityHashMap

  3. Map.Entry, AbstractMap, AbstractSet

  4. Arrays.asList : return a fixed-size list

  5. Set: HashSet/TreeSet/LinkedHashSet

  6. hashcode used for hashXX

  7. Map.Entry

  8. source and data structure of HashMap

    image http://www.cnblogs.com/chenssy/p/3521565.html
  9. how to correctly override hashCode()?

    • identical 恒等
    • fast and meaningful 考虑查找效率
    • in an even distribution of values 分布平均
  10. rehashing

performance test

list performance
set performance
map performance

I/O

  1. FileChannel,xxStream.getChannel, ByteBuffer -> asXXBuffer(view buffer), Charset
  2. clear/flip/rewind
  3. nio: MappedByteBuffer
  4. compression
  5. decorator pattern

enums

  1. static import
  2. the mystery of values(): static method added by the compiler
  3. Class.getEnumConstants()
  4. EnumSet are built on top of longs which is 64bit; it's ok when it contains more than 64 enums , think why
  5. < 64 RegularEnumSet; >= 64 JumboEnumSet
  6. EnumMap
  7. command design pattern using enums is so fantastic
  8. chain of responsibility pattern
  9. state machine
  10. multiple dispatching -> 2D Array

annotations

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Constrains{
    boolean primaryKey() default false;
    boolean allowNull() default true;
    boolean unique() default false;
}

@Target(ElementType.FIELD)
@Retention(RetetionPolicy.RUNTIME)
public @interface SQLString{
    int value() default 0;
    String name() default "";
    Constraints constraints() default @Constraints;
}

concurrency

  1. it seems counterintuitive that multithreaded program needs context switching cost
  2. concurrency imposes costs, including complexity costs, but these are usually outweighted by improvements in program design, resource balancing, and use conveniece
  3. interface: Runnable vs Callable
  4. enum TimeUnit
  5. ExecutorService exec = Executors.newCachedThreadPools / newFixedThreadPool
                              int maximumPoolSize,
                              long keepAliveTime,
                              TimeUnit unit,
                              BlockingQueue<Runnable> workQueue,
                              ThreadFactory threadFactory,
                              RejectedExecutionHandler handler)
  1. Executors
  2. Future FutureTask
  3. Sleeping: TimeUnit.MILLISECONDS.sleep(X);
  4. daemon thread, gc is a daemon thread in jvm?
  5. how Executors propagate exception
  6. getUncaughtExceptionHandler()
  7. volatile
  8. atomicity applies simple operation on primitive types except for long and double which are two seperate 32-bit operations
  9. volatile ensures visibility across application, as soon as a write occurs for that field, all reads will see the change
  10. java's increment a++ is not atomitic ,it involve both a read and a write
  11. Thread local storage, ThreadLocal
  12. BlockingQueue、CountDownLatch、CyclicBarrier、Semaphore

performance tune

  1. synchronized -> lock / atmoic
  2. lock-free container: CopyOnWriteArrayList ,ConcurrentHashMap
  3. ReadWriteLock
  4. Active Object, actors

task:

  1. wirte a general task util simplifying thread operations
  2. how jvm lock ja
  3. Lock, ReentranceLock, ReadWriteLock,Condition
  4. long vs double

THEN

  1. JDK: collection, exception,reflect.proxy, concurrency, nio...etc
  2. 刷题: codewars 基础部分(8kyu) 快速熟悉起来
  3. 《Effective Java》
  4. 《数据结构与算法 java语言描述》 内功 不解释

相关文章

网友评论

    本文标题:读:java编程思想 英文版

    本文链接:https://www.haomeiwen.com/subject/ahynnttx.html