0% found this document useful (0 votes)
38 views59 pages

Siri

The document discusses different types of streams in Java I/O and provides examples of reading and writing to files. It also defines serialization and deserialization in Java and lists some advantages of using generics.

Uploaded by

rogergold199
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)
38 views59 pages

Siri

The document discusses different types of streams in Java I/O and provides examples of reading and writing to files. It also defines serialization and deserialization in Java and lists some advantages of using generics.

Uploaded by

rogergold199
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/ 59

Define stream

List three streams for java IO


A stream is a sequence of data. In Java, a stream is composed of bytes. It's called a stream because it is like a
stream of water that continues to flow.In Java, 3 streams are created for us automatically. All these streams
are attached with the console.
1) System.out: standard output stream

2) System.in: standard input stream

3) System.err: standard error stream

Review a java program to read/write a text file

import java.io.FileOutputStream;
public class FileOutputStreamExample {
public static void main(String args[]){
try{
FileOutputStream fout=new FileOutputStream("D:\\testout.txt");
fout.write(65);
fout.close();
System.out.println("success...");
}catch(Exception e){System.out.println(e);}
}
}

import java.io.FileInputStream;
public class DataStreamExample {
public static void main(String args[]){
try{
FileInputStream fin=new FileInputStream("D:\\testout.txt");
int i=fin.read();
System.out.print((char)i);

fin.close();
}catch(Exception e){System.out.println(e);}
}
}

Define serialization and deserialization.

Serialization in Java is a mechanism of writing the state of an object into a byte-stream. It is mainly
used in Hibernate, RMI, JPA, EJB and JMS technologies.
The reverse operation of serialization is called deserialization where byte-stream is converted into
an object. The serialization and deserialization process is platform-independent, it means you can
serialize an object on one platform and deserialize it on a different platform.

For serializing the object, we call the writeObject() method of ObjectOutputStream class, and for
dese Deserialization is the process of reconstructing the object from the serialized state. It is the
reverse operation of serializationrialization we call the readObject() method
of ObjectInputStream class.

List advantages of generics.

Type safety:

One of the most significant benefits of using generics in Java is that it enhances the type safety of your code. With
generics, you can specify the type of data that a class, method, or interface can work with. This ensures that only the
specified data types are passed to the code, preventing runtime errors and improving the reliability of your program.

Code reuse:

Generics in Java allow you to write code that is more reusable. By specifying a type parameter in a generic class, method,
or interface, you can create code that can work with multiple data types. This reduces code duplication, improves code
maintainability, and makes your code more efficient.

Compile-time checking:

Another significant advantage of using generics in Java is that it enables compile-time checking of your code. This
means that errors can be detected early in the development process, rather than at runtime. This not only improves the
reliability of your program but also saves time and effort in debugging.

Improved performance:

Generics in Java can also improve the performance of your program. By using generics, the compiler can optimize your
code, reducing the number of casts and improving the overall performance of your program.

Greater flexibility:

Generics in Java provide greater flexibility in your programming. By allowing you to specify the type of data that a
class, method, or interface can work with, generics make it possible to create highly adaptable and flexible code. This
can be especially useful when working with complex data structures or when you need to write code that can work with
multiple data types.

Distinguish between ArrayList and Vector


Difference and similarities between HashSet and TreeSet

HashSet is a generic class of the Java collection framework. It extends AbstractSet and implements the Set interface.
It creates a collection that uses a hash table for storage. The hash table stores the information by using
the hashing mechanism.

Hashing uses the informational content to determine a unique value which is known as hash code. It is used as the index
in which data is stored that is associated with the key. The transformation of the key into hash code performed
automatically. The benefit of hashing is that it allows the execution time of add, contain, remove, and size operation to
remain constant even for large sets. Its time complexity for the operation search, insert, and delete is O(1).

TreeSet is a class of Java collection framework that extends AbstractSet and implements the Set, NavigableSet, and
SortedSet interface. It creates a collection that uses a tree for storage.

TreeSet is a generic class of the Java collection framework. It implements the Set interface. It uses TreeMap internally
to store the TreeSet elements. By default, it sorts the elements in natural order (ascending order). The order of sorting
depends on the Comparator that we have parsed. If no Comparator is parsed, it sorts the elements in the natural order.

Its performance is slow in comparison to HashSet because TreeSet sorts the elements after each insertion and deletion
operation.

It uses two methods comaperTo() or compare() to compare the elements. It is to be noted that the implementation of
TreeSet is not synchronized. It means that it is not thread-safe. The implementation must be synchronized externally if
multiple threads accessing a TreeSet concurrently and a thread try to modify the TreeSet.

It does not allow to store null elements. It throws NullPointerException if we try to insert a null element. It requires
more memory than TreeSet because it also maintains the comparator to sort the elements.
Its time complexity for the operation search, insert, and delete is O(log n) which is much higher than HashSet. It uses
a self-balancing BST (Red-Black Tree) to implement the TreeSet.

Distinguish between Iterator and Enumeration.

Iterator: It is a universal iterator as we can apply it to any Collection object. By using


Iterator, we can perform both read and remove operations. It is an improved version of
Enumeration with the additional functionality of remove-ability of an element.
Iterator must be used whenever we want to enumerate elements in all Collection
framework implemented interfaces like Set, List, Queue, Deque and also in all
implemented classes of Map interface. Iterator is the only cursor available for entire
collection framework
Enumeration: Enumeration (or enum) is a user-defined data type. It is mainly used to
assign names to integral constants, the names make a program easy to read and
maintain. In Java (from 1.5), enums are represented using the enum data type. Java
enums are more powerful than C/C++ enums. In Java, we can also add variables,
methods and constructors to it. The main objective of the enum is to define our own data
types(Enumerated Data Types).
Describe the I/O classes in java

The java.io package contains nearly every class you might ever need to perform input and
output (I/O) in Java. All these streams represent an input source and an output destination.
The stream in the java.io package supports many data such as primitives, object, localized
characters, etc.

A stream can be defined as a sequence of data. There are two kinds of Streams −

• InputStream: The InputStream is used to read data from a source.


• OutputStream: The OutputStream is used for writing data to a destination.

As described earlier, a stream can be defined as a sequence of data. The InputStream is


used to read data from a source and the OutputStream is used for writing data to a
destination.

Here is a hierarchy of classes to deal with Input and Output streams.

Explain different types of JDBC drivers.

JDBC Driver is a software component that enables java application to interact with the database. There are
1. JDBC-ODBC bridge driver
2. Native-API driver (partially java driver)
3. Network Protocol driver (fully java driver)
4. Thin driver (fully java driver)

1) JDBC-ODBC bridge driver


The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC bridge drive
function calls. This is now discouraged because of thin driver.

Advantages:

o easy to use.
o can be easily connected to any database.

Disadvantages:

o Performance degraded because JDBC method call is converted into the ODBC function calls.
o The ODBC driver needs to be installed on the client machine.

2) Native-API driver

The Native API driver uses the client-side libraries of the database. The driver converts JDBC method calls
written entirely in java.
Advantage:

o performance upgraded than JDBC-ODBC bridge driver.

Disadvantage:

o The Native driver needs to be installed on the each client machine.


o The Vendor client library needs to be installed on client machine.

3) Network Protocol driver


The Network Protocol driver uses middleware (application server) that converts JDBC calls directly
or indirectly into the vendor-specific database protocol. It is fully written in java.
Advantage:

o No client side library is required because of application server that can perform many tasks
like auditing, load balancing, logging etc.

Disadvantages:

o Network support is required on client machine.


o Requires database-specific coding to be done in the middle tier.
o Maintenance of Network Protocol driver becomes costly because it requires database-specific
coding to be done in the middle tier.

4) Thin driver

The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it is kn
language.
Advantage:

o Better performance than all other drivers.


o No software is required at client side or server side.

Disadvantage:

o Drivers depend on the Database.

Demonstrate Generic method and class with example

The Java Generics programming is introduced in J2SE 5 to deal with type-safe objects. It makes the code
stable by detecting the bugs at compile time.

Before generics, we can store any type of objects in the collection, i.e., non-generic. Now generics force the
java programmer to store a specific type of objects.

Advantage of Java Generics


There are mainly 3 advantages of generics. They are as follows:

1) Type-safety: We can hold only a single type of objects in generics. It doesn?t allow to store other
objects.

2) Type casting is not required: There is no need to typecast the object.

3) Compile-Time Checking: It is checked at compile time so problem will not occur at runtime. The good
programming strategy says it is far better to handle the problem at compile time than runtime
1. import java.util.*;
2. class TestGenerics1{
3. public static void main(String args[]){
4. ArrayList<String> list=new ArrayList<String>();
5. list.add("rahul");
6. list.add("jai");
7. //list.add(32);//compile time error
8.
9. String s=list.get(1);//type casting is not required
10. System.out.println("element is: "+s);
11.
12. Iterator<String> itr=list.iterator();
13. while(itr.hasNext()){
14. System.out.println(itr.next());
15. }
16. }
17. }

Illustrate Collection and collection framework.

The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects.

Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion,
manipulation, and deletion.

Java Collection means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue,
Deque) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet).

What is Collection in Java

A Collection represents a single unit of objects, i.e., a group.

What is a framework in Java

o It provides readymade architecture.

o It represents a set of classes and interfaces.

o It is optional.

What is Collection framework

The Collection framework represents a unified architecture for storing and manipulating a group of objects. It has:

1. Interfaces and its implementations, i.e., classes

2. Algorithm
Describe about Annotations and its types with example

Java Annotation is a tag that represents the metadata i.e. attached with class, interface, methods or fields to indicate
some additional information which can be used by java compiler and JVM.

Annotations in Java are used to provide additional information, so it is an alternative option for XML and Java marker
interfaces.

First, we will learn some built-in annotations then we will move on creating and using custom annotations.

Built-In Java Annotations

There are several built-in annotations in Java. Some annotations are applied to Java code and some to other annotations.

Built-In Java Annotations used in Java code

o @Override

o @SuppressWarnings

