Once a Java class implements a Java interface we can use an instance of that class as an instance of that interface like this.  public interface MyInterface {      public String hello = "Hello";      public void sayHello(); }      public class MyClass implements MyInterface {          public void sayHello() {             System.out.println(MyInterface.hello);         }         public void extra(){         System.out.println("this is extra");         }     }  MyInterface myInterface_instance = new MyClass ();  myInterface_instance .sayHello();   But my question is what is the advantage of creating like this?. If we do this it will narrow down the extra methods and attributes in the class that are not in the interface as well. ex  we can't use myInterface_instance.extra()  So why are we instantiating java interfaces like this, rather than assigning it to its own class instance like this?   MyClass myclass_instance = new MyClass ();
I have seen this mentioned a few times and I am not clear on what it means. When and why would you do this?   I know what interfaces do, but the fact I am not clear on this makes me think I am missing out on using them correctly.   Is it just so if you were to do:  IInterface classRef = new ObjectWhatever()   You could use any class that implements IInterface? When would you need to do that? The only thing I can think of is if you have a method and you are unsure of what object will be passed except for it implementing IInterface. I cannot think how often you would need to do that.   Also, how could you write a method that takes in an object that implements an interface? Is that possible?
Set same icon for all my Forms Is there any way to set the same icon to all my forms without having to change one by one? Something like when you setup GlobalAssemblyInfo for all your projects inside your solution. Securely erasing all data from a hard drive Player looses boot after tackle To prove Cayley-Hamilton theorem, why can't we substitute $A$ for $\lambda$ in $p(\lambda) = \det(\lambda I - A)$? Why would you put Identity Increment other than 1 in SQL? I have a basic doubt about the associativity of the cartesian product. Well, first wikipedia says that the cartesian product isn't associative, and there's a good argument for it: if $x\in E$, $y\in F$ and $z \in G$ the identity $((x,y), z)=(x,(y,z))$ would imply that $(x,y) =x$ and $(y,z) = z$ so that $((x,y),z)=(x,y,z)$ would mean nothing.  That's fine, I like this argument. However, in his book Calculus on Manifolds, Spivak says that the cartesian product is associative. He says: if $A \subset \mathbb{R}^m$, $B\subset \mathbb{R}^n$ and $C \subset \mathbb{R}^p$ then $(A\times B)\times C = A \times (B \times C)$, and both of these are denoted simply by $A \times B \times C$.  Well, this confuses me because Spivak is always very rigorous, so that he wouldn't state something that's not true in such way. Is Spivak or Wikipedia right ? Or Spivak's statement only works for subsets of euclidean spaces ?  Thanks in advance and sorry if this question is too basic. BGE everything white in playmode When I press P to play everything shows up white in the BGE. Shading is set to GLSL, and the objects are UV mapped and textured. It seems that vertex paint is overriding the material for the object even though it is unchecked in the material options.   Shading is set to GLSL   Objects have a texture applied Why don't languages raise errors on integer overflow by default? In several modern programming languages (including C++, Java, and C#), the language allows  to occur at runtime without raising any kind of error condition.  For example, consider this (contrived) C# method, which does not account for the possibility of overflow/underflow.  (For brevity, the method also doesn't handle the case where the specified list is a null reference.)    //Returns the sum of the values in the specified list. private static int sumList(List&lt;int&gt; list) {     int sum = 0;     foreach (int listItem in list)     {         sum += listItem;     }     return sum; }   If this method is called as follows:  List&lt;int&gt; list = new List&lt;int&gt;(); list.Add(2000000000); list.Add(2000000000); int sum = sumList(list);   An overflow will occur in the sumList() method (because the int type in C# is a 32-bit signed integer, and the sum of the values in the list exceeds the value of the maximum 32-bit signed integer). The sum variable will have a value of -294967296 (not a value of 4000000000); this most likely is not what the (hypothetical) developer of the sumList method intended.  Obviously, there are various techniques that can be used by developers to avoid the possibility of integer overflow, such as using a type like Java's , or the  keyword and  compiler switch in C#.  However, the question that I'm interested in is why these languages were designed to by default allow integer overflows to happen in the first place, instead of, for example, raising an exception when an operation is performed at runtime that would result in an overflow.  It seems like such behavior would help avoid bugs in cases where a developer neglects to account for the possibility of overflow when writing code that performs an arithmetic operation that could result in overflow.  (These languages could have included something like an "unchecked" keyword that could designate a block where integer overflow is permitted to occur without an exception being raised, in those cases where that behavior is explicitly intended by the developer; C# actually .)  Does the answer simply boil down to performance -- the language designers didn't want their respective languages to default to having "slow" arithmetic integer operations where the runtime would need to do extra work to check whether an overflow occurred, on every applicable arithmetic operation -- and this performance consideration outweighed the value of avoiding "silent" failures in the case that an inadvertent overflow occurs?  Are there other reasons for this language design decision as well, other than performance considerations? In a preadditive category, products are coproducts $\renewcommand{\phi}{\varphi}$ $\require{AMScd}$ My question is different from .  I want to see how in a preadditive category $\mathcal{C}$ a product is a coproduct, following . I'll write the proof up to the point where I get stuck.  Let $A=A_1,B=A_2$ be objects and suppose their product $P$ does exist, with projections $\pi_i:P\rightarrow A_i$. By considering a wedge  $$\begin{CD}A @&lt;{id_A}&lt;&lt;  A @&gt;{0_{AB}}&gt;&gt;  B\end{CD}$$  and the obvious analogous one with $A$ and $B$ exchanged, where $0_{A,B}$ is the zero morphism, we see that the product property implies the existence of two unique morphisms $k_i\in\mathcal{C}[A_i,P]$ s.t.  \begin{align*} \pi_j\circ k_i=\begin{cases} \mathrm{id}_i &amp;\text{if }i=j\\ 0_{A_i, A_j} &amp;\text{if }i\neq j \end{cases}. \end{align*} Using these equations and the definition of zero morphism, it's easy to see that the morphism $m\equiv k_1\circ \pi_1+ k_2\circ \pi_2$ satisfies $\pi_i\circ m=\pi_i$.   This is where I get stuck: In the linked proof, they now state that this implies $m=\mathrm{id}_P.$ But I don't see why this should be true.   Specifically, if $\phi\in\mathcal{C}[S,P]$ for some arbitrary object $S$, it is not apparent why $m\circ\phi=\phi$. All that we know is that there are some morphisms $x_i\in\mathcal{C}[S,A_i]$ that factor through $P$ via the universal property, but these are not necessarily unique.  And we learn even less about $m$ by looking at morphisms in $\mathcal{C}[P,S]$.  What am I missing here? Convert list of ints to one number? As a disclaimer, I must admit this may benefit me (I haven't checked), but probably not as significantly as most others. This issue is also something that has prevented me from answering questions by users with 1 rep in the past, especially if they are poorly fashioned. The Problem New users with a programming question find SO from various methods, such as google. They ask a question with haste, hoping for a quick answer -- which they usually receive. Many of these users have no interest in Stack Overflow itself, but are simply interested in getting the solution they require. As a result of this, they'll check the site regularly for the first day or two until a sufficient answer has been posted. Once they get what they need, they bail; without the required rep or understanding that they should up-vote and select a response as the answer. The Result A great many questions on SO are abandoned by users with no intention of ever coming back. The answer they require has been provided, but for one or more reasons they have neglected their duty of contributing back by way of awarding reputation. The Reach (Since Jeff loves Datum) Some queries on the data dump examine the reach of this 'problem'. The query I used is based on extensions of the following base query; SELECT p1.Id, p1.Score, p1.OwnerUserId, p2.OwnerUserId, p2.Score FROM posts p1  INNER JOIN posts p2 ON (p1.Id=p2.ParentId) LEFT JOIN users ON (p1.OwnerUserId=users.Id) WHERE p2.Score &gt;= 2  AND p2.Score = ( SELECT MAX(p3.Score) FROM posts p3 WHERE p3.ParentId=p1.Id ) AND users.Reputation &lt; 15 AND p1.PostTypeId = 1 AND p1.AcceptedAnswerId = 0  Result: 3,288 Questions by users with under 15 rep which have answers with 2+ up votes that have no accepted answer. Adding: AND (users.LastAccessDate-p1.LastActivityDate) &lt; 604800 // 1 week AND p1.CreationDate &lt; 1249084800 // 1249084800 is 1 week before latest dump data  to the where clause further reveals that 877 questions that have answers with 2+ up votes have no accepted answer, and the owner of the question has not returned since the week the question was asked. Modifying there where clause, and removing the left join: AND p1.OwnerUserId = 0    Reveals a staggering 3,675 questions with answers of 2+ votes by deleted users.  These are questions that were probably answered but the users who did the work can never be recognized. Building off the previous and using an even more restrictive WHERE clause WHERE p2.Score &gt;=5  Still 1,178 posts that can never have an accepted answer. How many posts are there with over 5 up votes that don't provide the correct answer? Modifying the where clause for Reputation to AND users.Reputation = 1  Still reveals 388 questions by users with 1 rep have been abandoned. Solution Similar to how bounty questions work, if a user has abandons the site (not active since x time after the question was asked) with a question that has answers with 2+ up votes, force the answer with the most up votes to be the selected answer. This will reduce the amount of questions that are unanswered, and also give users more of an incentive to answer questions by new users without extra hesitation.  Update Added more statistics for deleted users.  Please feel free to add/remove rules to make this a truly practical feature. How to provide a counterexample for if $n$ is prime, then $2^n -1$ is prime I have the following question where I need to provide a counterexample     if $n$ is prime, then $2^n -1$ is prime   The statement is invalid and I now that $2^n -1$ is not prime when $ n = 11$, but other than plugging in prime numbers is there any other way to figure out whether $2^n -1$ is prime if $n$ is prime? Combinatorial argument for $\sum\limits_{k=i}^{n}\binom{n}{k}\binom{k}{i} = \binom{n}{i}2^{n-i}$ 2 GROUP BY WITH DISTINCT , SUM , COUNT : PHP MYQL Ref :   I got answer (thanks coytech ) but i need one more column in its :  as per :  id | mid | pid | owgh | nwgh | 1    3      12    1.5    0.6 2    3      12    1.5    0.3 3    3      14    0.6    0.4 4    3      15    1.2    1.1 5    4      16    1.5    1.0 6    4      17    2.4    1.2  7    3      19    3.0    1.4   i got answer      Select mid ,          COUNT(distinct pid) as cpid  ,          SUM(nwgh) as totalnwgh  from test  GROUP BY mid   sqlfiddle :   mid  cpid       totalnwgh 3      4          3.8 4      2          2.2    But above i need one more column that's as below : totowgh  mid cpid        totalnwgh  totowgh 3      4          3.8        6.3 (DISTINCT value as per pid column) 4      2          2.2        3.9   where totowgh = 6.3 come by DISTINCT value of owgh column  as per distinct pid column  mid = 3 has count 5 but distinct pid  = 4 for mid=3 same way "distinct" owgh = 6.3 for mid=3 and distinct pid.  As pid=12 , column owgh value 1.5 is twice ...hence its is count 1 time hence,  1.5 + 0.6 + 1.2 + 3 = 6.3 ( please not this is as per DISTINCT value of pid )  Please note : i need distinct owgh value as per distinct pid or group by pid .. because if i replace value of owgh 0.6 with 1.5 then it will be 5.7 instead of 7.2 but value of owgh 0.6 belong to pid = 14 and not pid = 12 hence totalcount of owgh change ...but i need is 7.2  SEE WHAT I MEANS   : Where did Hogwarts get money for salaries, food and other purchases? Evolution of the Redundancy of the Genetic Code The definition of derivative of a function $f(x)$ is $$\lim_{h\to0} \frac{f(x+h)-f(x)}{h}$$  Using this definition, the derivative of $\sin\sqrt{x}$ will be:  $$\lim_{h\to0} \frac{\sin\sqrt{x+h}-\sin\sqrt{x}}{h}$$  $$\lim_{h\to 0} \frac{\cos\left(\frac{\sqrt{x+h}+\sqrt{x}}{2}\right)\sin\left(\frac{\sqrt{x+h}-\sqrt{x}}{2}\right)}{h}$$  Now i got stuck. How to find the limit or simplify this expression?  I get intuition that we have to use $$\lim_{x\to0}\frac{\sin x}{x} = 1$$  but that too is leading no where. I am unable to remove h from denominator.  NOTE  I know the derivative of $\sin\sqrt{x}$ is $\frac{\cos\sqrt{x}}{2\sqrt{x}}$ using chain rule, but this exercise was given to us for practice using division quotient. How to allow non-superusers to mount any filesystem? Is it possible to allow some particular users (e.g. members of a group) to mount any filesystem without superuser privileges on Linux?  Another question might have been "in what ways a user can harm a system by mounting filesystems?" Delay in 4-bit ripple carry adder? In pic below I have drawn a full adder and mentioned their delays, please help me to verify my answer. Can the Universe be deterministic and still allow free will? Possible Duplicate:             As asked in the title, can a Universe which is deterministic at its fundamental level still allow free will?