Dan Drillich

Ranch Hand
+ Follow
since Jul 09, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
23
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dan Drillich

Hi Puspender,

why cant we declare static variables inside a function body even the function is static? speaks about it.

I like this part -

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'.



Regards,
Dan
Hey Henno,

Encapsulation in Java with example says -

Advantages of encapsulation:
It improves maintainability and flexibility and re-usability: .... Since the implementation is purely hidden for outside classes ...



Regards,
Dan
Good Day,

Multithreading: Why this output? Is it deterministic? speaks about this subject.

I like the following from there -

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.



Regards,
Dan
Hi Ravi,

The distinction is made very clear at Checked versus unchecked exceptions.

Regards,
Dan
Hi Satyres,

Java - Polymorphism says -

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.



An example follows ...

Regards,
Dan
It's interesting to see the error message -



Regards,
Dan
Hey Vimlesh,

The official documentation explains nicely the usage of - String[] args at Lesson: A Closer Look at the "Hello World!" Application.

Regards,
Dan

hamada yam wrote:
if no static method then singleton is useless == invalid singleton , right ?


Useless is probably a better description than invalid ; - )

A very cute article at Navigate the deceptively simple Singleton pattern.

Regards,
Dan
Hey Lorenzo,

When should I choose inheritance over an interface when designing C# class libraries? is very interesting.

It says -


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.



and -


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.



Regards,
Dan
Hey Chris,

Adding this line -



And I get the error message -



Regards,
Dan
Henry Joe,

The following works -



Regards,
Dan
The error message is a cute and precise one -



Regards,
Dan
Akshay,

In most of my runs I get the output.

When does Java's garbage collection free a memory allocation? explains it nicely -

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.



Regards,
Dan
Why does StringBuffer/StringBuilder not override equals or hashCode? explains -

Because StringBuffer is mutable, and its primary use is for constructing strings.



Regards,
Dan
Hi Aman,

Looking at LinkedList vs. ArrayList and it says -


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.



The definitions explain why iteration in LinkedList is slow while insertion and deletion is faster than ArrayList and Vector.

In a LinkedList one has to traverse the list via links from one node to another, versus the simpler array.

For insertions and deletions, in a LinkedList, only a couple of references need to change while in an ArrayList an entire section of the array need to shift.

Regards,
Dan