Question 1
Assume a Java program declares int size = 10; int[] arr = new int[size]; and prints each element in sequence with no separators. Without any assignment to arr, what is printed?
Correct Answer:
0000000000
Explanation:
Java initializes arrays of primitive types with default values, and for int that default is 0. Creating an array of length 10 gives you ten elements, all starting as 0. If you print each element in order with no separators, you get ten zeros in a row: 0000000000. The code compiles cleanly because array creation with a size is valid and no assignments change those values before printing. So the observed output is ten zeros concatenated together.
Question 2
Which class is used to write objects to a file?
Correct Answer:
ObjectOutputStream
Explanation:
Serialization is the process of turning a Java object into a sequence of bytes so it can be saved to a file and later reconstructed. ObjectOutputStream is designed for this purpose: it writes the state of a Serializable object to an OutputStream, using methods like writeObject. When you pair it with a FileOutputStream, you can save the serialized object to a file. Other streams shown in the options write raw bytes (FileOutputStream, BufferedOutputStream) or human-readable text (PrintWriter), not the object’s full state, so they aren’t suitable for persisting objects. Remember that the class of the object must implement Serializable; otherwise an exception is raised during writing. In practice, you’d do something like new ObjectOutputStream(new FileOutputStream("data.ser")) and call writeObject(yourObject) before closing.
Question 3
Which statement accurately reflects the equals/hashCode contract?
Correct Answer:
If two objects are equal according to equals(), their hashCode must be equal
Explanation:
In Java, objects that are considered equal by the equals method must produce the same value from hashCode. This alignment is essential for hash-based collections like HashMap and HashSet to find and retrieve elements reliably. If two equal objects could have different hash codes, they would end up in different buckets, making lookups unpredictable or incorrect. Hash codes are used for hashing, not for sorting. Sorting relies on comparisons (like compareTo or a Comparator), while hashing relies on the hashCode value to bucket objects. If you override equals, you should also override hashCode to maintain this contract. It doesn’t matter whether the objects are mutable; what matters is consistency: objects that are equal must always yield the same hash code. If the fields involved in determining equality change after an object is placed in a hash-based collection, it can become unreachable or misplaced unless you carefully manage mutations.
Question 4
Which statement about volatile variables is false?
Correct Answer:
They guarantee atomicity for compound actions.
Explanation:
Volatile variables are about visibility across threads and the ordering of memory operations. When a thread writes to a volatile field, that write becomes visible to other threads that read that same field, and the JVM establishes a happens-before relationship: a write to a volatile happens-before every subsequent read of that volatile. This also helps prevent certain reordering around that access, so the sequence of reads and writes appears in a consistent order relative to the volatile access. But volatile does not guarantee atomicity for compound actions. If you perform a read-modify-write sequence (like counter++), those steps can interleave with other threads and lead to lost updates even with the variable marked volatile. For true atomicity, you need synchronization or atomic classes such as AtomicInteger. So the statement claiming atomicity for compound actions is the false one; the others correctly describe visibility, happens-before, and ordering guarantees provided by volatile.
Question 5
What does System.out.println(5 + 3); print?
Correct Answer:
8
Explanation:
When you add two integers in Java, the plus operator performs arithmetic addition. System.out.println prints the resulting value followed by a newline. Here, both operands are integers, so 5 + 3 equals 8, and that 8 is what gets printed. If one of the operands were a string, the plus operator would do string concatenation, producing something like "53" instead of a numeric 8. The other options come from those different possibilities or mistaken operations, but with two integers this expression yields 8.
Question 1
Exam overview

About this Exam

Prepare with the Java FPT Software (Fsoft) Academy Practice Test practice quiz. This question bank includes 10 questions covering printed, java, program, size, and prints. Use it to review important concepts, identify knowledge gaps, and build confidence for the related exam, course, or assessment.

More details

Additional Information

Java FPT Software (Fsoft) Academy Practice Test

This practice set contains 10 questions from the matching question bank and focuses on printed, java, program, size, and prints. Work through each question carefully, review the provided solutions, and revisit topics that need more study before your next attempt.

This is an independent study resource intended for practice and review; it is not an official examination or an endorsement by any organization named in the title.

Quiz information

Frequently Asked Questions

The complete question count is available after full access is unlocked.
No fixed duration is currently configured for this quiz.
Question explanations are included where they are available in the quiz content, helping you review the reasoning after answering.
Yes. You can retake the practice test again as you continue studying during your available access period.
After your access is confirmed, you can continue into the complete practice exam from this quiz flow.
Unless explicitly stated otherwise, this page provides independent practice material for study and exam preparation and is not the official examination itself.
Keep studying

Related Questions