Standard library highlights

Computer Science · Java

Question 1 of 10

0

    The wrapper class for the boolean primitive

    Capital letters and accents are ignored.

    Stuck? Read the explanation

    Unlocks at a streak of 5 correct answers in a row.

    Print a free worksheet (PDF)

    Embed this practice on your site or class page

    Paste this HTML into your page. Students practise right there; it is free and needs no account.

    Standard library highlights explained

    The Java standard library, also called the Java API, comes with the JDK, so these classes need no extra download. Key packages include java.lang, which is imported automatically, java.util for collections and utilities, java.io and java.nio.file for files, and java.time for dates and times.

    java.lang holds String, Math and the wrapper classes such as Integer. Math.sqrt, Math.max and Math.random are static methods, so no object is needed to call them. java.util includes Scanner for reading input, Arrays for sorting and printing arrays with Arrays.toString, and Random for pseudo-random numbers. java.time provides LocalDate and Duration. Its classes are immutable, so plusDays returns a new LocalDate and leaves the original unchanged. Check the API documentation for exact method names, since a wrong name is a common compile error.

    import java.time.LocalDate;
    import java.util.Arrays;
    
    int[] nums = {5, 2, 9};
    Arrays.sort(nums);
    System.out.println(Arrays.toString(nums));
    LocalDate d = LocalDate.of(2026, 1, 30);
    System.out.println(d.plusDays(2));
    

    Worked example

    Trace the program above.

    1. Arrays.sort rearranges nums in place into 2, 5, 9.
    2. Arrays.toString formats the array as [2, 5, 9].
    3. LocalDate.of(2026, 1, 30) is 30 January. Adding 2 days passes 31 January and lands on 1 February.
    4. The output is [2, 5, 9] on one line and 2026-02-01 on the next.

    What you will practise

    80 flashcards. Type your answer and get instant feedback.

    Example questions

    • The class for list-like collections
    • The class for key-value maps
    • The class for reading text input
    • The class for strings
    • The utility class for math functions
    • The class for unique, unordered elements
    • The legacy java.util class, a subclass of Vector, with push, pop and peek
    • The unsynchronized class for mutable character sequences

    …and 72 more.