Unit 4 - Practice Quiz

INT332 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the primary purpose of a build tool like Maven in software development?

Why build tools exist Easy
A. To automate processes like compiling, testing, and packaging code
B. To design the user interface of web applications
C. To write code for the developers automatically
D. To manage relational databases

2 Which of the following problems is commonly solved by using automated builds?

Problems solved by automated builds Easy
A. Inconsistent and error-prone manual compilation steps
B. Writing unit test logic
C. Network hardware failures
D. Designing application architecture

3 Which file serves as the core configuration file for a Maven project, defining dependencies and plugins?

Project Object Model (POM) Easy
A. build.xml
B. maven.config
C. pom.xml
D. package.json

4 In Maven's standard directory layout, where is the main Java source code expected to be placed?

Directory structure Easy
A. src/java/main
B. src/test/java
C. bin/java
D. src/main/java

5 What is a Maven build lifecycle?

Build lifecycle phases Easy
A. A well-defined sequence of phases to build and distribute a project
B. A graphical user interface for writing code
C. A database schema migration tool
D. A tool for monitoring server performance

6 Which Maven lifecycle phase translates the raw Java source code into bytecode (.class files)?

compile Easy
A. test
B. compile
C. validate
D. package

7 What is the primary function of the Maven package phase?

package Easy
A. To download dependencies from the internet
B. To compile the test source code
C. To bundle the compiled code into a distributable format like a JAR or WAR
D. To deploy the application to a live server

8 Which Maven phase copies the packaged artifact into the local repository, making it available as a dependency for other local projects?

install Easy
A. deploy
B. verify
C. install
D. package

9 What is the main purpose of a Parent POM in Maven?

Parent POM Easy
A. To act as the main executable file of the application
B. To convert Java code into Python code
C. To securely store passwords and API keys
D. To share common configurations and dependency versions across multiple sub-projects

10 Which Maven dependency scope should be used for a library like JUnit, which is only needed when executing unit tests?

Dependency scope Easy
A. compile
B. test
C. runtime
D. provided

11 How does Maven handle dependencies of dependencies (i.e., when a library you need requires another library)?

Transitive dependencies Easy
A. It prompts the user to download them manually
B. It requires you to write a custom bash script to fetch them
C. It automatically pulls them in as transitive dependencies
D. It ignores them, causing runtime errors

12 Which POM section allows you to centralize the versioning of dependencies without actually including them in the project?

Using dependency Management Easy
A. <dependencies>
B. <plugins>
C. <properties>
D. <dependencyManagement>

13 Which Maven plugin is responsible for running unit tests during the test phase?

Surefire plugin (unit testing) Easy
A. Maven Deploy Plugin
B. Maven Surefire Plugin
C. Maven Shade Plugin
D. Maven Compiler Plugin

14 What is the primary use of the Maven Shade plugin?

Shade plugin (uber jar) Easy
A. To create an "uber-jar" (fat jar) that contains both the compiled project code and all its dependencies
B. To encrypt the source code
C. To delete the target directory
D. To automatically format Java code

15 What is the main benefit of including the Maven Wrapper (mvnw) in a project's repository?

Maven wrapper (mvnw) Easy
A. It automatically writes unit tests for the project
B. It creates Docker containers automatically
C. It allows developers to build the project without having to install Maven manually on their system
D. It speeds up the compilation process by 50%

16 What does a plugin like dockerfile-maven-plugin allow developers to do?

Maven and Docker Integration: dockerfile-maven-plugin Easy
A. Compile Java code into Docker-compatible C++ code
B. Run Docker inside a Java Virtual Machine
C. Replace Maven entirely with Docker Compose
D. Build and push Docker images directly as part of the Maven build process

17 When Dockerizing a Maven application, what is typically copied into the final Docker image?

Dockerizing Maven-based applications Easy
A. The developer's IDE settings
B. The pom.xml file without any source code
C. The packaged artifact (e.g., JAR or WAR file) generated by Maven
D. The entire src folder and nothing else

18 In a continuous integration pipeline, where are final build artifacts (like JARs or Docker images) usually pushed for sharing and deployment?

