Viva Questions

Q) What is HTML?

HTML stands for Hyper Text Markup Language. It is a language of World Wide Web. It is a standard text formatting language which is used to create and display pages on the Web.

Q) What are Tags?

HTML tags are composed of three things: opening tag, content and ending tag. Some tags are unclosed tags.

HTML documents are made of two things:

content, and
tags
Content is placed between tags to display data on the web page.

Q) Do all HTML tags have end tag?

No. There are some HTML tags that don't need a closing tag. For example: <image> tag, <br> tag.

Q) What are some common lists that are used when designing a page?

There are many common lists which are used to design a page. You can choose any or a combination of the following list types:

Ordered list
Unordered list
Menu list
Directory list
Definition list

Q) What is the difference between HTML elements and tags?

HTML elements communicate to the browser to render text. When the elements are surrounded by brackets <>, they form HTML tags. Most of the time, tags come in pair and surround content.

Q) What is semantic HTML?

Semantic HTML is a coding style. It is the use of HTML markup to reinforce the semantics or meaning of the content. For example: In semantic HTML <b> </b> tag is not used for bold statement as well as <i> </i> tag is used for italic. Instead of these we use <strong></strong> and <em></em> tags.

Q) What is image map?

Image map facilitates you link many different web pages using a single image. You can define shapes in images that you want to make part of an image mapping.

Q) How to insert a copyright symbol on a browser page?

can insert a copyright symbol by using &copy; or &#169; in an HTML file.

Q) How do you keep list elements straight in an HTML file?

You can keep the list elements straight by using indents.

Q) Does a hyperlink only apply to text?

No, you can use hyperlinks on text and images both.

Q) What is a style sheet?

A style sheet is used to build a consistent, transportable, and well designed style template. You can add these templates on several different web pages.

Q) Can you create a multi colored text on a web page?

Yes. To create a multicolor text on a web page you can use <font color ="color"> </font> for the specific texts you want to color.

Q) Is it possible to change the color of the bullet?

The color of the bullet is always the color of the first text of the list. So, if you want to change the color of the bullet, you must change the color of the text.

Q) What is a marquee?

Marquee is used to put the scrolling text on a web page. You should put the text which you want to scroll within the <marquee>......</marquee> tag.

Q) How many tags can be used to separate section of texts?

There are three tags used to separate the texts. i.e. usually <br> tag is used to separate line of texts. Other tags are<p> tag and <blockquote> tag.

Q) How to make a picture a background image of a web page?

To make a picture a background image on a web page, you should put the following tag code after the </head> tag.

<body background = "image.gif">
Here, replace the "image.gif" with the name of your image file which you want to display on your web page.

Q) What are empty elements?

HTML elements with no content are called empty elements. For example: <br>, <hr> etc.

Q) What is the use of span tag? Give one example.

The span tag is used for following things:

For adding color on text
For adding background on text
Highlight any color text etc.
Example:

<p>
<span style="color:#ffffff;">
In this page we use span.
</span>
</p>

Q) What is the use of iframe tag?

An iframe is used to display a web page within a web page.

Syntax:

<iframe src="URL"></iframe>
Example:

<iframe src="demo_iframe.html" width="200px" height="200px"></iframe>
Target to a link:

<iframe src="http://www.javatpoint.com" name="iframe_a"></iframe>
HTML5 Interview Questions

Let's see a list of top HTML5 interview questions and answers.

Q) What is canvas in HTML5?

Canvas is an HTML area which is used to draw graphics.

Q) What is SVG?

HTML SVG is used to describe the two dimensional vector and vector/raster graphics.

Q) What are the different new form element types in HTML 5?

Following is a list of 10 important new elements in HTML 5:

Color
Date
Datetime-local
Email
Time
Url
Range
Telephone
Number
Search

Q) Is there any need to change the web browsers to support HTML5?

No. Almost all browsers (updated versions) support HTML 5. For example: Chrome, Firefox, Opera, Safari, IE etc.

Q) Which video formats are supported by HTML5?

