The rumor that Cersei's children were not fathered by Robert seems to be a popular one, within the realm of Westeros. Quite a few people, over time, mention it. Some even (rather brazenly) mention it to Cersei herself, and even Tywin Lannister. Joffrey refuses to believe that the rumor could have any merit because it would undermine his claim to the throne. Why would he ever give it any credence? It would remove him from power, and that's something he desperately loved.
At least in the show, I do get the impression that he was struggling with some cognitive dissonance about it, though. One one hand, he didn't want to believe he was the product of incest. On the other, he did ask his mother on a few occasions about why people would even say it, and Cersei obviously denied it, but I don't think he was ever entirely convinced that the rumors were baseless. By having the bastards killed, it eliminated any other children from ascending to the throne by claiming that their parentage gave them a better claim than Joffrey, Tommen, or Myrcella. It sort of ends the conversation altogether. The child of Robert Baratheon would be the heir to the throne before any of Robert's siblings, so killing the bastards eliminates them as a threat to Joffrey's kingship.
Whether it's Joffrey or Cersei giving the order seems sorta irrelevant to me, given how much sway Cersei has over her children. It's less obvious with Joffrey than it is with Tommen, but all she'd have to tell him is that the bastards want to take the throne, his birthright, from him and I think he'd follow through in the same way.