Pushing artifacts to registries Easy
A. A relational database management system
B. A text document on a shared drive
C. A local Git branch
D. An artifact repository or container registry (e.g., Nexus, Artifactory, Docker Hub)

19 How does Maven typically resolve version conflicts when the same transitive dependency is included multiple times with different versions?

Version conflicts & resolution Easy
A. It merges the source code of both versions
B. It always chooses the oldest version
C. It randomly selects a version
D. It uses the "nearest definition" strategy in the dependency tree

20 Which Maven phase copies the final packaged artifact to a remote repository to share it with other developers and projects?

deploy Easy
A. deploy
B. install
C. validate
D. test

21 A development team manually compiles their Java code, packages it, and copies it to a server. They frequently encounter the 'it works on my machine' syndrome. How does a build tool like Maven directly mitigate this specific issue?

Why build tools exist Medium
A. By dynamically converting Java source code into platform-native executable binaries.
B. By installing a localized IDE on every developer's machine to enforce syntax checking.
C. By standardizing the build process, dependency resolution, and environment expectations into a single configuration file.
D. By automatically writing unit tests for the source code to ensure cross-platform compatibility.

22 When integrating an application into a CI/CD pipeline, which of the following is the primary problem solved by utilizing an automated build process rather than a manual one?

Problems solved by automated builds Medium
A. Bypassing the compilation phase to directly package source code into deployable containers.
B. Ensuring reproducible, error-free builds that do not rely on human intervention or specific developer environments.
C. Eliminating the need for source code version control repositories like Git.
D. Automatically fixing compilation errors and syntax warnings in the developer's source code.

23 You need to define a custom version string 1.5.0 that will be used by multiple dependencies in your pom.xml. How should you define and reference this property?

Project Object Model (POM) Medium
A. Define it inside <config><version>1.5.0</version></config> and reference it as $config.version.
B. Define it inside <dependencyManagement><version>1.5.0</version></dependencyManagement> and reference it as ${version}.
C. Define it inside <properties><app.version>1.5.0</app.version></properties> and reference it as ${app.version}.
D. Define it inside <variables><app.version>1.5.0</app.version></variables> and reference it as @app.version@.

24 You are adding an application configuration file (app-config.xml) that must be present on the classpath during the execution of unit tests, but it MUST NOT be included in the final production JAR. Where should you place this file in the standard Maven directory structure?

Directory structure Medium
A. src/test/resources
B. src/main/resources
C. src/test/java
D. target/test-classes

25 A developer runs the command mvn install on a Maven project. Based on the default Maven lifecycle, which of the following phases will NOT be executed?

Build lifecycle phases Medium
A. package
B. test
C. deploy
D. compile

26 You want to ensure that your integration tests run and pass, and that the project meets quality criteria BEFORE it is copied into your local Maven repository. Which phase represents the culmination of these checks?

validate, compile, test, package, verify, install, deploy Medium
A. test
B. install
C. package
D. verify

27 In a multi-module Maven project, you want to ensure that all child modules use version 2.5.4 of a library if they choose to declare it, but you do not want to force the library to be included in modules that don't need it. How do you configure this in the Parent POM?

Parent POM Medium
A. Define the library within the <dependencies> section of the Parent POM.
B. Define the library within the <dependencyManagement> section of the Parent POM.
C. Define the library within the <plugins> section of the Parent POM.
D. Use the <modules> section to hardcode the dependency into specific child modules.

28 You are developing a Java web application that uses the Servlet API. The application server (like Tomcat) will provide this API when the application is deployed. Which dependency scope should you use for javax.servlet-api to prevent it from being packaged in the final WAR file?

Dependency scope Medium
A. compile
B. runtime
C. test
D. provided

29 Your project depends on Library A, which internally depends on Library B (v1.0). However, your project also requires Library B directly, but you specifically need version 2.0. To avoid unpredictable classpath behavior, how should you handle this?

Transitive dependencies Medium
A. Maven automatically resolves all version conflicts by always downloading the oldest version of a transitive dependency.
B. Change Library A's scope to provided so its transitive dependencies are ignored.
C. Declare Library B (v2.0) in the src/main/resources folder.
D. Use the <exclusion> tag inside Library A's dependency declaration to remove Library B, and explicitly declare Library B (v2.0) in your POM.