HTML 5 supports three types of video format:

mp4
webm
ogg


Q) Is audio tag supported in HTML 5?

Yes. It is used to add sound or music files on the web page.

Q) What is the difference between progress and meter tag?

The progress tag is used to represent the progress of the task only while the meter tag is used to measure data within a given range.

Q) What is the use of figure tag in HTML 5?

The figure tag is used to add a photo in the document on the web page.

Q) What is button tag?

The button tag is used in HTML 5. It is used to create a clickable button within HTML form on the web page. It is generally used to create a "submit" or "reset" button.

Q) What does details and summary tag?

The details tag is used to specify some additional details on the web page. It can be viewed or hidden on demand. The summary tag is used with details tag.

Q) What is datalist tag?

The HTML 5 datalist tag provides an auto complete feature on form element. It facilitates users to choose the predefined options.

Q) If I do not put <!DOCTYPE html> will HTML 5 work?

No, browser will not be able to identify that it is a HTML document and HTML 5 tags will not function properly.


Q) What is JavaScript?

JavaScript is a scripting language. It is different from Java language. It is object-based, lightweight and cross platform. It is widely used for client side validation.

Q) What is the difference between JavaScript and jscript?

Netscape provided the JavaScript language. Microsoft changed the name and called it JScript to avoid the trademark issue.In other words, you can say JScript is same as JavaScript, but it is provided by Microsoft.

Q) How to write a hello world example of JavaScript?

A simple example of JavaScript hello world is given below. You need to place it inside the body tag of html.

<script type="text/javascript">
document.write("JavaScript Hello World!");
</script>

Q) How to use external JavaScript file?

I am assuming that js file name is message.js, place the following script tag inside the head tag.

<script type="text/javascript" src="message.js"></script>


Q) Is JavaScript case sensitive language?

Yes.

Q) What is DOM? What is the use of document object?

DOM stands for Document Object Model. A document object represent the html document. It can be used to access and change the content of html.


Q) What is the use of window object?

The window object is automatically created by the browser that represents a window of a browser.

It is used to display the popup dialog box such as alert dialog box, confirm dialog box, input dialog box etc.


Q) What is the use of history object?

The history object of browser can be used to switch to history pages such as back and forward from current page or another page. There are three methods of history object.

history.back()
history.forward()
history.go(number): number may be positive for forward, negative for backward.

Q) How to write comment in JavaScript?

There are two types of comments in JavaScript.

Single Line Comment: It is represented by // (double forward slash)
Multi Line Comment: It is represented by slash with asterisk symbol as /* write comment here */

Q) How to create function in JavaScript?

To create function in JavaScript, follow the following syntax.

function function_name(){
//function body
}

Q) What are the JavaScript data types?

There are two types of data types in JavaScript:

Primitive Data Types
Non-primitive Data Types

Q) What is the difference between == and ===?

The == operator checks equality only whereas === checks equality and data type i.e. value must be of same type.

Q) How to write html code dynamically using JavaScript?

The innerHTML property is used to write the HTML code using JavaScript dynamically. Let's see a simple example:

document.getElementById('mylocation').innerHTML="<h2>This is heading using JavaScript</h2>";

Q) How to write normal text code using JavaScript dynamically?

The innerText property is used to write the simple text using JavaScript dynamically. Let's see a simple example:

document.getElementById('mylocation').innerText="This is text using JavaScript";

Q) How to create objects in JavaScript?

There are 3 ways to create object in JavaScript.

By object literal
By creating instance of Object
By Object Constructor
Let's see a simple code to create object using object literal.

emp={id:102,name:"Rahul Kumar",salary:50000}

Q) How to create array in JavaScript?

There are 3 ways to create array in JavaScript.

By array literal
By creating instance of Array
By using an Array constructor
Let's see a simple code to create array using object literal.

var emp=["Shyam","Vimal","Ratan"];  

Q) What does the isNaN() function?

The isNan() function returns true if the variable value is not a number.

Q) What is the output of 10+20+"30" in JavaScript?

