September 2012

JSP Interview / Practicer Questions

1. TLD files may be placed in any sub directory of -------

Ans: WEB_INF.

2. Assuming the standard JSTL prefix conventions are used, which JSTL tags would be used to iterate over collection of objects?
A. <x:forEach>
B. <c:iterate>
c. <c:forEach>
d. <c:forTokens>
e. <logic:iterates>
f. <logic:forEach>

Ans: <c:forEach>

3. <x:forEach> used for iterating over --------expressions.

Ans: XPath

4. <c:forTokens> used for iterating over --------- within a single string.

Ans : tokens

5. Which simple tag mechanism will tell a JSO page to stop processing?

a. Return SKIP_PAGE from the doTag method
b. Return SKIP_PAGE from the doEndTag method
c. Throw a SkipPageException from the doTag method
d. Throw a SKipPageException from doEndTag method

Ans : Throw a SkipPageException from the doTag method

6. Which are true about the classic tag model?

a. The tag interface can only be used to create empty tags.
b. The SKIP_PAGE constant is a valid return value of the doEndTag method.
c. The EVAL_BODY_BUFFERED constant is a valid return value of the doAfterBody method
d. The Tag interface only provides two values for the return value of the doStartTag method: SKIP_BODY and EVAl_BODY.
e. There are three tag interfaces Tag, Iteration Tag, and BodayTag, but only two built_in base classes: TagSupport and

BodyTagSupport

Ans: b and e.

7. Which about the findAncestorWit
hClass method are true?

a. It requires one parameter: A Class
b. It is a static method in the TagSupport class
c. It is a non-static method in the TagSupport class.
d. It is not defined by any of the standard JSP tag interfaces.
e. It requires two parameters : A tag and a class
f. It requires one parameter : A string representing the name of the taf to be found.
g. It requires two parameters : A Tag and a String , representing the name of the tag to be found.

Ans: b, d and e

8. Which must be true if you want to use dynamic attributes for a simple tag handler?

a. Your simple tag must not declare any static tag attributes
b. Your simple tag must use the element in the TLD.
c. Your simple tag handler must implement the DynamicAttributes interface

Ans: b and c

9. Which is true about tag files?

a. A tag file may be placed in any subdirectory of WEb_INF
b. A tag file must
have the file extension of .tag and .tags

Ans : b

10 which about doAfterBody() is true?

