Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Traps
• code with package or import declarations given in wrong order
• more than one package declaration
• file with more than one public class or interface declaration
• filename.java does not match name of public class declared in the file
• single-type imports for two classes in different packages but with the same simple
name
• single-type import with the same simple name as a class defined in the source file
• attempting to import a package vs a type ie import java.util vsimport java.util.*
• class attempting to extend more than one other class
• class declared both final and abstract
• an interface method declared as native or synchronized
• an interface method declared as static
• subclass with default constructor when the superclass does not have a no-args
constructor or it's no-arg constructor has a throws clause
• constructor declared with a return type
• an abstract method also declared private, native, final, synchronized, or strictfp
• an abstract method declared in a non-abstract class
• a native or abstract method with a method body
• method returning a type which is not convertible to the declared return type
• a void method returning a value
• a static method referencing this or super
• main() declared other than according to the standard convention
• local (automatic) variables declared with a modifier other than final
• identifiers names beginning with a number or # sign
• main listed as a possible keyword
• capitalized words listed as possible keywords; particularly wrapper classes Integer,
Boolean, etc
• C/C++ keywords listed as possible Java keywords
• an empty string vs null as the default value for a String object
• incorrect array declaration statements, particularly:
arrayType [#] varName;
• incorrect array initialization statements, particularly:
arrayType[] varName = new arrayType[2];
varName = { value, value, value };
• negative values for array index
• long value for array index
• array declaration used as an array creation statement
• variables of primitive type handled as Objects
• using the char literals \u000A or \u000D in comments or Strings
• String literal "c" assigned to char type
• using == operator to compare values of two different string reference variables
• variables requiring narrowing conversion being passed to methods without using
a cast
• assigning a typed byte or short variable to a char variable
• floating point operation throwing an ArithmeticException
• Bitwise operator precdence is: & ^ |
• assigning subclasses with the same parent to each other
• assigning a parent class to a subclass without a cast
• result of an integer operation on byte or short types being assigned to a byte or short
without an explicit cast
• a non-boolean value used for operand1 in a ternary expression
• using == to compare the contents of two different String objects
• using a new value based on a short-circuit operation that was never evaluated
• code that results in a primitive value being changed in a method (can't happen)
• code that results in an unchanged object value when it was changed in a method
• failing to cast a value to match a method parameter type ie assuming narrowing
conversion on a method call
• a non-boolean value used in a loop or if( ) statement
• using the assignment operator '=' vs '==' in an loop or if()statement
• using an expression vs a value promotable to int in a switch()block
• switch() blocks with duplicate case values
• switch() blocks with incorrectly 'typed' case statements
• switch() blocks with missing break statements (unintentionally causing code to fall
through to next case)
• attempting to access a variable declared in the initialization outside of the for-loop
• for()loop with incorrect initialization expression
• for()loop with a non-boolean expression
• a question that targets a specific object for garbage collection (can't be done)
• a question that presumes to force the gc to run (can only suggest it run)