Block are generated basically at random so there is a possibility that even if I generate a block, that I might not have been the first to generate that particular block, hence the need for confirmations. However, how can I programmatically check if I generated block number X?
You can compare your hash with the hash of that block in the active block chain.