There are teams of experts at the anti-virus companies that monitor new files, and analyse them (not just for the methods mentioned above - there are many different types & styles of virus).

They put the details for detecting the "virus" files into what is known as a Pattern file, and this is distributed to the users of their anti-virus software (so it can spot the virus files).

As there are so many viruses out there, it's best to leave it to the experts - on your own you'll never even catch up to where they were 5 years ago.