30 Your POM declares Dependency X first and Dependency Y second. Dependency X transitively brings in log-lib version 1.0. Dependency Y transitively brings in log-lib version 2.0. Both transitive dependencies are at the same depth in the dependency tree. According to Maven's mediation rules, which version of log-lib will be used?

Version conflicts & resolution Medium
A. The build will fail immediately due to a version conflict.
B. Version 1.0, because Maven uses the 'first declaration wins' strategy when depths are equal.
C. Version 2.0, because the last declared dependency overrides earlier ones.
D. Version 2.0, because Maven always resolves to the highest version number available.

31 What is the primary operational difference between declaring a dependency in <dependencies> versus <dependencyManagement>?

Using dependency Management Medium
A. <dependencies> downloads artifacts from the local repository, while <dependencyManagement> forces a download from a remote repository.
B. <dependencies> is used for internal project modules, while <dependencyManagement> is used exclusively for external third-party libraries.
C. <dependencies> includes the library in the build and classpath, while <dependencyManagement> only specifies default configurations (like version) for dependencies declared elsewhere.
D. <dependencyManagement> is used for plugins, whereas <dependencies> is used for standard Java libraries.

32 Your local machine runs Java 11 by default, but you need the Maven Compiler Plugin to compile your code strictly for Java 17. How can you configure this in the pom.xml?

Maven Plugins & Execution: Compiler plugin Medium
A. Set <java.version>17</java.version> in the <dependencies> section.
B. Change the pom.xml packaging type to <packaging>java-17</packaging>.
C. Configure the maven-compiler-plugin to use <source>17</source> and <target>17</target> (or <release>17</release>).
D. Pass the -Djava=17 flag in the command line when running mvn compile.

33 During an emergency hotfix deployment, you need to build the project and compile the test classes, but you want to SKIP the actual execution of the unit tests to save time. Which command achieves this?

Surefire plugin (unit testing) Medium
A. mvn install -Dmaven.test.skip=true
B. mvn install -P no-tests
C. mvn install -DskipTests
D. mvn install --exclude-tests

34 You are developing a standalone Java utility and want to package the application along with all of its dependencies into a single, executable 'uber-jar'. Which Maven plugin is best suited for this task and resolving potential classpath overlaps?

Shade plugin (uber jar) Medium
A. maven-dependency-plugin
B. maven-shade-plugin
C. maven-compiler-plugin
D. maven-surefire-plugin

35 A new developer clones your project repository but does not have Maven installed on their system. The repository contains mvnw and mvnw.cmd files. What is the correct way for them to build the project?

Maven wrapper (mvnw) Medium
A. They must manually download and install Maven first, as mvnw only configures environment variables.
B. They must run a Docker container to parse the mvnw file into a local Maven installation.
C. They can run ./mvnw clean install which will automatically download the correct Maven version and execute the build.
D. They should run mvn install --use-wrapper to trigger the build.

36 When using a Maven plugin to build Docker images (like dockerfile-maven-plugin or similar), how is the finalized JAR file name dynamically passed into the Dockerfile so that it can be copied into the image?

Maven and Docker Integration: dockerfile-maven-plugin Medium
A. By writing a Bash script in the post-integration-test phase to rename the JAR to app.jar.
B. By setting the Docker container's environment variable inside the src/main/resources/application.properties.
C. By using the <buildArgs> configuration in the plugin to map a Maven property like ${project.build.finalName} to an ARG in the Dockerfile.
D. By hardcoding the JAR name inside the Dockerfile, as Maven plugins cannot pass dynamic variables to Docker.

37 You are writing a multi-stage Dockerfile to build a Maven application. To optimize the Docker build cache and avoid re-downloading dependencies every time the source code changes, what is the best sequence of instructions?

Dockerizing Maven-based applications Medium
A. Copy only the src/ folder, run mvn compile, then copy the pom.xml.
B. Copy only pom.xml, run mvn dependency:go-offline, then copy the source code and run mvn package.
C. Run mvn clean install locally on the host, then copy the target JAR into the Docker image.
D. Copy all source code and pom.xml, then run mvn clean install.

