I was wondering recently why do both java.lang.Runtime
and java.lang.System
have the same methods for library loading, garbage collecting and similar operations. Is it because of historical reasons, for convenience, or they really differ? Both classes are available from JDK 1.0...
My guess (remember, its a guess), is that methods in the System
class are there for convenience. For example, System.gc();
is static, where Runtime.gc();
is an instance method. This makes the call easier to make, since you don't need to obtain a Runtime
instance.
System exposes various things it might be appropriate for a developer to use the System for.
I would be concerned about a programmer playing directly with the Runtime. For System to call the methods, they need to be exposed.
System provides an interface to the Runtime to enable access to Runtime methods that are appropriate to be called by programmers. Call the System methods and let them delegate appropriately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With