Wednesday, April 24, 2013

HTML Interview Questions

1. What is HTML?

HTML (HyperText Markup Language) is a Universal language which allows an individual using special code to create web pages to be viewed on the Internet.
2. What is a tag?

In HTML, a tag tells the browser what to do. When you write an HTML page, you enter tags for many reasons; to change the appearance of text, to show a graphic, or to make a link to another page.
3. What is the simplest HTML page?

HTML Code:
<HTML><HEAD><TITLE>This is my page title! </TITLE></HEAD>
<BODY> This is my message to the world! </BODY></HTML>
Browser Display: This is my message to the world!
4. How do I create frames? What is a frameset?

Frames allow an author to divide a browser window into multiple (rectangular) regions. Multiple documents can be displayed in a single window, each within its own frame. Graphical browsers allow these frames to be scrolled independently of each other, and links can update the document displayed in one frame without affecting the others.
You can’t just “add frames” to an existing document. Rather, you must create a frameset document that defines a particular combination of frames, and then display your content documents inside those frames. The frameset document should also include alternative non-framed content in a NOFRAMES element.
5. How can I include comments in HTML?

An HTML comment begins with “<!—“, ends with “--> “, and does not contain “--“ or “>” anywhere in the comment.
6. What is a Hypertext link?

A hypertext link is a special tag that links one page to another page or resource. If you click the link, the browser jumps to the link’s destination.
7. What is a DOCTYPE? Which one do I use?

According to HTML standards, each HTML document begins with a DOCTYPE declaration that specifies which version of HTML the document uses. Many browsers use the document’s DOCTYPE declaration to determine whether to use a stricter, more standards-oriented layout mode, or to use a “quirks” layout mode that attempts to emulate older, buggy browsers.
8. Can I nest tables within tables?

Yes, a table can be embedded inside a cell in another table. The main caveat about nested tables is that older versions of Netscape Navigator have problems with them if you don’t explicitly close you TR, TD, and TH elements. To avoid problems, include closing tags for you TR, TD, an TH even though the HTML specifications don’t require them.
9. How do you align a table to the right (or left)?

You use the <table align=”right”> property to float a table to the right. Put left in place of right to float right.
10. How can I use tables to structure forms?

Small forms are sometimes placed within a TD element within a table. This can be useful for positioning a form relative to other content, but it doesn’t help position the form-related elements relative to each other. The table must be within the form and then use the table to position the form elements.
11. How do I open a link into a new window?

Add target=”_blank” to your link syntax.
JavaScript interview questions and answers
By admin | May 28, 2006
  1. What’s relationship between JavaScript and ECMAScript? - ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript revision 3.
  2. What are JavaScript types? - Number, String, Boolean, Function, Object, Null, Undefined.
  3. How do you convert numbers between different bases in JavaScript? - Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16);
  4. What does isNaN function do? - Return true if the argument is not a number.
  5. What is negative infinity? - It’s a number in JavaScript, derived by dividing negative number by zero.
  6. What boolean operators does JavaScript support? - &&, || and !
  7. What does "1"+2+4 evaluate to? - Since 1 is a string, everything is a string, so the result is 124.
  8. How about 2+5+"8"? - Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.
  9. What looping structures are there in JavaScript? - for, while, do-while loops, but no foreach.
  10. How do you create a new object in JavaScript? - var obj = new Object(); or var obj = {};
  11. How do you assign object properties? - obj["age"] = 17 or obj.age = 17.
  12. What’s a way to append a value to an array? - arr[arr.length] = value;
  13. What is this keyword? - It refers to the current object.
  14. JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages
  15. JavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element
  16. JavaScript can read and write HTML elements - A JavaScript can read and change the content of an HTML element
  17. JavaScript can be used to validate data - A JavaScript can be used to validate form data before it is submitted to a server. This saves the server from extra processing
  18. JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the visitor's browser, and - depending on the browser - load another page specifically designed for that browser
  19. JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer



12. How do I let people download a file from my page?

