2 Language Fundamentals



52pickup is not a legal identifier. The first character of an identifier cannot be a digit.



In Java, the identifiers delete, thrown, exit, unsigned, and next are not keywords. Java has a goto keyword, but it is reserved and not currently used.



It is a completely valid comment. Comments do not nest. Everything from the start marker of a comment block (/*) until the first occurrence of the end marker of the comment block (*/) is ignored by the compiler.


(a) and (d)

String is a class, and "hello" and "t" denote String objects. Java only has the following primitive data types: boolean, byte, short, char, int, long, float, and double.


(a), (c), and (e)

Type (a) is a boolean data type, while types (c) and (e) are floating-point data types.



The bit representation of int is 32-bits wide and can hold values in the range ?231 through 231?1.


(a), (c), and (d)

The \uxxxx notation can be used anywhere in the source to represent unicode characters.



Local variable a is declared but not initialized. The first line of code declares the local variables a and b. The second line of code initializes the local variable b. Local variable a remains uninitialized.



The local variable of type float will remain uninitialized. Fields receive a default value unless explicitly initialized. Local variables remain uninitialized unless explicitly initialized. The type of the variable does not affect whether a variable is initialized or not.



The class will fail to compile since the package declaration can never occur after an import statement. The package and import statements, if present, must always precede any class definitions. If a file contains both import statements and a package statement, then the package statement must occur before the import statements.



Although nonsensical, an empty file is a valid source file. A source file can contain an optional package declaration, any number of import statements, and any number of class and interface definitions.


(d) and (f)

The main() method must be declared public, static, and void and takes a single array of String objects as argument. The order of the static and public keywords is irrelevant. Also, declaring the method final is irrelevant in this respect.


(a), (b), and (c)

Neither main, string, nor args are reserved keywords, but they are legal identifiers. In the declaration public static void main(String[] args), the identifier main denotes the method that is the main entry point of a program. In all other contexts, the identifier main has no predefined meaning.