0% found this document useful (0 votes)
28 views20 pages

CS506 FinalTerm Subjective Solved 2014

Uploaded by

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

CS506 FinalTerm Subjective Solved 2014

Uploaded by

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

CS506 Final Term Current Subjective Solved Year (2014)

Solved by: Saher (Well Wisher / Aqualeo)

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:

Thread.MAX_PRIORITY used to assign maximum priority

Q:Why thread is called light weight? (2)

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.

Q: syntax of El language. (2)

Answer:

${valid expression}

Q: why JSp support run time exception handling? (2)

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:

<%@ page errorPage="error.jsp" %>

redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during
request processing.

Q: cookies ka code writes krna tha (2)

Answer:

Cookie c = new cookie(“name”, “value”);

www.freeittips.com | solved by saher


Q: EJBs and JSp in which servers they run?(3)

Answer:

EJB runs on Application Server.

JSP runs on web server.

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.

Q: what happen when join() method is called in thread. (3)

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

thread to block efficiently until thread2 finishes its run() method

• 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:

String msg = "";

boolean repeatVisitor = false;

// reading cookies

Cookie[] cookies = request.getCookies();

www.freeittips.com | solved by saher


// if cookies are returned from request object

if (cookies != null) {

//search for cookie -- repeat

for (int i = 0; i < cookies.length; i++) {

// retrieving one cookie out of array

Cookie c = cookies[i];

// retrieving name & value of the cookie

String name = c.getName();

String val = c.getValue();

// confirming if cookie name equals“repeat” and

// value equals “yes”

if( name.equals("repeat") && val.equals("yes"))

msg= "Welcome Back";

repeatVisitor = true;

break; }

} // end for

} // end if

// if no cookie with name “repeat” is found

if (repeatVisitor== false)

// create a new cookie

Cookie c1 = new Cookie("repeat", "yes");

www.freeittips.com | solved by saher


// setting time after which cookies expires

c1.setMaxAge(60);

// adding cookie to the response

response.addCookie(c1);

msg = "Welcome Aboard";}

Q: different steps to write code thread creation interface .(5)

Answer:

Threads Creation Steps Using Interface

• Step 1 - Implement the Runnable Interface

class Worker implements Runnable

• Step 2 - Provide an Implementation of run() method

public void run( ){ }

• Step 3 - Instantiate Thread class object by passing Runnable object in the constructor

Worker w = new Worker (“first”);

Thread t = new Thread (w);

• Step 4 - Start thread by calling start() method

t.start();

Q: explain literals of EL. (5)

www.freeittips.com | solved by saher


Q: write the name of JSP scopes in EL. what happen if these scopes will miss. (5)

• 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.

Q 1 Define type <jsp:studenttag.study> </jsp:studenttag.study> (2marks)

Answer:

Tag with attribute


Q 2 Differentiate b/w java classes and servlet ? 2

Q 3 Code for creating user session?? 3

Answer:

1. Getting the user’ssession object

To get the user’s session object, we call the getSession()method of HttpServeltRequest that
returns the object of HttpSession

HttpSession sess = request.getSession(true);

www.freeittips.com | solved by saher


2. Storing information in a Session

To store information in Session object (sess), we use setAttribute() method of HttpSession


class. Session object works like a HashMap, so it is able to store any java object against key. So
you can store numberof keys and their values in pair form. For example,

sess.setAttribute(“sessionid”, ”123”);

3. Looking up information associated with a Session

To retrieve back the stored information from session object, getAttribute()method of

HttpSession class is used. For example,

String sid=(String)sess.getAttribute(“sessionid”);

4. Terminating a Session

sess.invalidate()

Q 4 Why HTTP is stateless protocol ? give example.3

Answer: Pageno:285 Chp:30

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

Q 6 Wite any 6 EL operators? 3

www.freeittips.com | solved by saher


Q 7 JSP code for action element <jsp: setProperty name = "name" value = "raza"/>

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

getRequestDispatcher(String path) of ServletContext returns a RequestDispatcher object

associated with the resource at the given path passed as a parameter.

Two important methods of RequestDispatcher are:

• forward(ServletRequest req, ServletResponse resp)

• include(ServletRequest req, ServletResponse resp)


Q 9 what do you know about EL (expression language)? 5

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

www.freeittips.com | solved by saher


and the XPath expression language.
Q 10 What steps perfom to make application in tomcat ? 5

Answer:

To make a new application e.g myapp in tomcat you need a specific folder hierarchy.

• Create a folder named myapp in C:\jakarta-tomcat-5.5.9\webapps folder. This name will


also appear in the URL for your application. For example

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.

Remember WEB-INFis case sensitive and it is notWEB_INF

• Configuration files such as web.xmlwill go in WEB-INF folder

(C:\jakarta-tomcat-5.5.9\webapps\myapp\WEB-INF)

• Create another folder inside WEB-INFfolder and change its name to classes.

Remember classesname is also case sensitive.

• Servlets and Java Beans will go in classes folder (C:\jakarta-tomcat-


5.5.9\webapps\myapp\WEB-INF\classes)

Q 11 Write javaBean code which pass tow variable name and address ?

Which layer support applet and servlet?

Answer:

Client Presentation layer support applet.

Server Presentation Layer supports servlet.

www.freeittips.com | solved by saher


difference between applet and servlet

Join thread ka code:

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

thread to block efficiently until thread2 finishes its run() method

• Calling join method can throw InterruptedException, so you must use try-catch block to

handle it

403 error code

Answer:

403: Indicates that access to the requested resource has been denied.

Nugget of EL expression:

Answer:

Syntax of EL

Expressions and identifiers

Arthimetic , logical and relational Operator.

Access implicit objects

Access map , beans,arrays and lists etc

