CS506 FinalTerm Subjective Solved 2014
CS506 FinalTerm Subjective Solved 2014
www.freeittips.com
All time you will not get same thread priority as you except. Why? Identify the predefined
constant used to assign thread priority.
Answer:
Answer:
Threads are light weight as compared to processes because they take fewer resources then a
process. A thread is easy to create and destroy. Threads share the same address space i.e.
multiple threads can share the memory variables directly, and therefore may require more
complex synchronization logic to avoid deadlocks and starvation.
Answer:
${valid expression}
Answer:
You can use the errorPage attribute of the page directive to have uncaught run-time exceptions
automatically forwarded to an error processing page. For example:
redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during
request processing.
Answer:
Answer:
Q: what will impact on java bean object is produce when it is stored in servlet request
object?? (3)
Answer:
This value signifies that, in addition to being bound to local variable, the bean object should be
placed in ServletRequest object for the duration of the current request. In other words, until
you continue to forward the request to another JSP/servlet, the beans values are available.
Answer:
Used when a thread wants to wait for another thread to complete its run() method
• For example, if thread2 sent the thread2.join() message, it causes the currently executing
• Calling join method can throw InterruptedException, so you must use try-catch block to
handle it
Q: aik code write krna tha k client ki request jo hai wo repeat visiter hai. complete nahi likhna
tha just repeat visitor ka (5)
Answer:
// reading cookies
if (cookies != null) {
Cookie c = cookies[i];
repeatVisitor = true;
break; }
} // end for
} // end if
if (repeatVisitor== false)
c1.setMaxAge(60);
response.addCookie(c1);
Answer:
• Step 3 - Instantiate Thread class object by passing Runnable object in the constructor
t.start();
• Page Scope
• Request Scope
• Session Scope
• Application Scope
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:
Answer:
To get the user’s session object, we call the getSession()method of HttpServeltRequest that
returns the object of HttpSession
sess.setAttribute(“sessionid”, ”123”);
String sid=(String)sess.getAttribute(“sessionid”);
4. Terminating a Session
sess.invalidate()
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 5 Write 6 request which client send to server ? 3
Answer:
Name.setproperty(“raza”);
Q 8 Comlpete request dispatcher code half was given ? 5
Answer:
RequestDispatcher provides a way to forward or include data from another source. The method
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
Answer:
To make a new application e.g myapp in tomcat you need a specific folder hierarchy.
http://localhost:8080/myapp/index.html
• All JSP and html files will be kept in main application folder (C:\jakarta- tomcat-
.5.9\webapps\myapp)
• Create another folder inside myapp folder and change its name to WEB-INF.
(C:\jakarta-tomcat-5.5.9\webapps\myapp\WEB-INF)
• Create another folder inside WEB-INFfolder and change its name to classes.
Q 11 Write javaBean code which pass tow variable name and address ?
Answer:
Answer:
• Used when a thread wants towait for another thread to complete its run() method
• For example, if thread2 sent the thread2.join() message, it causes the currently executing
• Calling join method can throw InterruptedException, so you must use try-catch block to
handle it
Answer:
403: Indicates that access to the requested resource has been denied.
Nugget of EL expression:
Answer:
Syntax of EL
Get a number in scriplets and takes its sequare and show result in expression
Answer:
<%
Int n,square;
Java bean
Initially C based CGI programs were on the server. Then template based technologies like ASP
and PHP were then introduced which allowed ease of use for designing complex web pages.
Sun Java introduced Servlets and JSP that provided more speed and security as well as better
tools for web page creation.
Answer:
urges its use for one time initialization (loading of resources, setting of parameters etc) just
as
• Executed once, when the servlet gets loaded for the first time
• The above two points make it an ideal place to perform the startup tasks which are done
in constructor in a normal class.
Answer:
200-299
Answer:
Application layer
Answer:
%>
Answer:
jsp:useBean is being equivalent to building an object in scriptlet. For example to build an object
of MyBean
<%
%>
Achieving above functionality using jsp:useBean action element will look like this:
Answer:
• This variable should list the base JDK installation directory, not the bin subdirectory
Answer:
Sun Microsystems introduced the Servlet API, in the later half of 1997, positioning it as a
powerful alternative for CGI developers who were looking around for an elegant solution that
was more efficient and portable than CGI (Common Gateway Interface) programming.
10. Write an EL expression which check that x is greater than equal to 5 and less than 10.
Answer:
11. As a java developer you have to keep record of visiting users who adds contents to your
site how you will do it?
Answer:
Answer:
My today paper
Answer:
JSP that is performing the job of controller is doing only processing and there is no view
available of it. It includes the logic of selecting JSP and to retrieve/store records from/to dataset
using JavaBeans. But remember the reason for introducing JSPs? JavaServer Pages are built for
presentation (view)only so JSP is really not a good place for such kind of logic. Concluding,
what’s the option we have? The answer is, use Servlets as controller.
Answer:
Answer:
1. Cookies
2. URL Rewriting
3. Hidden Fields
C:\program files\java\JDK-Root-Directory\bin……..2
Answer:
C:\program files\java\JDK-Root-Directory\
Easy to implement and to get start with web based application development
3. The code becomes a mixture of presentation, business and data access logic.
What problem can arise if a process A that needs 20 iteration to execute has highest priority
while process B needs 5 iteration but has lowest priority? Explain with reason……..3
Answer: Starvation can occur for lower-priority threads if the higher-priority threads
Which type of HttpRequest object methods are used to read the HTML form data submitted
by user?………3
Answer:
• getParameter(String name)
o Used to retrieve a single form parameter and returns String corresponding to name
specified.
• getParameterValues(String name)
o Returns an array of Strings objects containing all of the given values of the given
request parameter.
• getParameterNames()
o If you are unsure about the parameter names, this method will be helpful
If true is passed to the getSession() method, this method returns the current session associated
with this request, or, if the request does not have a session, it creates a new one. We can
confirm whether this session object (sess) is newly created or returned by using
isNew()method of HttpSession. In case of passing false, null is returned if the session doesn’t
exist.
Write a script that validate the phone number field in the form such a way if user leaves it
empty it receives a message “ phone number is required. It can’t be left empty……..5
Answer:
<HTML>
<HEAD>
<SCRIPT TYPE=”text/javascript”>
Function validateForm(thisform){
Return false;
</SCRIPT>
</HEAD>
Answer:
JSP comment:
These comments are not displayed in browser and have format like:
<%…comment…%>……..5
JSP comment:
These comments are not displayed in browser and have format like:
Write a web.xml for the servlet whose name is “MyFirstServlet” and its id is “VFirstServlet”.
This servlet is access through url name “ViewServlet”………5
Answer:
<web-app>
<servlet><servlet-name>MyFirstServlet</servlet-name>
</servlet-mapping> </servlet>
</web-app>
Web page
Has a UI
Web Service
No GUI
You have to add tow numbers getting from html field and declare a variable result in
decalarative tag and write the remaining code in scriptlets and write result in expression tag.
Answer:
<%!
Return op1+op2
%>
<%
String op2=request.getParameter(“num2”);
Int numb1=integer.parseInt(op1);
Int numb2=integer.parseInt(op2);
Res=sum(numb1, numb2);
%>
Sum is : <%=res%>
Write full code of using custom tag override dotag() method which will print “welcome to
custom tag.”
Answer:
MVC1
JSP that is performing the job of controller is doing only processing and there is no view
available of it. It includes the logic of selecting JSP and to retrieve/store records from/to dataset
using JavaBeans.
MVC 2
Create a class “AddBean “ Pass three values val1,val2,result. Also create a AddResult()
method which returns the sum of values.
Answer:
EJBs are special java class that are used to encapsulate business logic. They provide additional
benefits inbuilding up an application such as scalability, robustness, scalability etc
A java class that can be easily reused and composed to gather certain design conventions can
be a JavaBean.
// File PriorityEx.java
t1.setPriority (Thread.MIN_PRIORITY);
t2.setPriority (Thread.MAX_PRIORITY);
t1.start();
}//end main
} // end class
Answer: