Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is a 'Dependency Scope'? What are the different types of Dependency Scopes?

Answer»

The dependency scope pertains to all dependencies related to the present stage of the build.

The following are the several sorts of dependence scopes:

  • Compile- It's the default scope, and it shows which dependencies are available in the project's classpath.
  • Provided- It denotes that the dependency is delivered at runtime by the JDK, web server, or container.
  • Runtime- This INDICATES that the dependency is not required during compilation but is necessary during execution.
  • Test- It claims that dependencies are only available during the test compilation and execution phases.
  • SYSTEM- It implies that you MUST specify the system path.
  • Import- This means that the dependencies in that POM's section should be USED instead of the identified or specified POM.
2.

What do you understand about the term ‘Super POM’?

Answer»

Any POM file has the ability to point to its parent POM. There is a system-wide POM file that is automatically considered as the parent POM file if the parent POM element is absent. The super POM is the name GIVEN to this POM file. Finally, the super POM is used to EXTEND all of the application POM files. The apex of the POM hierarchy is the super POM file. The super POM file CONTAINS all of the default configurations. All of the configurations defined in the super POM file will be inherited by even the SIMPLEST version of a POM file. You can alter any option you want by redefining the same section in your application POM file.

3.

What exactly is MOJO?

Answer»

Every Maven plain Old Java OBJECT (MOJO) is an executable GOAL, and a PLUGIN pertains to the distribution of these MOJOs. MOJO allows Maven to add functionalities that it doesn't already have. In Maven, a MOJO is a single unit of the TASK.

4.

How to generate javadocs in Maven?

Answer»

The MAVEN-javadoc PLUGIN is used by Maven to generate a project's JAVADOCS. To create javadocs, this plugin internally USES the JDK\bin\javadoce.exe command. The javadocs for the project are GENERATED when the project is deployed with the mvn install command.

5.

How would you refer to a property declared in your pom.xml file?

Answer»

In order to refer to a property declared in your pom.xml, the property name MAKES use of the names of the XML COMPONENTS that designate the VALUE, with "pom" being ACCEPTED as a synonym for the project (root) element.

So ${pom.name} is the project's name, ${pom.version} is the project's version, ${pom.build.finalName} is the final name of the file generated when the built project is PACKAGED, and so on.

6.

What are the different types of Maven build profiles? In what ways can build profiles of maven be activated?

Answer»

The different types of Maven build profiles are:

  • Per-User: This is defined in the Maven settings.xml file.
  • Per PROJECT: This is defined in the project’s pom.xml.
  • Global: This is defined in the global Maven settings.xml file.

Maven build profiles can be activated or TRIGGERED in the FOLLOWING ways:

  • Using explicit commands
  • Maven settings
  • On the BASIS of environment variables
  • Configuration of the operating system
  • Present/missing FILES
7.

What are the locations where Maven dependencies are stored?

Answer»

MAVEN saves all of the JARs, dependency files, and other THINGS it downloads in the Maven local repository. All of the artifacts are kept locally in the Maven local repository, which is a folder on the local MACHINE.

8.

In Maven, what is a snapshot?

Answer»

A snapshot is a specific version of a PROJECT that shows the most recent development copy of the project being worked on. Maven always checks out a SNAPSHOT of the project in the REMOTE repository for each build.

As a result, ANYTIME Maven discovers a newer SNAPSHOT of the project, it downloads and replaces the project's older .jar file in the local repository.

9.

What is Maven's inheritance order?

Answer»

In MAVEN, the ORDER of INHERITANCE is:

  • Settings
  • CLI parameters
  • Parent POM
  • Project POM
10.

“Maven uses convention over configuration” - Why is it so?

Answer»
  • Because developers SIMPLY need to establish a Maven project while employing convention,  Maven uses convention over configuration. The rest of the STRUCTURE is generated automatically. In the CASE of configuration, build processes are to be created manually.
  • For SETTING up a project, creating artifacts, releasing code, and running unit tests, Maven has a number of CONVENTIONS.
11.

What are Maven plugins used for? What are the types of Maven plugins?

Answer»

MAVEN Plugins are used for:

  • Creating JAR files.
  • Creating WAR files.
  • Compiling the SOURCE code files.
  • Unit TESTING of the code.
  • Creating the project documentation.
  • Creating project reports.

Maven plugins are DIVIDED into two categories:

  • Build plugins:  These plugins are used throughout the build process and are configured in the pom.xml file's <build/> element.
  • Reporting plugins: These plugins are configured in the pom.xml's <reporting/> element and run during stage GENERATION.
12.

What are the different phases of the default life cycle?

Answer»

The different phases of the default lifecycle are:

  • VALIDATE: Make sure the project is correct and that you have all of the necessary information.
  • Test: Test the COMPILED source code USING an appropriate UNIT testing framework. These tests should not demand that the code be PACKED or deployed; instead, take the compiled code and package it in a manner that can be distributed, such as a JAR.
  • Compile: Compile the project's source code.
  • Verify: Perform any necessary checks on integration test findings to ensure that quality criteria are met.
  • Install: Adds the package to the local repository, allowing it to be used as a dependency in other projects.
  • Deploy: Copies the entire package to the remote repository for sharing with other developers and organizations, and is done in the build environment.
13.

In Maven, what do you mean by Clean, Default, and Site?

Answer»

