We report a study of the electronic structure and optical properties of uranium dioxide (UO2) based on the ab-initio density-functional theory and using the generalized gradient approximation. To correctly describe the strong correlation between 5f electrons of a uranium atom, we employ the on-site Hubbard U correction term and optimize the correlation parameter of the bulk uranium dioxide. Then we give the structural and electronic properties of the ground state of uranium dioxide. Based on the accurate electronic structure, we calculate the complex dielectric function of UO2 and the related optical properties, such as reflectivity refractive index, extinction index, energy loss spectra, and absorption coefficient.