CS506 Final Term Subjective Solved With References 2012 - 2013
CS506 Final Term Subjective Solved With References 2012 - 2013
CS506 Final Term Subjective Solved With References 2012 - 2013
www.freeittips.com
YEAR 2013
Why we use args[] array in main method of java?
Answer:
The args array contains all command line parameters passed in to your Java application.
Passing arguments from the command Line.Which can be used by the program as a set of parameters
to operate upon or produce a result based on a set of known parameters.
Web page
Has a UI
Interacts with user
Works with web browser client
Web Service
No GUI
Interacts with application
Works with any type of client
Types of Tags
Three types of can be constructed. These are:
1 Simple Tag
void display
{
name = n;
}
void display
{
id= n;
}
}//end bean class
Alternative name of business class:
Answer:
Also called application layer, it is only concerned with the application specific functionality. It is used to
implement business rules and to perform business tasks.
Comments Comments are ignored by JSP-to-servlet translator. Two types of comments are possibly
used in JSP.
HTML comment: These comments are shown in browser, means on taking view source of the web
page; these sorts of comments can be read. Format of HTML comments is like to
: <!-- comment text--> –
JSP comment: These comments are not displayed in browser and have format like:
<%-- comment text --%>
Q. Difference b/w Page-centric approach and page-with-bean approach.
Answer:
Pagentric Approach:
A web application that is collection of JSPs. Generally this approach is followed to get started with
developing web application.
The page-centric approach has lot of draw backs such as the code becomes a mixture of presentation,
business and data access logic. The maintenance and up-gradation of the application becomes a
nightmarScaling of such kind of application is also difficult and lots of code is also get duplicated.
Answer:
This approach is different from page-centric approach in a way that all the business logic goes into
JavaBeans. Therefore, the web application is a collection of JSPs and JavaBeans. But still this approach
is insufficient to separate different kind of logics
Answer:
EL also supports automatic type conversion; as a result primitive can implicitly wrap and unwrap
Answer:
If you run a jsp file first time it will take a longer time, because at the very first time the jsp file is converted
in JAVA, then it is compiled and finally it is loaded. But the compilation only happens once so the next time it
will be faster.
But every time you change a jsp file it will be re-complied.
Absolute method help to us to move cursor to any specific row in result set. If we call absolute method and
give value-1 as argument which row our cursor will point after calling absolute(-1)?
Answer:
For example, calling absolute(-1) positions the cursor on the last row; calling absolute(-2) moves the
cursor to next-to -last row, and so on.
-Throws Exception if ResultSet type is TYPE_FORWARD_ONLY
Write impact a java beans can produce when it is stored in page scope?
Answer:
Each page has its own page scope. Therefore objects stored in page scope are only available to same pages on
which they are created. Suppose page1 forwards the request to page2. Objects stored in request scope
remains available to page1 as well to page 2. Similar case is true for page 3 & page 4. If user makes a visit to all
these pages in one session, object’s values stored in session scope remains available on all these pages.
ResultSet object.
• Another advantage is, rows can be inserted, updated or deleted by using updatable
ResultSet object.
requestScope
sessionScope
applicationScope
1 Cookies
2 URL Rewriting
3 Hidden Fields
Answer:
InputStream is = s.getInputStream();
// now to convert byte oriented stream into character oriented buffered reader
These comments are not displayed in browser and have format like:
www.freeittips.com | solved by Saher
<%-- comment text --%>
A java class that can be easily reused and composed to gether certain design conventions can be a JavaBean.
If we do nit set any scope element which scope element will be set as default scope element (368)
The scope attribute can have one possible value out of page, request, session and application. If this attribute
is omitted, the default value of scope attribute is page. We’ll discuss in detail about scope shortly.
Answer:
$ { validExpression }
Answer:
A non-static inner class may have object instances that are associated with instances of the class's outer class.
A static inner class does not have any object instances.
Answer:
Answer:
The Expression Language, not a programming or scripting language, provides a way to simplify expressions in
JSP. It is a simple language that is geared towards looking up objects, their properties and performing simple
operations on them. It is inspired form both the ECMAScript and the XPath expression language.
Answer:
Many times when we get a chance to work on a small project, one thing we intend to do is to put all java files
into one single directory (folder). It is quick, easy and harmless. However if our small project gets bigger, and
the number of files is increasing, putting all these files into the same directory would be a nightmare for us. In
java we can avoid this sort of problem by using Packages.
In simple terms, a set of Java classes organized for convenience in the same directory to avoid the name
collisions. Packages are nothing more than the way we organize files into different directories according to
their functionality, usability as well as category they should belong to.
Value Binding:
Answer:
Method Binding:
Answer:
Unlike a value binding, a method binding does not represent an accessor method. Instead, a method binding
represents an activation method.
The individual’s responsibility of three participants(model, view & controller) is given below
. Model
The model represents the state of the component (i.e. its data and the methods required to manipulate
View;
The view renders the contents of a model and specifies how that data should be presented. There can
be multiple views for the same model within single applications or model may have different views in different
applications or operating systems.
. Controller:
The controller translates interaction with the view into action to be performed by the model. In a web
application, they appear as Get and Post HTTP request. The actions performed by the model include activating
business processes or changing the state of the model. Based on the user interactions and the outcome of the
model actions, the controller responds by selecting an appropriate view.
Answer:
To read the cookies that come back from the client, following steps are generally followed.
To read incoming cookies, get them from the request object of the HttpServeltRequest by calling
following method
This call returns an array of Cookies object corresponding to the name & values that came in the HTP request
header.
Correct the following object code cookie c=new cookie ("visit",10) 2 marks
Answer:
Answer:
page|request|session|application
Answer:
• May be attributes
Answer:
Write a code statement to remove the value associated with the "amazonsession"of object "session"
Answer:
session.removeAttribute (“amazonsession”);
Write any three features of java which are not presented in c/c++? 3
Answer:
Building an application in Java takes about 50% less time than in C or C++.
The core language is simpler than C++ -- no operator overloading, no pointers, no multiple inheritance
<jspforward page="vu.jsp">
Answer:
<%
RequestDispatcher rd = request.getRequestDispatcher(“vu.jsp”);
Answer:
o Dynamic attribute values of JSTL tags are specified using JSTL expression language (i.e.${ expression })
o Dynamic attribute values of JSTL tags are specified using JSP expression
o The RT based JSTL tag libraries along with URIs and preferred prefixes are given below in tabular format
Answer:
Hello World
then write to another file in reverse order it should look like this:-
Hello World
Answer: #internet
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.Reader;
try{
// input file
File in = new File(args[0]);
fis = new FileInputStream(in);
// an outputfile
File out = new File(args[1]);
// and a random access file of the same size as the input, so we can write in
reverse order
raf = new RandomAccessFile(out, "rw");
raf.setLength(in.length());
Answer:
HttpServlet class
• Extend your class from HttpServlet, if you want to write HTTP based servlets
You have your web project file in .WAR format inside dest directory. Explain how will you deploy your
web application? (3 marks)
Copy the web application archive file into directory $CATALINA_HOME/webapps/. When Tomcat is started,
it will automatically expand the web application archive file into its unpacked form, and execute the application
that way.
Explain why JAVA applets are better than Active-X components? (2 marks)
Answer: #internet
Java applets are downloaded in a machine-independent format and usually interpreted within the browser, while
ActiveX controls are binaries. The typical target system for an ActiveX control is, not surprisingly, one based
on an Intel Corp. processor that supports the Win32 interface, which generally means that it is running
Windows 95 or Windows NT.
Tiers are physically separated from each other. Layers are spread across tiers to build up an application. Two
or more layers can reside on one tier.
What are the requirement which a java should full fill to be javabeans.5 marks
Answer:
A java class that can be easily reused and composed together in an application.
Any java class that follows certain design conventions can be a JavaBean.
Answer: #internet
It’s quite difficult to manage. You need to allocate and deallocate carefully or you will find nasty error in your
program. One thing though, it is not actually "removed". In java, in fact, everything is pointer. The difference is,
java handles the allocating and de-allocating (the so called 'Garbage Collector'), not you
Answer: #internet
The purpose of a Destructor is usually to clear off unused variables and clean up the memory. Java has in built
memory handling mechanisms (Garbage collection) that clear off unused memory automatically. Hence there is
no requirement for destructors.
The args array contains all command line parameters passed in to your Java application.
Passing arguments from the command Line. Which can be used by the program as a set of parameters to
operate upon or produce a result based on a set of known parameters?
The web page is based on data submitted by the user. e.g. results page from search engines and order
confirmation pages at on line stores.
The Web page is derived from data that changes frequently. e.g. a weather report or news headlines page
Web page
Has a UI
Web Service
No GUI
Interacts with application
Works with any type of client
Types of Tags
Three types of can be constructed. These are:
1 Simple Tag
2 Tag with Attribute
3 Tag with Body
// no argument constructor
public PersonInfo()
name = "";
Id= "";
}
name = n;
}
void display
id= n;
}
write jsp page for the amount "amount" get from another page calculate zakat and display it.
Answer:
The bean objects stored in ServletContext is shared by all JSPs/servlets in the same web application.
Html code given insert spread sheet ms excel code to show id on another page? 3
In catch block any other exception catch before IOException? if no give reason 2
Answer:
o Bear in mind the Exception hierarchy when writing multiple catch clauses!
o If you catch Exception first and then IOException, the IOException will never be caught!
Answer:
jsp:useBean is being equivalent to building an object in scriptlet. For example to build an object of MyBean
using scriptlet is:
<%
%>
Achieving above functionality using jsp:useBean action element will look like this:
<jsp:useBean id = “m”
scope = “page”
class=“vu.MyBean” >
A collection represents group of objects know as its elements. Java has a built-in support for collections.
Collection classes are similar to STL in C++. An advantage of a collection over an array is that you don’t need to
know the eventual size of the collection in order to add objects to it. The java.utilpackage provides a set of
collection classes that helps a programmer in number of ways.
Write impact a java beans can produce when it is stored in page scope?
Answer:
In practice, beans created with page scopeare always accessed (their values) by jsp:getProperty,
jsp:setProperty, scriptlets or expressions later in the same page.
Answer:
The first step in constructing an exception handler is to enclose the code that might throw an exception within
a try block. In general, a try block looks like the following:
try {
code
}
catch and finally blocks . . .
Answer:
Write a code which shows the number of cookies that how many times that page been accessed ? (lec 31)
Answer:
Answer:
Ans:
Conversion of a primitive type to the corresponding reference type is called boxing, such as an int to a
java.lang.Integer. Conversion of the reference type to the corresponding primitive type is called unboxing,
such as Byte to byte.
Q4.Being a java front end developer, write the characteristics of tag with body custom tag and also give
example? 02
Q7.if we call the following methods in the following sequence and we refresh our page one time will the
session expire?
(i) Session.setMaxAge(160)
(ii) Session.invalidate() 03
Answer: # my view
Yes session will expire because of the fact that it lasts only for the current user session (i.e. until the user quits
the session) and will not be stored on the disk. Once page refreshed session will be expired.
In which situation executeQuery() and executeUpdate methods of statement object can be used for SQL?
03
Instance speaker{}
Do you find any problem in the above code? Explain your answer. 05
What are the two options through which we can assign unique session id to each user?
Cookie: it is used to keep the unique sessionID associated with each user.
URL rewriting provides another way for session tracking. With URL rewriting, the parameterthat we want to
pass back and forth between the server and client is appended to the URL. This appended information can be
retrieve by parsing the URL. This information can be in the form of:
• Added parameters, or
Write java code that show output “Welcome to Web Design And Development Course” (5 MARKS)
Does JSP support run time exception handling if yes then how? 2marks
• exception
This variable is of type java.lang.Throwable. Represents the exception that is passed to JSP error page.
EJBs and JSP/Servlets works in two different servers. As you already know, JSP and Servlets runs in a web
server where as EJBs requires an application server.
www.freeittips.com | solved by Saher
What information can be appended to URL. 3 marks
With URL rewriting, the parameter that we want to pass back and forth between the server and client is
appended to the URL. This appended information can be retrieve by parsing the URL. This information can be
in the form of:
• Added parameters, or
YEAR 2012
Q.1
Q.2
• Efficient
o Every request for a JSP is handled by a simple JSP java thread as JSP gets converted into a servlet. Hence,
the time to execute a JSP document is not dominated by starting a process.
Q.3
A web application that is collection of JSPs. Generally this approach is followed to get started with developing
web applications.
Q.4
Q.5
Answer: #internet
Q.6
• Representing UI components
• Handling events
• Data binding
• Automatic conversion
Q.7
Q.8
A socket is one endpoint of a two-way communication link between two programs running generally on a
network.
• The server listens through a special kind of socket, which is named as server socket.
• The sole purpose of the server socket is to listen for incoming request; it is not used for communication
Q.9
Question incomplete.
Q.10
Q.11
Q.12
Q13
$ {pageContext.out}
$ {param.id}
Q.14
Q.15
Answer: #internet
The primary advantage of using the HttpSession is that this allows storing not just text strings but entire Java
objects in the session. All the session-handling functionality of creating a session, checking the validity of a
session, retrieving the data stored for a session, and terminating a session is wrapped in the HttpSession.
Q.17
Q.18
Answer:
It is possible web server is running on one server machine while application server on another. Web server is
used to execute web pages like JSPs whereas application server is used to run special business objects like
Enterprise JavaBeans .
Q.19
Answer: Page no : 5
JVM
The JVM "verifier" checks the code when it is loaded to verify that it has the correct Structure -- that it does
not use an uninitialized pointer, or mix int and pointer types. This is one-time "static" analysis -- checking that
the code has the correct structure without running it.
Q.20
In Page-Centric Approach
Page-with-bean approach is different from page-centric approach in a way that all the business logic goes into
JavaBeans. Therefore, the web application is a collection of JSPs and JavaBeans.
Q.21
1. Db
2. Html
3. Jsp
Q.22 In hash Map we can put method to add objects into Hash Map. Is the code given below correct or not.
If there is problem then identify the problem
h.put(1, s1);
h.put(2, s2);
h.put(3, s3);
h.put("one". s1);
h.put("two". S2);
h.put("three". S3);
Q.23
String sid=(String)s.getAttribute(“student”);
Q.24
Write a single line to include a page ”vuHome.java” using custom tags. You can use any name for tag but
mention which you have chosen for which tag element.
In customtags.tld file :
<tag>
<name>coursetag</name>
<tag-class>vutag.vuHome</tag-class>
<body-content>empty</body-content>
</tag>
-In any other file in which you wanted to include that vuHome file using custom tags :
The next step is to call the tag by its name as defined in TLD. For example, if tag name is hello then we write:
www.freeittips.com | solved by Saher
<%-- calling coursetag value --%>
Q.25
The scope attribute can have one possible value out of page, request, session and application. If this attribute
is omitted, the default value of scope attribute is page.
Q.26
• Converts JDBC calls into database-specific calls such as SQL Server, Informix, Oracle or Sybase.
• Partly-Java drivers communicate with database-specific API (which may be in C/C++) using the Java Native
Interface.
Q.27
HTTP is a stateless protocol. Every request is considered independent of every other request. But many
applications need to maintain a conversational state with the client. A shopping cart is a classical example of
such conversational state. For Example:
Suppose a user logs on to the online bookshop, selects some books and adds them to his cart. He enters his
billing address and finally submits the order. HTTP cannot track session as it is stateless in nature and user
thinks that the choices made on page1 are remembered on page3.
Q. 28
www.freeittips.com | solved by Saher
Q.29
By using “web Service” for your application. Using web service, service users and service providers can be
dynamically connected.
Q.30
Q.31
Input.jsp //extra file in which we will get input from user in html form, this file is optional.
I didn’t write the complete code in this file because of the fact that it is not necessary.
<html>
<body>
</body>
</html>
TopView.jsp
<html>
<body>
</body>
</html>
BottomView.jsp
<html>
<body>
<div style="position:absolute;bottom:0;">
%>
</body>
</html>
VuHome.jsp
<html>
<body>
%>
</body>
</html>
Q.34:
Note: you are not required to write complete code. Just write code which will read from data and send
response to Welcome or Error page.
Login page:
<%
try{
String id = request.getParameter("userid");
String pwd = request.getParameter("pwd");
// comparing id & password with fix values
if(id.equals("vulms") && pwd.equals("admin")) {
// redirectign user to welcome.jsp
response.sendRedirect("welcome.jsp");
} else {
// redirecting user to error.jsp
response.sendRedirect("error.jsp"); }catch (Exception e) {
System.out.println(e.getMessage());
}
%>
Q.35: Being a java developer you have given a task define two initialization parameters. Define first
parameter for text file (out.txt) and other for DSN (studentDSN). You are required to write only necessary
code.
<init-param>//defining param 1
<param-name> out</param-name>
<param-value> out.txt</param-value>
</init-param>
<init-param> //defining param 2
<param-name> DSN </param-name>
<param-value> studentDSN </param-value> </init-param>
Q:36 Being a java developer you have given a task read two initialization parameters. Read first parameter
for text file (out) and other for DSN (studentDSN). You are required to write only necessary code.
TEXT FILE:
String out;
super.init(config);
out = config.getInitParameter("out");
Student DSN:
String student;
super.init(config);
student = config.getInitParameter("DSN”);
Q:37 Write the purpose of hash maps in session tracking through cookies?
HashMap is used to store information as key and values pairs. It is used in session tracking to store values
against keys and then retrieve that values when needed. Hash map has some advantages like it accept null
values and faster.
In the session tracking the HashMap store the individual user session information and Cookie (like JSESSIONID,
with unique value) is used to keep the unique “session ID” associated with each user. Then the session ID is
passed back and forth between user and the server and is used to retrieve the HashMap (session Information)
of the user from the HashMap at the server.
Q.38: What is other technique to remove server side over head while maintaining the state of user?
Once an HTTP transaction is finished, the server forgets all about it. Even if the same remote user connects a
few seconds later, from the server's point of view it's a completely new interaction and the script has to
reconstruct the previous interaction's state. The main issue in preserving state information is where to store it.
They can be broadly broken down into client-side and server-side.
Three typical solutions come across to accomplish session tracking and saving state of user. These are:
1. Cookies
2. URL Rewriting
3. Hidden Fields
Q.39: Being a java web developer you know each tag handler class must inherit from another class .what is
the name of that class?
Tag Handler is also a java class that is implicitly called when the associated tag is encountered in the JSP. Must
implement SimpleTag interface. Usually extend from SimpleTagSupport class that has already implemented
SimpleTag interface.
This operator can be applied to arrays & collections implementing List interface e.g. ArrayListetc.
Moreover, this operator can also be applied to collections implementing Map interface e.g. HashMapetc.
o For example,${ myMap[“id”] }returns the value associated with the id.
Q.41:Is it necessary that every try block must be followed by a catch block given reason to support your
answer?
Answer
The method can be accessed in same class, sub-class and same package.
Answer
Answer
Answer
What steps will we take in order to test whether the tomcat server is running or not?
Answer
Write the forms of Standard Directory Structure; which is used for the development of the web
components?
Answer
Answer
Suppose we have a program with main() method having static declaration and in another scenario without
static declaration. What could go wrong in either case?
Answer
………
Compiler generate the runn time error because the declaration is not mention because the P is small in
declare as public
What impact a JavaBeans object can produce when it is stored in Page scope?
Answer
What impact a JavaBeans object can produce when it is stored in Session object?
Answer
4. Presentation Layer
5. Business Layer
6. Data Layer
Answer
J2EE technology
Answer
7. Cookies are persistent as URL rewriting is not persistent and lost for the current secession.
8. Cookies are appropriate for both types of requests e.g. get and post where as the URL rewriting is
limited to get method only.
9. Does not produce any harm if the page is bookmarked.
10. Cookies are created by server just one therefore not communication and computational overhead
as in URL rewriting with every request.
11. If the server does not assign unique ID in URL rewriting the really creates problem where as this
problem does not exist in cookies.