Java - Interview Questions and Answers on Jar , War and Ear

Q1.  Difference between jar , war and ear ?

Ans. 

Jar is Java Archieve i.e compressed Class or Class / Java files.

War comprises of compressed Servlet class files,JSP FIles,supporting files, GIF and HTML files.

Ear comprise of compressed Java and web module files ( was files ).

Q2.  How can I change the default location of the generated jar when I command "mvn package"?

Ans. By default, the location of the generated jar is in ${project.build.directory} or in your target directory. We can change this by configuring the outputDirectory of maven-jar-plugin.

Q3.  What would you do if you have to add a jar to the project using Maven ?

Ans. If its already there in Maven local repository, We can add that as a dependency in the project pom file with its Group Id, Artifact Id and version.

We can provide additional attribute SystemPath if its unable to locate the jar in the local repository.

If its not there in the local repository, we can install it first in the local repository and then can add it as dependency.

Q4.  Can we generate Java Documentation using Export -> JavaDoc using a jar file ?

Ans. Yes, If the jar contains the source code. No, If it contains only classes.

Q5.  Which of the following is usually not part of EAR file ?

 a. Server Configuration files
 b. HTML and Media Files
 c. Application Configuration files
 d. Class files

Ans. Server Configuration files