You have got to practice, practice, practice.
You will usually find that looking at a bit of code in a book, or on a screen, that you can understand what it is doing. But when you come to write some code yourself that you don't understand the topic as well you thought you did. You forget the method names, what parameters the methods take, what exceptions they throw etc.