It's Java so any code you write that doesn't depend on any target specifcs will be fine. However there's different feature sets to target and other platform quirks so there will be sections of abstraction and interface code that will have to be written with Android in mind and same again for the full JRE on desktops.

So much for compile once run everywhere...

EDIT : unless as paul states, you use something like libGDX which handles all of that for you