This post is extracted from a side note in the book Objects First with Java, 7th edition.

The “First computer bug”. Source: Smithsonian National Museum of American History
Errors in computer programs are commonly known as “bugs.” Thus, programs that help in the removal of errors are known as “debuggers.”
The origin of the term is interesting, and often mis-attributed. There is a famous case of what is often referred to as “the first computer bug”—a real bug (a moth, in fact)—which was found inside the Mark II computer by Grace Murray Hopper, an early computing pioneer, in 1945. A logbook still exists in the National Museum of American History of the Smithsonian Institute that shows an entry with this moth taped into the book and the remark “First actual case of bug being found” (see the image above).
Long before this, however, Thomas Edison referred to faults in his inventions as “bugs”. The story goes that this, too, goes back to an actual insect crawling around in his electronics. Whether this story is strictly true or not is unknown. However, it is documented that he regularly referred to faults in his machines as “bugs” in his writings from the 1870s onwards, and probably coined the term.

Thomas Edison with a phonograph. Source: Wikimedia, public domain