3030 because 10+20 will be 30. If there is numeric value before and after +, it is treated is binary + (arithmetic operator).

Q) What is the output of "10"+20+30 in JavaScript?

102030 because after a string all the + will be treated as string concatenation operator (not binary +).

Q) Difference between Client side JavaScript and Server side JavaScript?

Client side JavaScript comprises the basic language and predefined objects which are relevant to running java script in a browser. The client side JavaScript is embedded directly by in the HTML pages. This script is interpreted by the browser at run time.

Server side JavaScript also resembles like client side java script. It has relevant java script which is to run in a server. The server side JavaScript are deployed only after compilation.

Q) In which location cookies are stored on the hard disk?

The storage of cookies on the hard disk depends on OS and the browser.

The Netscape navigator on Windows uses cookies.txt file that contains all the cookies. The path is : c:\Program Files\Netscape\Users\username\cookies.txt

The Internet Explorer stores the cookies on a file username@website.txt. The path is: c:\Windows\Cookies\username@Website.txt.

Q) What is the real name of JavaScript?

The original name was Mocha, a name chosen by Marc Andreessen, founder of Netscape. In September of 1995, the name was changed to LiveScript. In December 1995, after receiving a trademark license from Sun, the name JavaScript was adopted.

Q) What is the difference between undefined value and null value?

Undefined value: A value that is not defined and has no keyword is known as undefined value. For example:

int number;//Here, number has undefined value.
Null value: A value that is explicitly specified by the keyword "null" is known as null value. For example:

String str=null;//Here, str has a null value.

Q) How to set the cursor to wait in JavaScript?

The cursor can be set to wait in JavaScript by using the property "cursor". The following example illustrates the usage:

<script>
window.document.body.style.cursor = "wait";
</script>

Q) What is this?

var myArray = [[[]]];
Ans: Three dimensional array.

Q) Are Java and JavaScript same?

No, Java and JavaScript are the two different languages. Java is a robust, secured and object-oriented programming language whereas JavaScript is a client side scripting language with some limitations.

Q) What is negative infinity?

Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.

Q) What is difference between View state and Session state?

"View state" is specific to a page in a session whereas "Session state" is specific to a user or browser that can be accessed across all pages in the web application.

Q) What are the pop up boxes available in JavaScript?

Alert Box
Confirm Box
Prompt Box

Q) How can we detect OS of the client machine using JavaScript?

The navigator.appVersion string can be used to detect the operating system on the client machine.

Q) How to submit a form using JavaScript by clicking a link?

Let's see the JavaScript code to submit form on clicking the link.

<form name="myform" action="index.php">
Search: <input type='text' name='query' />
<a href="javascript: submitform()">Search</a>
</form>
<script type="text/javascript">
function submitform()
{
  document.myform.submit();
}
</script>

Q) Is JavaScript faster than ASP script?

Yes, because it doesn't require web server's support for execution.

Q) How to change the background color of HTML document using JavaScript?

<script type="text/javascript">
document.body.bgColor="pink";
</script>

Q) How to handle exceptions in JavaScript?

By the help of try/catch block, we can handle exceptions in JavaScript. JavaScript supports try, catch, finally and throw keywords for exception handling.

Q)What is JSP?

Java Server Pages technology (JSP) is used to create dynamic web page. It is an extension to the servlet technology. A JSP page is internally converted into servlet.


Q) What are the life-cycle methods for a jsp?

Method Description
public void jspInit() It is invoked only once, same as init method of servlet.
public void _jspService(ServletRequest request,ServletResponse)throws ServletException,IOException It is invoked at each request, same as service() method of servlet.
public void jspDestroy() It is invoked only once, same as destroy() method of servlet.

Q)What is difference between hide comment and output comment?

The jsp comment is called hide comment whereas html comment is called output comment. If user views the source of the page, the jsp comment will not be shown whereas html comment will be shown.

Q)What are the JSP implicit objects ?

JSP provides 9 implicit objects by default. They are as follows:

