Using Enum To Implement Singleton Pattern

In the previous post Singleton Pattern: When and How to use it effectively, we have 4 ways to implement  Singleton Pattern. Today, I share with you another way to implement it with Enum. This way was provided by Joshua Bloch in his 2nd Effective Java book.

Continue Reading...

Singleton Pattern: When and How to use it effectively

With this post I will show you what it Singleton Pattern and how to use it  effectively.
First, consider definition for Singleton Patten:
The Singleton Pattern ensures a class has only one instance, and provides a global point of access to it.
From this definition we can see the purpose of using this pattern:

It ensures we have at …

Continue Reading...

ByteTokenizer – a Java class util By Me

Vì nhu cầu để decode các gói tin của Yahoo Messenger nên mình viết thư viện ByteTokenize để sử dụng parse mảng các bytes (bytes array). Class ByteTokenizer tương tự như class java.util.StringTokenizer.
——————————————————————————–
In order to decode Yahoo Messenger packet received from Yahoo Messenger server, I’ve coded class ByteTokenizer, as java.util.StringTokenizer class. This class allows an …

Continue Reading...

12 mẹo viết Unit Test cho Lập Trình Viên

12 mẹo viết Unit Test cho Lập Trình Viên
Nội dung
1.    Viết Unit Test để giảm các rủi ro
2.    Viết một Test Case cho mỗi component quan trọng
3.    Viết Abstract Test Case và Test Utilities
4.    Viết các test hiệu quả (smart tests)
5.    Thiết lập môi trường phù hợp cho mỗi test
6.    Sử dụng Mock Object để …

Continue Reading...

Present unsigned number in Java – Biểu diễn số không dấu trong Java

Sáng nay vào công ty, một người bạn đồng nghiệp gặp phải vấn rắc rối về việc thể hiện được số nguyên không dấu (unsigned) trong Java.
Như chúng ta đã biết, trong Java thì các kiểu dữ liệu số: byte, short, int và long đều được xem là những số có dấu (signed). Chỉ có …

Continue Reading...