Self studying AP's

Hi I am a rising sophomore who is planning on self studying AP computer science and I was wondering whether or not you can retake AP’s. Because the course maybe offered my junior year and I was curious to know if I could take the exam my sophomore and junior year(if I don’t do so good sophomore year). I ws wondering what policy UCs have for this