AJ QB Answers
AJ QB Answers
• TreeMap:
o Not thread-safe.
• HashMap:
o Not thread-safe.
• Java Generics allow type-safe code by enabling classes, interfaces, and methods to operate
on specific types while providing compile-time type checking.
• Key Features:
o Example:
list.add("Hello");
5. What are Java lambda expressions? What are the advantages of them?
• Advantages:
Example:
new Thread(r).start();
• Explanation:
• Example:
</form>
In welcome.jsp:
<%
} else {
out.println("Username is missing!");
%>
10. Demonstrate the creation of custom tags with an example for formatting dates.
• Steps:
package customtags;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
@Override
getJspContext().getOut().print(formatter.format(date));
3. Use it in JSP:
<%@ taglib uri="customtags.tld" prefix="custom" %>
<custom:formatDate date="<%= new Date() %>" pattern="yyyy-MM-dd HH:mm a" />
12. What is the POJO Programming Model?
• POJO: Stands for Plain Old Java Object, representing simple Java classes without any specific
constraints (e.g., no inheritance or annotations).
• Example:
Advantages:
• Simplifies development.
7 Marks Questions
• Readability:
Lambdas reduce verbose code by replacing anonymous inner classes.
Example:
// Without lambda
@Override
};
// With lambda
Efficiency:
Example:
• Problem: Create a JSP page with fields for email and username, and display a personalized
welcome message.
• Solution:
<label>Email:</label>
<br />
<label>Username:</label>
<br />
</form>
<%
%>
<%
} else {
%>
<%
%>
• Explanation:
• Key Uses:
8 Marks Questions
list.add("Text");
Key Benefits:
3. Code Reusability:
System.out.println(item); } }
11. Create a reusable custom JSP tag <formatDate> to display a date.
• Output:
2024-11-11 10:15 AM
• Effectiveness:
3. Testability: POJOs can be unit tested easily without requiring complex setups.
In Spring Configuration:
</bean>
15. Evaluate Setter vs Constructor Dependency Injection with a code snippet.
• Constructor Injection:
• Constructor Injection:
this.repository = repository;
• Setter Injection:
public class Service {
private Repository repository;