[go: up one dir, main page]

0% found this document useful (0 votes)
12 views6 pages

MCA Advanced Java Answers N20121

The document provides an answer key for an Advanced Java exam, covering topics such as JSP code for calculating factorials, types of advice in Spring AOP, Spring Boot and database integration, and differences between List and Set. It also includes explanations of generic classes, REST controllers in Spring Boot, JSP with header/footer, auto-wiring in Spring, JdbcTemplate, session tracking methods in JSP, and the advantages of generics over non-generics. Each section contains code snippets and concise descriptions of concepts relevant to Java programming.

Uploaded by

godvenom2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

MCA Advanced Java Answers N20121

The document provides an answer key for an Advanced Java exam, covering topics such as JSP code for calculating factorials, types of advice in Spring AOP, Spring Boot and database integration, and differences between List and Set. It also includes explanations of generic classes, REST controllers in Spring Boot, JSP with header/footer, auto-wiring in Spring, JdbcTemplate, session tracking methods in JSP, and the advantages of generics over non-generics. Each section contains code snippets and concise descriptions of concepts relevant to Java programming.

Uploaded by

godvenom2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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.

You might also like