Once the file is uploaded to the server, you need to use an anchor reference tag to link to it.
Example:
<a href=”../files/foo.zip”>Download Foo Now!</a>
13. What is an Empty HTML Tag?

Empty HTML tags are tags that do not need to be closed when one is creating a HTML document.
Example: br (<br / )

CSS Interview Questions
1. What are Cascading Style Sheets?

Called (CSS) is a list of statements (or rules) that can assign various rendering properties to HTML elements. Style rules can be specified for a single element occurrence, multiple elements, and entire document, or even multiple documents at once.
2. What is class?

A group of instances of the same element to which a unique style can be attached.
3. What is grouping?

Gathering into a comma separated list two or more selectors that share the same style or into a semicolon separated list two or more declarations that are attached to the same selector.
4. What is ID selector?

ID selector is an individually identified (named) selector to which a specific style is declared. Using the ID attribute, the declared style can then be associated with one and only one HTML element per document as to differentiate it from all the other elements. They use the # character followed by a name.
5. What is contextual selector?

A contextual selector addresses a specific occurrence of an element. It is a string of individual selectors separated by white space, a search pattern, where only the last element in the pattern is addressed providing it matches the specified context. Example: “ td li {color: red} “
6. What does \ABCD (and \ABCDE) mean?

CSS allows Unicode characters to be entered by number. For example, if a class value in some Russian document contains Cyrillic letters EL PE (Unicode numbers 041B and 041F) and you want to write a style rule for that class, you can put that letter into the style sheet by writing:
.\041B\041F {font-style: italic;}
This works on all keyboards, so you don’t need a Cyrillic keyboard to write class names in Russian or another language that uses that script.
7. What are the advantages / disadvantages of various style methods?

External Style Sheet Advantages
- Can control styles for multiple documents at once.
- Classes can be created for use on multiple HTML element types in many documents.
- Selector and grouping methods can be used to apply styles under complex contexts.

External Style Sheet Disadvantages
- An extra download is required to import style information for each document.
- The rendering of the document may be delayed until the external style sheet is loaded.

Embedded Style Sheet Advantages
- Classes can be created for use on multiple tag types in the document.
- Selector and grouping methods can be used to apply styles under complex contexts
- No additional downloads necessary to receive style information.
Inline Style Disadvantages
- Does not distance style information from content.
- Cannot control styles for multiple documents at once.
- Author cannot create or control classes of elements to control multiple element types within the document.
- Selector grouping methods cannot be used to create complex element addressing scenarios.
8. What is property?

Property is a stylistic parameter (attribute) that can be influenced through CSS, e.g. font or width. There must always be a corresponding value or values set to each property.
9. What is the CSS clear property?
The clear property specifies which sides of an element where other floating elements are not allowed.
- This method cannot control styles for multiple documents at once.

Inline Style Advantages
- Useful for small quantities of style definitions.
- Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods.
What are the necessities of using HTML forms?
1. Gathering user information
2. Conducting Surveys
3. Interactive services
20. What are the sequences of steps for each HTTP request from a client to the server?
1. Making the connection
2. Making a request
3. The response
4. Closing the connection
What is XML?
  • XML stands for EXtensible Markup Language
  • XML is a markup language much like HTML
  • XML was designed to carry data, not to display data
  • XML tags are not predefined. You must define your own tags
  • XML is designed to be self-descriptive
  • XML is a W3C Recommendation



The Difference Between XML and HTML
XML is not a replacement for HTML.
XML and HTML were designed with different goals:
  • XML was designed to transport and store data, with focus on what data is
  • HTML was designed to display data, with focus on how data looks
HTML is about displaying information, while XML is about carrying information.
Some advantages of XML are: 
·         It is a platform independent language.
·         It is as easy as HTML.
·         XML is fully compatible with applications like JAVA, and it can be combined with any application which is capable of processing XML irrespective of the platform it is being used on.
·         XML is an extremely portable language to the extent that it can be used on large networks with multiple platforms like the internet, and it can be used on handhelds or palmtops or PDAs.
·         XML is an extendable language, meaning that you can create your own tags, or use the tags which have already been created.
·         It can be deployed on any network if it is amicable for usage with the application in use.
·         If the application can work along with XML, then XML can work on any platform and has no boundaries.
·         It is also vendor independent and system independent. While data is being exchanged using XML, there will be no loss of data even between systems that use totally different formats.