o @Deprecated

Built-In Java Annotations used in other annotations

o @Target

o @Retention

o @Inherited

o @Documented

Understanding Built-In Annotations

Let's understand the built-in annotations first.

@Override

@Override annotation assures that the subclass method is overriding the parent class method. If it is not so, compile
time error occurs.

Sometimes, we does the silly mistake such as spelling mistakes etc. So, it is better to mark @Override annotation that
provides assurity that method is overridden.

Types of Annotation

There are three types of annotations.

1. Marker Annotation

2. Single-Value Annotation

3. Multi-Value Annotation
1) Marker Annotation
An annotation that has no method, is called marker annotation. For example:

1. @interface MyAnnotation{}

The @Override and @Deprecated are marker annotations.

2) Single-Value Annotation

An annotation that has one method, is called single-value annotation. For example:

1. @interface MyAnnotation{
2. int value();
3. }

We can provide the default value also. For example:

1. @interface MyAnnotation{
2. int value() default 0;
3. }
How to apply Single-Value Annotation

Let's see the code to apply the single value annotation.

1. @MyAnnotation(value=10)

The value can be anything.

3) Multi-Value Annotation

An annotation that has more than one method, is called Multi-Value annotation. For example:

1. @interface MyAnnotation{
2. int value1();
3. String value2();
4. String value3();
5. }
6. }

Explain about Lambda expression and its uses

Lambda expression is a new and important feature of Java which was included in Java SE 8. It provides a clear and
concise way to represent one method interface using an expression. It is very useful in collection library. It helps to
iterate, filter and extract data from collection.
The Lambda expression is used to provide the implementation of an interface which has functional interface. It saves a
lot of code. In case of lambda expression, we don't need to define the method again for providing the implementation.
Here, we just write the implementation code.

Java lambda expression is treated as a function, so compiler does not create .class file.

Functional Interface

Lambda expression provides implementation of functional interface. An interface which has only one abstract method
is called functional interface. Java provides an anotation @FunctionalInterface, which is used to declare an interface
as functional interface.

Why use Lambda Expression

1. To provide the implementation of Functional interface.

2. Less coding.

Java Lambda Expression Syntax


1. (argument-list) -> {body}

Java lambda expression is consisted of three components.

1) Argument-list: It can be empty or non-empty as well.

2) Arrow-token: It is used to link arguments-list and body of expression.

3) Body: It contains expressions and statements for lambda expression.

Define Servlet.

Servlet technology is used to create a web application (resides at server side and generates a dynamic web page).

Servlet technology is robust and scalable because of java language. Before Servlet, CGI (Common Gateway Interface)
scripting language was common as a server-side programming language. However, there were many disadvantages to
this technology. We have discussed these disadvantages below.

There are many interfaces and classes in the Servlet API such as Servlet, GenericServlet, HttpServlet, ServletRequest,
ServletResponse, etc.

What is a Servlet?

Servlet can be described in many ways, depending on the context.

o Servlet is a technology which is used to create a web application.

o Servlet is an API that provides many interfaces and classes including documentation.

o Servlet is an interface that must be implemented for creating any Servlet.

o Servlet is a class that extends the capabilities of the servers and responds to the incoming requests. It can respond
to any requests.

o Servlet is a web component that is deployed on the server to create a dynamic web page.
List the advantages of servlet

There are many advantages of Servlet over CGI. The web container creates threads for handling the
multiple requests to the Servlet. Threads have many benefits over the Processes such as they share
a common memory area, lightweight, cost of communication between the threads are low. The
advantages of Servlet are as follows:

1. Better performance: because it creates a thread for each request, not process.
2. Portability: because it uses Java language.
3. Robust: JVM manages Servlets, so we don't need to worry about the memory leak, garbage
collection, etc.
4. Secure: because it uses java language

Define session and cookies

o A session is used to temporarily store the information on the server to be used across multiple pages of
the website. It is the total time used for an activity. The user session starts when he logs-in to a particular
network application and ends when the user logs out from the application or shutdowns the system.

o When we work on an application over the internet, the webserver doesn't know the user because the HTTP
protocol does not maintain the state. The information provided by the user on one page of the application (Let's
say Home) will not be transferred to another page. To remove this limitation, sessions are used. Session gets
started whenever a visitor first enters a website.

o The user information is stored in session variables, and these variables can store any type of value or data type
of an Object.

o Session values are much secured as these are stored in binary form or encrypted form and can only be decrypted
at the server. The session values are automatically removed when the user shutdowns the system or logout from
the application. To store the values permanently, we need to store them in the database.

o Each session is unique for each user, and any number of sessions can be used in an application; there is no
limitation to it.

o The user is identified with the help of sessionID, which is a unique number saved inside the server. It is saved
as a cookie, form field, or UR

o A cookie is a small text file that is stored on the user's computer. The maximum file size of a cookie is 4KB.
It is also known as an HTTP cookie, web cookie, or internet Cookie. Whenever a user visits a website for the
first time, the site sends packets of data in the form of a cookie to the user's computer.

o The cookies help the websites to keep track of the user's browsing history or cart information when they visit
their sites.

o It stores only the "String" data type.

o The information stored within cookies is not secure because this information is stored in text -format on the
client-side, which can be read by anyone.

o We can enable or disable the cookies as per the requirement.


o The cookies generated by a user are only be shown to them, and no other user can see those cookies.

o Cookies are created and shared between the server and browser with the help of an HTTP header.

o The path where the cookies are saved is decided by the browser, as Internet explorer usually stored them
in Temporal Internet File Folder.

o When we visit YouTube channel and search for some songs, next time whenever we visit YouTube, cookies
read our browsing history and shows similar songs or last played songs.

Outline the advantages of JSP over servlet

Servlet JSP

Servlets are faster as compared to JSP, as JSP is slower than Servlets, as the first
they have a short response time. step in the JSP lifecycle is the conversion
of JSP to Java code and then the
compilation of the code.

Servlets are Java-based codes. JSP are HTML-based codes.

Servlets are harder to code, as here, the JSPs are easier to code, as here Java is
HTML codes are written in Java. coded in HTML.

In an MVC architecture, Servlets act as the In MVC architectures, the JSPs act as a
controllers. view to present the output to the users.

The service() function can be overridden The service() function cannot be


in Servlets. overridden in JSPs.

The Servlets are capable of accepting all The JSPs are confined to accept only the
types of protocol requests. HTTP requests.

Modification in Servlets is a time- Modification is easy and faster in JSPs as


consuming and challenging task, as here, we just need to refresh the pages.
one will have to reload, recompile, and
then restart the servers.

Servlets require the users to enable the JSPs provide session management by
default sessions management explicitly, as default.
Servlets do not provide default session
management.

Servlets require us to implement the JSPs give us the flexibility to separate the
business logic and presentation logic in business logic from the presentation logic
the same servlet file. using javaBeans.

Servlets can handle extensive data JSPs cannot handle data processing
processing. functions efficiently.
Servlets do not provide the facility of JSPs can provide the facility of building
writing custom tags. the JSP tags easily, which can directly call
javaBeans.

In Servlets, we do not have implicit In JSPs, we have support for implicit


objects. objects.

Servlets are hosted and executed on Web JSP is compiled in Java Servlets before
Servers. their execution. After that, it has a similar
lifecycle as Servlets.

We need to import all the packages at the In JSPs, we can import packages
top of the Servlets. anywhere in the file.

List the three types of scripting elements in JSP

The scripting elements provides the ability to insert java code inside the jsp. There are three types of
scripting elements:

o scriptlet tag
o expression tag
o declaration tag

JSP scriptlet tag

A scriptlet tag is used to execute java source code in JSP. Syntax is as follows:

1. <% java source code %>


JSP expression tag

The code placed within JSP expression tag is written to the output stream of the response. So you need not
write out.print() to write data. It is mainly used to print the values of variable or method.

Syntax of JSP expression tag

1. <%= statement %>


JSP declaration tag

2. The JSP declaration tag is used to declare fields and methods.


3. The code written inside the jsp declaration tag is placed outside the service() method of auto
generated servlet.
4. So it doesn't get memory at each request.

Syntax:<%! field or method declaration %>


List out the JSP directives

The jsp directives are messages that tells the web container how to translate a JSP page into the
corresponding servlet.

There are three types of directives:

o page directive
o include directive
o taglib directive

Syntax of JSP Directive

1. <%@ directive attribute="value" %>

JSP page directive

The page directive defines attributes that apply to an entire JSP page.

Syntax of JSP page directive

<%@ page attribute="value" %>

Attributes of JSP page directive

o import
o contentType
o extends
o info
o buffer

Jsp Include Directive


The include directive is used to include the contents of any resource it may be jsp file, html file or text file.
The include directive includes the original content of the included resource at page translation time (the jsp
page is translated only once so it will be better to include static resource).

JSP Taglib directive

The JSP taglib directive is used to define a tag library that defines many tags. We use the TLD (Tag
Library Descriptor) file to define the tags. In the custom tag section we will use this tag so it will be
better to learn it in custom tag.

Syntax JSP Taglib directive


1. <%@ taglib uri="uriofthetaglibrary" prefix="prefixoftaglibrary" %>
List out the JSP action tags

There are many JSP action tags or elements. Each JSP action tag is used to perform some specific
tasks.

The action tags are used to control the flow between pages and to use Java Bean. The Jsp action
tags are given below.

JSP Action Tags Description

jsp:forward forwards the request and response to another resource.

jsp:include includes another resource.

jsp:useBean creates or locates bean object.

jsp:setProperty sets the value of property in bean object.

jsp:getProperty prints the value of property of the bean.

jsp:plugin embeds another components such as applet.

jsp:param sets the parameter value. It is used in forward and include mostly.

jsp:fallback can be used to print the message if plugin is working. It is used in jsp:plugin.

Define java bean

JavaBean

A JavaBean is a Java class that should follow the following conventions:

o It should have a no-arg constructor.

o It should be Serializable.

o It should provide methods to set and get the values of the properties, known as getter and setter methods.

Why use JavaBean?