Automatic type conversion.

Get a number in scriplets and takes its sequare and show result in expression

Answer:

<%

Int n,square;

www.freeittips.com | solved by saher


<%>

Java bean

Correct errors in codes exception throw ka tha code

Difference btwn template and non template

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.

What is the alternative of constructor in servlet?

Answer:

Init() method is used as constructor in servlet. There is no constructor available in Servlet so


this

urges its use for one time initialization (loading of resources, setting of parameters etc) just
as

the init()method of applet.

Initialize stage has the following characteristics and usage

• Executed once, when the servlet gets loaded for the first time

• Not called for each client request

• The above two points make it an ideal place to perform the startup tasks which are done
in constructor in a normal class.

www.freeittips.com | solved by saher


2. What does 200 code indicate?

Answer:

200-299

ƒ Values in the 200s signify thatthe request was successful.

ƒ 200: Means everything is fine.

3. What is other name of business layer?

Answer:

Application layer

4. Write methods used to get values from HTML page?

Answer:

<% String n = request.getParameter("id");

%>

5. What is alternative code of jsp special tag useBean?

Answer:

jsp:useBean is being equivalent to building an object in scriptlet. For example to build an object
of MyBean

using scriptlet is:

<%

MyBean m = new MyBean( );

%>

Achieving above functionality using jsp:useBean action element will look like this:

<jsp:useBean id = “m” scope = “page” class=“vu.MyBean” >

6. Write path of JAVA_HOME variable?

Answer:

www.freeittips.com | solved by saher


JAVA_HOME indicates the root directory of your jdk. Set the JAVA_HOME environment
variable to tell Tomcat, where to find java

• This variable should list the base JDK installation directory, not the bin subdirectory

8. Convert this ordinary code to java beans.

9. How servlet is more efficient than CGI?

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:

${ (x >= 5) && (x <10) }

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:

13. Write tag library of these

-> EL based internationalization

-> RT based xml

Answer:

<%@ taglib uri=” ” prefix=”fmt”>

<%@ taglib uri=” ” prefix=”fmt_rt”>

My today paper

www.freeittips.com | solved by saher


Why controller is implemented as servlet?........2

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.

How JSP pages are informed about the error page?……..2

Answer:

<%@ page isErrorPage=”true” %> //

IsError Page is used to declare a jsp page as error page

HTTP is a stateless protocol, what do we need to do in order to make it possible for it to


maintain states?……..2

Answer:

Three typical solutions comeacross to accomplish session tracking. These are:

1. Cookies

2. URL Rewriting

3. Hidden Fields

Correct the following path for setting JAVA_HOME variable

C:\program files\java\JDK-Root-Directory\bin……..2

Answer:

C:\program files\java\JDK-Root-Directory\

Give one advantage and two disadvantage of page centric approach……..3

www.freeittips.com | solved by saher


Answer:

Easy to implement and to get start with web based application development

The page centric approach has the following drawbacks

1. The maintenance of the application becomes a nightmare.

2. A lot of code is also get duplicated.

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

never terminate, sleep, or wait for I/O indefinitely.

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

What happens if:

We set true as a request.getSession(true);

We set false as a request.getSession(false);……..5

www.freeittips.com | solved by saher


Answer:

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){

If(thisform.name.value=”Null” || this form.name.value=””){

Alert(“Phone number is required”);

Return false;

</SCRIPT>

</HEAD>

What is the hidden comment in JSP? Explain this syntax

Answer:

JSP comment:

These comments are not displayed in browser and have format like:

www.freeittips.com | solved by saher


<%-- comment text --%>

<%…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-class> VFirstServlet </servlet-class></servlet>

<servlet > <servlet-name>MyFirstServlet</servlet-name>

<servlet-mapping> <url-pattern> /ViewServlet </url-pattern>

</servlet-mapping> </servlet>

</web-app>

Data transfer 5 marks ka


Web Service and web pages difference 3 marks

Web page

Has a UI

Interacts with user

Works with web browser client

Web Service

No GUI

Interacts with application

www.freeittips.com | solved by saher


Works with any type of client

ka aur ek action element of JSP likhne ka method 3 marks ka


Answer:

<jsp:actionElement attribute=”val”> body</jsp:actionElement>

 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:

<%!

Public int sum(int op1, int op2){

Return op1+op2

%>

<%

String op1 = request.getParameter(“num1”);

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:

 Differentiate between MVC1 and MVC 2 with respect to view.

www.freeittips.com | solved by saher


Answer:

MVC1

JSP is used to manage requests and give response.

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

JSP page is only used for processing views

Controller is used to handle requests.

Response Is given through JSP pages

What is the disadvantage of threading using inheritance?

Write the two ways to read initialization parameter from servlet?

Create a class “AddBean “ Pass three values val1,val2,result. Also create a AddResult()
method which returns the sum of values.

What is difference b/w EJB and JavaBeans.

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.

Write a Thread procedure that displays following output.

www.freeittips.com | solved by saher


Answer: Page no : 217

// File PriorityEx.java

public class PriorityEx{

public static void main (String args[ ]){

//instantiate two objects

Worker first = new Worker (“first job”);

Worker second = new Worker (“second job”);

//create two objects

Thread t1 = new Thread (first );

Thread t2 = new Thread (second);

//set thread priorities

t1.setPriority (Thread.MIN_PRIORITY);

t2.setPriority (Thread.MAX_PRIORITY);

//start threads to execute

t1.start();

www.freeittips.com | solved by saher


t2.start();

}//end main

} // end class

How to declare functions and variables in Jsp action elements.

Write the equivalent code of scriptlet:

<jsp:out name=”id” default=0 />

Answer:

www.freeittips.com | solved by saher

You might also like