Skip to content
QuiznExam

java.lang Class in Java

Test your knowledge of the java.lang package and its commonly used classes, including Object, String, StringBuilder, Math, System, Wrapper classes, and the Runtime class.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. Which package is automatically imported into every Java program?

    • A. java.lang
    • B. java.util
    • C. java.io
    • D. java.net
    Show answer

    A. java.lang

    The java.lang package is automatically imported by the Java compiler, so its commonly used classes can be referenced without an explicit import statement.

  2. 2. Which is the root class of the Java class hierarchy?

    • A. Object
    • B. Class
    • C. System
    • D. Main
    Show answer

    A. Object

    java.lang.Object is the superclass of all Java classes, either directly or indirectly.

  3. 3. Which method is commonly overridden to provide a textual representation of an object?

    • A. toString()
    • B. getText()
    • C. printObject()
    • D. stringValue()
    Show answer

    A. toString()

    The Object class provides toString(), which can be overridden to return a meaningful textual representation of an object.

  4. 4. Which class represents an immutable sequence of characters in Java?

    • A. String
    • B. StringBuilder
    • C. StringBuffer
    • D. CharacterArray
    Show answer

    A. String

    String objects are immutable, meaning their contents cannot be changed after the object is created.

  5. 5. Which class is commonly used to create and modify a mutable sequence of characters?

    • A. StringBuilder
    • B. String
    • C. Character
    • D. Text
    Show answer

    A. StringBuilder

    StringBuilder provides a mutable sequence of characters and is useful when repeated string modifications are needed.

  6. 6. Which class provides mathematical utility methods such as sqrt(), pow(), and abs()?

    • A. Math
    • B. Number
    • C. Arithmetic
    • D. Calculate
    Show answer

    A. Math

    The java.lang.Math class provides static methods for common mathematical operations.

  7. 7. Which class provides access to standard input, output, and error streams?

    • A. System
    • B. Console
    • C. Stream
    • D. IO
    Show answer

    A. System

    The java.lang.System class provides fields such as System.in, System.out, and System.err.

  8. 8. Which class in java.lang is the wrapper class for the primitive int type?

    • A. Integer
    • B. Int
    • C. NumberInt
    • D. IntWrapper
    Show answer

    A. Integer

    Integer is the wrapper class corresponding to the primitive int type.

  9. 9. Which method can convert a String containing an integer into an int primitive?

    • A. Integer.parseInt()
    • B. Integer.toInteger()
    • C. Integer.convert()
    • D. Integer.getIntValue()
    Show answer

    A. Integer.parseInt()

    Integer.parseInt() parses a String argument and returns its value as a primitive int.

  10. 10. Which java.lang class represents a single character?

    • A. Character
    • B. Char
    • C. CharValue
    • D. SingleCharacter
    Show answer

    A. Character

    The Character class wraps a value of the primitive char type and provides useful character-related methods.

  11. 11. Which class is the superclass of numeric wrapper classes such as Integer, Double, and Float?

    • A. Number
    • B. Numeric
    • C. ObjectNumber
    • D. Primitive
    Show answer

    A. Number

    java.lang.Number is the abstract superclass for several numeric wrapper classes, including Integer, Double, and Float.

  12. 12. Which class provides methods related to the Java runtime environment?

    • A. Runtime
    • B. Environment
    • C. JVM
    • D. Execution
    Show answer

    A. Runtime

    The java.lang.Runtime class provides access to information and functionality related to the Java runtime environment.

  13. 13. Which method of the System class can be used to obtain the current time in milliseconds?

    • A. currentTimeMillis()
    • B. getCurrentMillis()
    • C. timeMillis()
    • D. nowMillis()
    Show answer

    A. currentTimeMillis()

    System.currentTimeMillis() returns the current time in milliseconds since the Unix epoch.

  14. 14. Which class provides methods for converting strings to primitive values such as boolean, byte, short, and long?

    • A. Wrapper classes
    • B. StringBuilder
    • C. Object
    • D. System
    Show answer

    A. Wrapper classes

    Wrapper classes such as Boolean, Byte, Short, and Long provide parsing methods for converting String values into corresponding primitive values.

  15. 15. Which method of Object can be used to compare two object references for equality?

    • A. equals()
    • B. compare()
    • C. sameAs()
    • D. equalTo()
    Show answer

    A. equals()

    The Object class defines equals(), which can be overridden by classes to provide logical equality comparison.