Servlets
Q:
Explain the life cycle methods of a Servlet.
A:
The javax.servlet.Servlet interface defines the three methods known as life-cycle method.
public void init(ServletConfig config) throws ServletException
public void service( ServletRequest req, ServletResponse res) throws ServletException, IOException
public void destroy()
First the servlet is constructed, then initialized wih the init() method.
Any request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet.

The servlet is removed from service, destroyed with the destroy() methid, then garbaged collected and finalized.

Q:
What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?
A:
The getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a "/" it is interpreted as relative to the current context root.

The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface cannot accepts relative paths. All path must sart with a "/" and are interpreted as relative to curent context root.

Q:
Explain the directory structure of a web application.
A:
The directory structure of a web application consists of two parts.
A private directory called WEB-INF
A public resource directory which contains public resource folder.

WEB-INF folder consists of
1. web.xml
2. classes directory
3. lib directory

Q:
What are the common mechanisms used for session tracking?
A:
Cookies
SSL sessions
URL- rewriting

Q:
Explain ServletContext.
A:
ServletContext interface is a window for a servlet to view it's environment. A servlet can use this interface to get information such as initialization parameters for the web applicationor servlet container's version. Every web application has one and only one ServletContext and is accessible to all active resource of that application.

Q:
What is preinitialization of a servlet?
A:
A container doesnot initialize the servlets ass soon as it starts up, it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading. The servlet specification defines the <load-on-startup> element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up. The process of loading a servlet before any request comes in is called preloading or preinitializing a servlet.

Q:
What is the difference between Difference between doGet() and doPost()?
A:
A doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have this limitation. A request string for doGet() looks like the following:
http://www.allapplabs.com/svt1?p1=v1&p2=v2&...&pN=vN
doPost() method call doesn't need a long text tail after a servlet name in a request. All parameters are stored in a request itself, not in a request string, and it's impossible to guess the data transmitted to a servlet only looking at a request string.

Q:
What is the difference between HttpServlet and GenericServlet?
A:
A GenericServlet has a service() method aimed to handle requests. HttpServlet extends GenericServlet and adds support for doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1).
Both these classes are abstract.