38 When configuring Maven to deploy a built artifact to a remote private registry (like Nexus or Artifactory), you must provide authentication credentials. According to Maven security best practices, where should these credentials be stored?

Pushing artifacts to registries Medium
A. In the src/main/resources/credentials.properties file.
B. Inside the project's pom.xml under the <repository> tag.
C. As plaintext arguments passed to the mvn deploy command.
D. In the developer's local ~/.m2/settings.xml file mapped to the repository ID.

39 Your Java application connects to a MySQL database. You need the MySQL JDBC driver to connect at runtime, but your code is written exclusively using the generic java.sql interfaces, so the driver is not needed for compilation. Which dependency scope is most appropriate for the MySQL driver?

Dependency scope Medium
A. runtime
B. provided
C. compile
D. test

40 A CI/CD pipeline executes the command mvn clean deploy. How does Maven process this command?

validate, compile, test, package, verify, install, deploy Medium
A. It runs the clean phase simultaneously with the deploy phase using multithreading.
B. It runs the clean lifecycle, then runs only the deploy phase of the default lifecycle.
C. It runs the clean phase, then sequentially executes all default lifecycle phases starting from validate up to and including deploy.
D. It bypasses compile and test to rapidly push the existing artifact to the remote repository.

41 In a Maven dependency tree, Project A depends on Lib B and Lib C. Lib B depends on Lib D (version 2.0). Lib C depends on Lib E, which in turn depends on Lib D (version 1.0). If Lib B is declared before Lib C in Project A's POM, which version of Lib D is included in the final artifact, and why?

Version conflicts & resolution Hard
A. Lib D (version 2.0), because Maven uses the 'nearest definition' rule, and the path to version 2.0 is shorter (depth 2 vs depth 3).
B. Lib D (version 2.0), because Lib B was declared first in the POM, triggering the 'first declaration wins' rule.
C. Lib D (version 1.0), because Maven prefers the oldest stable version to ensure backward compatibility.
D. The build will fail with a dependency conflict error unless <dependencyManagement> is explicitly used to resolve it.

42 Project A imports a Bill of Materials (BOM) in its <dependencyManagement> section, which specifies com.example:core-lib:1.0. In the <dependencies> section of Project A, com.example:core-lib is declared with version 2.0. Module B, a child of Project A, declares com.example:core-lib without a version. What version of core-lib does Module B resolve?

Using dependency Management Hard
A. The build fails because Module B must explicitly specify a version when a conflict exists in the parent.
B. Version 1.0, because the BOM imported in <dependencyManagement> takes absolute precedence over local declarations.
C. Version 1.0 for Project A, but Module B will fail to compile due to ambiguity.
D. Version 2.0, because direct dependency declarations override versions managed in <dependencyManagement>, and this override is inherited.

43 A parent POM defines the maven-antrun-plugin exclusively inside the <pluginManagement> section and binds an execution to the validate phase. A child module inherits from this parent but does not mention the maven-antrun-plugin in its own POM. What happens when mvn validate is run on the child module?

Parent POM Hard
A. The maven-antrun-plugin executes during the validate phase of the child module.
B. The build fails because the plugin in the parent POM requires an explicit <skip>false</skip> parameter to propagate to children.
C. The plugin executes, but only if the child module has a <packaging>pom</packaging> configuration.
D. The maven-antrun-plugin does not execute because <pluginManagement> only configures plugins; they must be explicitly declared in the child's <plugins> section to be invoked.

44 When creating an Uber JAR using the maven-shade-plugin for an application heavily utilizing the Spring Framework, the resulting JAR throws schema errors at runtime. This happens because multiple dependencies contain different META-INF/spring.handlers files. How must this be resolved in the Shade plugin configuration?

Shade plugin (uber jar) Hard
A. Exclude the META-INF/spring.handlers from all dependencies using the <filters> configuration.
B. Use the ServicesResourceTransformer to relocate the schema packages to a shaded directory.
C. Use the ManifestResourceTransformer to specify a custom main class.
D. Use the AppendingTransformer specifically mapped to the META-INF/spring.handlers resource.

45 A project declares Dependency X with <scope>provided</scope>. Dependency X transitively depends on Dependency Y with <scope>compile</scope>. What is the effective scope of Dependency Y in the root project?

