0% found this document useful (0 votes)
60 views11 pages

WT Viva Questions

Servlets are Java programs that extend the capabilities of servers and respond to requests from clients. The life cycle of a servlet involves initialization, request handling, and destruction stages. Servlets run in the address space of the web server, providing better performance than traditional CGI scripts. Common servlet methods include init() for initialization, service() for request handling, and destroy() for cleanup.

Uploaded by

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

WT Viva Questions

Servlets are Java programs that extend the capabilities of servers and respond to requests from clients. The life cycle of a servlet involves initialization, request handling, and destruction stages. Servlets run in the address space of the web server, providing better performance than traditional CGI scripts. Common servlet methods include init() for initialization, service() for request handling, and destroy() for cleanup.

Uploaded by

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

Servlets

1. What is a Servlet?

Answer: A Servlet is a Java program that extends the capabilities of servers and
responds to requests from clients. It is a server-side technology used for developing
dynamic web applications.

2. What is the life cycle of a Servlet?

Answer: The life cycle of a Servlet involves the following stages:

 Initialization: Servlet is loaded and its init() method is called.


 Request Handling: Servlet processes client requests by calling the service()
method.
 Destruction: Servlet is unloaded and its destroy() method is called.

3. How does a Servlet differ from a traditional CGI script?

Answer: Unlike CGI scripts, Servlets run in the address space of the web server,
providing better performance. Servlets are platform-independent because they are
written in Java, and they reuse the existing process, unlike CGI, which creates a
new process for each request.

4. Explain the init() method in a Servlet.

Answer: The init() method is called when a Servlet is first loaded into memory. It
is used for one-time initialization tasks, such as loading resources or establishing
database connections. It is called by the servlet container.

5. What is the purpose of the service() method?

Answer: The service() method is responsible for handling client requests. It


receives requests from the clients, processes them, and sends back the response. It
is called by the servlet container.

6. Differentiate between doGet() and doPost() methods.

Answer: Both doGet() and doPost() are methods used to handle HTTP requests.
 doGet() is used for handling HTTP GET requests, typically used for data
retrieval.
 doPost() is used for handling HTTP POST requests, which are used for
submitting data.

7. How does a Servlet communicate with a JSP page?

Answer: A Servlet can communicate with a JSP page by setting attributes in the
request or session scope. The Servlet can use the RequestDispatcher to forward
the request to the JSP page.

8. What is the purpose of the destroy() method?

Answer: The destroy() method is called when a Servlet is unloaded from the
server. It is used for performing cleanup tasks, such as closing database
connections or releasing resources.

9. Explain the difference between the sendRedirect() and forward() methods.

Answer:

 sendRedirect() sends a response to the client with a new URL, and the
client's browser makes a new request to that URL.
 forward() forwards the request from one Servlet to another Servlet or JSP
page on the server without involving the client's browser.

10. How do you handle exceptions in a Servlet?

Answer: Exceptions in a Servlet can be handled using the try, catch, and finally
blocks. Alternatively, the error-page element in the deployment descriptor
(web.xml) can be used to specify an error page for handling exceptions.

These questions cover fundamental concepts related to Servlets. Adjust the level of
complexity based on the depth of Servlet knowledge expected in your viva
examination
11. Explain about Servlet API?

12. What are the JDBC Drivers?


JSP:

1. What is JSP?

Answer: JSP stands for JavaServer Pages. It is a technology used for developing
web pages that support dynamic content, and it allows Java code to be embedded
into HTML pages.

2. Differentiate between servlets and JSP.

Answer: Servlets are Java programs that execute on the server-side to handle
requests, while JSP is a technology that mixes HTML and Java code to create
dynamic web content. JSPs are easier to write and maintain than servlets for web
page development.

3. How does a JSP page get converted into a servlet?

Answer: When a JSP page is requested for the first time, the JSP engine translates
it into a servlet. This servlet is then compiled, loaded, and executed by the servlet
container.

4. What are directives in JSP?

Answer: Directives in JSP provide global information about an entire page and are
defined between <%@ and %> tags. Examples include page directives for setting
attributes like contentType, import, session, and buffer.

5. Explain the difference between include directive and include action.

Answer:

 Include Directive (<%@ include %>): It includes the content of another