According to Java white paper, it is a reusable software component. A bean encapsulates many objects into one object
so that we can access this object from multiple places. Moreover, it provides easy maintenance.

A JavaBean property may be read, write, read-only, or write-only. JavaBean features are accessed through two methods
in the JavaBean's implementation class:

1. getPropertyName ()

For example, if the property name is firstName, the method name would be getFirstName() to read that property. This
method is called the accessor.

2. setPropertyName ()
For example, if the property name is firstName, the method name would be setFirstName() to write that property. This
method is called the mutator.

Advantages of JavaBean

The following are the advantages of JavaBean:/p>

o The JavaBean properties and methods can be exposed to another application.

o It provides an easiness to reuse the software components.

Name some JSTL core tags

The JSTL core tag provides variable support, URL management, flow control etc. The syntax used for including JSTL
core library in your JSP is:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

Tags Description

c:out It display the result of an expression, similar to the way <%=...%> tag work.

c:import It Retrives relative or an absolute URL and display the contents to either a String in 'var',a

c:set It sets the result of an expression under evaluation in a 'scope' variable.

c:remove It is used for removing the specified scoped variable from a particular scope.

c:catch It is used for Catches any Throwable exceptions that occurs in the body.

c:if It is conditional tag used for testing the condition and display the body content only if th

c:choose, c:when, c:otherwise It is the simple conditional tag that includes its body content if the evaluated condition is

c:forEach It is the basic iteration tag. It repeats the nested body content for fixed number of times o

c:forTokens It iterates over tokens which is separated by the supplied delimeters.

c:param It adds a parameter in a containing 'import' tag's URL.

c:redirect It redirects the browser to a new URL and supports the context-relative URLs.

c:url It creates a URL with optional query parameters.


Name some JSTL function tags

The JSTL function provides a number of standard functions, most of these functions are common
string manipulation functions. The syntax used for including JSTL function library in your JSP is:

1. <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

JSTL Functions Description

fn:contains() It is used to test if an input string containing the specified substring in a program.

fn:containsIgnoreCase() It is used to test if an input string contains the specified substring as a case insensitive

fn:endsWith() It is used to test if an input string ends with the specified suffix.

fn:escapeXml() It escapes the characters that would be interpreted as XML markup.

fn:indexOf() It returns an index within a string of first occurrence of a specified substring.

fn:trim() It removes the blank spaces from both the ends of a string.

fn:startsWith() It is used for checking whether the given string is started with a particular string value.

fn:split() It splits the string into an array of substrings.

fn:toLowerCase() It converts all the characters of a string to lower case.

fn:toUpperCase() It converts all the characters of a string to upper case.

fn:substring() It returns the subset of a string according to the given start and end position.

fn:substringAfter() It returns the subset of string after a specific substring.

fn:substringBefore() It returns the subset of string before a specific substring.

fn:length() It returns the number of characters inside a string, or the number of items in a collectio

fn:replace() It replaces all the occurrence of a string with another string sequence.
Outline the advantages of MVC

Benefits of using MVC :


• Organizes large-size web applications –
As there is segregation of the code among the three levels, it becomes extremely easy to
divide and organize web application logic into large-scale applications (which are required to
be managed by large teams of developers). The major advantage of using such code
practices is that it helps to find specific portions of code quickly and allows the addition of
new functionality with ease.

• Supports Asynchronous Method Invocation (AMI) –


Since the MVC architecture works well with JavaScript and its frameworks, it is no surprise
that it also supports the use of Asynchronous Method Invocation (AMI), allowing developers
to build faster loading web applications. It means that MVC applications can be made to
work even with PDF files, site-specific browsers, and also for desktop widgets.

• Easily Modifiable –
Using the MVC methodology allows easy modification of the entire application.
Adding/updating the new type of views is simplified in the MVC pattern (as a single section is
independent of the other sections). So, any changes in a certain section of the application will
never affect the entire architecture. This, in turn, will help to increase the flexibility and
scalability of the application.
• Easy planning and maintenance –
The MVC paradigm is helpful during the initial planning phase of the application because it gives the
developer an outline of how to arrange their ideas into actual code. It is also a great tool to help limit code
duplication, and allow easy maintenance of the application.

• Returns data without formatting –


By returning un-formatted data, the MVC framework empowers you to create your own view engine. For
example, any type of data can be formatted using HTML, but with the MVC framework, you can also
format the data using the Macromedia Flash or Dream viewer. It is helpful for the developers because the
same components can be re-used with any interface.

• Supports TTD (test-driven development) –


A major advantage of the MVC pattern is that it simplifies the testing process by a great deal. It makes it
easier to debug large-scale applications as multiple levels are structurally defined and properly written in
the application. Thus making it trouble-free to develop an application with unit tests.

• Multiple Views –
In the MVC architecture, developing different view components for your model component is easily
achievable. It empowers you to develop different view components, thus limiting code duplication as it
separates data and business logic.

Explain the Servlet Life Cyle and its architecture

The web container maintains the life cycle of a servlet instance. Let's see the life cycle of the servlet:

1. Servlet class is loaded.


2. Servlet instance is created.
3. init method is invoked.
4. service method is invoked.
5. destroy method is invoked.

As displayed in the above diagram, there are three states of a servlet: new, ready and end. The servlet is in
new state if servlet instance is created. After invoking the init() method, Servlet comes in the ready state. In
the ready state, servlet performs all the tasks. When the web container invokes the destroy() method, it
shifts to the end state.

1) Servlet class is loaded

The classloader is responsible to load the servlet class. The servlet class is loaded when the first request for the servlet
is received by the web container.

2) Servlet instance is created

The web container creates the instance of a servlet after loading the servlet class. The servlet instance is created only
once in the servlet life cycle.

3) init method is invoked

The web container calls the init method only once after creating the servlet instance. The init method is used to initia
javax.servlet.Servlet interface. Syntax of the init method is given below:

4) service method is invoked

The web container calls the service method each time when request for the servlet is received. If servlet is not initialized,
it follows the first three steps as described above then calls the service method. If servlet is initialized, it calls the service
method. Notice that servlet is initialized only once

5) destroy method is invoked

The web container calls the destroy method before removing the servlet instance from the service. It gives the servlet
an opportunity to clean up any resource for example memory, thread etc

Illustrate the Session tracking techniques.


Session simply means a particular interval of time.
Session Tracking is a way to maintain state (data) of an user. It is also known as session management in servlet.

Http protocol is a stateless so we need to maintain state using session tracking techniques. Each time user requests to
the server, server treats the request as the new request. So we need to maintain the state of an user to recognize to
particular user.

HTTP is stateless that means each request is considered as the new request. It is shown in the figure given below:

Why use Session Tracking?

To recognize the user It is used to recognize the particular user.

Session Tracking Techniques

There are four techniques used in Session tracking:

1. Cookies

2. Hidden Form Field

3. URL Rewriting

4. HttpSession

Cookies in Servlet

A cookie is a small piece of information that is persisted between the multiple client requests.

A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum
age, and a version number.

How Cookie works

By default, each request is considered as a new request. In cookies technique, we add cookie with response from the
servlet. So cookie is stored in the cache of the browser. After that if request is sent by the user, cookie is added with
request by default. Thus, we recognize the user as the old user.
2) Hidden Form Field

In case of Hidden Form Field a hidden (invisible) textfield is used for maintaining the state of an user.

In such case, we store the information in the hidden field and get it from another servlet. This approach is better if we
have to submit form in all the pages and we don't want to depend on the browser.

Let's see the code to store value in hidden field.

1. <input type="hidden" name="uname" value="Vimal Jaiswal">

Here, uname is the hidden field name and Vimal Jaiswal is the hidden field value

3)URL Rewriting
In URL rewriting, we append a token or identifier to the URL of the next Servlet or the next resource. We can send
parameter name/value pairs using the following format:

url?name1=value1&name2=value2&??

A name and a value is separated using an equal = sign, a parameter name/value pair is separated from another parameter
using the ampersand(&). When the user clicks the hyperlink, the parameter name/value pairs will be passed to the server.
From a Servlet, we can use getParameter() method to obtain a parameter value.

4) HttpSession interface
In such case, container creates a session id for each user.The container uses this id to identify the particular user.An
object of HttpSession can be used to perform two tasks:

1. bind objects

2. view and manipulate information about a session, such as the session identifier, creation time, and last accessed
time.
Explain JSP implicit objects
There are 9 jsp implicit objects. These objects are created by the web container that are available to all the jsp pages.

The available implicit objects are out, request, config, session, application etc.

Object Type

out JspWriter

request HttpServletRequest

response HttpServletResponse

config ServletConfig

application ServletContext

session HttpSession

pageContext PageContext

page Object

exception Throwable

Illustrate MVC architecture with neat diagram.


The Model-View-Controller (MVC) is a well-known design pattern in the web development field. It is way to
organize our code. It specifies that a program or application shall consist of data model, presentation
information and control information. The MVC pattern needs all these components to be separated as
different objects.

In this section, we will discuss the MVC Architecture in Java, alongwith its advantages and disadvantages and
examples to understand the implementation of MVC in Java.

What is MVC architecture in Java?


The model designs based on the MVC architecture follow MVC design pattern. The application logic is
separated from the user interface while designing the software using model designs.

The MVC pattern architecture consists of three layers:

o Model: It represents the business layer of application. It is an object to carry the data that can also
contain the logic to update controller if data is changed.

o View: It represents the presentation layer of application. It is used to visualize the data that the model
contains.

o Controller: It works on both the model and view. It is used to manage the flow of application, i.e. data
flow in the model object and to update the view whenever data is changed.

In Java Programming, the Model contains the simple Java classes, the View used to display the data and the
Controller contains the servlets. Due to this separation the user requests are processed as follows:

1. A client (browser) sends a request to the controller on the server side, for a page.

2. The controller then calls the model. It gathers the requested data.

3. Then the controller transfers the data retrieved to the view layer.

4. Now the result is sent back to the browser (client) by the view.

Outline the advantages of hibernate framework


