I just wrote a Java program that cannot lose at a game of Tic-Tac-Toe. Your best hope is to tie it in a game.
You can find the full code here: github.com
It works by using the minimax algorithm. I'll be writing an article about this on my personal blog soon.
I would appreciate it very much if you could take a peek at the code and tell me what you think. Any feedback would be very much appreciated!