Dependency scope Hard
A. Compile
B. Provided
C. Runtime
D. It is completely excluded from the root project.

46 When running integration tests with the maven-failsafe-plugin, what is the key functional difference between stopping at the integration-test phase versus proceeding to the verify phase?

verify Hard
A. There is no difference; the maven-failsafe-plugin binds identically to both phases.
B. The integration-test phase requires an active Docker daemon, while the verify phase is used purely for offline static analysis.
C. The integration-test phase only compiles integration test sources; the actual execution occurs in the verify phase.
D. The integration-test phase executes the tests but does not fail the build if tests fail; the verify phase evaluates the results and fails the build if necessary.

47 You are utilizing the Maven Wrapper (mvnw) to ensure uniform build environments. A developer's machine resides behind a strict corporate firewall that blocks direct access to Maven Central, preventing mvnw from downloading the Maven distribution. How can you configure the wrapper to fetch the Maven distribution from an internal Artifactory server?

Maven wrapper (mvnw) Hard
A. Modify the distributionUrl property inside the .mvn/wrapper/maven-wrapper.properties file.
B. Set the MAVEN_HOME environment variable on the developer's machine to point to the internal Artifactory.
C. Update the settings.xml file in the .mvn directory to include a mirror for central.
D. Add the internal repository URL to the <pluginRepositories> section of the project POM.

48 When utilizing the dockerfile-maven-plugin to build a Docker image, you want to dynamically pass the final built JAR filename into the Dockerfile as an argument. How is this correctly accomplished mapping Maven coordinates to Docker ARGs?

Maven and Docker Integration: dockerfile-maven-plugin Hard
A. By setting <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> inside the <environmentVariables> block of the plugin.
B. By renaming the jar using the maven-assembly-plugin to app.jar and hardcoding COPY app.jar / in the Dockerfile.
C. By using the Maven filtering mechanism on the Dockerfile via the maven-resources-plugin before the dockerfile-maven-plugin executes.
D. By declaring ARG JAR_FILE in the Dockerfile and passing <buildArgs><JAR_FILE>${project.build.finalName}.jar</JAR_FILE></buildArgs> in the plugin configuration.

49 A CI pipeline needs to push a compiled Maven artifact to a private Nexus repository. The repository URL is defined in the project's POM under <distributionManagement>. Authentication is required. Where and how must the credentials be configured to ensure Maven successfully authenticates during the deploy phase?

Pushing artifacts to registries Hard
A. In a credentials.json file located in the .mvn directory.
B. Inside the <distributionManagement> block of the POM, using the <username> and <password> tags.
C. By passing them as command-line arguments: mvn deploy -Drepo.username=user -Drepo.password=pass.
D. In the ~/.m2/settings.xml file under <servers>, mapping the <server><id> exactly to the <repository><id> specified in the POM's <distributionManagement>.

50 A developer executes mvn package -DskipTests. Which of the following accurately describes the behavior of the maven-surefire-plugin and the build lifecycle in this scenario?

Surefire plugin (unit testing) Hard
A. Only classes annotated with @Ignore or @Disabled are skipped; all other unit tests are executed.
B. Test sources are compiled into the target/test-classes directory, but the actual execution of unit tests is bypassed.
C. Unit tests execute, but their failures are ignored and do not fail the build.
D. Test sources are neither compiled nor executed, completely bypassing the test-compile and test phases.

51 To solve the problem of non-reproducible builds where two builds from identical source code generate JARs with different SHA-256 hashes, what Maven property should be configured to ensure deterministic archive entries?

Problems solved by automated builds Hard
A. <maven.build.timestamp.format>
B. <maven.compiler.deterministic>
C. <reproducible.builds.enabled>
D. <project.build.outputTimestamp>

52 A legacy Java project contains source code in both src/main/java and src/legacy/java. How can you correctly configure Maven to compile sources from both directories without breaking standard plugin lifecycles?

Directory structure Hard
A. Use the build-helper-maven-plugin with the add-source goal to register src/legacy/java as an additional source root.
B. Move src/legacy/java into src/main/resources and configure the <resources> tag.
C. Set <sourceDirectory>src/main/java,src/legacy/java</sourceDirectory> in the POM's <build> section.
D. Configure the maven-compiler-plugin <includes> tag to scan the root src directory recursively.

