code: private static double computePerimeter(Geometry geometry) {
          double sum = 0;
          for (int i = 0; i < geometry.getNumGeometries(); i++) {
              Geometry subGeom = geometry.getGeometryN(i);
              if (subGeom instanceof Polygon) {
                  sum += ((Polygon) subGeom).getExteriorRing().getLength();
              } 
          }
          return sum;
      }
docs: Compute the perimeter
  @param geometry
  @return