Howdy. 

When we write a programn in Java we need to define at least a class. 

Inside the class we can static members: variables and procedures. 

These static members exist as soon as we compile the class. 

Visibility modifiers are not as crucial as whether the members are static
or non-static. A non-static member is called an instance member. Instance
variables are usually initialized by constructors. Constructors are just
initialization procedures they are not members. A surprising rule is that
if you don't write any constructor in your class there will be one there, 
the no-arg default constructor. (default: in absence of something explicit)

But these are all instance concepts. Let's define our own version of
Math.sqrt(...) maybe by using our C211 knowledge in this context.


class Math {
   
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Math a = new Math();
> a
Math@6067fc03


class Math {
  // double --> double 
  static double fun(double number) {
    return 2 * number;     
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Math.fun(3)
6.0


class Exercise {
  public static void main(String[] args) {
    System.out.println( Math.fun(2.4) ); 
  }
}

class Math {
  // double --> double 
  static double fun(double number) {
    return 2 * number;     
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Exercise
4.8


class Exercise {
  public static void main(String[] args) {
    System.out.println( java.lang.Math.max(2, 4) ); 
  }
}

class Math {
  // double --> double 
  static double fun(double number) {
    return 2 * number;     
  }
  public static void main(String[] args) {
    System.out.println( Math.fun( -2.3) );  
  }
}

class Math {
  static double sqrt(double number) {
    double low = 0, high = number; 
    double guess = (high + low) / 2; 
    System.out.println( low + " " + high + " " + number + " " + guess );
    do { 
      if ( guess * guess - number > 0 ) 
        high = guess;
      else if ( guess * guess - number < 0 ) 
        low = guess; 
      else 
        break;
      guess = (high + low) / 2;
    } while ( (high - low) > java.lang.Math.pow(10, -12));
    return guess; 
  }
  public static void main(String[] args) {
    System.out.println( Math.sqrt( 2 ) + " " + java.lang.Math.sqrt( 2 ));  
    System.out.println( Math.sqrt( 3 ) );  
    System.out.println( Math.sqrt( 6 ) );  
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Math
0.0 2.0 2.0 1.0
1.414213562372879 1.4142135623730951
0.0 3.0 3.0 1.5
1.7320508075689531
0.0 6.0 6.0 3.0
2.4494897427831575


static methods should be called by the class name that they belong to,
folowed by a period (dot operator), followed by their name. Examples:

Integer.parseInt(...)

http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#parseInt(java.lang.String)

Programs are written for people and only incidentally are run by the
computer. So using this convention will simplify things.

class Egg {
  static int fun(int a) {
    return 1 + a; 
  }
  int fun(int a, int b) {
    return a + b;  
  }
  /* this won't work though:
   * int fun(int a) {
   *   return 1 + a; 
   * } // reason: same signature
   */
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Egg.fun(4)
5


Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Egg.fun(3, 4)
Static Error: No method in static Egg with name 'fun' matches this invocation
    Arguments: (int, int)
    Candidate signatures: int fun(int)
> Egg a = new Egg()
> a
Egg@3a73875e
> a.fun(4, 5)
9
> a.fun(8)
9
>