Jaskerat singh 1 AJ UT-1
Advanced java question answers.
Q1) what are generics? Explain implementation and give a suitable
example
Ans: Generics in Java provide a way to create classes, interfaces, and methods that
can work with different types. They were introduced in Java 5 to enforce type safety
at compile-time and facilitate the creation of reusable and flexible code.
In Java, generics use type parameters, denoted by angle brackets (< >), to specify
and enforce the types used in classes, interfaces, and methods. This allows you to
create classes that can operate on different types without sacrificing type safety.
Generics provide the following benefits:
Type Safety: Detect errors at compile-time rather than at runtime.
Reusability: Create flexible, generic classes that can be used with various data
types.
Elimination of Type Casting: Avoid explicit casting of objects from Object to
specific types.
Let us create a simple generic class in Java, for instance, a generic Box class that can
store and retrieve any type of object.
Implementation:
public class Box<T> {
private T content;
public void set (T content) {
[Link] = content;
}
public T get () {
return content;
Jaskerat singh AJ UT 1
Jaskerat singh 2 AJ UT-1
}
}
Example
public class Main {
public static void main (String [] args) {
Box<Integer> intBox = new Box<> ();
[Link](10);
[Link]("Integer value in the box: " + [Link]());
Box<String> stringBox = new Box<> ();
[Link]("Hello, Generics!");
[Link]("String value in the box: " + [Link]());
}
}
In this example, the Box class is defined with a generic type T. The set method takes
an object of type T, and the get method returns an object of type T. When using the
Box class, you specify the type inside angle brackets (<>), such as Box<Integer>
and Box<String>, to work with specific types.
Jaskerat singh AJ UT 1
Jaskerat singh 3 AJ UT-1
Q2) Different types of wildcards in java.
Ans: In Java, question marks are known as Wildcards which we can use in
generic programming. Wildcards are used to represent the unknown type. We can
use java wildcards in a parameter, local variable, or field and as a return type.
The java generic types are not compatible with one another, this is one of the
differences between them and arrays. This incompatibility is removed by using the
wildcard(?) as an actual parameter.
There are two types of parameters that a programmer can pass to a method in the
form of in and out parameters, they are as follows:
1. in variable:
in variable is a variable that provides the program with the actual data to work
with. Let us consider a method, path (source, destination), in this method the
source variable acts as the in variable, as it provides the data to work with.
2. out variable:
The out variable calculates and updates the data provided by the in variable. Let us
consider the same method, path (source, destination), in this method the destination
variable acts as the out variable, as it calculates the destination path with the help
of the data provided by the source variable and updates it.
Types of Wildcards in Java
1. Upper Bounded Wildcards:
The upper Bounded Wildcards helps us relax the restriction on the type of variable
in the method. If we want to relax the restriction on the variable type, we use this
type of wildcards.
Syntax:
private static double sum (List <? extends Number > my_List)
package [Link];
import [Link].*;
public class Upperbound
{
public static void main(String[] args) {
List < Integer > integer_List = [Link](1, 3, 5, 7);//Integer List
Jaskerat singh AJ UT 1
Jaskerat singh 4 AJ UT-1
[Link]("Total sum is:" + sum(integer_List));
List < Double > double_List = [Link](1.2, 3.4, 5.6, 7.8);//Double List
[Link]("Total sum is: " + sum(double_List));
}
private static double sum(List < ?extends Number > my_List)//Using ? to relax
restriction of input type.
{
double sum = 0.0;
for (Number iterator: my_List)
{
sum = sum + [Link]();
}
return sum;
}
}
2. Lower Bounded Wildcards:
To widen the use of the type of variable, we can use the Lower Bounded
Wildcards.
For example: If we use List<Integer>, we will be able to take only a list of
integers and not any other type of variables. Using Lower Bounded Wildcards, we
can use List<Number> and List<Object> to take integer input. This also allows us
to widen the type of variable and let us take any type of variable. Can this be
achieved by using the ? character followed by the super keyword.
Syntax:
public static void printLowerBounded(List <? super Integer > LowerBounded_list)
3. Unbounded Wildcards:
We can use the unbounded Wildcard to specify the type of wildcard along with the
wildcard character(?). We use this wildcard when the code inside the method is
using the objects and when the execution of the method does not depend upon the
parameter type.
Syntax:
private static void print_List(List <?>Unbounded_list)
Jaskerat singh AJ UT 1
Jaskerat singh 5 AJ UT-1
package [Link];
import [Link].*;
public class Unbounded
{
public static void main(String[] args)
{
List < Integer > int_List = [Link](1, 3, 5, 7);//Integer List
List < Double > double_List = [Link](10.2, 15.3, 20.4,
25.5);//Double list
print_List(int_List);
print_List(double_List);
}
private static void print_List(List < ?>Unbounded_list)//unbounded
wildcard used
{
[Link](Unbounded_list);
}
}
Jaskerat singh AJ UT 1
Jaskerat singh 6 AJ UT-1
Q3) importance of boxing, unboxing, autoboxing in generics and
collections.
Ans: In Java, boxing, unboxing, and autoboxing are essential concepts
that significantly impact how generics and collections operate. These
concepts are critical for working with primitive types in conjunction
with generics and collections. Understanding these mechanisms is
crucial for efficient and effective handling of data in Java.
Boxing and Unboxing:
Boxing: It refers to the process of converting a primitive type to its
corresponding wrapper class object. For instance, converting an `int` to
an `Integer` or a `double` to a `Double`. This is typically done using
constructors or valueOf methods in wrapper classes.
Unboxing: It is the reverse process, converting a wrapper class object
back to its primitive type. For example, converting an `Integer` to an
`int` or a `Double` to a `double`.
Example of Boxing and Unboxing:
// Boxing: Converting int to Integer
int primitiveInt = 10;
Integer wrappedInt = [Link](primitiveInt); // Boxing
// Unboxing: Converting Integer to int
int anotherInt = [Link](); // Unboxing
Jaskerat singh AJ UT 1
Jaskerat singh 7 AJ UT-1
Autoboxing:
Autoboxing: Introduced in Java 5, it is the automatic conversion of
primitive types to their corresponding wrapper class objects and vice
versa, which happens implicitly by the Java compiler. This simplifies the
code by handling the boxing and unboxing process automatically.
Example of Autoboxing:
// Autoboxing: Implicit conversion of int to Integer
int primitiveInt = 10;
Integer wrappedInt = primitiveInt; // Autoboxing
// Autoboxing: Implicit conversion of Integer to int
Integer anotherInt = 20;
int unboxedInt = anotherInt; // Autoboxing
Importance in Generics and Collections:
1. Generics and Type Safety:
- When working with generics, Java collections (like `ArrayList`,
`HashMap`, etc.), they cannot directly store primitive types; they only
accept objects. Boxing allows the use of wrapper classes for primitives,
enabling their storage in collections.
Jaskerat singh AJ UT 1
Jaskerat singh 8 AJ UT-1
2. Generic Types:
- Generics ensure type safety by specifying types. Autoboxing allows
seamless handling of primitive types within generic classes and
methods, allowing them to accept both primitive types and their
corresponding wrapper classes.
3. Performance Implications:
- While autoboxing simplifies code, it can impact performance.
Autoboxing and unboxing involve the creation of additional objects,
potentially causing overhead in memory and execution time. Bulk
autoboxing/unboxing operations can be less efficient.
4. Convenience and Readability:
- Autoboxing enhances code readability and convenience by
simplifying the syntax, making it more concise and reducing the need
for explicit casting between primitives and their wrapper classes.
5. Compatibility and Interoperability:
-Boxing, unboxing, and autoboxing ensure compatibility between
generic types and collections, allowing easy interaction between generic
types and primitive types without sacrificing type safety.
These mechanisms are crucial for efficiently utilizing generics and
collections in Java, ensuring type safety, readability, and performance
while handling both primitive types and their corresponding wrapper
classes in various contexts.
Jaskerat singh AJ UT 1
Jaskerat singh 9 AJ UT-1
Q4) any 2 implementations of list interface.
Ans: ArrayList
This class is implemented in the collection framework. It provides us with dynamic
arrays in Java. It can be slower than standard arrays but has more advantages for
programs where multiple manipulation in the array is needed.
Example
Creation of List object using Array List Class
import [Link].*;
import [Link].*;
public class ListObjArrayList{
public static void main(String[] args){
int n = 10; // initializing size of array list
List<Integer> arr = new LinkedList<Integer>(); // declaring the list with initial
size n
for(int i = 1;i <= n;i++){
[Link](i); // adding elements in the list
}
[Link](arr); // printing the list
[Link](5); // removing the element at index 5 of the list
[Link](arr); // printing the new list after deletion
for(int j = 0;j < [Link]();j++){
[Link]([Link](j) + " "); // printing the elements one by one
}
}
}
LinkedList
This class is implemented in the collection framework. It inherently implements the
linked list data-structure. This class has characteristics of a linear data structure,
where every element is a separate object with its individual data and address part.
Each element is linked with the help of pointers and addresses. Insertion and deletion
operations are easy to perform here, that is why they are preferred over the arrays.
Jaskerat singh AJ UT 1
Jaskerat singh 10 AJ UT-1
Example
Creation of List object using Linked List Class.
import [Link].*;
import [Link].*;
public class ListObjLinkedList{
public static void main(String[] args){
int n = 10; // initializing size of linked list
List<Integer> link = new LinkedList<Integer>(); // declaring the list with initial
size n
for(int i = 1;i <= n;i++){
[Link](i); // adding elements in the list
}
[Link](link); // printing the list
[Link](5); // removing the element at index 5 of the list
[Link](link); // printing the new list after deletion
for(int j = 0;j < [Link]();j++){
[Link]([Link](j) + " "); // printing the elements one by one
}
}
}
Jaskerat singh AJ UT 1
Jaskerat singh 11 AJ UT-1
Q5) any 2 implementations of set interface.
Ans: The `Set` interface in Java is a part of the `[Link]` package and extends the
`Collection` interface. It represents a collection that cannot contain duplicate
elements and does not guarantee the order of elements. Two common
implementations of the `Set` interface in Java are `HashSet` and `TreeSet`.
1. HashSet:
`HashSet` is an implementation of the `Set` interface that uses a hash table for its
underlying data structure. It does not guarantee the order of elements and allows
`null` elements. This implementation offers constant-time performance for basic
operations like `add`, `remove`, `contains`, and more, assuming a good hash
function that evenly distributes elements across the table.
Example:
import [Link];
import [Link];
public class HashSetExample {
public static void main (String [] args) {
// Creating a HashSet
Set<String> hashSet = new HashSet<> ();
// Adding elements to the HashSet
[Link]("Apple");
[Link]("Banana");
[Link]("Orange");
[Link]("Apple"); // Adding a duplicate element, which will not be added
// Displaying the elements in the HashSet
Jaskerat singh AJ UT 1
Jaskerat singh 12 AJ UT-1
[Link]("Elements in HashSet: " + hashSet);
// Removing an element
[Link]("Banana");
[Link]("HashSet after removing 'Banana': " + hashSet);
// Checking if an element is present
[Link]("Does HashSet contain 'Orange'? " +
[Link]("Orange"));
}
}
2. TreeSet:
`TreeSet` is another implementation of the `Set` interface that stores elements in a
sorted order. It uses a self-balancing red-black tree internally to maintain the
elements in sorted order. Unlike `HashSet`, `TreeSet` does not allow `null`
elements and offers guaranteed log(n) time cost for basic operations (add, remove,
contains).
Example:
import [Link];
import [Link];
public class TreeSetExample {
public static void main (String [] args) {
// Creating a TreeSet
Set<String> treeSet = new TreeSet<> ();
Jaskerat singh AJ UT 1
Jaskerat singh 13 AJ UT-1
// Adding elements to the TreeSet
[Link]("Apple");
[Link]("Banana");
[Link]("Orange");
[Link]("Apple"); // Adding a duplicate element, which will not be added
// Displaying the elements in the TreeSet
[Link]("Elements in TreeSet: " + treeSet);
// Removing an element
[Link]("Banana");
[Link]("TreeSet after removing 'Banana': " + treeSet);
// Checking if an element is present
[Link]("Does TreeSet contain 'Orange'? " +
[Link]("Orange"));
}
}
Both `HashSet` and `TreeSet` are implementations of the `Set` interface and offer
different characteristics based on the underlying data structures they use.
Understanding their differences and performance considerations is crucial while
choosing the appropriate set implementation based on the specific requirements of
the program.
Jaskerat singh AJ UT 1
Jaskerat singh 14 AJ UT-1
Q6) jsp lifecycle.
Ans: A Java Server Page life cycle is defined as the process that started with its
creation which later translated to a servlet and afterward servlet lifecycle comes
into play. This is how the process goes on until its destruction.
Following steps are involved in the JSP life cycle:
1. Translation of JSP page to Servlet
2. Compilation of JSP page (Compilation of JSP into [Link])
3. Classloading ([Link] to [Link])
4. Instantiation (Object of the generated Servlet is created)
5. Initialization(jspInit() method is invoked by the container)
6. Request processing(_jspService()is invoked by the container)
7. JSP Cleanup (jspDestroy() method is invoked by the container)
We can override jspInit(), jspDestroy() but we cannot override _jspService()
method.
This is the first step of the JSP life cycle. This translation phase deals with the
Syntactic correctness of JSP. Here [Link] file is translated to [Link].
Jaskerat singh AJ UT 1
Jaskerat singh 15 AJ UT-1
[Link] of JSP page: Here the generated java servlet file ([Link]) is
compiled to a class file ([Link]).
[Link]: The classloader loads the Java class file into the memory. The
loaded Java class can then be used to serve incoming requests for the JSP page.
[Link]: Here an instance of the class is generated. The container manages
one or more instances by providing responses to requests.
[Link]: jspInit() method is called only once during the life cycle
immediately after the generation of the Servlet instance from JSP.
[Link] processing: _jspService() method is used to serve the raised requests by
JSP. It takes request and response objects as parameters. This method cannot be
overridden.
[Link] Cleanup: To remove the JSP from the container or to destroy the method for
servlets jspDestroy()method is used. This method is called once, if you need to
perform any cleanup task like closing open files or releasing database connections
jspDestroy() can be overridden.
Jaskerat singh AJ UT 1
Jaskerat singh 16 AJ UT-1
Q7) different types of scripting tags in JSP.
Ans: In JavaServer Pages (JSP), scripting tags are used to embed Java code within
an HTML page. They help in executing Java code within the JSP to dynamically
generate content. There are three main types of scripting tags in JSP:
1) Scriptlet Tag (<% ... %>):
The scriptlet tag is used to write Java code directly within a JSP file. It allows for
the execution of arbitrary Java code, which is placed between <% and %> tags.
This code is executed every time the JSP page is processed.
Example:
<%
String message = "Hello, this is a scriptlet tag!";
[Link](message);
%>
The scriptlet tag can contain any valid Java code.
Variables declared in a scriptlet have local scope within that scriptlet.
Code within scriptlet tags is executed during the JSP's service method,
which might impact the page's performance.
2)Declaration Tag (<%! ... %>):
The declaration tag is used to declare fields, methods, or other members available
across multiple methods and throughout the JSP page. Declarations are typically
used to define global variables or methods.
Example:
<%! int counter = 0; %>
<%! void incrementCounter() {counter++;} %>
Declarations are typically used for defining class-level variables and
methods.
They are declared outside the main service method and are accessible
throughout the JSP page.
They are converted into instance variables and methods by the JSP
container.
3)Expression Tag (<%= ... %>):
Jaskerat singh AJ UT 1
Jaskerat singh 17 AJ UT-1
The expression tag is used to insert the result of a single Java expression into the
output HTML. It is shorthand for printing the result of the expression using
[Link]().
Example:
<p>
The value of counter is: <%= counter %>
</p>
The expression tag is primarily used for embedding the result of a single
expression within the HTML output.
It automatically calls the [Link]() method to display the result of the
expression.
It can contain variables, method calls, and other expressions whose results
are directly inserted into the HTML output.
Jaskerat singh AJ UT 1
Jaskerat singh 18 AJ UT-1
Q8) description of directives in JSP
Ans: Directives supply directions and messages to a JSP container. The directives
provide global information about the entire page of JSP. Hence, they are an
essential part of the JSP code. These special instructions are used for translating
JSP to servlet code.
Directives supply directions and messages to a JSP container. The directives
provide global information about the entire page of JSP. Hence, they are an
essential part of the JSP code. These special instructions are used for translating
JSP to servlet code. In this chapter, you will learn about the different components
of directives in detail.
The syntax of Directives looks like:
<%@ directive attribute="" %>
There are 3 types of directives:
[Link] directive:
The page directive is used for defining attributes that can be applied to a complete
JSP page. You may place your code for Page Directives anywhere within your JSP
page. However, in general, page directives are implied at the top of your JSP page.
The basic syntax of the page directive is:
<%@ page attribute = "attribute_value" %>
The XML equivalent for the above derivation is:
<jsp:[Link] attribute = "attribute_value" />
The attributes used by the Page directives are:
buffer: Buffer attribute sets the buffer size in KB to control the JSP page's
output.
contentType: The ContentType attribute defines the document's MIME
(Multipurpose Internet Mail Extension) in the HTTP response header.
autoFlush: The autofill attribute controls the behavior of the servlet output
buffer. It monitors the buffer output and specifies whether the filled buffer
Jaskerat singh AJ UT 1
Jaskerat singh 19 AJ UT-1
output should be flushed automatically, or an exception should be raised to
indicate buffer overflow.
errorPage: Defining the "ErrorPage" attribute is the correct way to handle
JSP errors. If an exception occurs on the current page, it will be redirected to
the error page.
extends: extends attribute used for specifying a superclass that tells whether
the generated servlet must extend or not.
import: The import attribute is used to specify a list of packages or classes
used in JSP code, just as Java's import statement does in a Java code.
isErrorPage: This "isErrorPage" attribute of the Page directive is used to
specify that the current page can be displayed as an error page.
info: This "info" attribute sets the JSP page information, which is later
obtained using the getServletInfo() method of the servlet interface.
isThreadSafe: Both the servlet and JSP are multithreaded. If you want to
control JSP page behavior and define the threading model, you can use the
"isThreadSafe" attribute of the page directive.
Language: The language attribute specifies the programming language used
in the JSP page. The default value of the language attribute is "Java".
Session: In JSP, the page directive session attribute specifies whether the
current JSP page participates in the current HTTP session.
isELIgnored: This isELIgnored attribute is used to specify whether the
expression language (EL) implied by the JSP page will be ignored.
isScriptingEnabled: This "isScriptingEnabled" attribute determines if the
scripting elements are allowed for use or not.
[Link] directive:
The JSP "include directive" is used to include one file in another JSP file. This
includes HTML, JSP, text, and other files. This directive is also used to create
templates according to the developer's requirement and breaks the pages in the
header, footer, and sidebar.
To use this, Include Directive, you must write it like:
<%@ include file = "relative url" >
The XML equivalent of the above way of representation is:
<jsp:[Link] file = "relative url" />
Example:
Jaskerat singh AJ UT 1
Jaskerat singh 20 AJ UT-1
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding = "ISO-8859-1"%>
<%@ include file="directive_header_code.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1" />
<title>Include Directive Example</title>
</head>
<body>
<p>This file includes a header file named
directive_header_code.jsp</p>
</body>
</html>
In the above example of JSP code, a JSP header file is being added to the
current JSP file using "include directive".
[Link] directive:
The JSP taglib directive is implemented to define a tag library with "taglib" as its
prefix. Custom tag sections of JSP use taglib. JSP's taglibdirective is used as
standard tag libraries.
To implement taglib, you must write it like this:
<%@ taglib uri="uri" prefix="value"%>
Example:
<%@ taglib uri = "[Link] prefix = "w3tag" %>
<!DOCTYPE html>
<html>
<body>
<mytag: hi/>
</body>
</html>
Jaskerat singh AJ UT 1
Jaskerat singh 21 AJ UT-1
Q9) any 2-4 standard actions of JSP in detail.
Ans: jsp offers various standard tags to simplify web development and the
integration of Java code within HTML. Two fundamental standard tags in JSP are
the `<jsp:include>` tag and the `<jsp:useBean>` tag.
1. `<jsp:include>`:
The `<jsp:include>` tag is used to include another resource, such as another JSP
page or a servlet response, within the current JSP page during the execution phase.
This inclusion is processed on the server-side before the final output is sent to the
client.
USAGE:
<jsp:include page="[Link]" />
-DynamicContent Inclusion: This tag allows for dynamic content inclusion during
runtime, enabling modular development and reuse of common content.
- Inclusion of External Resources:It can include external resources like other JSP
pages, HTML files, servlet responses, etc.
- Passing Parameters: It can also pass parameters to the included resource.
Example with parameter passing:
```jsp
<jsp:include page="[Link]">
<jsp:param name="title" value="Welcome to my Website" />
</jsp:include>
The `[Link]` could then access the parameter using `${[Link]}`.
2. `<jsp:useBean>`
Jaskerat singh AJ UT 1
Jaskerat singh 22 AJ UT-1
The `<jsp:useBean>` tag is used to instantiate and access JavaBeans (Java classes
designed to encapsulate data and provide business logic). It is used for managing
JavaBean components within JSP pages.
Usage:
<jsp:useBean id="user" class="[Link]" scope="session" />
- Instantiating JavaBeans:It instantiates JavaBeans to be used in the JSP. The `id`
attribute assigns a name to the instantiated object, and the `class` attribute specifies
the class name.
- Scope Management: The `scope` attribute defines the scope in which the bean is
stored (e.g., `request`, `session`, `application`, etc.).
- Automatic Object Creation:If the bean does not exist, it is automatically created.
If it already exists, it retrieves the existing instance.
Example with usage:
<jsp:useBean id="user" class="[Link]" scope="session" />
<jsp:setProperty name="user" property="username" value="JohnDoe" />
<jsp:getProperty name="user" property="username" />
This example instantiates a `User` bean, sets the `username` property, and retrieves
it.
Both `<jsp:include>` and `<jsp:useBean>` tags provide essential functionalities to
facilitate modular development and the integration of Java components within JSP
pages. Understanding their use cases and proper implementation is crucial for
efficient and maintainable web application development in JSP.
Jaskerat singh AJ UT 1
Jaskerat singh 25 AJ UT-1
Q10) Explain In detail session handling using cookies and using
API.
Ans:
session handling in Java using cookies and APIs involves managing user sessions
by maintaining state information across multiple requests. This is crucial for web
applications to keep track of user data and actions during their interaction with the
application.
Cookies Overview: Cookies are small pieces of data stored in the client's
browser. They are used to store user information and settings. In Java, you
can manage session using cookies by storing a unique identifier in the user's
browser and associating it with session data on the server.
Steps for Session Handling using Cookies in Java:
Create a Session ID: When a user visits the site, a unique session ID is
generated and associated with that user's session.
Store Session Data: On the server-side, the session ID is used to store and
retrieve user-specific data associated with that session.
Set a Cookie: The generated session ID is sent to the client's browser as a
cookie.
Manage Cookie Expiry: Cookies have a lifespan. By default, they are
session cookies (expire when the browser is closed) or can be set with a
specific expiration time.
Java Cookie Handling Example:
import [Link];
import [Link];
import [Link];
// Creating a new session ID
String sessionId = "generatedSessionId"; // Normally, this is generated
dynamically
Jaskerat singh AJ UT 1
Jaskerat singh 26 AJ UT-1
// Creating a cookie
Cookie sessionCookie = new Cookie("JSESSIONID", sessionId);
[Link](3600); // Setting the cookie expiration time (in seconds)
// Adding the cookie to the response
[Link](sessionCookie);
// Retrieving session ID from request
Cookie[] cookies = [Link]();
if (cookies != null) {
for (Cookie cookie : cookies) {
if ("JSESSIONID".equals([Link]())) {
String sessionId = [Link]();
// Use sessionId to retrieve session-specific data from the server
}
}
}
Session Handling using APIs:
Java APIs for Session Management:
Java provides APIs to handle session management in web applications.
Servlets, JSP, and frameworks like Java EE offer session management
capabilities.
In Servlets, the HttpSession object is commonly used for session
management. It allows storing and retrieving session attributes.
Steps for Session Handling using APIs in Java:
Creating a Session: A session is created when a user first accesses the
application. Use [Link]() to obtain the session object.
Jaskerat singh AJ UT 1
Jaskerat singh 27 AJ UT-1
Storing and Retrieving Data: The HttpSession object is used to store and
retrieve session-specific data.
Managing Session Lifecycle: The server manages the session lifecycle,
including creation, tracking session expiration, and invalidation.
Example of Session Handling using Servlets:
import [Link];
import [Link];
// Get or create a session
HttpSession session = [Link]();
// Storing data in the session
[Link]("username", "JohnDoe");
// Retrieving data from the session
String username = (String) [Link]("username");
Jaskerat singh AJ UT 1