Author Archive

Java learning note – Fun with code 01

November 24, 2014 Leave a comment

Today my friend asked me about char data type with plus (+) operator. This is his code:

public class App
public static void main( String[] args )
char a, b, c;
a = 'A';
b = '+';
c = '4';
System.out.println(a + b + c + d);




And suddenly I remember one thing, “If either operand is a String, the + operator becomes a String concatenation operator. If both operand are numbers, the + operator is the addition operator”. Read more…

Java learning note – Serialization 01

November 17, 2014 Leave a comment

With serialization we can stream our Java object to a sequence of byte and restore these objects from this stream of bytes. To make a Java object serializable you implement the interface. This is only a marker interface which tells the Java platform that the object is serializable.

Classes ObjectInputStream and ObjectOutputStream are high-level streams that contain the methods for serializing and deserializing an object, usually we wrap them arround lower-level classes FileOutputStream. The magic happens with just two methods:
ObjectOutputStream.writeObject(); – for serialize object
ObjectInputStream.readObject(); – for deserialize object

public class Person implements Serializable
private static final long serialVersionUID = -2344139368896541663L;

private String firstName;
private String lastName;
private int age;

public Person() {


public Person(String firstName, String lastName, int age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;

public String getFirstName() {
return firstName;

public void setFirstName(String firstName) {
this.firstName = firstName;

public String getLastName() {
return lastName;

public void setLastName(String lastName) {
this.lastName = lastName;

public int getAge() {
return age;

public void setAge(int age) {
this.age = age;

Read more…

Categories: JAVA

Redis Learning Note – 08 Command in Redis (Sorted Set)

November 15, 2014 Leave a comment

Every member of a Sorted Set is associated with score, that is used in order to take the sorted set ordered, from the smallest to the greatest score. While members are unique, scores may be repeated. Sorted sets are sorted by their score in an ascending way. The same element only exists a single time, no repeated elements are permitted. The score can be modified both by ZADD that will update the element score, and as a side effect, its position on the sorted set, and by ZINCRBY that can be used in order to update the score relatively to its previous value. The current score of an element can be retrieved using the ZSCORE command, that can also be used to verify if an element already exists or not.

When multiple elements have the same score, they are ordered lexicographically (they are still ordered by score as a first key, however, locally, all the elements with the same score are relatively ordered lexicographically). The lexicographic ordering used is binary, it compares strings as array of bytes.

Read more…

Categories: Redis

Redis Learning Note – 07 Command in Redis (Hash)

November 15, 2014 Leave a comment

HMGET key field [field …]
Returns the values associated with the specified fields in the hash stored at key.
For every field that does not exist in the hash, a nil value is returned. Because a non-existing keys are treated as empty hashes, running HMGET against a non-existing key will return a list of nil values.
HDEL key field [field …]
Removes the specified fields from the hash stored at key. Specified fields that do not exist within this hash are ignored. If key does not exist, it is treated as an empty hash and this command returns 0.
HLEN key
Returns the number of fields contained in the hash stored at key.


Read more…

Categories: Redis

Redis Learning Note – 06 Command in Redis (Set)

November 15, 2014 Leave a comment

Unordered collection of unique strings

SADD key member [member …]
Add the specified members to the set stored at key.
SREM key member [member …]
Remove the specified members from the set stored at key.
Returns the set cardinality (number of elements) of the set stored at key.
Returns all the members of the set value stored at key.


Read more…

Categories: Redis

Redis Learning Note – 05 Command in Redis (List)

November 11, 2014 Leave a comment

RPUSH key value [value …]
Append one or multiple values at the tail of the list stored at key.
LPUSH key value [value …]
Prepend one or multiple values at the tail of the list stored at key.
LRANGE key start stop
Get a range of elements from a list. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element and so on, the rightmost item is included.



Read more…

Categories: Redis

Redis Learning Note – 04 Command in Redis (String)

November 10, 2014 Leave a comment

In Readis, STRINGs are used to store three types of values:

  1. Byte string value.
  2. Integer value.
  3. Floating-point value.

Integers and floars can be incremented or decremented by an arbitary numeric value (integers turning into floats as necessary).

INCR key
Increment the integer value of a key by one. The string stored at the key is interpreted as a base-10 64 bit signed integer to execute the operation.

DECR key
Decrement the integer value of a key by one.

DECRBY key decrement
Decrement the integer value of a key by the given number.

INCRBY key increment
Increment the integer value of a key by the given amount.

Read more…

Categories: Redis

Get every new post delivered to your Inbox.