Hibernate is a Java framework that simplifies the development of Java application to interact with
the database. It is an open source, lightweight, ORM (Object Relational Mapping) tool. Hibernate
implements the specifications of JPA (Java Persistence API) for data persistence.

Advantages of Hibernate Framework

Following are the advantages of hibernate framework:

1) Open Source and Lightweight

Hibernate framework is open source under the LGPL license and lightweight.
2) Fast Performance

The performance of hibernate framework is fast because cache is internally used in hibernate framework. There are two
types of cache in hibernate framework first level cache and second level cache. First level cache is enabled by default.

3) Database Independent Query

HQL (Hibernate Query Language) is the object-oriented version of SQL. It generates the database independent queries.
So you don't need to write database specific queries. Before Hibernate, if database is changed for the project, we need
to change the SQL query as well that leads to the maintenance problem.

4) Automatic Table Creation

Hibernate framework provides the facility to create the tables of the database automatically. So there is no need to create
tables in the database manually.

5) Simplifies Complex Join

Fetching data from multiple tables is easy in hibernate framework.

6) Provides Query Statistics and Database Status

Hibernate supports Query cache and provide statistics about query and database status.

Define ORM
ORM Tool

An ORM tool simplifies the data creation, data manipulation and data access. It is a programming technique that maps
the object to the data stored in the database.

The ORM tool internally uses the JDBC API to interact with the database.

List the supported databases and technologies for hibernate


Supported Databases

Hibernate supports almost all the major RDBMS. Following is a list of few of
the database engines supported by Hibernate −

• HSQL Database Engine


• DB2/NT
• MySQL
• PostgreSQL
• FrontBase
• Oracle
• Microsoft SQL Server Database
• Sybase SQL Server
• Informix Dynamic Server
Supported Technologies

Hibernate supports a variety of other technologies, including −

• XDoclet Spring
• J2EE
• Eclipse plug-ins
• Maven

List the properties of hibernate

Hibernate Properties

Following is the list of important properties, you will be required to configure


for a databases in a standalone situation −

Sr.No. Properties & Description

1 hibernate.dialect
This property makes Hibernate generate the appropriate SQL for the chosen database.

2 hibernate.connection.driver_class
The JDBC driver class.

3 hibernate.connection.url
The JDBC URL to the database instance.

4 hibernate.connection.username
The database username.

5 hibernate.connection.password
The database password.

6 hibernate.connection.pool_size
Limits the number of connections waiting in the Hibernate database connection pool.

7 hibernate.connection.autocommit
Allows autocommit mode to be used for the JDBC connection.

If you are using a database along with an application server and JNDI, then
you would have to configure the following properties −

Sr.No. Properties & Description


hibernate.connection.datasource
1 The JNDI name defined in the application server context, which you are using for the
application.

2 hibernate.jndi.class
The InitialContext class for JNDI.

3 hibernate.jndi.<JNDIpropertyname>
Passes any JNDI property you like to the JNDI InitialContext.

4 hibernate.jndi.url
Provides the URL for JNDI.

5 hibernate.connection.username
The database username.

hibernate.connection.password
6
The database password.

Define HQL /List out the advantages of HQL


Hibernate Query Language (HQL) is same as SQL (Structured Query Language) but it doesn't depends on the table of
the database. Instead of table name, we use class name in HQL. So it is database independent query language.

Advantage of HQL

There are many advantages of HQL. They are as follows:

o database independent

o supports polymorphic queries

o easy to learn for Java Programmer

Define hibernate caching. List its types.


Hibernate caching improves the performance of the application by pooling the object in the cache. It is useful when we
have to fetch the same data multiple times.

There are mainly two types of caching:

o First Level Cache, and

o Second Level Cache

First Level Cache

Session object holds the first level cache data. It is enabled by default. The first level cache data will not be available to
entire application. An application can use many session object.

Second Level Cache

SessionFactory object holds the second level cache data. The data stored in the second level cache will be available to
entire application. But we need to enable it explicitely.
EH (Easy Hibernate) Cache

o Swarm Cache

o OS Cache

o JBoss Cache

Interpret HCQL
The Hibernate Criteria Query Language (HCQL) is used to fetch the records based on the specific criteria. The Criteria
interface provides methods to apply criteria such as retreiving all the records of table whose salary is greater than 50000
etc.

Advantage of HCQL

The HCQL provides methods to add criteria, so it is easy for the java programmer to add criteria. The java programmer
is able to add many criteria on a query.

Example of HCQL to get all the records

1. Crietria c=session.createCriteria(Emp.class);//passing Class class argument


2. List list=c.list();

Define Batch fetching


Instead of executing a single query, we can execute a batch (group) of queries. It makes the performance fast. It is
because when one sends multiple statements of SQL at once to the database, the communication overhead is reduced
significantly, as one is not communicating with the database frequently, which in turn results to fast performance.

The java.sql.Statement and java.sql.PreparedStatement interfaces provide methods for batch processing.

Advantage of Batch Processing

Fast Performance

List out cache provider in HQL


Caching in Hibernate refers to the technique of storing frequently accessed data in memory to improve the
performance of an application that uses Hibernate as an Object -Relational Mapping (ORM) framework. Hibernate
provides two levels of caching:
1. First-Level Cache: Hibernate uses a session-level cache, also known as a first-level cache, to store the
data that is currently being used by a specific session. When an entity is loaded or updated for the first
time in a session, it is stored in the session-level cache. Any subsequent request to fetch the same entity
within the same session will be served from the cache, avoiding a database round-trip. The session-level
cache is enabled by default and cannot be disabled.
2. Second-Level Cache: Hibernate also supports a second-level cache, which is a shared cache across
multiple sessions. This cache stores data that is frequently used across different sessions, reducing the
number of database queries and improving the overall performance of the application. The second-level
cache can be configured with various caching providers, such as Ehcache, Infinispan, and Hazelcast.
3. Ehcache: Ehcache is a popular open-source caching library that provides an efficient in-memory caching
solution for Hibernate. It supports various features such as expiration policies, distributed caching, and
persistent caching.
Hibernate provides several second-level cache providers that can be used to store cached data in a shared
cache across multiple sessions. These include:
4. Infinispan: Infinispan is an open-source data grid platform that provides a distributed cache for Hibernate.
It supports various caching modes such as local, replicated, and distributed caching and provides features
such as expiration policies, transactions, and data eviction.
5. Hazelcast: Hazelcast is an open-source in-memory data grid that provides a distributed caching solution for
Hibernate. It supports various features such as distributed caching, data partitioning, data replication, and
automatic failover.
6. JBoss Cache: JBoss Cache is a popular open-source caching library that provides a scalable and distributed
caching solution for Hibernate. It supports various features such as distributed caching, data replication, and
transactional caching.
7. Caffeine: Caffeine is a high-performance in-memory caching library that provides a fast and efficient
caching solution for Hibernate. It supports various features such as expiration policies, eviction policies,
and asynchronous loading.

What is JPA?
The Java Persistence API (JPA) is a specification of Java. It is used to persist data between Java object and relational
database. JPA acts as a bridge between object-oriented domain models and relational database systems.

As JPA is just a specification, it doesn't perform any operation by itself. It requires an implementation. So, ORM tools
like Hibernate, TopLink and iBatis implements JPA specifications for data persistence .

Define JPQL/Tabulate the features of JPQL


The JPQL (Java Persistence Query Language) is an object-oriented query language which is used to perform database
operations on persistent entities. Instead of database table, JPQL uses entity object model to operate the SQL queries.
Here, the role of JPA is to transform JPQL into SQL. Thus, it provides an easy platform for developers to handle SQL
tasks.

JPQL is an extension of Entity JavaBeans Query Language (EJBQL), adding the following important features to it: -

o It can perform join operations.

o It can update and delete data in a bulk.

o It can perform aggregate function with sorting and grouping clauses.

o Single and multiple value result types.

JPQL Features
o It is a platform-independent query language.

o It is simple and robust.

o It can be used with any type of database such as MySQL, Oracle.

o JPQL queries can be declared statically into metadata or can also be dynamically built in code

Illustrate Hibernate architecture with diagram.


The Hibernate architecture includes many objects such as persistent object, session factory, transaction
factory, connection factory, session, transaction etc.
The Hibernate architecture is categorized in four layers.

o Java application layer


o Hibernate framework layer
o Backhand api layer
o Database layer

Let's see the diagram of hibernate architecture:

This is the high level architecture of Hibernate with mapping file and configuration file.

Elements of Hibernate Architecture


For creating the first hibernate application, we must know the elements of Hibernate architecture. They are as follows:
SessionFactory

The SessionFactory is a factory of session and client of ConnectionProvider. It holds second level cache (optional) of
data. The org.hibernate.SessionFactory interface provides factory method to get the object of Session.

Session

The session object provides an interface between the application and data stored in the database. It is a short -lived
object and wraps the JDBC connection. It is factory of Transaction, Query and Criteria. It holds a first -level cache
(mandatory) of data. The org.hibernate.Session interface provides methods to insert, update and delete the object. It
also provides factory methods for Transaction, Query and Criteria.

Transaction

The transaction object specifies the atomic unit of work. It is optional. The org.hibernate.Transaction interface
provides methods for transaction management.

ConnectionProvider

It is a factory of JDBC connections. It abstracts the application from DriverManager or DataSource. It is optional.

TransactionFactory

It is a factory of Transaction. It is optional.

Demonstrate Multi level cache scheme in hibernate


Caching is a mechanism to enhance the performance of a system. It is a buffer memorythat lies between the
application and the database. Cache memory stores recently used data items in order to reduce the number of database
hits as much as possible.

Caching is important to Hibernate as well. It utilizes a multilevel caching scheme as explained below −
First-level Cache

The first-level cache is the Session cache and is a mandatory cache through which all requests must pass. The Session
object keeps an object under its own power before committing it to the database.

If you issue multiple updates to an object, Hibernate tries to delay doing the update as long as possible to reduce the
number of update SQL statements issued. If you close the session, all the objects being cached are lost and either
persisted or updated in the database.

