Nothing in this sentence is receiving an object (that would use dative). Instead, we have "haben" which like most verbs uses the accusative case. Simply put, the accusative case is used to indicate the object which relates to the subject. This sentence has the subject "I" and the thing that is had is "a friend." Since "Freund" is a masculine noun, the indefinite article in the accusative case is "einen."
Hope this helps!
Freund -> male friend/boyfriend
Freundin -> female friend/girlfriend
Freunde -> friends (male or mixed)
Freundinnen -> friends (female only, but this might sound oddly specific)
Context should clear up the abiguity, but you can always add "von mir" to them to mean friend rather than boyfriend/girlfriend. Using possesive pronouns usually implies boyfriend/girlfriend. Now having said that, this sentence should definitely be "boyfriend," in my opinion, due to the fact that people (usually) have more than just one friend so this sentence points out a particular friend as being special.
The purals can also mean boyfriends/girlfriends if your talking about exes or a group of people's significant others, for instance.
Might have gone a bit overboard on the explanation, but hopefully this helps!
Freund is a masculine word, and here it is the direct object of the verb habe (i.e., it is the noun that the verb is directly acting upon), so you have to inflect the indefinite article ein to match the accusative case (the case for direct objects). The masculine singular accusative inflection of ein is einen.