Your question is trivially answered if you visit the OWL API page .
The OWL API is a Java library specifically built for manipulating OWL
ontologies. There are a number of code example and a tutorial which
explain in detail how to manipulate OWL ontologies.
PS. Lorenz: there's no such thing as StarDog :) The system is called
Stardog. We've been wondering for a very-very long time (pretty much
since the first beta releases) why people call it StarDog and why that
is so sticky.