10 Free Practice Questions for 1Z0-808 Certification
All 10 questions shown below with complete explanations
int is 32 bits (4 bytes) in Java.
In Java, the 'int' primitive data type is always 32 bits (4 bytes) regardless of the platform, which is part of Java's platform independence guarantee. An int can store values from -2,147,483,648 to 2,147,483,647 (2^31-1 to -2^31). This fixed size ensures that Java programs behave consistently across different operating systems and hardware architectures. Other primitive sizes are: byte (8 bits), short (16 bits), long (64 bits), char (16 bits), float (32 bits), double (64 bits), and boolean (implementation dependent, typically 1 bit). Understanding these sizes is crucial for memory management and choosing appropriate data types.
Identifiers cannot start with a digit, cannot use hyphens, and cannot be Java keywords. _total starts with an underscore and follows the rules.
Java identifiers must follow specific rules: they cannot start with a digit (eliminates 2value), cannot use hyphens as they are interpreted as operators (eliminates hello-world), and cannot be reserved keywords (eliminates int). Identifiers can start with letters, underscores, or dollar signs. The underscore character is a valid starting character for identifiers, making _total a valid identifier, though starting with underscore is discouraged by naming conventions.
$ and _ are legal anywhere in an identifier, though their use is discouraged for readability. Java identifiers are case-sensitive and have no formal length limit.
Java identifier rules: cannot start with digits (only letters, underscore, or dollar sign), are case-sensitive (myVar and MyVar are different), can contain $ and _ anywhere in the identifier, and have no formal length limit in the language specification. The dollar sign and underscore are legal characters in identifiers, though their use is discouraged by Java naming conventions for regular variables and methods.
Spaces are not allowed in identifiers. myVar, MAX_VALUE, and _count are all valid.
Spaces are not allowed anywhere in Java identifiers. An identifier must be a continuous sequence of valid characters without any whitespace. The other options myVar (camelCase), MAX_VALUE (constant naming), and _count (underscore prefix) are all syntactically valid identifiers, though _count goes against Java naming conventions.
Line 11 generates a compiler error because a double literal (3.8) cannot be assigned to an int.
Line 13 generates a compiler error because primitives (byte) do not have methods.
Line 14 generates a compiler error because primitives (int) do not have methods.
Lines 10 and 15 compile successfully.
Line 11 fails because assigning a double literal (3.8) to an int requires an explicit cast.
Line 13 fails because myAnimals is a primitive byte, and primitives do not have methods like length().
Line 14 fails because myScore is a primitive int, which also has no methods.
Line 10 is valid because the literal 8 fits within the range of byte.
Line 15 is valid since String provides the length() method.
Therefore, the lines that generate compiler errors are 13, 14, and 11 - A, B, C.
None of the given options correctly describe the outputs. Statement 1 (String literal) produces 'true true' because both variables reference the same string pool object. Statement 2 (new String) produces 'true false' because equals() compares content (true) while == compares references (false for different objects).
Java stores string literals in the string pool, where identical literals share the same memory reference.
In Statement 1, "Boston" already exists in the pool (from city1), so city2 refers to the same pooled object as city1.
Because of this, both equals() (content check) and == (reference check) return true true.
In Statement 2, new String("Boston") forces creation of a new, distinct object in the heap, bypassing the pool.
The contents remain identical, so equals() returns true, but the references differ, so == returns false β true false.
Since no answer choice matches true true and true false, the only correct choice is E (None of the above).
The @ symbol is not allowed in identifiers. Unicode characters are allowed, so Greek letters are technically valid, though not recommended.
Java identifiers:
CAN use: letters (Unicode allowed), digits, _, $
CANNOT use: symbols like @, #, !, %, &, etc.
Cannot start with a digit
Cannot be a keyword
Now check each option:
A β $Amount. Valid β $ is allowed.
B β Ξ±ΟΞΉΞΈΞΌΟΟ (Greek letters). Valid β Java allows full Unicode in identifiers.
C β my@value. Invalid β @ is not allowed in identifiers.
D β value_123. Valid β letters, underscore, digits β all allowed.
Class (uppercase C) is not a keyword. Java is case-sensitive, so this is valid. Only class (lowercase) is reserved.
Java is case-sensitive, which means Class and class are completely different identifiers. The keyword class (lowercase) is reserved and cannot be used as an identifier, but Class (uppercase C) is not a keyword and can be used as a variable name. This code will compile successfully and print 5. However, using Class as a variable name could be confusing since it resembles the Class type, so it is not recommended for code readability.
Java allows Unicode characters in identifiers, including Greek and Chinese. However, it is best practice to use English for readability.
Java supports Unicode characters in identifiers, which means characters from various languages including Greek (Ξ±ΟΞΉΞΈΞΌΟΟ), Chinese (ε η΄ ), and Latin scripts are syntactically valid. The underscore in student_name is also perfectly valid. However, while Unicode characters are allowed, it is best practice to use ASCII characters (English letters) for code readability, maintainability, and compatibility across different development environments and teams.
Options B, C, and D compile: binary and hexadecimal literals are valid, and widening conversions (int to double) are allowed. Options A, E, F have syntax or type errors.
Let's analyze each option: A) int value = 8L; - Does not compile. 8L is a long literal, and assigning a long to an int requires explicit casting due to potential data loss. B) int value = 0b110; - Compiles. 0b110 is a binary literal representing decimal 6, which is a valid int value. C) int value = 0xF; - Compiles. 0xF is a hexadecimal literal representing decimal 15, which is a valid int value. D) double value = 0xF; - Compiles. 0xF is an int literal by default (decimal 15), which is then widened to double. E) double value = 1_3_.5_0; - Does not compile. Underscores cannot be placed adjacent to decimal points (1_3_.5_0 has underscore before decimal point). F) int value = 2_5_; - Does not compile. Underscores cannot be at the end of numeric literals. The valid options use proper numeric literal syntax and compatible type assignments.
Access all 1624 more questions covering all OCA topics
β 1,624 practice questions
β 29 full certification tests
β Chapter-wise practice exams
β Detailed explanations for every answer
β Progress tracking & certificates