1Z0-811 · Question #69
Which package would you import to use the Random class?
The correct answer is C. java.util. java.util is the correct package because it contains utility classes like Random, ArrayList, Scanner, and Date - general-purpose tools for everyday programming tasks. java.io handles input/output operations like file reading and streams, not random number generation. java.math…
Question
Options
- Ajava.io
- Bjava.math
- Cjava.util
- Djava.lang
How the community answered
(26 responses)- A8% (2)
- B4% (1)
- C88% (23)
Explanation
java.util is the correct package because it contains utility classes like Random, ArrayList, Scanner, and Date - general-purpose tools for everyday programming tasks. java.io handles input/output operations like file reading and streams, not random number generation. java.math provides classes for high-precision arithmetic (BigDecimal, BigInteger), not general utilities. java.lang is automatically imported and contains core classes like String, Math, and Object, but not Random.
Memory tip: Think "util = utility belt" - java.util is your Swiss Army knife for common tools. If you need something practical that doesn't fit neatly into I/O, math precision, or core language features, it's almost certainly in java.util.
Topics
Community Discussion
No community discussion yet for this question.