Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

8. Good Citizenship > Static Methods

Static Methods

Static methods have one wonderful use: as a black-box, standalone, stateless method. The use of static methods of the Math class in Java illustrates good use. When you call the Math.sqrt() method, you don’t worry that a subsequent call might return the cube root instead of the square root because some state within the sqrt() method changed. Static methods work well when they are completely stateless. You get into trouble when you start mixing staticness and state.

Static Methods and Hawaii

For many years, I worked at a consulting and training company, and we taught a wide variety of Java topics. I got what was considered the Holy Grail of teaching gigs: two classes to two groups of developers in Hawaii. The schedule had me there two weeks (one week per class), three weeks back home, and then there again for the second set of classes for two weeks. And, of course, I was required to stay over the weekend, and as a good company man, I managed to persevere. It was a tough class, however, because all of the students came from a mainframe background. I remember one student who couldn’t quite grasp the concept of matching curly brace....


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint