A: 

Keep a static private instance

class Foo {
    private static Foo myInstance = new Foo();

    public static void MyPretendInstanceMethod() {
        myInstance.doBar();
    }

    private void doBar() {
        // do stuff here
    }

}

Add synchronization as necessary.

glowcoder
+1  A: 

class methods share the same memory location for all instances of the object

So do instance methods. The code for all methods of a class exists only once. The difference is that instance methods always require an instance (and its fields) for context.

If I were to create a class variable to keep track of errors, wouldn't that introduce a situation where process A could trigger an error in process B? Can instance methods even access class variables?

Yes and yes. This is why having non-final static fields is generally considered a bad thing.

Michael Borgwardt
"This is why having static fields is generally considered a bad thing." ... except for "constants" (final primitive/inmutable) which are read only.
leonbloy
So if I were to re-declare all of the methods as instance methods (remove the static keyword) then I would not incur a memory penalty? That is, each new page request wouldn't require any more memory than if the methods were static?
jsumners
@jsumners: it would require you to create at least one instance, which takes up about 8 bytes plus whatever instance fields you define - not worth worrying about, in other words.
Michael Borgwardt
Thanks. I believe this answer, and discussion, addresses my question most directly.
jsumners
A: 

Static methods can only access static class variables. They cannot access instance variables because static methods are not tied to any specific instance of the class.

You don't need to create a new instance of a class in order to access a static member or variable (as long as it's public). In your example, you can call methodB like this:

String bString = MyClass.methodB();

As you can see, no new instance had to be created.

But because methodA is not static, you must create an instance of the class in order to call it, like you did in your example:

MyClass myClass = new MyClass();
String aString = myClass.methodA();
Michael Angstadt