It may depend a little on what your code can access, but either way you should read Ed Schröder's pages on this topic. Schröder was the author of the Rebel Chess software until his retirement about a decade ago. In the '90s Rebel was the strongest consumer/commercial chess software and the first such to beat a GM (Anand). Since retiring he turned Rebel into ProDeo and released it for free on his website.
Start with this introduction, though you should already know all that, then have a look at this more in depth explanation. Then check this page for details on adding Rebel/ProDeo books to any engine (will require compiling C code for each platform you want your engine to be able to work). You should be able to add to the books from PGN records before compiling them.
EDIT: Not quite sure why this was voted down, but probably the mention of C when the OP states Java. I should mention that most chess processing software is in C or C++ because it provides better processing capabilities; it compiles to assembly language or machine code, unlike Java, which requires the JVM to run and that makes Java less efficient. Yes, it is possible to compile Java into machine code, but hardly anyone ever does it because then it is no longer platform independent (such as it is). So the OP will be running into the C hurdle no matter what.
Beyond that, these sites on the chess programming wiki on opening books and opening suites may be of use. You'll find a bunch of Ed Scröder's stuff there because he is one of the pioneers who made the shift from hardware electronic chess systems (e.g. Mephisto) to personal computing software. With the added bonus that now he's giving his software and, more importantly, his knowledge away to whoever wants it. If that's really not enough to immerse one's self in the subject then nothing is.