Clearly, droids are programmed with, or given, a male or female gender. The majority of droid characters are clearly, and definitely, given a male identity and consistently referred to as 'he.' However, TC-14 certainly seemed to be female, plus the server droid in the diner in Episode II and I'm sure there are more.
Is this a part of their programming? Is there a difference between the body of TC-14 and C-3PO for example which makes them have a gender? Could C-3PO be reprogrammed as female, and would this be complicated or more like changing the voice on a sat nav/GPS system? Is it determined by their owner when purchased or first activated?
(These questions are to prompt an answer to the overall one - I don't think I'm really asking multiple questions here).