Second-level Cache

Second level cache is an optional cache and first-level cache will always be consulted before any attempt is made to
locate an object in the second-level cache. The second level cache can be configured on a per-class and per-collection
basis and mainly responsible for caching objects across sessions.

Any third-party cache can be used with Hibernate. An org.hibernate.cache.CacheProvider interface is provided, which
must be implemented to provide Hibernate with a handle to the cache implementation.

Query-level Cache

Hibernate also implements a cache for query resultsets that integrates closely with the second-level cache.

This is an optional feature and requires two additional physical cache regions that hold the cached query results and
the timestamps when a table was last updated. This is only useful for queries that are run frequently with the same
parameters.

Explain JPA ORM and its framework, mapping types

Object Relational Mapping (ORM) is a functionality which is used to develop and maintain a relationship between an
object and relational database by mapping an object state to database column. It is capable to handle various database
operations easily such as inserting, updating, deleting etc.

ORM Frameworks

Following are the various frameworks that function on ORM mechanism: -

o Hibernate

o TopLink

o ORMLite

o iBATIS

o JPOX
Mapping Directions

Mapping Directions are divided into two parts: -

o Unidirectional relationship - In this relationship, only one entity can refer the properties to another. It contains
only one owing side that specifies how an update can be made in the database.

o Bidirectional relationship - This relationship contains an owning side as well as an inverse side. So here every
entity has a relationship field or refer the property to other entity.

Types of Mapping

Following are the various ORM mappings: -

One-to-one - This association is represented by @OneToOne annotation. Here, instance of each entity is related
to a single instance of another entity.

o One-to-many - This association is represented by @OneToMany annotation. In this relationship, an instance


of one entity can be related to more than one instance of another entity.

o Many-to-one - This mapping is defined by @ManyToOne annotation. In this relationship, multiple instances
of an entity can be related to single instance of another entity.

o Many-to-many - This association is represented by @ManyToMany annotation. Here, multiple instances of an


entity can be related to multiple instances of another entity. In this mapping, any side can be the owing side.

Tabulate Basic JPQL operations and advanced operations.

JPQL allows us to create both static as well as dynamic queries. Now, we will perform some basic JPQL
operations using both type of queries on the below table.

Basic JPQL Operations:

Operation Description Example


Retrieve data from one or more
SELECT Clause entities. SELECT e FROM Employee e

Specifies the entity or entities from


FROM Clause which to retrieve data. FROM Employee

Filters the results based on specified


WHERE Clause conditions. FROM Employee e WHERE e.salary > 50000

Sorts the result set based on


ORDER BY Clause specified criteria. FROM Employee e ORDER BY e.salary DESC

Used for grouping results based on SELECT e.department, AVG(e.salary) FROM


GROUP BY and certain criteria and filtering grouped Employee e GROUP BY e.department HAVING
AVG(e.salary) > 50000
HAVING Clauses results.
Advanced JPQL Operations:

Operation Description Example


Perform inner and outer SELECT e FROM Employee e JOIN e.department d WHERE
Joins joins between entities. d.name = 'IT'

Use queries within queries FROM Employee e WHERE e.salary > (SELECT AVG(salary) FROM
Subqueries to retrieve data. Employee)

Predefine queries with a


Named name in entity classes for @NamedQuery(name="highSalaryEmployees", query="SELECT
Queries reuse. e FROM Employee e WHERE e.salary > 80000")

Use aggregate functions


Aggregate like COUNT, SUM, AVG,
Functions MAX, MIN. SELECT COUNT(e) FROM Employee e

Polymorphic Retrieve objects of a FROM Payment p WHERE TYPE(p) IN (ChequePayment,


Queries superclass or subclass. CreditCardPayment)

Dynamic Construct queries Using Criteria API or building JPQL strings based on
Queries dynamically at runtime. user inputs.
Use named parameters in
Named queries for better
Parameters readability and reusability. FROM Employee e WHERE e.name = :employeeName

Control database
concurrency by applying
Locking locks to entities. FROM Employee e WHERE e.id = :empId FOR UPDATE

Define IOC
The IoC container is responsible to instantiate, configure and assemble the objects. The IoC container gets
informations from the XML file and works accordingly. The main tasks performed by IoC container are:

o to instantiate the application class

o to configure the object

o to assemble the dependencies between the objects

There are two types of IoC containers. They are:

1. BeanFactory

2. ApplicationContext

List the applications of spring framework


The Spring Framework is a comprehensive framework for enterprise Java development, and it is widely used for
building a variety of applications across different domains. Here are some of the key applications of the Spring
Framework:

1. Web Applications:
• Spring MVC provides a robust and flexible framework for building web applications. It follows the
Model-View-Controller (MVC) design pattern and integrates seamlessly with other Spring features.
2. Enterprise Applications:
• Spring facilitates the development of enterprise-level applications by providing support for various
enterprise features, such as dependency injection, transaction management, and declarative services.
3. Microservices:
• Spring Boot, an extension of the Spring Framework, simplifies the development of microservices. It
provides an opinionated approach to microservices architecture, making it easier to build, deploy, and
scale microservices.
4. RESTful Web Services:
• Spring MVC and Spring Boot support the development of RESTful web services. Spring's integration
with Jackson for JSON processing and support for RESTful principles make it a popular choice for
building scalable and maintainable REST APIs.
5. Data Access:
• Spring provides a comprehensive data access framework that simplifies database access. It supports
JDBC, ORM frameworks like Hibernate, JPA (Java Persistence API), and provides declarative
transaction management.
6. Batch Processing:
• Spring Batch is a module within the Spring Framework that facilitates the development of batch
processing applications. It provides features for reading, processing, and writing large volumes of
data.
7. Messaging Applications:
• Spring Integration is a part of the Spring portfolio that facilitates the integration of enterprise systems
through messaging. It supports messaging patterns and provides adapters for various messaging
systems.
8. Caching:
• Spring's caching abstraction simplifies the integration of caching mechanisms into applications. It
supports different caching providers and helps improve performance by caching frequently used data.
9. Security:
• Spring Security is a powerful and customizable authentication and access control framework. It is
widely used to secure Java applications, including web applications and RESTful services.
10. Dependency Injection and IoC:
• The core concept of Spring is Inversion of Control (IoC) and Dependency Injection (DI). This makes
the code more modular, testable, and maintainable by reducing dependencies and promoting loose
coupling.
11. Testing:
• The Spring Framework supports testing through the use of the Spring TestContext Framework. It
allows for the integration of unit tests, integration tests, and end-to-end tests in a Spring environment.

Illustrate the advantages of Spring framework


There are many advantages of Spring Framework. They are as follows:

1) Predefined Templates

Spring framework provides templates for JDBC, Hibernate, JPA etc. technologies. So there is no need to write too much
code. It hides the basic steps of these technologies.

Let's take the example of JdbcTemplate, you don't need to write the code for exception handling, creating connection,
creating statement, committing transaction, closing connection etc. You need to write the code of executing query only.
Thus, it save a lot of JDBC code.

2) Loose Coupling

The Spring applications are loosely coupled because of dependency injection.

3) Easy to test

The Dependency Injection makes easier to test the application. The EJB or Struts application require server to run the
application but Spring framework doesn't require server.
4) Lightweight

Spring framework is lightweight because of its POJO implementation. The Spring Framework doesn't force the
programmer to inherit any class or implement any interface. That is why it is said non -invasive.

5) Fast Development

The Dependency Injection feature of Spring Framework and it support to various frameworks makes the easy
development of JavaEE application.

6) Powerful abstraction

It provides powerful abstraction to JavaEE specifications such as JMS, JDBC, JPA and JTA.

7) Declarative support

It provides declarative support for caching, validation, transactions and formatting .

Define Dependency lookup and its problem.


The Dependency Lookup is an approach where we get the resource after demand.

There are mainly two problems of dependency lookup.

o tight coupling The dependency lookup approach makes the code tightly coupled. If resource is changed, we
need to perform a lot of modification in the code.
o Not easy for testing This approach creates a lot of problems while testing the application especially in black
box testing.

Define Dependency Injection.


Dependency Injection (DI) is a design pattern that removes the dependency from the programming code so
that it can be easy to manage and test the application. Dependency Injection makes our programming code
loosely coupled.

Define Spring Boot


Spring Boot is a project that is built on the top of the Spring Framework. It provides an easier and faster way to set up,
configure, and run both simple and web-based applications.It is a Spring module that provides the RAD (Rapid
Application Development) feature to the Spring Framework. It is used to create a stand-alone Spring-based application
that you can just run because it needs minimal Spring configuration.

In short, Spring Boot is the combination of Spring Framework and Embedded Servers.
In Spring Boot, there is no requirement for XML configuration (deployment descriptor). It uses convention over
configuration software design paradigm that means it decreases the effort of the developer.

What is Autowiring? What are the features in it?


Autowiring feature of spring framework enables you to inject the object dependency implicitly. It
internally uses setter or constructor injection.Autowiring can't be used to inject primitive and string
values. It works with reference only.

Autowiring Modes
There are many autowiring modes:

No. Mode Description

1) no It is the default autowiring mode. It means no autowiring bydefault.

2) byName The byName mode injects the object dependency according to name of the bean. In such

case, property name and bean name must be same. It internally calls setter method.

3) byType The byType mode injects the object dependency according to type. So property name

and bean name can be different. It internally calls setter method.

4) constructor The constructor mode injects the dependency by calling the constructor of the class. It calls

the constructor having large number of parameters.

5) autodetect It is deprecated since Spring 3.

Define AOP. Why use AOP?


Aspect Oriented Programming (AOP) compliments OOPs in the sense that it also provides modularity. But the key
unit of modularity is aspect than class.

AOP breaks the program logic into distinct parts (called concerns). It is used to increase modularity by cross-cutting
concerns.

A cross-cutting concern is a concern that can affect the whole application and should be centralized in one location in
code as possible, such as transaction management, authentication, logging, security etc.

Why use AOP?

It provides the pluggable way to dynamically add the additional concern before, after or around the actual logic.