Object Type
1) out JspWriter
2) request HttpServletRequest
3) response HttpServletResponse
4) config ServletConfig
5) session HttpSession
6) application ServletContext
7) pageContext PageContext
8) page Object
9) exception Throwable

Q)What is difference between include directive and include action?

include directive include action
1) The include directive includes the content at page translation time. 1) The include action includes the content at request time.
2) The include directive includes the original content of the page so page size increases at runtime. 2) The include action doesn't include the original content rather invokes the include() method of Vendor provided class.
3) It's better for static pages. 3) It's better for dynamic pages.
6) Is JSP technology extensible?

Yes. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.

Q) How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?

You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" %> within your JSP page.

Q) How can I prevent the output of my JSP or Servlet pages from being cached by the browser?

(OR) How to disable caching on back button of the browser?

<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setHeader ("Expires", "0"); //prevents caching at the proxy server
%>

Q) How can we handle the exceptions in JSP ?

There are two ways to perform exception handling, one is by the errorPage element of page directive, and second is by the error-page element of web.xml file.


Q) What are the two ways to include the result of another page. ?

There are two ways to include the result of another page:

By include directive
By include action

Q) How can we forward the request from jsp page to the servlet ?

Yes ofcourse! With the help of forward action tag, but we need to give the url-pattern of the servlet.

forward action tag

Q) Can we use the exception implicit object in any jsp page ?

No. The exception implicit object can only be used in the error page which defines it with the isErrorPage attribute of page directive.


Q) How is JSP used in the MVC model?

JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it plays the role of the view. The controller deals with calling the model and the business classes which in turn get the data, this data is then presented to the JSP for rendering on to the client.

forward action tag
Q) What are context initialization parameters?

Context initialization parameters are specified by the <context-param> in the web.xml file, these are initialization parameter for the whole application and not specific to any servlet or JSP.


Q) What are the different scope values for the <jsp:useBean> tag?

There are 4 values:

page
request
session
application

Q)What is the difference between ServletContext and PageContext?-

ServletContext gives the information about the container whereas PageContext gives the information about the Request.

Q)What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?

request.getRequestDispatcher(path) is used in order to create it we need to give the relative path of the resource whereas context.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.

Q) What is EL in JSP?

The Expression Language(EL) is used in JSP to simplify the accessibility of objects. It provides many objects that can be used directly like param, requestScope, sessionScope, applicationScope, request, session etc.

Q)What is basic differences between the JSP custom tags and java beans?

Custom tags can manipulate JSP content whereas beans cannot.
Complex operations can be reduced to a significantly simpler form with custom tags than with beans.
Custom tags require quite a bit more work to set up than do beans.
Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.
Q) Can an interface be implemented in the jsp file ?

No.

Q) What is JSTL?

JSP Standard Tag Library is library of predefined tags that ease the development of JSP.


Q) How many tags are provided in JSTL?

There are 5 type of JSTL tags.

core tags
sql tags
xml tags
internationalization tags
functions tags

Q) Which directive is used in jsp custom tag?

The jsp taglib directive.

Q) What are the 3 tags used in JSP bean development?

jsp:useBean
jsp:setProperty
jsp:getProperty

Q) How to disable session in JSP?

<%@ page session="false" %>

1) How many objects of a servlet is created?

Only one object at the time of first request by servlet or web container.

Q) What is the life-cycle of a servlet?

Servlet is loaded
servlet is instantiated
servlet is initialized
service the request
servlet is destroyed

Q) What are the life-cycle methods for a servlet?

Method Description
public void init(ServletConfig config) It is invoked only once when first request comes for the servlet. It is used to initialize the servlet.
public void service(ServletRequest request,ServletResponse)throws ServletException,IOException It is invoked at each request.The service() method is used to service the request.
public void destroy() It is invoked only once when servlet is unloaded.

Q) Who is responsible to create the object of servlet?

The web container or servlet container.

Q) When servlet object is created?

At the time of first request.


Q) What is difference between Get and Post method?