resource at translation time. The included content becomes part of the JSP
page during compilation.
 Include Action (<jsp:include>): It includes the content of another resource
at runtime. The included content is dynamically added when the page is
requested.
6. What is a taglib in JSP?

Answer: A taglib (tag library) in JSP is a collection of custom tags that extend the
functionality of JSP. Taglibs are defined in the web.xml file and enable the use of
custom tags in JSP pages.

7. Explain the use of JSP expressions.

Answer: JSP expressions (<%= %>) are used to insert dynamic content into the
HTML page. The expression is evaluated, converted to a string, and inserted into
the place where the expression appears in the HTML.

8. What is the purpose of JSP declarations?

Answer: JSP declarations (<%! %>) are used to declare variables and methods
that can be used later in the JSP page. Declarations are placed outside the HTML
tags.

9. How can you handle exceptions in JSP?

Answer: Exceptions in JSP can be handled using the <%@ page


errorPage="error.jsp" %> directive to specify an error page. The error page can
then retrieve information about the exception using the Exception object.

10. What is the difference between forward and sendRedirect?

Answer:

 Forward (RequestDispatcher.forward()): It forwards the request from one


resource to another on the server. The client is not involved, and the URL
remains the same.
 SendRedirect (response.sendRedirect()): It sends a redirect response to
the client, and the client's browser makes a new request to the redirected
URL.
JAVA SCRIPT

1. What is JavaScript?

Answer: JavaScript is a high-level, interpreted programming language primarily


used for creating dynamic content on the client side of web applications. It is often
embedded within HTML and executed by web browsers.

2. Differentiate between JavaScript and Java.

Answer: Despite the similar names, JavaScript and Java are different:

 JavaScript is a scripting language primarily used for client-side web


development.
 Java is a programming language used for a variety of applications, including
server-side development.

3. How do you declare variables in JavaScript?

Answer: Variables in JavaScript are declared using the var, let, or const keyword.

4. Explain the difference between null and undefined in JavaScript.

Answer:

 null represents the intentional absence of any object value.


 undefined represents the absence of a defined value, often the default value
of uninitialized variables.

5. What is the purpose of the this keyword in JavaScript?

Answer: The this keyword in JavaScript refers to the current execution context. Its
value depends on how a function is called:

 In a method, this refers to the object that owns the method.


 In a function, this refers to the global object (e.g., window in a browser).

6. Explain the concept of closures in JavaScript.


Answer: A closure is a function bundled with its lexical environment, allowing it
to access variables from its outer (enclosing) scope even after that scope has
finished executing. Closures are created whenever a function is defined within
another function.

7. How do you add an event listener in JavaScript?

Answer: You can add an event listener using the addEventListener method. For
example:

javascriptCopy code
document . getElementById ( "myButton" ). addEventListener ( "click" , function () {
alert ( "Button clicked!" ); });

8. What is the purpose of the setTimeout function?

Answer: The setTimeout function in JavaScript is used to schedule the execution


of a function after a specified delay in milliseconds.

9. How do you iterate through elements in an array in JavaScript?

10. Explain the concept of AJAX in JavaScript.

Answer: AJAX (Asynchronous JavaScript and XML) is a technique used to create


dynamic and asynchronous web applications. It allows web pages to be updated
asynchronously by exchanging small amounts of data with the server behind the
scenes.

These questions cover various aspects of JavaScript. Adjust the complexity based
on the level of understanding expected in your viva examination.

11. JAVA Script Implicit objects

12.javascript methods

PHP
1. What is PHP?

Answer: PHP (Hypertext Preprocessor) is a server-side scripting language widely


used for web development. It is embedded within HTML and executed on the
server to generate dynamic web pages.

2. How do you start and end a PHP script?

Answer: A PHP script is initiated with <?php and terminated with ?>. For
example:

3. What is the difference between echo and print in PHP?

Answer: Both echo and print are used to output data, but echo can take multiple
parameters, while print can only take one parameter. echo is slightly faster, and it
does not return a value, whereas print returns 1, so it can be used in expressions.

4. Explain the difference between == and === in PHP.

Answer:

 == is the equality operator, which checks if the values are equal after type