1. class A{
2. public void m1(){...}
3. public void m2(){...}
4. public void m3(){...}
5. public void m4(){...}
6. public void m5(){...}
7. public void n1(){...}
8. public void n2(){...}
9. public void p1(){...}
10. public void p2(){...}
11. public void p3(){...}
12. }

There are 5 methods that starts from m, 2 methods that starts from n and 3 methods that starts from p.

Understanding Scenario I have to maintain log and send notification after calling methods that starts from m.

Problem without AOP We can call methods (that maintains log and sends notification) from the methods starting with
m. In such scenario, we need to write the code in all the 5 methods.

But, if client says in future, I don't have to send notification, you need to change all the methods. It leads to the
maintenance problem.

Solution with AOP We don't have to call methods from the method. Now we can define the additional concern like
maintaining log, sending notification etc. in the method of a class. Its entry is given in the xml file.

In future, if client says to remove the notifier functionality, we need to change only in the xml file. So, maintenance is
easy in AOP.

Outline the advantages of Spring MVC framework .

Spring MVC architecture


A Spring MVC is a Java framework which is used to build web applications. It follows the Model-View-Controller
design pattern. It implements all the basic features of a core spring framework like Inversion of Control, Dependency
Injection.

A Spring MVC provides an elegant solution to use MVC in spring framework by the help of DispatcherServlet.
Here, DispatcherServlet is a class that receives the incoming request and maps it to the right resource such as
controllers, models, and views.
Spring Web Model-View-Controller

o Model - A model contains the data of the application. A data can be a single object or a collection of objects.

o Controller - A controller contains the business logic of an application. Here, the @Controller annotation is used
to mark the class as the controller.

o View - A view represents the provided information in a particular format. Generally, JSP+JSTL is used to create
a view page. Although spring also supports other view technologies such as Apache Velocity, Thymeleaf and
FreeMarker.

o Front Controller - In Spring Web MVC, the DispatcherServlet class works as the front controller. It is
responsible to manage the flow of the Spring MVC application.

Understanding the flow of Spring Web MVC

o As displayed in the figure, all the incoming request is intercepted by the DispatcherServlet that works as the
front controller.

o The DispatcherServlet gets an entry of handler mapping from the XML file and forwards the request to the
controller.

o The controller returns an object of ModelAndView.

o The DispatcherServlet checks the entry of view resolver in the XML file and invokes the specified view
component.
Advantages of Spring MVC Framework

Let's see some of the advantages of Spring MVC Framework:-

o Separate roles - The Spring MVC separates each role, where the model object, controller, command object,
view resolver, DispatcherServlet, validator, etc. can be fulfilled by a specialized object.

o Light-weight - It uses light-weight servlet container to develop and deploy your application.

o Powerful Configuration - It provides a robust configuration for both framework and application classes that
includes easy referencing across contexts, such as from web controllers to business objects and validators.

o Rapid development - The Spring MVC facilitates fast and parallel development.

o Reusable business code - Instead of creating new objects, it allows us to use the existing business objects.

o Easy to test - In Spring, generally we create JavaBeans classes that enable you to inject test data using the setter
methods.

o Flexible Mapping - It provides the specific annotations that easily redirect the page.

Define REST
REpresentational State Transfer (REST) is a software architectural style that defines the constraints to create web
services. The web services that follows the REST architectural style is called RESTful Web Services. It differentiates
between the computer system and web services. The REST architectural style describes the six barriers.

List the advantages of RESTful webservice .

1. Supports all types of data formats

In other types of APIs, you are limited in your choice of data formats. However, RESTful APIs support all data

formats.

2. Works wonders with web browsers

In RESTful APIs, you can send an HTTP request, get JavaScript Object Notation (JSON) data in response, and parse

that data to use it on the client applications. This makes it the best choice for web browsers. Furthermore, you can

easily integrate these APIs with your existing website.


3. Uses less bandwidth

Thanks to JSON, RESTful APIs use less bandwidth as compared to other types of APIs. However, this stands true for

JSON-based web APIs only. An XML-based web API will have a similar payload to its non-RESTful counterpart

whether it adheres to the REST architectural constraints or not.

4. Does not need to be designed from scratch

In most cases, you can get models that you can modify and use. For example, NetApp and Mailgun provide a

complete tutorial and source code for building a private API. In some cases, maybe when developing a private API,

you will need to design the API from scratch, and for that, you can get a lot of support from Stack Overflow.

5. Easy for most developers

RESTful APIs use HTTP methods for communication. You can use Python, JavaScript (Node.js), Ruby, C#, and a

number of other languages to develop these APIs, making them easier to work with for most developers.

Illustrate Spring framework architecture


Spring could potentially be a one-stop shop for all your enterprise applications. However, Spring is modular, allowing
you to pick and choose which modules are applicable to you, without having to bring in the rest. The following section
provides details about all the modules available in Spring Framework.

The Spring Framework provides about 20 modules which can be used based on an application requirement.

Core Container

The Core Container consists of the Core, Beans, Context, and Expression Language modules the details of which are
as follows −

• The Core module provides the fundamental parts of the framework, including the IoC and Dependency
Injection features.
• The Bean module provides BeanFactory, which is a sophisticated implementation of the factory pattern.
• The Context module builds on the solid base provided by the Core and Beans modules and it is a medium to
access any objects defined and configured. The ApplicationContext interface is the focal point of the Context
module.
• The SpEL module provides a powerful expression language for querying and manipulating an object graph at
runtime.
Data Access/Integration

The Data Access/Integration layer consists of the JDBC, ORM, OXM, JMS and Transaction modules whose detail is
as follows −

• The JDBC module provides a JDBC-abstraction layer that removes the need for tedious JDBC related coding.
• The ORM module provides integration layers for popular object-relational mapping APIs, including JPA,
JDO, Hibernate, and iBatis.
• The OXM module provides an abstraction layer that supports Object/XML mapping implementations for
JAXB, Castor, XMLBeans, JiBX and XStream.
• The Java Messaging Service JMS module contains features for producing and consuming messages.
• The Transaction module supports programmatic and declarative transaction management for classes that
implement special interfaces and for all your POJOs.
Web

The Web layer consists of the Web, Web-MVC, Web-Socket, and Web-Portlet modules the details of which are as
follows −

• The Web module provides basic web-oriented integration features such as multipart file-upload functionality
and the initialization of the IoC container using servlet listeners and a web-oriented application context.
• The Web-MVC module contains Spring's Model-View-Controller (MVC) implementation for web
applications.
• The Web-Socket module provides support for WebSocket-based, two-way communication between the client
and the server in web applications.
• The Web-Portlet module provides the MVC implementation to be used in a portlet environment and mirrors
the functionality of Web-Servlet module.
Miscellaneous

There are few other important modules like AOP, Aspects, Instrumentation, Web and Test modules the details of
which are as follows −

• The AOP module provides an aspect-oriented programming implementation allowing you to define method-
interceptors and pointcuts to cleanly decouple code that implements functionality that should be separated.
• The Aspects module provides integration with AspectJ, which is again a powerful and mature AOP
framework.
• The Instrumentation module provides class instrumentation support and class loader implementations to be
used in certain application servers.
• The Messaging module provides support for STOMP as the WebSocket sub-protocol to use in applications. It
also supports an annotation programming model for routing and processing STOMP messages from
WebSocket clients.
• The Test module supports the testing of Spring components with JUnit or TestNG frameworks.

Explain about AOP and its uses.


Aspect-Oriented Programming (AOP) is a programming paradigm that focuses on modularizing cross-cutting
concerns in software development. Cross-cutting concerns are aspects of a program that affect multiple modules and are
often scattered throughout the codebase. Examples of cross-cutting concerns include logging, security, transaction
management, and error handling. AOP provides a way to separate these concerns from the main business logic,
promoting better code organization and maintainability.

Uses and Benefits of AOP:

