MCA Semester I - Advanced Java (N20121) Answer Key
Q1
a. JSP Code for Factorial:
<%@ page language="java" %>
<html>
<body>
<form method="post">
Enter a number: <input type="text" name="num"/>
<input type="submit" value="Calculate"/>
</form>
<%
if (request.getParameter("num") != null) {
int n = Integer.parseInt(request.getParameter("num"));
int fact = 1;
for (int i = 1; i <= n; i++) {
fact *= i;
out.println("Factorial of " + n + " is: " + fact);
%>
</body>
</html>
b. Types of Advice in Spring AOP:
1. Before Advice
2. After Returning
3. After Throwing
MCA Semester I - Advanced Java (N20121) Answer Key
4. After (Finally)
5. Around Advice
c. Spring Boot & DB Integration:
Spring Boot simplifies DB integration with auto-configuration, JPA support, and dependency management.
d. JDBC as Java Objects:
- Improves code reuse and maintainability
- Uses JPA annotations, clean DAO/Repository patterns
e. List vs Set:
List: Ordered, allows duplicates.
Set: Unordered, no duplicates.
f. Resolving Circular Dependency:
Use setter injection, @Lazy annotation, or restructure code.
MCA Semester I - Advanced Java (N20121) Answer Key
Q2
a. Generic Class Box<T>:
class Box<T extends Comparable<T>> {
private T value;
public Box(T value) { this.value = value; }
public int compare(Box<T> other) {
return this.value.compareTo(other.value);
b. Spring Boot & @RestController:
@RestController enables REST APIs by returning JSON/XML directly.
Simplifies development by avoiding view resolution.
MCA Semester I - Advanced Java (N20121) Answer Key
Q3
a. JSP with header/footer:
form.html:
<form action="main.jsp" method="post">
Enter Name: <input name="ename">
</form>
main.jsp:
<jsp:include page="header.jsp"/>
<%
String name = request.getParameter("ename");
out.println("Welcome " + name);
%>
<jsp:include page="footer.jsp"/>
header.jsp and footer.jsp contain static HTML with date and company info.
MCA Semester I - Advanced Java (N20121) Answer Key
Q4
a. Auto-wiring in Spring:
Modes - no, byName, byType, constructor
@Autowired is commonly used for dependency injection.
b. JdbcTemplate:
Improves maintainability, reduces boilerplate.
Use RowMapper, DAO pattern, and NamedParameterJdbcTemplate for complex queries.
MCA Semester I - Advanced Java (N20121) Answer Key
Q5
a. Session Tracking in JSP:
1. Cookies: persistent, browser-based
2. URL Rewriting: session id in URL
3. Hidden Fields: in forms
4. HttpSession: server-side storage
b. Generics vs Non-Generics:
Generics provide type safety, cleaner code, better performance.
Non-generics require casting and are error-prone.