javafx detect collision

Java
if(rectangle1.getBoundsInParent.intersects(rectangle2.getBoundsInParent)){

//do something

}
Source

Also in Java: