Subhendu Dash wrote:
Ivan Jozsef Balazs wrote:
Subhendu Dash wrote:Is there any method present in Java API
Is the private stuff per definition not part of the API, the Application Programming Interface?
Yes it is..in fact it provides the best way to hide our implementation from the outside world and thus encapsulating our code..but here my question was about having a private method in an API.. which no one can call..so what's the use of it. And if the scenario is that some framework or JVM calls it internally then whats the point of mentioning it int the API..
If I'm the author of the API, I'll create private methods just like anybody else. Methods that I will use internally but that are not intended to be called by anyone else.
The private readObject() and writeObject() in the serialization mechanism are oddballs, special cases. I'm not sure why they were done that way, but I'm sure at the time somebody had a reason that seemed to make sense. Even though no normal Java code can call them, the JVM can do whatever it wants. It has to be able to, otherwise nothing could ever get done. Presumably the JVM knows about the serialization mechanism, and as part of that process it has special rules that tell it to call those methods at the appropriate time.