Barney tells Sam that he did his part to whip the dreaded Hun, which would technically mean he served in WWI, although it's more likely that Barney meant WWII. In the Reunion episode, we learn that Barney graduated from high school in 1946. However, in the much later episode, The Return of Barney Fife, we are told that he graduated in 1948. Since World War II ended in 1945, it's not very likely that Barney would've served in it. Sam says that he served during the Korean War.