title: Java how to register a class instance so that any class can find
body: <p>Suppose I have a Java class like this:</p>
  
  <pre><code>public class FibSolver{
      int fib(int n){
          //returns n-th term of fibonacci sequence
      }
  }
  </code></pre>
  
  <p>I want to register an instance of this class (called FibService), just like RMI service does when registering .stub files, so that other classes that need this service can call it doing something like this:</p>
  
  <pre><code>FibSolver f = (FibSolver) FindMyService("FibService");
  int fib5 = f.fib(5);
  </code></pre>
  
  <p>But I'm doing this from the beginning and don't want to use RMI.</p>
  
  <p>It is also possible to have multiple different classes working as public services, so I'd rather have something like a .stub file than static instances of each class.</p>
  
  <p>How can I do this registering/retrieving instances of services thing?</p>