How to use java class without main method : <p>I was looking for a code of "Whale_optimization_algorithm" in Java and I found it on a site but when I am trying to run it. It shows the error of "could not find or load Main class Whale_optimization_algorithm.java"
But it compiled successfully.</p>

<p>Here is the Code</p>

<pre><code>package test;

import java.io.*;

abstract class f_xj
{
abstract double func(double x[]);
}

public class Whale_optimization_algorithm {



    double A;   
    double C;   
    double a;
    double a2;
    double b;
    double l;
    double p;
    double r1;
    double r2;
    double Leader_score;
    double[] Leader_pos;
    double D_Leader;
    double distance2Leader;
    double[] Lower;
    double[] Upper;
    double[] X_rand;
    double D_X_rand;
    int Maxiter;
    int rand_leader_index;
    double[][] Positions;
    double[] Fitness;
    int N;
    int D;
    f_xj ff;


    public Whale_optimization_algorithm(f_xj iff, int iMaxiter, double[] iLower, double[] iUpper, int iN)
    {
    ff=iff; 
    Maxiter=iMaxiter;   
    Lower=iLower;   
    Upper=iUpper;   
    D=Lower.length;
    N=iN;
    Positions=new double[N][D];
    Fitness=new double[N];
    Leader_pos=new double[D];
    X_rand=new double[D];
    Leader_score=100000000000.0;

    }


    void init()
    {
      for(int i=0;i&lt;N;i++)
      {for(int j=0;j&lt;D;j++)
         {Positions[i][j]=Lower[j]+((Upper[j]-Lower[j])*Math.random());}}

    }


    double[][] solution()
    {
    init(); 
    int iter=0; 

       while(iter&lt;Maxiter)
       {
           for(int i=0;i&lt;N;i++)
           {
               for(int j=0;j&lt;D;j++)
               {if ((Positions[i][j]&lt;Lower[j]) || (Positions[i][j]&gt;Upper[j]))
                  {Positions[i][j]=Lower[j]+((Upper[j]-Lower[j])*Math.random());}}   

               Fitness[i]=ff.func(Positions[i]);   

               if(Fitness[i]&lt;Leader_score)
               {
                  Leader_score=Fitness[i];
                  for(int j=0;j&lt;D;j++)
                  {Leader_pos[j]=Positions[i][j];}     
               }

           }       
           a=2.0 - (double)iter*(2.0/(double)Maxiter);
           a2= -1.0 + (double)iter*(-1.0/(double)Maxiter);

           for(int i=0;i&lt;N;i++)
           {
            r1=Math.random();   
            r2=Math.random();
            A=2.0*a*r1-a;
            C=2.0*r2;   
            b=1.0;  
            l=(a2-1.0)*Math.random() + 1.0;
            p=Math.random();

                 for(int j=0;j&lt;D;j++)
                 {
                      if (p&lt;0.5)
                      {
                          if (Math.abs(A)&gt;=1.0)
                          {
                              rand_leader_index=(int)Math.floor((double)N*Math.random());
                              X_rand[j]=Positions[rand_leader_index][j]; 
                              D_X_rand=Math.abs(C*X_rand[j] - Positions[i][j]);     
                              Positions[i][j]=X_rand[j] - A*D_X_rand;
                          }    
                          else if (Math.abs(A)&lt;1)
                          {
                          D_Leader=Math.abs(C*Leader_pos[j] - Positions[i][j]);
                          Positions[i][j]=Leader_pos[j]-A*D_Leader;    
                          }
                      }    
                      else if (p&gt;=0.5)
                      {
                       distance2Leader=Math.abs(Leader_pos[j] - Positions[i][j]);   
                       Positions[i][j]=distance2Leader*Math.exp(b*l)*Math.cos(l*2.0*Math.PI) +  Leader_pos[j]; 
                      }

                 }
            }

       iter++;   
       }


            double out[][]=new double[2][D];
            out[0][0]=Leader_score;
            for(int i=0;i&lt;D;i++)
            {out[1][i]=Leader_pos[i];}
            return out;

}

    void toStringnew()
    {
      double[][] out=solution();
      System.out.println("Optimized value = "+out[0][0]);
      for(int i=0;i&lt;D;i++)
      {System.out.println("x["+i+"] = "+out[1][i]);}    
    }


    void toTxtfile()
            {   String named="whale_plateframe_f36_ackley.txt";
                String line="";
                int lineNo;
                try
                   {
                   FileWriter fw=new FileWriter(named,true);       
                   BufferedWriter bw=new BufferedWriter(fw);
                   LineNumberReader lnr=new LineNumberReader(new FileReader(named));   
                   lnr.setLineNumber(1);
                   for(int i=1;i&lt;=lnr.getLineNumber();i++)
                   {bw.newLine();}
                   double[][] dd=solution();
                   Double d1d=new Double(dd[0][0]);
                   String s1=d1d.toString();
                   int nn=dd[1].length;
                   Double[] val=new Double[nn];
                   String[] str=new String[nn];
                   for(int i=0;i&lt;nn;i++)
                   {val[i]=new Double(dd[1][i]);}
                   for(int i=0;i&lt;nn;i++)
                   {str[i]=val[i].toString();}
                   bw.write(s1+" ");
                   for(int i=0;i&lt;nn;i++)
                   {bw.write(str[i]+" ");}
                   bw.close();
                   lnr.close();
                   }catch(IOException e)
                   {e.printStackTrace();}

            }
}
</code></pre>

<p>Please Help me. I am new to Java.
If i've to add method how can i add it or call this class in method?</p>
