Tag Archives: Java

Java Multi Thread Basics 2

1. Singleton Design Pattern check null after get lock to avoid instantiate multiple times (other thread passed first null check and are waiting for the lock) 2. Producer and Consumer problem is not like Read and Write, it doesn’t allow … Continue reading

Posted in CS Research&Application, Uncategorized | Tagged , , | Leave a comment

Programming Retrospection (Aug 4)

1. If the problem requirement is very complex, try to convert to simpler one. (In industry, you always get business requirement which is not efficient in technology, you should convert to a tech efficient algorithm/requirement) 标准复杂,就转换标准(蓄水池问题) 在工业界拿到的商业需求可能不是技术上的最优解,这种情况下就要优化需求(把商业需求转换成技术需求)。 2. Tow pointers … Continue reading

Posted in CS Research&Application, Uncategorized | Tagged , , | Leave a comment

Java Multi Thread Basics

1. Textbook questions (Summary – Divide – Summary) Process (application, program) vs Thread (share memory) Concurrency(progress at same time, some fast and others slow, single core) vs Parallelism (execute at same time, multi-core) Runnable (interface) vs Threads (class)   2. … Continue reading

Posted in CS Research&Application, Uncategorized | Tagged , | Leave a comment

Java Design Patterns

Advanced Class Design Pattern Singleton Factory Builder Deps Injection Scale is large enough (then need Design Pattern) Project Requirement Epic Fantasy Story Role Play Game (RPG) Turn-based Strategy fighting system Treasure Collection Players Pick Roles NPC Roles Analysis Ability promotion … Continue reading

Posted in CS Research&Application, Uncategorized | Tagged , | Leave a comment

Java Basic Object Oriented Concepts

Lambda: {arguments} -> {statements} Functional Interface: Comparator, Function, Predicates Method Reference: Class::method Default Method: implementation in Interface Stream: map, reduce, sort, filter Collectors: joining, toList, summingInt… Map: putIfAbsent, computeIfPresent, Tree Node (separate chain) Optional Basic OO in Java (Class is … Continue reading

Posted in CS Research&Application, Uncategorized | Tagged , | Leave a comment

Java 8 features

Pass by value in Java Primitive Value, copy Object, copy of reference Out of memory (Heap, method, copy of reference) Stack overflow (Stack, object, instance) Java 8 features Lambda expression (interface, extract one abstract method, mark as function interface) Method … Continue reading

Posted in CS Research&Application, Uncategorized | Tagged | Leave a comment

Java Basics (Sorting, Classes)

Sorting if same time complexity, check # of swaps # of comparisons o(n^2) Insertion sort > Bubble sort > Selection sort in place (maybe only o(1) space) stable (same numbers’ relative position are same, 2,3,4,5(1),5(2)) o(nlogn) Quick sort o(1) extra … Continue reading

Posted in CS Research&Application, Uncategorized | Tagged , | Leave a comment