Site hosted by Angelfire.com: Build your free website today!
scjp section 4: language fundamentals
 
  • Identify correctly constructed package declarations, import statements, class declarations (of all forms including inner classes) interface declarations, method declarations (including the main method that is used to start execution of a class), variable declarations, and identifiers.

Declarations

  1. Source Files
    • must end with .java
    • 0 or 1 top-level public class, if 1 then name file ClassName.java
    • Three top-level elements in order: (but none are required)
      1. package declarations
      2. import statements
      3. class definitions

  2. Class Declarations
    • a top-level class can only be public or have the default (i.e. package) access
    • an inner class may not have static variables

  3. Interface Declarations
    • cannot have constructors
    • cannot be declared final
    • variables are final and static by default and must be assigned values on creation

  4. Method Declarations
    • public static void main (String[] args) {...
    • methods can't be overriden to be more private: private > default > protected > public

  5. Variable Declarations and Identifiers
    • by default, a literal is either an int or a double.
      • so float f = 1.125; gives a compiler error as 1.125 is a double (must suffix with an f for floats and an l for longs)
      • but byte b = 1; doesn't as Java relaxes and first sees if the literal fits inside the type
      • but if have pre-typed the value e.g. int i = 1; byte b = i; will not compile
      • note: char c = '1'; and char c = 1; are both legal
    • Legal Identifiers
      • not a keyword/reserved word
      • must start with a letter, a $ or an _
      • case sensitive

  • Identify classes that correctly implement an interface where that interface is either java.lang.Runnable or a fully specified interface in the question.

Interfaces

  • ClassName() implements InterfaceName { ...
    • must implement all the methods declared by the interface or declare itself abstract
    • if implements Runnable must implement the method public void run()

  • State the correspondence between index values in the argument array passed to a main method and command line arguments.

Command-line Arguments

  • java ClassName arg[0] arg[1] ..., arg's passed into the main method as an array of strings

  • Identify all Java programming language keywords. Note: There will not be any questions regarding esoteric distinctions between keywords and manifest constants.

Java Keywords and Reserved Words

  • package, import, class, extends, implements, interface
  • public, private, protected
  • abstract, final, volatile, static, transient, native, strictfp, synchronized
  • ijf, else, do, while, for, switch, case, default, break, continue, return, (goto)
  • new, instanceof
  • boolean, byte, short, char, int, float, long, double, (const)
  • true, false, null, void, super, this
  • throws, throw, try, catch, finally
  • assert

  • State the effect of using a variable or array element of any kind when no explicit assignment has been made to it.

Variables and Initialization

  1. Member (Instance) Variables
    • alive for life of object
    • automatically assigned a default value on declaration (if not initialized here also)
    • static - initialized at class load-time
      non-static - initialized just before the class constructor is executed

  2. Automatic (Method Local) Variables
    • alive for life of it's enclosing method
    • compiler error if not explicitly initialized

  3. Array Elements
    • automatically assigned a default value on construction of array (see arrays in Section 1)

  • State the range of all primitive formats, data types and declare literal values for String and all primitive types using all permitted formats bases and representations.

Primitive Data Types

  • Size and Range
    Type Bits Signed? Range Integral/F.p.
    boolean 1 no (true|false) -
    byte 8 yes -27 to 27 - 1 integral
    char 16 no 0 to 216 - 1 (Unicode \u0000 to \uFFFF) integral
    short 16 yes -215 to 215 - 1 integral
    int 32 yes -231 to 231 - 1 Integral/F.p.
    float 32 yes +/- 1.4 x 10-45 to 3.4 x 1038 f.p.
    long 64 yes -263 to 263 - 1 integral
    double 64 yes +/- 4.9 x 10-324 to 1.8 x 10308 f.p.
  • Signed integral types - use two's complement, Signed f.p. types - use IEEE std.
  • (Float|Double).(NaN|POSITIVE_INFINITY|NEGATIVE_INFINITY)
    e.g. -10.0/0 will result in Double.NEGATIVE_INFINITY

Literals

boolean: (true|false)
char: 'w', '\u4567' (unicode - hex digits), and escape characters: '\\', '\n', '\r', '\t', '\f', '\'', '\"', '\b''
integral:
  • in decimal, octal (prefix with 0) or hexadecimal (prefix with 0x or 0X)
  • if in hex, letters a-f or A-F
  • by default, literal is 32-bit, so to indicate a long (64-bit) suffix with l or L
  • compiler will determine size of a single literal according to target of assignment eg. short s = 9; is O.K.
floating point:
  • decimal
  • E or e for scientific notation
  • by default, f.p. literal is 64-bit, so to indicate a float (32-bit) suffix with f or F
string literals: between double (") quotes