0% found this document useful (0 votes)
1 views3 pages

Advanced Java DSEB4 Answers

The document is an answer key for an Advanced Java exam, covering topics such as static vs dynamic websites, servlets, jQuery, JSP, session handling, MIME types, and design patterns. It includes code snippets and definitions for various concepts, as well as comparisons between technologies like JSP and PHP. The structure consists of multiple questions, each with specific answers and examples.

Uploaded by

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

Advanced Java DSEB4 Answers

The document is an answer key for an Advanced Java exam, covering topics such as static vs dynamic websites, servlets, jQuery, JSP, session handling, MIME types, and design patterns. It includes code snippets and definitions for various concepts, as well as comparisons between technologies like JSP and PHP. The structure consists of multiple questions, each with specific answers and examples.

Uploaded by

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

## 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="error.jsp" %>`
- `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 = request.getSession();
session.setAttribute("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; out.println(a); %>
```

**(b)** *Session using HttpSession*


```java
HttpSession session = request.getSession();
String name = (String) session.getAttribute("name");
```

**(c)** *Spring MVC & Config File*


- Spring MVC: Model-View-Controller pattern.
- Config file: `applicationContext.xml` 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(input.split('').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()

You might also like