What are some common beginner's mistakes?

PLEASE send us your favorite examples for inclusion here!
The book of C.Horstmann (John Wiley & Son) has a nice list of these.
  1. Common Problem List from Sun's tutorial.
  2. Mysterious bugs:
    These are bugs that you do not even know where to look, but it is not in your code. Very often, it has to do with your ENVIRONMENT. Think of the ENVIRONMENT as the values that are assigned to certain variables, and your compiler, etc, depend on the values of these variables. In particular, Java depends on an environment variable called CLASSPATH. This is set to the list of directories in your system which Java will search to look for libraries, etc. Make sure that your CLASSPATH is correctly set! Actually, the use of CLASSPATH is being deprecated starting with Java 1.2: you may want to "unset" the CLASSPATH (or set it to the empty string "") to get Java to work properly.
  3. The main trouble, or the NoClassDefFoundError:

    Question:

    	> Hi, I am having a baffling java problem.
    	> Whenever I try to run a program, I get a message saying
    	> Exception in thread "main" java.lang.NoClassDefFoundError: myNode
    	> Even when I know there is nothing wrong with the program,
    	> I get that message.  Can you tell me how to fix that?  Thanks.
    	
    Answer: there two possible problems.
    (1) See previous item about CLASSPATH. We suggest you undefine CLASSPATH (but keep the old value somewhere if you like). If this does not work, modify the current value of CLASSPATH to include the current directory (.)
    (2) The "main" procedure is very special. You must use the following header for this procedure:
            public static void main(Strings[] args)   // OK, you COULD re-name
                 // "args" if you like.  But it is standard, why choose to confuse?
            public static void main()           // error!
            public static int main()            // error!
    	
  4. Uninitialized Variables: The Java compiler is careful to make sure that all variables are initialized before first use. You may get this error if your initialization is inside some try block. One way to fix this is to put the analogous initialization in the corresponding catch block.
  5. Forgetting that Java is Case Sensitive or accidental switch of cases:
    • You define a class "Fibonacci" and put it in a file "fibonacci.java".
      (instead of "Fibonacci.java".
    • You accidentally called your main program "Main".
      You may wonder why your program could compile with no errors but when you try to execute it, it complains "missing main function".
    • You accidentally type "If" instead of "if" (very common reflex typing, since you are supposed to capitalize the first letter in a sentence). The compiler thinks "If" is a name of a method, and its error message probably will not help you check the case of "if".
  6. Main Program:
    The header for the main program is most likely to be
    
    	public static void main(String[] args)
    	or
    	public static void main(String args[])
    	
    Common mistakes:
    -- you forget the ``[]'' after ``Strings''
    -- alternatively, you forget the ``[]'' after ``args''
    -- you put ``void'' before ``static''.

    Unacceptable variants (some java compiler, esp. older ones may not complain):

    
    	public static void main()
           		// no arguments 
    	public static int main(String args[])
    		// returns an int ("C" style main)
    	

    Another mistake of "C" programmers is to think that args[0] stores the number of arguments in args[]. Of course, this number is args.length.

  7. Basic Syntax:
    -- forgetting a semicolon at the end of a statement
    -- stray semicolons. Learn your rules for semicolons! Here is an insidious one:
    	while (flag);
    	 {
    	   ...body of while loop
    	 }
    	// the compiler does not complain but the
    	// effects of this code is surely wrong!
    	
    -- Writing "=" (assignment) when you really want "==" (equality test).
  8. Numerical:
    -- using integer division when you meant a floating point division. E.g., if you had
    int i = 2; int j = 3; double k = i/j;
    the result in k is 0.0.
  9. new:
    -- to obtain a new object of class C, you need to assign a "new" to a variable of type C. E.g. suppose you have a class named "foo".
    foo X = new foo();
    It is easy to forget the "new" in this line of code. The double appearance of "foo" may also seem uncomfortable, but this is the syntax.