Q:
What is the difference between ServletContext and ServletConfig?
A:
ServletContext: Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized
ServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet.
1. What is the difference between JSP and Servlets ?
JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP. But a servlet can support any protocol like HTTP, FTP, SMTP etc.
2. What is difference between custom JSP tags and beans?
Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. To use custom JSP tags, you need to define three separate components: the tag handler class that defines the tag’s behavior ,the tag library descriptor file that maps the XML element names to the tag implementations and the JSP file that uses the tag library
JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags
Custom tags and beans accomplish the same goals — encapsulating complex behavior into simple and accessible forms. There are several differences:
Custom tags can manipulate JSP content; 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 usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page. Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.
3. What are the different ways for session tracking?
Cookies, URL rewriting, HttpSession, Hidden form fields
4. What mechanisms are used by a Servlet Container to maintain session information?
Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information
5. Difference between GET and POST
In GET your entire form submission can be encapsulated in one URL, like a hyperlink. query length is limited to 255 characters, not secure, faster, quick and easy. The data is submitted as part of URL.
In POST data is submitted inside body of the HTTP request. The data is not visible on the URL and it is more secure.
6. What is session?
The session is an object used by a servlet to track a user’s interaction with a Web application across multiple HTTP requests. The session is stored on the server.
7. What is servlet mapping?
The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets.
8. What is servlet context ?
The servlet context is an object that contains a information about the Web application and container. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use.
9. What is a servlet ?
servlet is a java program that runs inside a web container.
10. Can we use the constructor, instead of init(), to initialize servlet?
Yes. But you will not get the servlet specific things from constructor. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.
12. How many JSP scripting elements are there and what are they?
There are three scripting language elements: declarations, scriptlets, expressions.
13. How do I include static files within a JSP page?
Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase.
14. How can I implement a thread-safe JSP page?
You can make your JSPs thread-safe adding the directive <%@ page isThreadSafe="false" % > within your JSP page.
15. What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?
In request.getRequestDispatcher(path) in order to create it we need to give the relative path of the resource. But in resourcecontext.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.
16. What are the lifecycle of JSP?
When presented with JSP page the JSP engine does the following 7 phases.
Page translation: -page is parsed, and a java file which is a servlet is created.
Page compilation: page is compiled into a class file
Page loading : This class file is loaded.
Create an instance :- Instance of servlet is created
jspInit() method is called
_jspService is called to handle service calls
_jspDestroy is called to destroy it when the servlet is not required.
17. What are context initialization parameters?
Context initialization parameters are specified by the in the web.xml file, these are initialization parameter for the whole application.
18. What is a Expression?
Expressions are act as place holders for language expression, expression is evaluated each time the page is accessed. This will be included in the service method of the generated servlet.
19. What is a Declaration?
It declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as semicolons separate them. The declaration must be valid in the scripting language used in the JSP file. This will be included in the declaration section of the generated servlet.
20. What is a Scriptlet?
A scriptlet can contain any number of language statements, variable or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables to use later in the file, write expressions valid in the page scripting language, use any of the JSP implicit objects or any object declared with a . Generally a scriptlet can contain any java code that are valid inside a normal java method. This will become the part of generated servlet’s service method.

Servlet interview questions