53 A project is defined with <packaging>pom</packaging>. You execute the command mvn deploy. Which of the following statements is true regarding the execution of the compiler and surefire plugins during this run?

deploy Hard
A. The build fails immediately because mvn deploy cannot be executed on POM packaged projects.
B. Both plugins execute normally because deploy triggers all prior phases.
C. Neither plugin executes because POM packaging explicitly unbinds the goals normally associated with compilation and testing.
D. The compiler plugin executes, but the surefire plugin is skipped automatically for POM projects.

54 When resolving the Effective POM, which of the following configuration sources has the highest overriding precedence for defining a specific property value?

Project Object Model (POM) Hard
A. Properties defined directly in the project's pom.xml <properties> section.
B. Properties injected via system environment variables.
C. Properties defined in an active profile within the ~/.m2/settings.xml file.
D. Properties defined in the <properties> section of the project's parent pom.xml.

55 When configuring the maven-compiler-plugin to run a custom annotation processor (e.g., MapStruct or Lombok), what is the effect of declaring the processor dependency inside the <annotationProcessorPaths> configuration tag rather than in the project's general <dependencies>?

Compiler plugin Hard
A. It isolates the annotation processor so it does not leak into the project's runtime or compile classpath, strictly keeping it as a build-time tool.
B. It forces the compiler to use the system classloader (<useSystemClassLoader>true) to bypass memory limits.
C. It causes the compiler to process annotations recursively through all transitive dependencies.
D. It automatically skips the compile phase and only runs during the generate-sources phase.

56 When writing a multi-stage Dockerfile for a Maven application to optimize build caching, what is the correct order of operations to ensure that dependency downloading is cached as a separate Docker layer?

Dockerizing Maven-based applications Hard
A. COPY pom.xml RUN mvn compile COPY src RUN mvn package
B. COPY src and pom.xml RUN mvn clean package
C. RUN mvn clean install COPY target/app.jar ENTRYPOINT java -jar app.jar
D. COPY pom.xml RUN mvn dependency:go-offline COPY src RUN mvn package

57 Project A declares direct dependencies on Module B and Module C. Module B depends on Lib D (v1.0). Module C also depends on Lib D (v1.0). If you explicitly declare an <exclusion> for Lib D inside the dependency block for Module B in Project A's POM, what happens to Lib D?

Transitive dependencies Hard
A. The build fails because an exclusion must be mirrored across all dependencies that provide it.
B. Lib D is entirely removed from the classpath of Project A.
C. Lib D is still included in Project A's classpath because it is transitively provided via Module C.
D. Lib D is downgraded to a provided scope.

58 Which of the following restrictions applies to the import dependency scope in Maven?

Dependency scope Hard
A. It can only be used to import custom Maven plugins into the <pluginManagement> section.
B. It can only be used with <type>pom</type> and must be placed inside the <dependencyManagement> section.
C. It is functionally identical to the system scope but allows relative paths to local repositories.
D. It must be accompanied by the <optional>true</optional> tag.

59 A custom Maven plugin has a goal specifically bound to the process-classes phase. A developer executes mvn test-compile. Will the custom plugin execute?

Build lifecycle phases Hard
A. No, because process-classes is part of the default lifecycle which occurs after test-compile.
B. Yes, because process-classes precedes test-compile in the default build lifecycle.
C. No, because test-compile creates an isolated lifecycle fork that excludes process phases.
D. Yes, but only if the plugin is explicitly bound to the test profile.

60 In a Maven tree, Dependency A requests Lib X with version range [1.0, 2.0). Dependency B requests Lib X with version range [1.5, 2.5]. If both A and B are included in a project, what version constraint will Maven use to resolve Lib X?

Version conflicts & resolution Hard
A. Maven resolves the intersection of the ranges: [1.5, 2.0).
B. Maven will resolve the highest upper bound: 2.5.
C. Maven will throw a DependencyResolutionException because version ranges cannot be automatically merged.
D. Maven will resolve the lowest available version: 1.0.