Search this site


 Java tutorials  Synchronization and concurrency  wait/notify  synchronized keyword
 Java 5: ConcurrentHashMap

Sun-Certified Java Programmer (SCJP) Exam Tips

In real-world programming, we tend to take it for granted that the IDE will remind us of certain bits of Java syntax, the parameters to a given method, or even the methods that a particular class makes available. But rightly or wrongly, the SCJP certification exam requires you to know off by heart some of these awkward bits of syntax. The following is aimed to be a "crib list" for moderately experienced programmers for whom some of the awkward corner cases of syntax or basic API use may have slipped their attention because they're so used to the IDE doing the work. This isn't a list of everything you need to know for the exam— it's assumed, for example, that you will know the very basics of Java syntax and some of the most basic API calls that you'd use "every day in programming".

  • variable names (and other identifiers) can contain letters, digits, underscores and currency symbols; letters can be any Unicode letter (accented letters, Chinese characters etc are fine); they must not start with a digit1;
  • identifiers can't be keywords; as well as int, class etc, some rare keywords you may not be familiar with are strictfp, transient, assert;
  • const and goto are Java keywords! They're "reserved" and don't currently do anything in Java, but you can't name variables after them.
    int const = 3;
  • floating-point literals are assumed by the compiler to be doubles, meaning that the following won't compile!
    float f = 2.5;
  • the modulo (%) operation returns a result that is the sign of the left-hand operand
  • an integer literal starting with 0 is octal!
    // Doesn't assign decimal 13!
    int x = 013;
    In this case, 013 will actually be the decimal number 8*1 + 3 = 11!
  • ASCII and Unicode values of characters can be escaped, either as (where d is a digit):
    • \ddd for the ASCII value in octal
    • \udddd for the Unicode value
  • instance and static variables defined inside a class are initialised to zero by default; local variables must be assigned a value before they are first read (but need not be assigned one before then);
  • arrays can be declared with either format as follows:
    String[] args = ...
    String args[] = ...
  • the equals() method of Number implementations returns false if a different class of Number is being compared with;
  • >> is a shift right that preserves the sign; >>> always shifts zero into the sign bit, thus resulting in a positive number;
  • a left shift is always <<: there's no option but to "shift off" the sign bit;
  • when using + if one of the operands is a String then the other is converted to a String before the appending operation is performed;
  • with bitwise operations, both operands are always converted to at least an int or long (as necessary to fit the "largest" operand in terms of how many bits it takes up) before the operation is carried out;
  • a new thread is always started by calling start() on the given Thread object&mash; beware of questions with code that calls Thread.run();
  • a synchronized non-static method acquires the lock on the specific object in question; a static synchronized method acquires the lock on the class;
  • List, Map, Set, SortedMap and SortedSet are interfaces: there are no actual collection classes with these names;
  • in JDK 1.4, the standard SortedMap implementation is TreeMap;
  • in terms of actual interfaces, a Map is not a Collection;
  • an object's equals() method must be transitive: that is, a.equals(b) should return the same as b.equals(a)
  • two equal objects must have equal hash codes (where equality means that equals() returns true), but the reverse is not true: two objects could have the same hash code and actually be different;

1. Strictly, the definition is that allowed characters are those for which Character.isJavaIdentifierPart() returns true, and that even includes a few control characters!