Comparing Arrays and LinkedList, we know it is easy for Array to access element(takes O(1)), but hard to insert or delete(takes O(n)), LinkedList is opposite, access element takes O(n), but deletion and insertion is easy(takes O(1)).

What about comparing elements and find a sepecfic elemnt in a sorted array?

Well, we can do linear search (O(n)). Loop through the elements in array and find out the value that is exact same as target value.

We can also use binary search: repeatedly dividing the search interval in harf to narrow down the search. Binary search only takes O(logn) time complexity.

Continue reading

Recently I found when I use a boolean value in multiple threads, it is not thread-safe enough. For example, in one thread you are writing values for a boolean value, in another thread you are checking the boolean in order to process the thread. How does the program know the value when you check? This suitation also happens in other values not limited to boolean.

We should aviod checking and writing a value in multiple thread in the same time. Here is a simple solution I found: use java.util.concurrent.atomic package. Atomic Collections support lock-free thread-safe programming on single variables.

Continue reading

Remember in article synch/Asynch Callback in Java I wrote, multithreading in Java is important and can improve performance. We can use callbacks to notify some threads finish executing. What if we don’t need to pass arguments, but we still want to implements multithreads falixable? Another simple way to let a thread wait and wake up is to use Object.wait() and Object.notify().

Keep in mind that:

  • Object.wait() means suspend a thread.
  • Object.notify() means wake a thread up.
Continue reading

Callback Function

Image a senario, you have several threads executed at the same time, how can you know some threads are already finished? Maybe you want to execuate a thread after another thread, then how can you control the flow? Here, we can use callback functions.

A callback function is a function passed into another function as an argument. The purpose of it is to inform a class Sync/Async if some work in other class is down.

In java, we can implement calbaks by interface. Here is the steps:

Continue reading

Understanding the storages in an Android device, you can easily check or transfer files in both directions: your app and the device. For example, if your app have a licence file, and you want to check the permission, you can store licence file in Android device for further updating and changing.

Continue reading
  • page 1 of 1
Author's picture

Amy Zhu

To learn without thinking is blindness, to think without learning is idleness.


Mapsted Software Engineer


Toronto, ON