## 2023 – Advanced Java (DSE-B-4) – ANSWER KEY
### Q1. Answer any five (2×5 = 10 marks)
**(a)** *Static vs Dynamic Website*
- Static: Content is fixed, served directly from the server.
- Dynamic: Content is generated at runtime based on user interaction or database.
**(b)** *service() method in Servlet*
- It is invoked for every request and contains business logic.
- Signature: `public void service(ServletRequest req, ServletResponse res)`
**(c)** *focus() in jQuery*
```javascript
$("#input").focus(function() {
$(this).css("background", "yellow");
});
```
**(d)** *setMaxAge() and getMaxAge()*
- `setMaxAge(int seconds)`: Sets cookie lifetime.
- `getMaxAge()`: Returns time (in seconds) until cookie expires.
**(e)** *JavaScript vs jQuery*
- JavaScript: Scripting language.
- jQuery: JS library simplifying DOM, AJAX, animations.
**(f)** *JSP Exception Handling Method*
- `errorPage` directive: `<%@ page errorPage="[Link]" %>`
- `isErrorPage="true"` on target page
**(g)** *Implicit Objects in JSP*
- `request`, `response`, `session`, `application`, `out`, `exception`, `config`,
`page`, `pageContext`
**(h)** *jsp include directive vs action*
- `include directive`: Compile-time inclusion.
- `include action`: Runtime inclusion.
---
### Q2. (2+5+3 = 10 marks)
**(a)** *Session Definition*
- Used to store user data for the duration of a web interaction.
**(b)** *HttpSession Handling*
```java
HttpSession session = [Link]();
[Link]("user", "Debastab");
```
**(c)** *MIME Definition*
- Multipurpose Internet Mail Extensions.
- Represents file content types like `text/html`, `image/png`.
---
### Q3. (2+5+3 = 10 marks)
**(a)** *JSP Scriptlets*
```jsp
<% int a = 10; [Link](a); %>
```
**(b)** *Session using HttpSession*
```java
HttpSession session = [Link]();
String name = (String) [Link]("name");
```
**(c)** *Spring MVC & Config File*
- Spring MVC: Model-View-Controller pattern.
- Config file: `[Link]` or annotation-based.
---
### Q4. (2+5+3 = 10 marks)
**(a)** *jQuery Class & Universal Selectors*
```javascript
$(".myClass") // Class selector
$("*") // Universal selector
```
**(b)** *Form Validation Rules*
- required, email, minlength, maxlength, pattern
**(c)** *dblclick() Example*
```javascript
$("#btn").dblclick(function() {
alert("Double clicked!");
});
```
---
### Q5. (4+4+2 = 10 marks)
**(a)** *Non-numeric Validation + Reverse*
```javascript
let input = prompt("Enter input");
if (!isNaN(input)) {
alert("Data must be non-numeric");
} else {
alert([Link]('').reverse().join(''));
}
```
---
### Q6. (5+2+3 = 10 marks)
**(a)** *Singleton Design Pattern*
- Ensures a class has only one instance.
```java
class Singleton {
private static Singleton instance = null;
private Singleton() {}
public static Singleton getInstance() {
if(instance == null) instance = new Singleton();
return instance;
}
}
```
**(b)** *this keyword in JS*
- Refers to current object in context.
**(c)** *Timers in JS*
- `setTimeout()`: Executes code after delay.
- `setInterval()`: Executes code repeatedly after intervals.
---
### Q7. (3+3+4 = 10 marks)
**(a)** *Multiple Requests in Servlet*
- Only one servlet instance is created.
- Multiple threads handle multiple requests.
**(b)** *JSP vs PHP*
- JSP: Compiled, Java-based.
- PHP: Interpreted, loosely typed, easier to learn.
**(c)** *jQuery Style Sheet Application*
```javascript
$("p").css("color", "blue");
```
---
### Q8. (Any Two – 5×2 = 10 marks)
**(a)** *JDBC*
- Java API to connect to databases.
- Uses Connection, Statement, ResultSet.
**(b)** *jQuery Selectors*
- $("#id"), $(".class"), $("div")
**(c)** *DAO vs DTO*
- DAO: Manages DB operations.
- DTO: Transfers data between layers.
**(d)** *Servlet Lifecycle*
1. init()
2. service()
3. destroy()