How does rubbing cause the transfer of electrons from one object to the other? I have just learnt about electrostatics. Why would there be a transfer of electrons? Is it because of the difference of the materials (i.e. triboelectric series)? So in the case of two different materials contacting each other, will there still be transfer of electrons?
 A: The ability to make material charged by rubbing is called the "triboelectric effect" – "tribo-" is related to rubbing in Greek. When two materials are in touch, a chemical bond develops between the surface molecules of both material, because of differences in their electrochemical potential. When separated, the electrons may stay with one of the materials.
Just for the sake of the argument, imagine that you "rub" Na and Cl. They naturally produce molecules of NaCl on the interface. But the molecule is really $Na^+Cl^-$, so when you separate them, the Na molecule remains positively charged while the chlorine is negatively charged. This is not a realistic example because Cl is a gas :-) but it works in a similar way for more realistic materials.
See half a dozen of other related articles on this server:

https://physics.stackexchange.com/search?q=triboelectric

A: Lubos' answer already here is very good. Just explaining something...
There are terms like Ionization energy, Electron affinity and Electronegativity (mostly used in chemistry) both describe the love for the atoms towards the electrons. The two former ones denote the energy involved while the latter one denotes the ability for transferring electrons.
It's good to say that this "charging by rubbing" effect is a surface phenomenon. Let's consider that you rub a material at one part of the triboelectric electric series with a material at another part. During this friction, the surface atoms of both the materials are pressed together bringing the electron clouds to a closer proximity thereby causing an interaction, which results in the transfer of electrons among the clouds. There are various possibilities for such transferring of electrons (perhaps, not required here)...
It should be noted that these transferred electrons are not so stable. Once they get some contact (like touching), the atoms readily lose these electrons (in accordance with the series) because the ionized ones act in a way on how to "lose their extra electrons or gain deficient electrons" under normal conditions.
Response to your comment:

Air is very likely to lose electrons. Does this mean the matters around us are constantly gaining electrons? Why can't we feel it when we are touching the matter?

Indeed, air is likely to get ionized. The triboelectric series specifically says that materials of the same kind (or those nearer to each other) don't transfer charges when rubbed with each other. Unless you provide a constant supply of electric field (to break its potential barrier), air doesn't have to get ionized. If it does, we can feel the charges like : "Hairs getting up" like that...
