How Does a Best Practice Come About?
Slowly, and with experience. But let’s take a step back first and look at how anyone becomes an expert in a specific environment. A programmer goes through four steps when learning to program with any modern language, including Java:[1]
You learn the syntax of the language, usually through a tutorial of some sort. In the case of Java, you quickly learned, for example, that, unlike with C++, there was no “delete” keyword for memory deallocation. The garbage collector took care of that automatically. You also learned that the Java language designers included a “synchronized” keyword to help you avoid common threading issues.
You learn the environment that you’re programming toward. Is it on a 2 GHz PC, or an embedded controller with limited memory on a cell phone? Are you targeting a PDA with access to a business network? Are you compiling toward a supercomputer Internet server that must handle millions of connections per day? Perhaps it’s only one of the above. Perhaps all.
You learn how to use one or more specialized libraries and APIs with the language. Often, this involves a more direct tutorial or reference book. For example, a good many of you learned how to use the servlet API by reading one of our books, Java Servlet Programming. Or perhaps you learned from some other book,[2] or even from an article on the Internet.
You slowly begin to gain experience, gleaning tips and tricks for using both the language and the APIs in the defined environment. ...