There are are a ton of great answers for your questions on StackOverflow:
And of course, Google is always your friend: