It’s common in a lot of classes in JDK, just a few examples:
- java.util.Properties
- load0
- store0
- java.lang.Thread
- start0
- stop0
- setPriority0
Usually they are private native methods (like in Thread class), but sometimes they are just private (Properties class)
I’m just curious if anybody know if there is any history behind that.
The use of zero suffixes on method names is just a convention to deal with cases where you have a public API method and a corresponding private method. In the Java SE libraries, this is commonly used for the
nativemethods that provide the underlying functionality implemented by the classes. (You can see what is going on by looking at the OpenJDK source code.)But your questions are:
Because someone thought it would be a good idea. It is not strictly necessary since they typically could have overloaded the public methods instead. And since the zero suffix matters are private, the naming of methods should not be relevant beyond the class and its native implementation.
There is no mention of this convention in the original Java Style Guide. In fact, I think it predates Java. I vaguely recall seeing it in C libraries in 4.x BSD Unix. That was the mid 1980’s. And I wouldn’t be surprised if they adopted it from somewhere else.