It's compatible with many Java libraries and IDEs etc. It isn't compatible with Java apps because the UI framework has to be different on a phone. Porting Java apps thereby requires changing only a minority of things rather than everything.
It's like asking why you can write C programs on Windows even though it doesn't provide an X server.
It's like asking why you can write C programs on Windows even though it doesn't provide an X server.