For example today there are ".codes", ".farm" and ".vaijes" newly available. How do big companies like google, facebook, twitter, .. keep sure that they are the first who register their name on the new domain? Is there any contract they have with the domain registrar?
There are two approaches which they usually follow.
They register the domain themselves.
They have teams which routinely monitor for registration on domains sounding similar to their watchlist. Once such a domain pops up, they work on taking down the domain citing anti-cybersquatting and filing a domain name dispute to agencies such as WIPO.
When a company wants a domain name which is similar to one of their trademarks, they can sue for the domain. In such a dispute over a domain name, companies with a trademark usually get preference over private people who do not. An example case was when Microsoft sued for MikeRoweSoft.com.
In that case it was about a domain name just phonetically similar to their trademark. Also, the owner of that domain was not just a squatter but had legitimate use for the domain.
Result: MS got the domain through a settlement. But reading between the lines of the settlement definitely shows that the settlement was a PR decision, not a legal one. When they wouldn't have been afraid of media backlash, Microsoft would have won.