Basically, the APPLICATION value is a hardcoded constant. The value for the APPLICATION constant is obtained from the ASN.1 BER encoding specifications. In ASN.1 BER encodings each value has an associated tag and length. A tag is composed of tag class and tag number. There are four tag classes: universal, application, context-specific, private. These four values are encoded as two bits on the positions 8 and 7 of the first octet of the tag encoding. The bits corresponding to the application class are 01 (bit 8 and bit 7), and translated in hex this gives the 0x40 bit mask, which is used below to compute the tag values using bitwise operations.
For more details about the BER encoding, see for example http://luca.ntop.org/Teaching/Appunti/asn1.html.