1. Separation of Concerns:
• AOP promotes the separation of cross-cutting concerns from the main business logic, leading to
cleaner and more modular code.
2. Code Reusability:
• Aspects can be reused across different modules or projects, reducing code duplication and promoting
a DRY (Don't Repeat Yourself) approach.
3. Improved Maintainability:
• AOP makes it easier to maintain and modify code by isolating cross-cutting concerns. Changes to a
concern can be made in one place, affecting all modules where the aspect is applied.
4. Enhanced Readability:
• AOP improves code readability by removing clutter related to cross-cutting concerns from the main
business logic. This makes it easier to understand and maintain the core functionality of the
application.
5. Dynamic Cross-Cutting:
• AOP allows for dynamic application of aspects at runtime. This flexibility is useful for scenarios
where you want to enable or disable certain behaviors based on configuration or runtime conditions.
6. Aspect Interoperability:
• Aspects can be developed independently and combined to achieve the desired functionality. This
promotes a modular and reusable approach to handling cross-cutting concerns.
7. Consistent Application of Policies:
• AOP enables the consistent application of policies or rules across an application. For example,
security policies, logging policies, and transaction management rules can be applied uniformly.
8. Simplified Error Handling:
• AOP can simplify error handling by separating error-handling code from the main business logic. This
leads to more focused error-handling modules that can be reused across the application.
9. Testing and Debugging:
• AOP can facilitate testing and debugging by allowing developers to focus on the core functionality
during testing, without the distraction of cross-cutting concerns.
10. Flexibility in Design:
• AOP provides flexibility in the design of applications, allowing developers to address non -functional
requirements separately from the functional requirements.

Difference between Spring framework and Spring Boot

Spring Spring Boot

Spring Framework is a widely used Java EE Spring Boot Framework is widely used to develop
framework for building applications. REST APIs.

It aims to simplify Java EE development that makes It aims to shorten the code length and provide the
developers more productive. easiest way to develop Web Applications.

The primary feature of the Spring Framework The primary feature of Spring Boot is Autoconfiguration
is dependency injection. . It automatically configures the classes based on the
requirement.

It helps to make things simpler by allowing us to It helps to create a stand-alone application with less
develop loosely coupled applications. configuration.

The developer writes a lot of code (boilerplate It reduces boilerplate code.


code) to do the minimal task.
To test the Spring project, we need to set up the Spring Boot offers embedded server such as Jetty and
sever explicitly. Tomcat, etc.

It does not provide support for an in-memory It offers several plugins for working with an embedded
database. and in-memory database such as H2.

Developers manually define dependencies for the Spring Boot comes with the concept of starter in pom.xml
Spring project in pom.xml. file that internally takes care of downloading the
dependencies JARs based on Spring Boot Requirement.

What are all the tasks of Maven.


Maven is a powerful project management tool that is based on POM (project object model). It is used for projects build,
dependency and documentation.

1. It makes a project easy to build

2. It provides uniform build process (maven project can be shared by all the maven projects)

3. It provides project information (log document, cross referenced sources, mailing list, dependency list, unit test
reports etc.)

4. It is easy to migrate for new features of Maven

Maven Build Lifecycle

The Maven build follows a specific lifecycle to deploy and distribute the target project.
There are three built-in lifecycles:

• default: the main lifecycle, as it’s responsible for project deployment


• clean: to clean the project and remove all files generated by the previous build
• site: to create the project’s site documentation

A Maven phase represents a stage in the Maven build lifecycle. Each phase is responsible for a specific task.
Here are some of the most important phases in the default build lifecycle:

• validate: check if all information necessary for the build is available


• compile: compile the source code
• test-compile: compile the test source code
• test: run unit tests
• package: package compiled source code into the distributable format (jar, war, …)
• integration-test: process and deploy the package if needed to run integration tests
• install: install the package to a local repository
• deploy: copy the package to the remote repository

Maven Goal

Each phase is a sequence of goals, and each goal is responsible for a specific task.
When we run a phase, all goals bound to this phase are executed in order.
Here are some of the phases and default goals bound to them:
• compiler:compile – the compile goal from the compiler plugin is bound to the compile phase
• compiler:testCompile is bound to the test-compile phase
• surefire:test is bound to the test phase
• install:install is bound to the install phase
• jar:jar and war:war is bound to the package phase

Distinguish between ANT and Maven


Ant and Maven both are build tools provided by Apache. The main purpose of these technologies
is to ease the build process of a project.

There are many differences between ant and maven that are given below:

Ant Maven

Ant doesn't has formal conventions, so we need to Maven has a convention to place source code,
provide information of the project structure in compiled code etc. So we don't need to provide
build.xml file. information about the project structure in pom.xml file.

Ant is procedural, you need to provide information Maven is declarative, everything you define in the
about what to do and when to do through code. You pom.xml file.
need to provide order.

There is no life cycle in Ant. There is life cycle in Maven.

It is a tool box. It is a framework.

It is mainly a build tool. It is mainly a project management tool.

The ant scripts are not reusable. The maven plugins are reusable.

It is less preferred than Maven. It is more preferred than Ant.

Illustrate briefly about Maven elements and its sub elements

Element Description

project It is the root element of pom.xml file.

modelVersion It is the sub element of project. It specifies the modelVersion. It should be set to 4.0.0.

groupId It is the sub element of project. It specifies the id for the project group.

artifactId It is the sub element of project. It specifies the id for the artifact (project). An artifact is
something that is either produced or used by a project. Examples of artifacts produced
by Maven for a project include: JARs, source and binary distributions, and WARs.

version It is the sub element of project. It specifies the version of the artifact under given group.
Element Description

packaging defines packaging type such as jar, war etc.

name defines name of the maven project.

url defines url of the project.

dependencies defines dependencies for this project.

dependency defines a dependency. It is used inside dependencies.

scope defines scope for this maven project. It can be compile, provided, runtime, test and system.

Define POM
POM is an acronym for Project Object Model. The pom.xml file contains information of project and configuration
information for the maven to build the project such as dependencies, build directory, source directory, test source
directory, plugin, goals etc.

Maven reads the pom.xml file, then executes the goal .

What is is the use of Junit functional testing?


It is an open-source testing framework for java programmers. The java programmer can create test
cases and test his/her own code.It is one of the unit testing framework.

JUnit is a Java testing framework that makes writing reliable and efficient tests easy. It can be used for applications
made in most languages but is particularly suited for testing Java applications. JUnit can also be used to
create automated tests.

JUnit framework is one of the most popular Java testing frameworks. It offers several features that make writing tests
easy, including support for multiple test cases, assertions, and reporting. JUnit is also versatile, allowing tests to be
written in various languages.

Outline the automation testing tools for functional automation


The automation testing is used to change the manual test cases into a test script with the help of some automation tools.

We have various types of automation testing tools available in the market. Some of the most commonly used automation
testing tools are as follows:

o Selenium

o Watir

o QTP

o Telerik Studio

o Testim
o Applitools

Selenium

It is an open-source and most commonly used tool in automation testing. This tool is used to test web-based applications
with the help of test scripts, and these scripts can be written in any programming language such as java, python, C#, Php,
and so on

Features of Selenium

This tool is most popular because of its various features. Following are standard features of Selenium:

o Selenium supports only web-based application, which means that the application can be opened by the browser
or the URL like Gmail, Amazon, etc.

o Selenium does not support a stand-alone application, which means that the application is not opened in the
browser or URL like Notepad, MS-Word, Calculator, etc.

o Selenium web driver is the latest tool in the selenium community that removes all the drawbacks of the previous
tool (selenium-IDE).

o Selenium web-driver is powerful because it supports multiple programming languages, various browsers, and
different operating systems and also supports mobile applications like iPhone, Android.

Watir

Watir stands for web application testing in ruby which is written in the Ruby programming language. testing in ruby.
It is a web application testing tool, which is open-source and supports cross-browser testing tool and interacts with a
platform like a human that can validate the text, click on the links and fill out the forms.

Features of Watir

Following are the characteristics of Watir testing tools:

o It supports various browsers on different platforms like Google Chrome, Opera, Firefox, Internet Explorer, and
Safari.

o Watir is a lightweight and powerful tool.

o We can easily download the test file for the UI.

o We can take the screenshots once we are done with the testing, which helps us to keep track of the intermediate
testing.

o This tool has some inbuilt libraries, which helps to check the alerts, browser windows, page-performance, etc.

QTP

QTP tool is used to test functional regression test cases of the web-based application. QTP stands for Quick Test
Professional, and now it is known as Micro Focus UFT [Unified Functional Testing]. This is very helpful for the
new test engineer because they can understand this tool in a few minutes. QTP is designed on the scripting language
like VB script to automate the application.

Features of QTP
Following are the most common features of QTP:

o This tool support record and playback feature.

o QTP uses the scripting language to deploy the objects, and for analysis purposes, it provides test reporting.

o Both technical and non-technical tester can use QTP.


o QTP supports multiple software development environments like Oracle, SAP, JAVA, etc.

o With the help of QTP, we can test both desktop and web-based applications.

o In this tool, we can perform BPT (Business process testing).

Telerik Studio

It is modern web application which support functional test automation. With the help of this tool, we can test the load,
performance, and functionality of the web and mobile applications and also identify the cross-browser issues.

Features of Telerik test studio

Below are some essential features of Telerik test studio:

o Telerik test studio allows us to deliver quality products on time.


o This tool supports all types of applications, such as desktop, web, and mobile.

o This tool supports Asp.Net, AJAX, HTML, JavaScript, WPF, and Silverlight application testing.

o It supports multiple browsers like Firefox, Safari, Google Chrome, and Internet Explorer for the test execution
process.

o With the help of this tool, we can do the sentence based UI validation.

o Testim

It is another automation testing tool, which can execute the test case in very little time and run them in various web and
mobile applications. This tool will help us to enhance the extensibility and stability of our test suites. It provides the
flexibility to cover the functionalities of the platform with the help of JavaScript and HTML.

Features of Testim

o The Test stability is very high in testim tool.

o This tool will support parallel execution.

o In this tool, we can capture the screenshots.

o This tool will automatically create the tests.

o With the help of this tool, we can perform requirements-based and parameterized testing.

Applitools

This tool is used to check the look and feel and user's feedback on the application. It can easily incorporate with the
presented test instead of creating a new analysis. Applitools is a monitoring software, which provides visual application
management and AI-powered visual UI testing. It is an open-source tool that helps us to deliver a quality product.
Features of Applitools

Below are the characteristics of Applitools:

o This tool has active user access management.

o For various devices, it allows cross-browser testing.


o It will deliver the visual test reports to the users.

o It is available on the public and dedicated cloud.

Outline the automation testing tools for non-functional automation

Non-functional testing is a type of software testing to test non-functional parameters such as


reliability, load test, performance and accountability of the software. The primary purpose of non-
functional testing is to test the reading speed of the software system as per non-functional
parameters. The parameters of non-functional testing are never tested before the functional
testing.

JMeter
JMeter is one of the widely used tools in the market to perform reliability testing and automation testing. The tool is
available for free of cost and is generally used in web and FTP ApplicationsJMeter is an Apache product, which has a
good reputation for compatibility testing. The tool is highly used for measuring and analysing the performance of
programs.

Pros of Jmeter

• User-friendly
• Used for FTP Applications
• Quality Compatibility testing

Cons of Jmeter

• Consumes a lot of time

Forecast
Forecast is one of the most popular applications, which offers a wide range of options. Therefore, it is important for
users to consider having input data in detail.A detailed set of data related to scalability testing and recovery testing
play a major role for results. Hence, Forecast provides an easy to use interface to enjoy maximum mileage.

Pros of Forecast

• Easy to use interface


• Cost friendly
• Quick results
Cons of Forecast

• Limited options

Loadrunner
The reputation of the testing tool is one of the supreme factors because it defines quality. LoadRunner is a fabulous
tool because it offers accurate results in performance testing. The tool has gained a lot of reputation in offering stress
test results with quality.LoadRunner is a Micro Focus product, which has the capacity to simulate a lot of users at the
same time. The special analyzing strategy in the tool provides a wide room to enjoy the performance.

Pros of LoadRunner

• Accurate results in performance testing


• Stress results in information
• Multiple users

Cons of LoadRunner

• No User-friendly interface

Loadster
The modern-day tools and applications are coming with extra features to attract. Loadster is a new tool, which comes
with cloud hybrid load testing technique. The technique allows users to test large scale applications and high-
performance websites.The tool offers quality results in volume testing parameters of the software system. Loadster
allows users to improve the technique because it helps in improving stability.

Pros of Loadster

• Extra features
• New and modern set of options
• Hybrid load testing techniques

Cons of Loadster

• Not suitable for small scale applications

Loadstorm
There are huge benefits of non-functional testing tools. it is vital for testers to know the actual objective of the testing
process before starting. A strong set of functional requirements enable the tool to complete the process with productive
results.Loadstorm is a powerful tool, which is available to test various program components. So, the hybrid set of
features enables testers to save time without affecting the performance.

Pros of Loadstorm

• Quality functional requirements


• Powerful Tool
• Tests various program components
Cons of Loadstorm

• Not available for free

Load Complete
It is a known fact that testers prefer using a simple and efficient tool to reduce manual effort. The tools enable the user
to execute performance testing and Localization Testing.It is evident that every product requires a set of different
testing parameters. So, it is important to check for a tool, which provides an expert report after the process.

Pros of Load Complete

• Simple tool
• Efficiency
• Localization testing features

Cons of Load Complete

• Large process cycle

Loadtracer
Loadtracer is one of the most effective tools, which is generally used to test program performance. The fully
developed tool has a unique set of functionalities. The functionalities are available for testers to enhance the
performance of the program.It is evident that web applications are in need of a proper set of tools to test regularly.
Loadtracer gives a wide room for testers to perform all kinds of testing at low costs.

Pros of Loadtracer

• Tests program performance


• Fully developed tool
• Suitable for web applications

Cons of Loadtracer

• No user-friendly Interface

Neoload
Automation Testing is a modern concept, which allows people to save a lot of money. Hence, It is obvious that testers
find automated ways to save time without compromising on productivity.NeoLoad is a fine application, which
offers Automation Options to enhance performance. The tool provides quality results while testing various kinds of
projects. Projects include APIs, web applications and so on.

Pros of Neoload

• Suitable for APIs


• Automation options
• High-quality process
Cons of Neoload

• Consumes time in automation

What is Selenium Webdirver?


Selenium Webdriver is an open-source collection of APIs which is used for testing web applications. The Selenium
Webdriver tool is used for automating web application testing to verify that it works as expected or not. It mainly
supports browsers like Firefox, Chrome, Safari and Internet Explorer. It also permits you to execute cross -browser
testing.

Selenium WebDriver is a web framework that permits you to execute cross-browser tests. This tool is used
for automating web-based application testing to verify that it performs expectedly.
Selenium WebDriver allows you to choose a programming language to create test scripts

Describe Maven project and it advantages


Maven is a project and build management tool. It is most commonly used in Java-based frameworks.
Apache Software Foundation developed it. Maven is a Yiddish word that means "gatherer of
information".

Maven automatically downloads project JARs, libraries, and other files. In the pom.xml file, only
information about the version of the software and the type of dependencies must be included. Maven
can manage projects in Ruby, C#, and other languages. It is responsible for building projects, their
dependencies, and documenting them.

ANT (Another Neat Tool), another tool created by Apache Software Foundation, is used to build and
deploy projects. Maven, however, is much more potent than ANT. Maven, like ANT, has simplified the
process of building. Maven, therefore, has simplified the lives of developers.

Advantages of Maven
• Maven manages all the processes, such as building, releasing, documentation, and distribution of the
projects
• Maven automatically includes all necessary dependencies for your project after reading the pom.xml
file.
• It is very easy to create projects using jar, war, and so on as per requirements.
• Maven allows you to start projects easily in various environments, and you don't have to worry about
dependency injection, builds, processing, etc.
• The process of adding a new dependency can be extremely easy. You just need to write the code for the
dependency in the pom.xml file.

Explain different types of Maven repository .


A maven repository is a directory of packaged JAR file with pom.xml file. Maven searches for
dependencies in the repositories. There are 3 types of maven repository:

1. Local Repository
2. Central Repository
3. Remote Repository

Maven searches for the dependencies in the following order:

Local repository then Central repository then Remote repository.

Local Repository

Maven's local repository is a directory on your machine in which all the project components are kept.
When the Maven build is finished, Maven automatically downloads all the dependencies jars to
Maven's local repository.

The default maven local repository is the user_home/m2 directory.

The default path can be modified in settings.xml.

Central Repository

If dependencies are not found in the local repository, Maven then searches the central repository.
Maven then downloads the dependencies to the local repository.

Apache Maven group developed the central repository, and it is hosted on the web.

Like the local repository, the path of the central repository can be modified in setting.xml.

Remote Repository

It is similar to the central repository. When Maven wants to download a dependency, it goes to a
remote repository. The remote repository is present on a web server and is widely used to host the
internal projects of an organization.

Explain Maven directory structure


Maven Directory Structure
Maven has own standard for directory structure to create in a project. So we no need specify any directory on the project
level for sources, resources, tests, plugins etc. And also we don’t need to configure for creating directory structure on the
pom.xml file it is internal functionality of maven.
SourceDirectory
-src This is src directory which contains two more such as main and test directories inside. The main directory is for your
source code and test directory is for test code.
-main Under the main directory there are many more directories such as java, resources, webapps etc.
-java The java directory contains all java codes and packages
-resources The resources directory contains other resources needed by your project. This could be property filesused for
internationalization of an application, or something else.
-webapp The webapp directory contains your Java web application, if your project is a web application.
-test Under test directory contains two directories such as java and resources.
TargetDirectory
-target The target directory is created by Maven. It contains all the compiled classes, JAR files etc. produced by Maven.
When executing the clean build phase, it is the target directory which is cleaned.

Illustrate Selenium feature and limitations, Tool suite.


o Selenium is an open source and portable Web testing Framework.
o Selenium IDE provides a playback and record feature for authoring tests without the need to
learn a test scripting language.
o It can be considered as the leading cloud-based testing platform which helps testers to record
their actions and export them as a reusable script with a simple-to-understand and easy-to-
use interface.
o Selenium supports various operating systems, browsers and programming languages.
Following is the list:
o Programming Languages: C#, Java, Python, PHP, Ruby, Perl, and JavaScript
o Operating Systems: Android, iOS, Windows, Linux, Mac, Solaris.
o Browsers: Google Chrome, Mozilla Firefox, Internet Explorer, Edge, Opera, Safari, etc.
o It also supports parallel test execution which reduces time and increases the efficiency of
tests.
o Selenium can be integrated with frameworks like Ant and Maven for source code compilation.
o Selenium can also be integrated with testing frameworks like TestNG for application testing
and generating reports.
o Selenium requires fewer resources as compared to other automation test tools.
o WebDriver API has been indulged in selenium whichis one of the most important
modifications done to selenium.
o Selenium web driver does not require server installation, test scripts interact directly with the
browser.
o Selenium commands are categorized in terms of different classes which make it easier to
understand and implement.
o Selenium Remote Control (RC) in conjunction with WebDriver API is known as Selenium 2.0.
This version was built to support the vibrant web pages and Ajax.

Selenium Limitations
o Selenium does not support automation testing for desktop applications.

o Selenium requires high skill sets in order to automate tests more effectively.

o Since Selenium is open source software, you have to rely on community forums to get your technical
issues resolved.

o We can't perform automation tests on web services like SOAP or REST using Selenium.

o We should know at least one of the supported programming languages to create tests scripts in
Selenium WebDriver.

o It does not have built-in Object Repository like UTF/QTP to maintain objects/elements in centralized
location. However, we can overcome this limitation using Page Object Model.

o Selenium does not have any inbuilt reportingcapability; you have to rely on plug -ins
like JUnit and TestNG for test reports.

o It is not possible to perform testing on images. We need to integrate Selenium with Sikuli for image
based testing.

o Creating test environment in Selenium takes more time as compared to vendor tools like UFT, RFT,
Silk test, etc.

o No one is responsible for new features usage; they may or may not work properly.

o Selenium does not provide any test tool integration for Test Management.

Selenium is not just a single tool but a suite of software, each with a different approach to support
automation testing. It comprises of four major components which include:

1. Selenium Integrated Development Environment (IDE)


2. Selenium Remote Control (Now Deprecated)
3. WebDriver
4. Selenium Grid

1.Selenium Integrated Development Environment (IDE)


Selenium IDE is implemented as Firefox extension which provides record and playback functionality
on test scripts. It allows testers to export recorded scripts in many languages like HTML, Java, Ruby,
RSpec, Python, C#, JUnit and TestNG. You can use these exported script in Selenium RC or Webdriver.

>Selenium IDE has limited scope and the generated test scripts are not very robust and portable.

2. Selenium Remote Control


Selenium RC (officially deprecated by selenium)allows testers to write automated web application UI
test in any of the supported programming languages. It also involves an HTTP proxy server which
enables the browser to believe that the web application being tested comes from the domain
provided by proxy server.

3. Selenium WebDriver
Selenium WebDriver (Selenium 2) is the successor to Selenium RC and is by far the most important
component of Selenium Suite. SeleniumWebDriverprovides a programming interface to create and
execute test cases. Test scripts are written in order to identify web elements on web pages and then
desired actions are performed on those elements.

Selenium WebDriver performs much faster as compared to Selenium RC because it makes direct
calls to the web browsers. RC on the other hand needs an RC server to interact with the web browser.
4. Selenium Grid
Selenium Grid is also an important component of Selenium Suite which allows us to run our tests on
different machines against different browsers in parallel. In simple words, we can run our tests
simultaneously on different machines running different browsers and operating systems.

Selenium Grid follows the Hub-Node Architecture to achieve parallel execution of test scripts. The
Hub is considered as master of the network and the other will be the nodes. Hub controls the
execution of test scripts on various nodes of the network

ss

You might also like