Posts

Java Multi-Threading synchronization interview question

Image
The multi-threading synchronization questions always concentrate on a few keywords: wait, notify, notifyAll, synchronized, volatile. The following question is the hardest, I ever met. The thread t1 should print integer number from 1–52, the thread t2 should print character from A-Z, the question is how to let the final result to be 12A34B56C… by implement Printer class. (The Printer class is already finished by the way) public class Main { public static void main ( String [ ] args ) { System . out . println ( "Hello World!" ) ; Printer p = new Printer ( ) ; Thread t1 = new NumberPrinter ( p ) ; Thread t2 = new LetterPrinter ( p ) ; t1 . start ( ) ; t2 . start ( ) ; } } public class LetterPrinter extends Thread { private Printer p ; public LetterPrinter ( Printer p ) { this . p = p ; } public void run ( ) { for ( char c = 'A' ; c < = ...

Light-BLE Release Note

Image
About two years ago, I published my debugging toolkit in Android for Bluetooth LE development, after that, I left that field, wearable-BLE equipment development just quit that job and join a new one. And now at this moment, I quit the job again, to summarize my collections during the past two years. There are two keynotes: my skills sharper a lot at Android App development, second,  Light-BLE  was still my most popular project. During the past one year, there are at least four people contact me for debugs and more stable demos. Finally, I am here to announce the release of the beta-2 version of Light-BLE, it is actually be rewritten. This is the first version release note two years ago. http://zpcat.blogspot.com/2014/03/lightble-practical-app-tool-to-develop.html So, what was changed compared with the two years ago? 1. New Architecture I rewrite this project to compatible with the legendary MVP architecture, which decoupled the View and logical data layer, make...

Android Job Interview Questions

Image
In this post, I tried to wrote some Job interview questions, that I met during my Job interview journey. Yeah, some of the them are still so fresh, because I mess up them a lot. However, A sketch notebook is always better than a good memory, especially in the situation of the lack practice exercise. finalize function The finalize method is used in JVM’s GC collection. But, it was said that it never guaranteed to be called during the collection, that’s means unpredictable, so I guess why I should put the resource release code into an unpredictable method, still be puzzled. How to write a singleton and thread-safe class? Following is an ordinary Singleton class without thread-safe features. public class Singular { private static Singular sInstance ; private Singular ( ) { } public static Singular getInstance ( ) { if ( sInstance = = null ) { sInstance = new Singular ( ) ; } return sInstance ; ...

Dependency Injection in Android with Dagger 2

Image
Dependency Injection in Android with Dagger 2 Dagger’s Power Dagger 2 is the upgraded version of the original Square’s Dagger, designed for dependency injection(DI) technology for java. DI’s sensational ability is to decouple the dependency relationship between objects, clear the code, and also let developer focus to the functional classes. In the complex framework & architecture, DI becomes the standard component, like Spring. Similarly, If you wanna write agile and maintainable code in a large and long-term run Android project, Dagger should be an not so bad option. How to install codepath/android_guides Many Android apps rely on instantiating objects that often require other dependencies. For instance, a Twitter API… github.com The first step always to install Dagger 2, unfortunately, the  official document did not give any details in Android’s Gradle build environment. Yeah, Dagger is not just for Android, but for any Java Project. The good news is above...

ReactiveX Operations

Image
ReactiveX Operations Table of Contents Resources ReactiveX Operations Sample Source code 1 Resources http://reactivex.io/documentation/operators.html http://reactivex.io/tutorials.html https://github.com/ReactiveX/RxJava/wiki/Additional-Reading 2 ReactiveX Operations To understand ReactiveX, We must consider everything as a stream, after that, the operations of ReactiveX stream was so complicated, that we can trade them as a new language, which operates the stream. The ReactiveX's Official document classify its operations as following categories: Creating Observables Transforming Observables Filtering Observables Combining Observables Error Handling Operations Observable Utility Operators Conditional and Boolean Operators Mathematical and Aggregate Operators BackPressure Operators Connectable Observable Operators Operators to Convert Observables Beside above categories, ReactiveX also provides the strategy to practice those operation...

My Emacs Configuration

Image
My Emacs Configuration Table of Contents What is it? How to install my configure The most complicated part Code location 1 What is it? I have at least three desktop machines works right now, running Mac OS and Linux. I found that's a messy and dirty job to configure my emacs again and again after reinstalling the system. This project is a convenience collection my configurations of emacs and reinstalls them quickly into another machine. I had worked in a similar project formerly, not a so pleasure experience, I commit everything located in ~/.emacs.d into a git repository, after realize how silly it is, I abandon that project. This new project is an upgraded version, more light weight, just upload my own configuration without the third party modules. 2 How to install my configure steps 1 create your .emacs.d directory into your home directory cd ${ HOME } mkdir .emacs.d steps 2 clone the code into your ${HOME}/.emacs.d directory cd ${ ...

Learning Lua

Image
Learning Lua Table of Contents Background Tables metatable functions coroutine Lua as Object-oriented programming 1 Background Lua as an embedded language was popular in the game industry and also in any embedded scenario. I tried to wrote a Lua module for Nginx, which already has a ported Lua environment inside. And since this is my first time to get familiar with Lua, and to enjoy its simplicity. My learning materials were no special, but its official document . I wrote my notes down in order for future review. 2 Tables To understand table is to understand Lua, or in another word, Lua's syntax was nothing but just tables, no more. Tables in Lua is in similar with the dictionary in Python, in my view. a = {} a.x = 1 a[ 'x' ] = 1 2.1 metatable Lua's metatable is similar to magic methods in python. 3 functions Lua as a functional programming language, because the function is also the first-class variable. That...