1.         What is a servlet?
Servlets are modules that extend request/response-oriented servers,such as Java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database. Servlets are to servers what applets are to browsers. Unlike applets, however, servlets have no graphical user interface.
2.         Whats the advantages using servlets over using CGI?
Servlets provide a way to generate dynamic documents that is both easier to write and faster to run. Servlets also address the problem of doing server-side programming with platform-specific APIs: they are developed with the Java Servlet API, a standard Java extension.
3.         What are the general advantages and selling points of Servlets?
A servlet can handle multiple requests concurrently, and synchronize requests. This allows servlets to support systems such as online
real-time conferencing. Servlets can forward requests to other servers and servlets. Thus servlets can be used to balance load among several servers that mirror the same content, and to partition a single logical service over several servers, according to task type or organizational boundaries.
4.         Which package provides interfaces and classes for writing servlets? javax
5.         What’s the Servlet Interface?
The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or, more
commonly, by extending a class that implements it such as HttpServlet.Servlets > Generic Servlet > HttpServlet > MyServlet.
The Servlet interface declares, but does not implement, methods that manage the servlet and its communications with clients. Servlet writers provide some or all of these methods when developing a servlet.
6.         When a servlet accepts a call from a client, it receives two objects. What are they?
ServletRequest (which encapsulates the communication from the client to the server) and ServletResponse (which encapsulates the communication from the servlet back to the client). ServletRequest and ServletResponse are interfaces defined inside javax.servlet package.
7.         What information does ServletRequest allow access to?
Information such as the names of the parameters passed in by the client, the protocol (scheme) being used by the client, and the names
of the remote host that made the request and the server that received it. Also the input stream, as ServletInputStream.Servlets use the input stream to get data from clients that use application protocols such as the HTTP POST and GET methods.
8.         What type of constraints can ServletResponse interface set on the client?
It can set the content length and MIME type of the reply. It also provides an output stream, ServletOutputStream and a Writer through
which the servlet can send the reply data.
9.         Explain servlet lifecycle?
Each servlet has the same life cycle: first, the server loads and initializes the servlet (init()), then the servlet handles zero or more client requests (service()), after that the server removes the servlet (destroy()). Worth noting that the last step on some servers is done when they shut down.
10.      How does HTTP Servlet handle client requests?
An HTTP Servlet handles client requests through its service method. The service method supports standard HTTP client requests by dispatching each request to a method designed to handle that request.
JDBC interview questions and answers
By admin | September 1, 2004
Thanks to Sachin Rastogi for sending in Java database interview questions.
1.        What are the steps involved in establishing a JDBC connection? This action involves two steps: loading the JDBC driver and making the connection.
2.        How can you load the drivers?
Loading the driver or drivers you want to use is very simple and involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code will load it:
Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);
Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ, you would load the driver with the following line of code:
Class.forName(”jdbc.DriverXYZ”);
3.        What will Class.forName do while loading drivers? It is used to create an instance of a driver and register it with the
DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.
4.        How can you make the connection? To establish a connection you need to have the appropriate driver connect to the DBMS.
The following line of code illustrates the general idea:
String url = “jdbc:odbc:Fred”;
Connection con = DriverManager.getConnection(url, “Fernanda”, “J8?);
5.        How can you create JDBC statements and what are they?
A Statement object is what sends your SQL statement to the DBMS. You simply create a Statement object and then execute it, supplying the appropriate execute method with the SQL statement you want to send. For a SELECT statement, the method to use is executeQuery. For statements that create or modify tables, the method to use is executeUpdate. It takes an instance of an active connection to create a Statement object. In the following example, we use our Connection object con to create the Statement object
Statement stmt = con.createStatement();
6.        How can you retrieve data from the ResultSet?
JDBC returns results in a ResultSet object, so we need to declare an instance of the class ResultSet to hold our results. The following code demonstrates declaring the ResultSet object rs.
ResultSet rs = stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”);
String s = rs.getString(”COF_NAME”);
The method getString is invoked on the ResultSet object rs, so getString() will retrieve (get) the value stored in the column COF_NAME in the current row of rs.
7.        What are the different types of Statements?
Regular statement (use createStatement method), prepared statement (use prepareStatement method) and callable statement (use prepareCall)
8.       How can you use PreparedStatement? This special type of statement is derived from class Statement.If you need a
Statement object to execute many times, it will normally make sense to use a PreparedStatement object instead. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement’s SQL statement without having to compile it first.
9.  PreparedStatement updateSales =
10.   con.prepareStatement("UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?");
11.      What does setAutoCommit do?
When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and will be automatically committed right after it is executed. The way to allow two or more statements to be grouped into a transaction is to disable auto-commit mode:
12.     How do you call a stored procedure from JDBC?
The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open
Connection object. A CallableStatement object contains a call to a stored procedure.
13.   CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
14.   ResultSet rs = cs.executeQuery();
JSP interview questions and answers

1.         What is JSP? Describe its concept. JSP is a technology that combines HTML/XML markup languages and elements of Java programming Language to return dynamic content to the Web client, It is normally used to handle Presentation logic of a web application, although it may have business logic.

