NOTE: this question was previously marked as a duplicate. It's subtly different, though: the  asked what the difference is between the two syntaxes; whereas I know there's no difference in meaning, and I'm asking in that case why Java allows both.  Why does Java allow both  int x[];   and  int[] x;   when I declare an array?  The latter makes much more sense: the variable is called x, not x[], and its type is int[], not int. Why not just enforce this? Allowing two different syntaxes seems just to invite confusion and inconsistency. It even appears to make it possible to declare a two-dimensional array as  int[] x[];   which is bordering on unreadable.  Is it something borrowed from C? (Why would C do it that way round, anyway?)
5148
I have recently been thinking about the difference between the two ways of defining an array:   int[] array int array[]   Is there a difference?
90560
In most programming languages, integer and real (or float, rational, whatever) types are usually disjoint; 2 is not the same as 2.0 (although most languages do an automatic conversion when necessary). In addition to technical reasons, this separation makes sense -- you use them for quite different purposes.  Why did they choose to say $\mathbb{Z} \subset \mathbb{R}$ in math? In other words, why are 2 and 2.0 considered the same?  When you are working in $\mathbb{R}$, does it make any difference whether some elements, eg. 2.0, also belong to $\mathbb{Z}$ or not?
25516
I have heard that the Java implementation of Generics is not as good as the C# implementation. In that the syntax looks similar, what is it that is substandard about the Java implementation, or is it a religious point of view?
40034
Coming from C++ to Java, the obvious unanswered question is why didn't Java include operator overloading?  Isn't Complex a, b, c; a = b + c; much simpler than Complex a, b, c; a = b.add(c);?  Is there a known reason for this, valid arguments for not allowing operator overloading? Is the reason arbitrary, or lost to time?
5812
Why does the  exist in modern languages such as C# and Java? Is it purely a self documenting code feature, or does it serve any actual purpose?  For instance the following example:  Class1 obj = new Class1();  Class1 foo() {     return new Class1(); }   Is as easy to read as the more Pythonesque way of writing it:  Class1 obj = Class1();  Class1 foo() {     return Class1(); }   EDIT:  hit the nail on the head with the clarification of the question: Why did they choose this syntax?
106441
I have a method like this:  public static &lt;T&gt; boolean isMemberOf(T item, T[] set) {     for (T t : set) {         if (t.equals(item)) {             return true;         }     }     return false; }   Now I try to call this method using a char for T:  char ch = 'a'; char[] chars = new char[] { 'a', 'b', 'c' }; boolean member = isMemberOf(ch, chars);   This doesn't work. I would expect the char and char[] to get autoboxed to Character and Character[], but that doesn't seem to happen.  Any insights?
25568
How is parseInt() different from valueOf() ?   They appear to do exactly the same thing to me (also goes for parseFloat(), parseDouble(), parseLong() etc, how are they different from Long.valueOf(string) ?  Also, which one of these is preferable and used more often by convention?
109558
Are these two equivalent?  char * aString = "This is a string.";  char aString[] = "This is a string.";  From my understanding, C++ stores strings by their addresses, so the pointer is getting a valid address. I assume the strings are also stored as type char? But how does it know how much memory to allocate for the string? Normally, char arrays need their array size preset. I believe the [] type arrays are counted by the compiler before compilation. Is this what happens for the string literal pointer as well?  On to my second question, what is the difference between these two:  int someNumber;  int * someNumber = new int;  The second is supposed to be dynamic allocation. If I understand the concept right, it allocates the memory as soon as it reads the declaration. But what happens in the standard declaration? Basically, I need to understand how dynamic allocation is advantageous over standard declarations.
118553
In C++ I can't use a method if I declare it after the calling method.    Does this order matter in other languages like Java or C#?
37844
Is there a good reason why there is no Pair&lt;L,R&gt; in Java? What would be the equivalent of this C++ construct? I would rather avoid reimplementing my own.  It seems that 1.6 is providing something similar (AbstractMap.SimpleEntry&lt;K,V&gt;), but this looks quite convoluted.
26977
In Java, an array IS AN Object. My question is... is an Object constructor called when new arrays is being created? We would like to use this fact to instrument Object constructor with some extra bytecode which checks length of array being constructed. Would that work?
37260
In C# and in Java (and possibly other languages as well), variables declared in a "try" block are not in scope in the corresponding "catch" or "finally" blocks.  For example, the following code does not compile:  try {   String s = "test";   // (more code...) } catch {   Console.Out.WriteLine(s);  //Java fans: think "System.out.println" here instead }   In this code, a compile-time error occurs on the reference to s in the catch block, because s is only in scope in the try block.  (In Java, the compile error is "s cannot be resolved"; in C#, it's "The name 's' does not exist in the current context".)  The general solution to this issue seems to be to instead declare variables just before the try block, instead of within the try block:  String s; try {   s = "test";   // (more code...) } catch {   Console.Out.WriteLine(s);  //Java fans: think "System.out.println" here instead }   However, at least to me, (1) this feels like a clunky solution, and (2) it results in the variables having a larger scope than the programmer intended (the entire remainder of the method, instead of only in the context of the try-catch-finally).  My question is, what were/are the rationale(s) behind this language design decision (in Java, in C#, and/or in any other applicable languages)?
53663
My question is told in a few words: Why do you write $E[X]$ in square brackets instead of something like $E(X)$? Probably it is not a "function". How would you call it then? This question also applies for $Var[X]$.
95859
Why does C/C++ differentiates in case of array index out of bound #include &lt;stdio.h&gt; int main() {     int a[10];     a[3]=4;     a[11]=3;//does not give segmentation fault     a[25]=4;//does not give segmentation fault     a[20000]=3; //gives segmentation fault     return 0; }  I understand that it's trying to access memory allocated to process or thread in case of a[11] or a[25] and it's going out of stack bounds in case of a[20000]. Why doesn't compiler or linker give an error, aren't they aware of the array size? If not then how does sizeof(a) work correctly?
14488
I saw this in , in reference to shortcomings of the Java spec:  There are more shortcomings and this is a subtle topic. Check  out: public class methodOverloading{      public static void hello(Integer x){           System.out.println(&quot;Integer&quot;);      }       public static void hello(long x){           System.out.println(&quot;long&quot;);      }       public static void main(String[] args){          int i = 5;          hello(i);      } }  Here &quot;long&quot; would be printed (haven't checked it myself), because the compiler chooses widening over auto-boxing. Be careful when using auto-boxing or don't use it at all!  Are we sure that this is actually an example of widening instead of autoboxing, or is it something else entirely? On my initial scanning, I would agree with the statement that the output would be &quot;long&quot; on the basis of i being declared as a primitive and not an object.  However, if you changed hello(long x)  to hello(Long x)  the output would print &quot;Integer&quot; What's really going on here?  I know nothing about the compilers/bytecode interpreters for java...
58615
Have you ever tried this before?  static void Main(string[] args) {     int x = 10;     x = x++;     Console.WriteLine(x); }   Output: 10.  but for   static void Main(string[] args) {     int x = 10;     x++;     Console.WriteLine(x); }   Output: 11.  Could anyone explain why this?
91748
Why would someone want to use a linked-list over an array?  Coding a linked-list is, no doubt, a bit more work than using an array and one may wonder what would justify the additional effort.  I think insertion of new elements is trivial in a linked-list but it's a major chore in an array. Are there other advantages to using a linked list to store a set of data versus storing it in an array?  This question is not a duplicate of  because the other question is asking specifically about a particular Java class while this question is concerned with the general data structures.