Hope it helps, but your question is not about a chunk of code that you can copy/paste, its more about "basic" concepts. So for this kind of things I really recommend you to follow some tutorial because you will understand all the underlying concepts better. Cheers!