Get Post
1) Limited amount of data can be sent because data is sent in header. Large amount of data can be sent because data is sent in body.
2) Not Secured because data is exposed in URL bar. Secured because data is not exposed in URL bar.
3) Can be bookmarked Cannot be bookmarked
4) Idempotent Non-Idempotent
5) It is more efficient and used than Post It is less efficient and used

Q) What is difference between PrintWriter and ServletOutputStream?

PrintWriter is a character-stream class where as ServletOutputStream is a byte-stream class. The PrintWriter class can be used to write only character-based information whereas ServletOutputStream class can be used to write primitive values as well as character-based information.

Q) What is difference between GenericServlet and HttpServlet?

The GenericServlet is protocol independent whereas HttpServlet is HTTP protocol specific. HttpServlet provides additional functionalities such as state management etc.

Q) What is servlet collaboration?

When one servlet communicates to another servlet, it is known as servlet collaboration. There are many ways of servlet collaboration:

RequestDispacher interface
sendRedirect() method etc.

Q) What is the purpose of RequestDispatcher Interface?

The RequestDispacher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp. This interceptor can also be used to include the content of antoher resource.


Q) Can you call a jsp from the servlet?

Yes, one of the way is RequestDispatcher interface for example:

RequestDispatcher rd=request.getRequestDispatcher("/login.jsp");
rd.forward(request,response);

Q) Difference between forward() method and sendRedirect() method ?

forward() method sendRedirect() method
1) forward() sends the same request to another resource. 1) sendRedirect() method sends new request always because it uses the URL bar of the browser.
2) forward() method works at server side. 2) sendRedirect() method works at client side.
3) forward() method works within the server only. 3) sendRedirect() method works within and outside the server.
Q) What is difference between ServletConfig and ServletContext?

The container creates object of ServletConfig for each servlet whereas object of ServletContext is created for each web application.

Q) What is Session Tracking?

Session simply means a particular interval of time.

Session Tracking is a way to maintain state of an user.Http protocol is a stateless protocol.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.


Q) What are Cookies?

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.


Q) What is difference between Cookies and HttpSession?

Cookie works at client side whereas HttpSession works at server side.

Q) What is filter?

A filter is an object that is invoked either at the preprocessing or postprocessing of a request. It is pluggable.


Q) How can we perform any action at the time of deploying the project?

By the help of ServletContextListener interface.

Q) What is the disadvantage of cookies?

It will not work if cookie is disabled from the browser.


Q) How can we upload the file to the server using servlet?

One of the way is by MultipartRequest class provided by third party.


Q) What is load-on-startup in servlet?

The load-on-startup element of servlet in web.xml is used to load the servlet at the time of deploying the project or server start. So it saves time for the response of first request.


Q) What if we pass negative value in load-on-startup?

It will not affect the container, now servlet will be loaded at first request.


Q) What is war file?

A war (web archive) file specifies the web elements. A servlet or jsp project can be converted into a war file. Moving one servlet project from one place to another will be fast as it is combined into a single file.



Q) How to create war file?

The war file can be created using jar tool found in jdk/bin directory. If you are using Eclipse or Netbeans IDE, you can export your project as a war file.

To create war file from console, you can write following code.

jar -cvf abc.war *
Now all the files of current directory will be converted into abc.war file.

Q) What are the annotations used in Servlet 3?

There are mainly 3 annotations used for the servlet.

@WebServlet : for servlet class.
@WebListener : for listener class.
@WebFilter : for filter class.
Q) Which event is fired at the time of project deployment and undeployment?

ServletContextEvent.

Q) Which event is fired at the time of session creation and destroy?

HttpSessionEvent.

Q) Which event is fired at the time of setting, getting or removing attribute from application scope?

ServletContextAttributeEvent.

Q) What is the use of welcome-file-list?

It is used to specify the welcome file for the project.

Q) What is the use of attribute in servlets?

Attribute is a map object that can be used to set, get or remove in request, session or application scope. It is mainly used to share information between one servlet to another.

Visit My Blog: vinay-kumar-saini.blogspot.com/

1 comment: