In Java, static means that it's a variable/method of a class, it belongs to the whole class but not to one of its certain objects. This means that static keyword can be used only in a 'class scope'.
Advantages of encapsulation:
It improves maintainability and flexibility and re-usability: .... Since the implementation is purely hidden for outside classes ...
Race conditions tend to be "deterministic" in testing scenarios and only break when loads spike (i.e. in production). that's what make them so "fun" to track down.
A reference variable can refer to any object of its declared type or any subtype of its declared type. A reference variable can be declared as a class or interface type.
hamada yam wrote:
if no static method then singleton is useless == invalid singleton , right ?
When should I choose inheritance over an interface when designing C# class libraries?
Generally, the rule goes something like this:
- Inheritance describes an is-a relationship.
- Implementing an interface describes a can-do relationship.
In general, classes are the preferred construct for exposing abstractions.
The main drawback of interfaces is that they are much less flexible than classes when it comes to allowing for the evolution of APIs. Once you ship an interface, the set of its members is fixed forever. Any additions to the interface would break existing types implementing the interface.
A class offers much more flexibility. You can add members to classes that you have already shipped. As long as the method is not abstract (i.e., as long as you provide a default implementation of the method), any existing derived classes continue to function unchanged.
[ . . . ]
One of the most common arguments in favor of interfaces is that they allow separating contract from the implementation. However, the argument incorrectly assumes that you cannot separate contracts from implementation using classes. Abstract classes residing in a separate assembly from their concrete implementations are a great way to achieve such separation.
When you set the reference of any object to null, it becomes available for garbage collection. It still occupies the memory until the garbage collector actually runs. There are no guarantees regarding when GC will run except that it will definitely run and reclaim memory from unreachable objects before an OutOfMemoryException is thrown.
You can call System.gc() to request garbage collection, however, that's what it is - a request. It is upto GC's discretion to run.
Because StringBuffer is mutable, and its primary use is for constructing strings.
ArrayList - The ArrayList is actually encapsulating an actualy Array, an Object[].
LinkedList - The LinkedList is implemented using nodes linked to each other. Each node contains a previous node link, next node link, and value, which contains the actual data.