code: public static Geometry longestLine(Geometry geomA, Geometry geomB) {
          Coordinate[] coords = new MaxDistanceOp(geomA, geomB).getCoordinatesDistance();
          if(coords!=null){
              return geomA.getFactory().createLineString(coords);
          }
          return null;
      }
docs: Return the longest line between the points of two geometries.
  @param geomA
  @param geomB
  @return