2.         What are the lifecycle phases of a JSP?
JSP page looks like a HTML page but is a servlet. When presented with JSP page the JSP engine does the following 7 phases.
A.        Page translation: -page is parsed, and a java file which is a servlet is created.
B.        Page compilation: page is compiled into a class file
C.        Page loading : This class file is loaded.
D.        Create an instance :- Instance of servlet is created
E.        jspInit() method is called
F.         _jspService is called to handle service calls
G.        _jspDestroy is called to destroy it when the servlet is not required.
3.         What is a translation unit? JSP page can include the contents of other HTML pages or other JSP files. This is done by using the include directive. When the JSP engine is presented with such a JSP page it is converted to one servlet class and this is called a translation unit, Things to remember in a translation unit is that page directives affect the whole unit, one variable declaration cannot occur in the same unit more than once, the standard action jsp:useBean cannot declare the same bean twice in one unit.
4.         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.
5.         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.
6.         What is a output comment? A comment that is sent to the client in the viewable page source. The JSP engine handles an output comment as un-interpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser.
7.         What is a Hidden Comment? A comment that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags. A hidden comment is not sent to the client, either in the displayed JSP page or the HTML page source. The hidden comment is useful when you want to hide or “comment out” part of your JSP page.
8.         What is a Expression? Expressions are act as place holders for language expression, expression is evaluated each time the page is accessed.
9.         What is a Declaration? It declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as semicolons separate them. The declaration must be valid in the scripting language used in the JSP file.
10.      What is a Scriptlet? A scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables or methods to use later in the file, write expressions valid in the page scripting language, use any of the JSP implicit objects or any object declared with a <jsp:useBean>.
11.       What are the implicit objects? List them. Certain objects that are available for the use in JSP documents without being declared first. These objects are parsed by the JSP engine and inserted into the generated servlet. The implicit objects are:
§  request
§  response
§  pageContext
§  session
§  application
§  out
§  config
§  page
§  exception
12.       What’s the difference between forward and sendRedirect? When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container And then returns to the calling method. When a sendRedirect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completely new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.
13.       What are the different scope values for the <jsp:useBean>? The different scope values for <jsp:useBean> are:
§  page
§  request
§  session
§  application
14.       Why are JSP pages the preferred API for creating a web-based client program? Because no plug-ins or security policy files are needed on the client systems(applet does). Also, JSP pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design. This means personnel involved in web page design do not need to understand Java programming language syntax to do their jobs.
15.       Is JSP technology extensible? Yes, it is. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.
16.       What is difference between custom JSP tags and beans? Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. Custom tags and beans accomplish the same goals — encapsulating complex behavior into simple and accessible forms. There are several differences:

Filter  
A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both. 
FilterChain  
A FilterChain is an object provided by the servlet container to the developer giving a view into the invocation chain of a filtered request for a resource. 
FilterConfig  
A filter configuration object used by a servlet container to pass information to a filter during initialization. 
RequestDispatcher  
Defines an object that receives requests from the client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server. 
Servlet  
Defines methods that all servlets must implement. 
ServletConfig  
A servlet configuration object used by a servlet container to pass information to a servlet during initialization. 
ServletContext  
Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file. 
ServletContextAttributeListener  
Implementations of this interface receive notifications of changes to the attribute list on the servlet context of a web application. 
ServletContextListener  
Implementations of this interface receive notifications about changes to the servlet context of the web application they are part of. 
ServletRequest  
Defines an object to provide client request information to a servlet. 
ServletRequestAttributeListener  
A ServletRequestAttributeListener can be implemented by the developer interested in being notified of request attribute changes. 
ServletRequestListener  
A ServletRequestListener can be implemented by the developer interested in being notified of requests coming in and out of scope in a web component. 
ServletResponse  
Defines an object to assist a servlet in sending a response to the client. 
SingleThreadModel  
Ensures that servlets handle only one request at a time.

§  Custom tags can manipulate JSP content; 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 usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page.
§  Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.

Classes and Interfaces of Servlet

The javax.servlet package defines the contract between container and the servlet class. It provides the flexibility to container vendor to implement the API the way they want so long as they follow the specification. To the developers, it provides the library to develop the servlet based applications.
Interfaces of javax.Servlet
 Classes of javax.Servlet

ServletContextAttributeEvent  
This is the event class for notifications about changes to the attributes of the servlet context of a web application. 
ServletContextEvent  
This is the event class for notifications about changes to the servlet context of a web application. 
ServletException  
Defines a general exception a servlet can throw when it encounters difficulty. 
ServletRequestAttributeEvent  
This is the event class for notifications of changes to the attributes of the servlet request in an application. 
ServletRequestEvent  
Events of this kind indicate lifecycle events for a ServletRequest. 
ServletRequestWrapper  
Provides a convenient implementation of the ServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet. 
ServletResponseWrapper  
Provides a convenient implementation of the ServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet. 
UnavailableException  
Defines an exception that a servlet or filter throws to indicate that it is permanently or temporarily unavailable

 Abstract Classes
GenericServlet  
Defines a generic, protocol-independent servlet. 
ServletInputStream  
Provides an input stream for reading binary data from a client request, including an efficientreadLine method for reading data one line at a time. 
ServletOutputStream  
Provides an output stream for sending binary data to the client

0 comments:

Post a Comment