code: public double distance2(double[] point1, double[] point2) throws Exception {
      if (point1.length == point2.length) {
        Double sum = 0D;
        for (int i = 0; i < point1.length; i++) {
          double tmp = point2[i] - point1[i];
          sum = sum + tmp * tmp;
        }
        return sum;
      }
      else {
        throw new Exception("Exception in Euclidean distance: array lengths are not equal");
      }
    }
docs: Calculates the square of the Euclidean distance between two multidimensional points represented
  by the rational vectors.
  
  @param point1 The first point.
  @param point2 The second point.
  @return The Euclidean distance.
  @throws Exception In the case of error.