The THREE built-in BUILD life CYCLES are:

  • Clean: The clean lifecycle is in CHARGE of project cleaning.
  • Default: The project deployment is handled by the default lifecycle.
  • SITE: The creation of the project's site documentation is referred to as the site lifecycle.
14.

What command should one use to install JAR files in the Local Repository?

Answer»
  • JAR FILES are installed in the local repository using mvn install.
  • The FOLLOWING PLUGIN is used to manually install the JAR into the local Maven repository: install-FILE-Dfile = <file path&GT;
15.

What are the different types of Maven repositories? Discuss.

Answer»

The three types of repositories of MAVEN are:

  • Local repository
  • Central repository
  • REMOTE repository

Maven scans these repositories for dependencies. Maven looks in the Local repository first, then the Central repository, and finally the Remote repository if the Remote repository is defined in the POM.

  • Local Repository: Local repository is a directory on the developer's device. The local repository contains all of Maven's dependencies. Even though several PROJECTS rely on dependencies, Maven only needs to download them once.
  • Central Repository: The Maven community has built the central Maven repository. Maven searches this central repository for any dependencies that aren't available in your local repository. The dependencies are subsequently downloaded into your local repository by Maven.
  • Remote Repository: Maven may download dependencies from a remote repository HOSTED on a WEB server. It is frequently used to host internal organization projects. The dependencies are subsequently downloaded into your local repository by Maven.
16.

What elements are used for creating a pom.xml file?

Answer»

The following elements are necessary for creating a pom.xml file:

  • project- The root element of the pom.xml file is the project.
  • modelVersion- It identifies which version of the POM model you're working with. For MAVEN 2 and Maven 3, USE version 4.0.0.
  • groupId- groupId is the project group's identifier. It is unique, and you will most LIKELY use a group ID that is similar to the project's root Java package name.
  • artifactId- It is used for naming the project you're working on.
  • version- The version number of the project is contained in the version element. If your project has been released in multiple versions, it is helpful to list the versions.

Other Pom.xml File Elements

  • dependencies- This element is used to establish a project's dependency list.
  • dependency- dependency is used inside the dependencies tag to define a dependency. The groupId, artifactId, and version of each dependency are listed.
  • name- This element is used to give our Maven project a name.
  • scope- This element is used to specify the scope of this maven project, which can include compile, runtime, test, among other things.
  • packaging- The packaging element is used to package our project into a JAR, WAR, and other output FORMATS.
17.

List a few differences between Maven and ANT.

Answer»
AntMaven
Because Ant LACKS formal conventions, we must include PROJECT structure information in the BUILD.xml file.Maven has a convention for storing SOURCE code, compiled code, and so forth. As a result, we don't need to provide project structure information in the pom.xml file.
Ant is procedural, so you'll need to write code to tell it what to do and when to do it. You must MAINTAIN order.Maven has a convention for storing source code, compiled code, and so forth. As a result, we don't need to provide project structure information in the pom.xml file.
Ant has no life cycle.Maven has a life cycle.
Ant is a toolbox.Maven is a framework.
Ant is primarily a build tool.Maven is primarily a project management tool.
The ant scripts can not be reused.The maven plugins can be reused.
18.

How does Maven work?

Answer»

Maven works in three steps:

  • Reading the pom.xml file is the first step.
  • The dependencies MENTIONED in pom.xml are then downloaded from the central repository into the LOCAL repository.
  • Finally, it builds and generates a report based on the REQUIREMENTS, as well as handles life CYCLES, PHASES, goals, plugins, and other tasks.
19.

Discuss the core concepts of Maven.

Answer»

The core concepts of Maven are:

  • POM Files: Project Object Model (POM) files are XML files that include information about the project and configuration information used by Maven to construct the project, such as dependencies, source directory, plugin, goals, and so on. When you want to run a maven command, you PROVIDE it with a POM file to run. To complete its configuration and functions, Maven reads the pom.xml file.
  • Dependencies and Repositories: Repositories are folders containing bundled JAR files, and dependencies are external Java libraries necessary for Project. The local repository is simply a folder on your computer's hard drive. Maven retrieves dependencies from a central Maven repository and places them in your local repository if they aren't found in the local Maven repository.
  • Build LIFE Cycles, Phases, and Goals: A build life cycle is made up of a series of build phases, each of which contains a set of goals. A build lifecycle, phase, or goal is referred to as a Maven command. When a lifecycle is asked to be run using the maven command, all of the build steps in that life cycle are likewise run. When a build phase is requested to be executed, it is followed by all build phases in the given sequence.
  • Build Profiles: Build Profiles are a set of configuration parameters that allow you to build your project using a variety of SETUPS. For example, you might need to develop and test your project on your local computer. You can add different build profiles to your POM files using its profile elements to enable different builds, which can be triggered in a variety of ways.
  • Build Plugins: Build Plugins are used to accomplish a certain task. A plugin can be ADDED to the POM file. Maven comes with various pre-installed plugins, but you can also write your own in Java.
20.

When should one use Maven?

Answer»

The Maven Build Tool can be used in the following CONDITIONS:

  • When the project has a large NUMBER of DEPENDENCIES. Then, using Maven, you can easily manage those dependencies.
  • When the version of a dependency changes frequently. To update dependencies, simply update the version ID in the pom file.
  • Maven makes it simple to handle CONTINUOUS BUILDS, integration, and testing.
  • When you need a quick way to generate documentation from source code, this is the tool you use. It helps in compiling source code, and then packaging it into JAR or ZIP files.