Last Updated: January 3, 2026
30 quizzes
Use a utility method without qualifying it with the class name after a static import
int maxValue = (a, b);Click an option to fill the blank:
Reference a class from another package without using its fully qualified name
List<String> names = new <>();Click an option to fill the blank:
Declare the package at the top of a source file to organize related classes
com.example.billing;Click an option to fill the blank:
What is the main purpose of a Java package?
Where must the package declaration appear in a Java source file?
Which import allows you to use ArrayList without qualifying it?
What happens if two imported packages contain classes with the same simple name?
What does a static import allow you to do?
Which file defines a Java module's dependencies and exported packages?
Which keyword in module-info.java declares a dependency on another module?
What is true about packages in a Java module by default?
What does requires transitive com.example.utils; mean in module-info.java?
Which statement about import statements is correct?
Order the steps to create and use a class from a custom package in another class.
Drag and drop to reorder, or use the arrows.
Order the steps to define and consume a Java module that provides a math utility package.
Drag and drop to reorder, or use the arrows.
What is the output of this code when using a class from another package via import?
1package com.example.app;
2
3import java.util.ArrayList;
4
5public class Main {
6 public static void main(String[] args) {
7 ArrayList<String> list = new ArrayList<>();
8 list.add("A");
9 list.add("B");
10 System.out.println(list.get(1));
11 }
12}What is the output when using a static import of Math methods?
1import static java.lang.Math.*;
2
3public class TestStaticImport {
4 public static void main(String[] args) {
5 int result = max(3, 7) - min(2, 5);
6 System.out.println(result);
7 }
8}What is the output when using two classes with the same name but different packages via fully qualified name?
1package com.example.use;
2
3class com_example_a_Message {
4 public static String get() { return "A"; }
5}
6
7class com_example_b_Message {
8 public static String get() { return "B"; }
9}
10
11public class Main {
12 public static void main(String[] args) {
13 String a = com_example_a_Message.get();
14 String b = com_example_b_Message.get();
15 System.out.println(a + b);
16 }
17}What is the output when a module exports a package containing a simple utility method?
1package com.example.util;
2
3public class GreetingUtil {
4 public static String build(String name) {
5 return "Hello, " + name;
6 }
7}
8
9class Main {
10 public static void main(String[] args) {
11 String msg = GreetingUtil.build("JPMS");
12 System.out.println(msg);
13 }
14}What is the output when using a constant via static import?
1package com.example.circle;
2
3import static java.lang.Math.PI;
4
5public class Area {
6 public static void main(String[] args) {
7 double area = PI * 1 * 1;
8 System.out.println((int)area);
9 }
10}Find the bug related to the package declaration and imports.
Click on the line(s) that contain the bug.
public class ReportService { package com.example.reports; import java.util.List; public void generate(List<String> lines) { System.out.println("Report size: " + lines.size()); }}Find the bug in this module descriptor and related class.
Click on the line(s) that contain the bug.
module com.example.app { require java.sql; exports com.example.app.service;} package com.example.app.service; public class DbService { public String getDriverName() { return java.sql.Driver.class.getName(); }}Match each Java keyword with its use in packages or modules.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each module directive with its purpose.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code so that a class is correctly declared in a package and imported elsewhere.
com.example.services;public class EmailService { public void send(String to) { System.out.println("Sending to " + to); }}// In another file com.example.services.EmailService;class App { public static void main(String[] args) { EmailService service = new EmailService(); service.send("user@example.com"); }}Click an option to fill blank 1:
Complete the module descriptor to expose a package and depend on java.sql.
com.example.data { java.sql; com.example.data.repository;}Click an option to fill blank 1:
Complete the static import usage so that methods and constants from Math are used without qualification.
static java.lang.Math.*;public class Geometry { public static double circleLength(double r) { return 2 * * r; }}Click an option to fill blank 1:
Complete the imports to use List and LocalDate without qualifying them.
java.util.List; java.time.LocalDate;public class Booking { private List<LocalDate> dates;}Click an option to fill blank 1:
Click the line where a wildcard import is used for java.util classes.
Click on the line to select.
package com.example.demo; import java.util.*;import java.time.LocalDate; public class Demo { public static void main(String[] args) { List<String> list = new ArrayList<>(); System.out.println(list.isEmpty()); }}Click the line that declares the name of the module.
Click on the line to select.
module com.example.orders { requires java.logging; exports com.example.orders.api;}