a. doAfterBody() is only called on tags that extend TagSupport.
b. doAfterBody() is only called on tags that extend Iteration TagSupport
c. Assuming no exceptions occur, doAfterBody() is called after doStartTag(0 for any tag that implements Iteration Tag and

returns EVAL_BODY_INCLUDE from doStarttag()

Ans: c

JSP Interview / Practicer Questions - II

11. <%a taglib prefix="my" uri="/WEB-INF/myTags.tld" %>
<my:tag1>
<%--JSP content --%>
</my:tag1>

The tag handler for my:tag1 is TagHandler and extends TagSupport. What happens when the instance of TagHandler calls the getParent method?

a. A JSPException is thrown
b. The null value is returned
c. A NullPointerException is thrown
d. An IllegalStateException is thrown

Ans : b

12. Which is true about the lifecycle of a Simple tag?

a. The release method is called after the dotag method
b. The setJSPBody method is always called before the dotags method.
c. The setParent and setJSPContext methods are called immediately before the tag attributes are set.

Ans: c

13. Public Class Exampletag extends TagSupport
{
Private String param;
Public void setParam(String p) { param = p; }
Public int doStartTag () throws JspException {
// insert code here
// more code here
}
}

which inserted at line 14. Would be gauaranteed to assign the value of the request scoped attribute param to the local variable p?

Ans. String p = pageContext.getRequest().getAttribute("param");

14. Which are valid method calls on a PageContext object?

Answers :
1. getAttribute("key");
2. findAttribute("key");
3. getAttributeScopt("key");
4. getAttribute("key", PageContext.SESSION_SCOPE);

15. Which is most efficient JspContext method to call to access an attribute that is known to be in application scope?

a. getPageContext()
b. getAttribute(String);
c. findAttribute(String);
d. getAttribute(String int);

Ans : d

16. What is the best strategy when implementing a custom tag for finding the value of an attribute whose scope is unknown?

a. Check all scopes with single
pageContext.getAttribute(String) call
b. Check all scopes with single
pageContext.findAttribute(string) call
c. Check each scope with calls to
pageContext.getAttribute(String, int)
Ans : b

17. Tag File Model

Ans : 1. The <jsp:doBody> standard action can only be used in Tag Files.
2. The Allowable file extensions for tag Files are .tag and .tagx
3. For each attribute declared and specified in a tag File, the container creates a page-scoped attribute with the same name.

18. Which is valid tag files?
a. <jsp::dpBody/>
b. <jsp:invoke fragement="frag"/>
c. <%@page imports="java.util.Date">
d. <%@variable name-given ="date" variable-class="java.utilDate" %>
e. <%@ attribute name="name" value="blank" type="java.lang.String" %>

Ans: a, b, d

19. Which returns the enclosing tag when called from within a tag handler class?

a. getParent();
b. getAncestor();
c. findAncestor();
d. getEnclosingTag()

Ans : a

20. Given a web applications tructure
/WEB-INF/tags/mytags/mytags/tag1.tag
/WEB-INF/tags/tags/tag2.tag
/WEB-INF/tags3.tag
/tag4.tag

which tags could be used by an appropriate taglib directive?

a. Tag1.tag
b. Tag2.tag
c. Tag3.tag
d. Tag4.tag

Ans: Tag1.tag and Tag2.tag

Is it possible to use multiple input files in easytrive? Or Merge the input files based on position validation in easytrive?

Yes, both were possible in easytrive and it will read first file till end of file then go to next one.

//FILEIN DD DISP=SHR,DSN=XXXXXXX.XXXXXXXX.XXXXX.XXXX.A1
//
DD DISP=SHR,DSN=XXXXXXX.XXXXXXXX.XXXXX.XXXX.A2
//
DD DISP=SHR,DSN=XXXXXXX.XXXXXXXX.XXXXX.XXXX.A3
//
DD DISP=SHR,DSN=XXXXXXX.XXXXXXXX.XXXXX.XXXX.A4
//
DD DISP=SHR,DSN=XXXXXXX.XXXXXXXX.XXXXX.XXXX.A5
//FILEOUT DD DSN=XXXXXXX.XXXX.XXXXXXXX.FILEOT,
//
DISP=(NEW,CATLG,DELETE),SPACE=(CYL,(XXX,XXX),RLSE),
//
DCB=(LRECL=80,RECFM=FB,BLKSIZE=0),UNIT=XXXXX
//SYSIN
DD *
FILE FILEIN
IN-XXX-TYP
63 1
A
IN-XXX
22 9
A
*
FILE FILEOUT
XXX
01 9
A
I
W
03
N 0
JOB INPUT FILEIN
IF IN-XXX-TYP = 'X'
XXX = IN-XXX
PUT FILEOUT
END-IF
*

It will read the first file first record and see the 63rd position is having value as ‘X’ then write into
output file else it will go and read next record. Once it reached first file end of record then go to
second file and continue the process. The job completes only 5 input file has been read from 1 st record
to last record.

Servlet Questions to practice and prepare for interview

1. What is the function of servlet context:

Ans: Gives the information of the container.

2. What is the function of the page context?

Ans: Gives the information of the request

Is it possible to recover the dataset that got deleted in mainframe?

Use the option 6 – Command (Enter TSO or Workstation commands) and place the below in ===>

HLIST DSN('XXXXXXX.XXXX.XXX.XXXXXXXX') BOTH – This is to find out in which volume (VOL)
deleted dataset present. It will show with dataset creation and volume that present based
on date you can use the volume in below command.

HRECOVER ('XXXXXXX.XXXX.XXX.XXXXXXXX') NEWNAME ('XXXXXXX.XXXX.XXXXXXX.XXX.XXXX’) VOL(XXX)

It will place the recovered dataset in new name from that volume.

Write multiple output files based on criteria by using easytrive.

//FILEIN DD DSN=XXXXXXX.XXXXXXXX.XXXXXXX.XXXXXXXX,DISP=SHR
//FILEOUT DD DSN=XXXXXXX.XXXXX.XXXXXXX.XXXXXXX.XXXXX.OUT1,
//
DISP=(NEW,CATLG,CATLG),UNIT=(XXXXX),
//
DCB=(RECFM=FB,LRECL=XX,BLKSIZE=0),
//
SPACE=(CYL,(XX,XX),RLSE)
//FILEOUT1 DD DSN=XXXXXXX.XXXXX.XXXXXXX.XXXXXXX.XXXXX.OUT2,

//
DISP=(NEW,CATLG,CATLG),UNIT=(XXXXX),
//
DCB=(RECFM=FB,LRECL=XX,BLKSIZE=0),
//
SPACE=(CYL,(XX,XX),RLSE)
//FILEOUT2 DD DSN=XXXXXXX.XXXXX.XXXXXXX.XXXXXXX.XXXXX.OUT2,
//
DISP=(NEW,CATLG,CATLG),UNIT=(SYSDA,12),
//
DCB=(RECFM=FB,LRECL=436,BLKSIZE=0),
//
SPACE=(CYL,(9000,500),RLSE)
//*
//SYSIN
DD *

FILEIN
XXXXXXXX-XXXX-XXXX-XX
01
07 N
XXXXXXXX-XXX-XXXX-XXX
45
01 A
FILE XXXXXXX
OXXXX
01
80 A
OUT-XXXXX
01
07 N
OUT-XXXXXX
09
01 A
FILE XXXXXXX1
OXXX2
01
80 A
FILE XXXXXXX2
OXXX3
01
80 A
XXXX7
W
1
N
XXXXX
W
5
N VALUE 0
*-----------------------------------------------*
* PROCEDURE AREA
*
*-----------------------------------------------*
JOB INPUT FILEIN
OUT-XXXXX = XXXXXXXX-XXXX-XXXX-XX
OUT-XXXXXX = XXXXXXXX-XXX-XXXX-XXX
OXXX2 = ORXXX
OXXX3 = OXXXX
IF XXXXXXXX-XXX-XXXX-XXX = 'M'
PUT XXXXXXX
ELSE
IF XXXXXXXX-XXX-XXXX-XXX = 'T'
PUT XXXXXXX1
ELSE
PUT XXXXXXX2
END-IF
END-IF
END-IF

COMPARE TWO FILES AND WRITE THE RECORDS THAT WERE NOT PRESENT IN FIRST FILE.

//*--------------------------------------------------------------------
//* COMPARES BOTH THE GDG AND WRITE THE RECORDS THAT ARE NOT PRESENT IN
//* GDG(-1) TO A PS.
//*--------------------------------------------------------------------
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//IN1 DD DSN=...
GDG(-1) - FB/80
//IN2 DD DSN=...
GDG(0) - FB/80
//SORTOUT DD DSN=... OUTPUT FILE - FB/80
//SYSIN DD *
JOINKEYS F1=IN1,FIELDS=(Starting position, till how much position you want to compare,
format of the key position values)
JOINKEYS F2=IN2,FIELDS=( Starting position, till how much position you want to compare,
format of the key position values)
JOIN UNPAIRED,F2,ONLY
OPTION COPY
/*

How to find the records count in particular file.

//CTRCDS EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=XXXXXXX.XXXXXX.XXXXXXXX.XXXX,DISP=SHR

//OUT DD DUMMY
//TOOLIN DD *
COUNT FROM(IN)
/*

How to check in particular file had empty or not.

//*--------------------------------------------------------------------
//*STEP RETURN RC=12, IF FILE IN IS EMPTY.
//*--------------------------------------------------------------------
//STEP1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=...
//TOOLIN DD *
COUNT FROM(IN) EMPTY
/*

How to use Database Call by using easytrive?

The PSB needs to specify in program execute step like below.
//XXXX EXEC XXXXXXXX,PROG=XXXXXXX,PSB=XXXXXXXX

%XXXXXXXX – Record layout for database which you want to use
JOB INPUT (XXXXXXXX) – Database name
RETRIEVE XXXXXXXX +
SELECT (XXXXXXXX ID 'XX')
IF XXXX-XX = 'XX'
It read the database and record found in it.
END-IF

How to read Database through input file by using easytrive?

The PSB needs to specify in program execute step like below.
//XXXX EXEC XXXXXXXX,PROG=XXXXXXX,PSB=XXXXXXXX
FILE HV01BPAA DLI(XXXXXXXX 1)
PCB-XXX-XXXX 1 8 A
PCB-XXXXXXX-XXXXX 9 2 A
PCB-STATUS-CODE 11 2 A
PCB-XXXX-XXXXXX 13 4 A
PCB-XXXXXXX-XXX 17 4 B
PCB-XXXXXXX-XXXX 21 8 A
PCB-XXXXXX-XXX-XX 29 4 B
PCB-XXX-XXXX-XXXXXXX 33 4 B
PCB-XXX-XX-XXXX 37 24 A
%XXXXXXXX
FILE INPFIL
XX-XXXX 1 50 A
XXXXXX 19 4 P 0

FILE OUTFILE
XXX-XXX 1 60 A
XXX-XXXX 1 8 N
*-----------------------------------------------*
* SSA-XXXX *
* ----------------------------------------------*
SSA-XXXXXXXX-QUAL W 26 A VALUE 'XXXXXXXX'
SSA-XXXXXXXX-LPA SSA-XXXXXXXX-QUAL +08 1 A VALUE '('
SSA-XXXXXXXX-XXX SSA-XXXXXXXX-QUAL +09 8 A VALUE 'XXXXXXXX'
SSA-XXXXXXXX-XXX SSA-XXXXXXXX-QUAL +17 2 A VALUE '= '
SSA-HV01SPA1-KEY SSA-XXXXXXXX-QUAL +19 6 A
SSA-XXXXXXXX-RPA SSA-XXXXXXXX-QUAL +25 1 A VALUE ')'
* ----------------------------------------------*
JOB INPUT FILEIN FINISH DISPLAY-CTR

PERFORM XXXXXXX-XXXX-XXXMENT
IF XXXX-XXXXXX-CODE = ' '
XXX-XXXX = DATABASE-XXXX
PUT OUTFILE
ELSE
DISPLAY 'XXXX-XXXXXX-CODE ' XXXX-XXXXXX-CODE
STOP
END-IF
*************************************************
GXXXXXX-XXXX-XXXMENT. PROC
*************************************************
FUNCTION = 'GU '
XXXXXXXX-XXXX-XX = XXXX-XX
CPRCSCPY-PROCESS-COMP = 11
SSA-XXXXXXXX-LPA = '('
SSA-XXXXXXXX-KEY = XXXXXXXX
SSA-COUNT = 1
DLI XXXXXXXX XXXXXXXX FUNCTION +
XXXXX XXX-XXXXX +
SSA (SSA-XXXXXXXX-QUAL)
XXXX-XXXXXX-CODE = PCB-STATUS-CODE
END-PROC

How to use DB2 Call by using easytrive?

PARM DB2SSID('XXXX')
*----------------------------------------------------------------
*
FILE XXXXOUT FB (080 0)
OU_XXXXXX 01 080 A
OU_XXX 01 5 A
FILLER1 06 1 A
OU_XXX1 07 9 A
FILLER2 16 1 A
OU_XXX2 17 9 A
FILLER3 26 1 A
*** WORKING STORAGE***
WS_XXX_XXX W 5 A
WS_XXX_XXX1 W 9 P
WS_XXX_XXX2 W 9 P
*
WS-XXXXXX W 1 A VALUE 'Y'
*
*----------------------------------------------------------------
JOB INPUT SQL

SELECT +
XXX_XXX_XXX, +
XXX_XXX_XXX1, +
XXX_XXX_XXX2 +
FROM +
XXXX.XXXX_XXXX_XXXX +
ORDER BY +
XXX_XXX_XXX +
INTO +
:WS_XXX_XXX, +
:WS_XXX_XXX1, +
:WS_XXX_XXX2

IF WS-XXXXXX = 'Y'
OU_XXXXXX = W-XXXXXX
PUT FILEOUT
WS-SWITCH = 'N'
END-IF

PERFORM XXXX_DATA
PUT XXXXOUT

GOTO JOB

XXXX_DATA. PROC

OU_XXX_XXX = WS_XXX_XXX
OU_XXX_XXX1 = WS_XXX_XXX1
OU_XXX_XXX2 = WS_XXX_XXX2
FILLER1 = X'05'
FILLER2 = X'05'
FILLER3 = X'05'
FILLER4 = X'05'
FILLER5 = X'05'
FILLER6 = X'05'

END-PROC

Mainframe - Is it possible to copy only first 100 records from one file to other file?

Yes, it’s possible to copy by using SORT utility.

SUM FIELDS=(starting position of first column, length of first column, based on variable format use
PD or ZD),STOPAFT=(in which record you want to STOP copy).

Mainframe - Is it possible to skip first 100 records while copy from one file to other file?

Yes, it’s possible by using SORT utility.

SUM FIELDS=(starting position of first column, length of first column, based on variable format use
PD or ZD),SKIPREC=(how many records you want to SKIP copy).

Example :

//DDName EXEC PGM=SORT
//SORTIN DD DSN=XXXXXXXXXXXXXXXXX,
// DISP=SHR
//SORTOUT DD DSN=XXXXXXXXXXXXXXXXXXXX,
// DISP=(NEW,CATLG,DELETE),
// UNIT=XXXXX,SPACE=(XXX,(XX,XX),XXXX),
// DCB=(*.SORTIN) Output file created using properties from input file.
//SORTWK01 DD UNIT=XXXXX,SPACE=(XXX,(X,X))
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,7,CH,A,9,2,CH,D),SKIPREC=(100)
SORT FIELDS
(1,7,CH,A) – 1 – starting position of first column, 7 – length of the variable, CH – Alphabetic or

alphanumeric, A – Ascending.
(9,2,CH,A) - 9 - starting position second column, 2 - length of the variable, CH - Alphabetic or
alphanumeric, D - Ascending.
SKIPREC
(100) - 100 – first 100 records will be skipped in input file while copy to other file.