coercion.
 === is the identical operator, which checks if the values are equal and of the
same type.

5. How do you include one PHP file into another?

Answer: The include and require statements are used to include one PHP file into
another.

 include('filename.php'); includes the file and generates a warning if the file


is not found.
 require('filename.php'); includes the file and produces a fatal error if the
file is not found.

6. What is the purpose of the $_GET and $_POST variables in PHP?


Answer:

 $_GET is used to collect form data sent in the URL (as query parameters).
 $_POST is used to collect form data sent with the HTTP POST method.

7. Explain the use of sessions in PHP.

Answer: Sessions in PHP are used to store user information across multiple pages.
The session_start() function initiates a session, and $_SESSION is used to store
and retrieve session variables.

8. What is the purpose of the header() function in PHP?

Answer: The header() function is used to send raw HTTP headers. It is often used
for redirecting users to another page, setting cookies, or specifying the content type
of the page.

9. How do you connect to a MySQL database in PHP?

Answer:

 Using MySQLi (MySQL Improved) extension:


phpCopy code
$conn = new mysqli ( $servername , $username , $password , $dbname );
 Using PDO (PHP Data Objects):
phpCopy code
$conn = new PDO ( "mysql:host=$servername;dbname=$dbname" ,
$username , $password );

10. Explain the concept of error handling in PHP.

Answer: Error handling in PHP involves functions like error_reporting(),


ini_set(), and try-catch blocks for exceptions. Common error types include notices,
warnings, and fatal errors. The set_error_handler() function can be used to define
custom error handlers.

These questions cover various aspects of PHP. Adjust the complexity based on the
level of understanding expected in your viva examination.
XML
1. What is XML?

Answer: XML stands for eXtensible Markup Language. It is a markup language


designed for storing and transporting data. It is both human-readable and machine-
readable, making it suitable for representing structured information.

2. Explain the basic syntax of an XML document.

Answer: An XML document consists of a prolog, element hierarchy, and optional


miscellaneous content. The basic syntax is as follows:

3. What is an XML prolog?

Answer: The XML prolog is the first line in an XML document and typically
includes the XML version and encoding information. For example:

4. Differentiate between attributes and elements in XML.

Answer:

 Elements: Represent the structure and hierarchy of data. They can contain
text, other elements, or both.
 Attributes: Provide additional information about an element. They are
always included in the start tag and follow the name-value pair format.

5. Explain the concept of well-formed and valid XML documents.

Answer:

 Well-formed XML: Follows the basic syntax rules of XML. It has a prolog,
properly nested elements, and correct use of attributes.
 Valid XML: Not only well-formed but also adheres to a Document Type
Definition (DTD) or XML Schema Definition (XSD) that defines the
document's structure and data types.

6. What is the purpose of CDATA in XML?


Answer: CDATA (Character Data) is used to include blocks of text that should not
be treated as markup. It is often used to include code snippets or other content that
might be interpreted as XML entities.

7. Explain the difference between DTD and XSD.

Answer:

 DTD (Document Type Definition): It is an older method for defining the


structure and legal elements of an XML document. DTDs are declared
within the document or referenced externally.
 XSD (XML Schema Definition): It is a more modern and powerful way of
defining XML document structure. XSDs are typically separate files and
provide more detailed data type definitions.

8. How can you comment in XML?

Answer: XML comments are written using the <!-- ... --> syntax. For example:

9. What is the purpose of namespaces in XML?

Answer: XML namespaces are used to avoid naming conflicts by allowing


different XML vocabularies to coexist within the same document. They are defined
using the xmlns attribute.

10. Explain the concept of XML validation.

Answer: XML validation is the process of checking whether an XML document


complies with a specific Document Type Definition (DTD) or XML Schema
Definition (XSD). It ensures that the document adheres to the defined structure,
data types, and constraints.

These questions cover key aspects of XML. Adjust the complexity based on the
level of understanding expected in your viva examination.

11. What are the XML parsers?


Answer: DOM(Document Object Model)
SAX ( Simple API for XML)
12. Types of DTD’s
BASIC HTML TAGS:

Header tags
Marque tags
List tags
Table tags
row span,
col span
Anchor tag
CSS
Internal CSS
External CSS

You might also like