Yes, Java fern can be planted in sand. With that said, you need to be careful when planting your Java fern. You can only plant the roots, but not the rhizomes. If the rhizomes are covered in sand, the Java fern won’t be able to absorb any nutrients, causing it to stop growing, rot, and slowly die.
If you can’t differentiate the roots and rhizomes, it’s best to err on the side of caution and avoid planting the fern. In the wild, Java fern is usually found on rocks or driftwood, so you should consider attaching your Java fern to rocks, wood pieces, or decorations in the tank instead.
Alternatively, you can also let the fern float around freely in the water.