0% found this document useful (0 votes)
353 views124 pages

Read - It Mt2 For 2-Sem

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1/ 124

Question

Option1
QNo
AY001 Which of the following process 1, Bytecode
converts Java programming verification m
language code to a set of
bytecodes? m

AY002 Which of the following values 1, 'true' m


is a type of the boolean data
type? m

Option2

Option3

Option4

2, Compilation 3, Class
m
loading m

4, Execution m

2, "true" m

4, boolean m

3, true m

AY003 Your program needs to use


1, import App; m 2, imports
the App class present in the
foo.bar.App;
foo.bar package. Which of the
m
following statements imports
the class to your program? m

3, import
foo.bar.*; m

AY004 Consider the following


statements:

3, Statement A 4, Both Statement A and


is false while Statement B are false. m
Statement B is
true. m

Statement A: String is a
primitive data type to
represent a sequence of
characters.
Statement B: You can declare
a String variable as:
String str="I am a
String";
Select the correct option for
the preceding statements: m

1, Stetement A is2, Both


true while
Statement A
Statement B is and
false. m
Statement B
are true. m

4, import foo.*; m

AY005 Consider the following


statements:

1, Both
2, Both
Statement A and Statement A
Statement B are and
Statement A: A constructor
true. m
Statement B
must have the same name as
are false. m
that of the class.
Statement B: The return type
of a constructor must be void.

3, Statement A 4, Statement A is false while 3


is true while Statement B is true. m
Statement B is
false. m

Select the correct option for


the preceding statements: m

AY006 Select the correct integer


1, 8 bits m
length for the int data type. m

2, 16 bits m

3, 32 bits m

4, 64 bits m

AY007 Which of the following is a


valid Java identifier? m

1, $const m

AY008 The _____________ option of 1, -cp m


the compiler enables you to
compile class files to a
different directory than that of
the source files. m

2, const m

3, long m

2, -source m 3, -g m

4, new m

4, -d m

AY009 Select the correct option that 1, java


2, javac
3, java
4, java MyApp m
shows the command to
class=MyApp m MyApp.java m MyApp.java m
execute the MyApp Java
class. m

AY010 To compile and execute Java


programs, you need to set the
PATH environment variable to
___________________. m

1, The working
directory that
contains the
source files of
the program. m

2, The
3, The
4, The installation directory of 3
java_root/lib java_root/bin the Java technology software.
directory,
directory,
m
where
where
java_root is java_root is
the installation the installation
directory of directory of the
the Java
Java
technology
technology
software. m software. m

AY011 ________ is the default value 1, 1 m


of the double datatype: m

2, 0.0D m

3, 1.0D m

AY012 The _________ variables of a 1, static m


class are created when the
class is loaded and continues
to exist as long as the class is
loaded. m

2, member m 3, local m

4, null m

4, instance m

AY013 All Java classes directly or


1, Main m
indirectly extends the _______
class. m

2, Class m

3, String m

4, Object m

AY014 In a Java program, a Manager 1, super(); m


class extends an Employee
super class. Which of the
following statement will you
use in the Manager class to
invoke the default constructor
of the Employee class? m

2,
Employee();
m

3,
4, Employee.super(); m
Manager.super
(); m

AY015 Consider the following code:


public class Example
{
public static void
main(String args[])
{
String [] direction =
{"East","West","North","South"
};

1, The code will 2, The code


execute and
will throw a
display South as runtime
the output. m
exception. m

3, The code
will execute
and display
North as the
output. m

4, The code will execute but 2


will not display any output. m

1, 0 m

3, 5 m

4, 6 m

System.out.println(direction[4])
;
}
}
What will be the outcome
when the preceding code is
executed?
m

AY016 Consider the following code:


public class Example
{
public static void main(String
[] args)
{
for(int i=1; i<5; i++)
{
System.out.println("Hello");
}
}
}
On execution how many times
the above code will display
the Hello word? m

2, 4 m

AY017 Consider the following code:

1, The code will


execute with the
public class Example{
output Hello
public static void main (String world Hello
args [])
world m
{
String str;
str = str+"Hello world";
System.out.println(str);
}
}

2, The code
will execute
with the
output Hello
world m

3, The code
will not
compile m

4, The code will compel but


will not execute. m

4, size() m

What will be the outcome on


compiling and executing the
preceding code? m

AY018 Which of the following options 1, size m


will you use to determine the
number of elements that an
array contains? m

2, length() m 3, length m

AY019 Which of the following options 1, &&&& m


is a short-circuit logical
operator? m

AY020 Consider the following code:


public class Example
{
static int num;
public static void
main(String args[])
{
System.out.println(num);
}
}
What will be the outcome on
executing the following code?
m

2, && m

3, | m

4, ! m

1, The code will 2, The code 3, The code 4, The code will throw an
2
execute and
will execute will execute
exception as the num variable
display null. m and display 0. and display 1. is not initialized. m
m
m

AY021 Which of the following code


will compile, execute, and
display the word Hello? m

1, public class
Example
{

2, public class 3, public class 4, public class Example


3
Example
Example
{
{
{
public static void
public static
public
public
main(String args[])
void main(String static void
static void
{
args[])
main(String main(String
String str1="hello";
{
args[])
args[])
String str2="Hello";
int
{
{
num1;
if(str1.equals(str2))
int
String
String
{
num2;
str1=new
str1="Hello";
String("Hello")
if(num1==num2) ;
String
System.out.println("Hello");
{
str2="Hello";
String
}
str2=new
System.out.printl String("Hello") if(str1==str2)
}
n("Hello");
;
{
}
m
}
if(str1==str2) System.out.pri
}
{ ntln("Hello");
}
m
}
System.out.pri
ntln("Hello");
}
}
} m
}
}
m

AY022 Consider the following code:


public class Example
{
public static void
main(String args[])
{
String [] names =
{"Linux","Unix","Windows","Ma
c OS"};
for(String list : names )
System.out.println(list);
}
}
Select the correct option for
the preceding code?
m

AY023 Consider the following


statements:
Statement A: When your
class extends a super class,
your class inherits all the
public methods of the super
class.
Statement B: When your class
extends a super class, your
class inherits all the
constructors of the super
class.
Select the correct option for
the preceding statements: m

1, The code will 2, The code


execute but will will not
not display any compile. m
output. m

3, The code 4, The code will compile but


will execute
will throw an exception on
and display
execution. m
Linux, Unix,
Windows, and
Mac OS. m

1, Both
2, Statement 3, Statement A 4, Both Statement A and
Statement A and A is true while is false while Statement B are false. m
Statement B are Statement B Statement B is
true. m
is false. m
true. m

AY024 Consider the following class


declaration:
class Example
{
/* class body*/
}

1, The Example
class is
accessible to all
classes m

2, The
Example
class is
accessible to
the classes
within the
same
package m

3, The
4, The Example class is
2
Example class accessible to its subclasses.
is not
m
accessible to
any classes m

Which of the following


statements is true regarding
the preceding class? m

AY025 Consider the following


statements:
Statement A: Operator ||
returns true if one of the
operands is true.
Statement B: Operator ||
returns false if both operands
are false.
Select the correct option for
the preceding statements: m

1, Both
2, Statement 3, Statement A 4, Both Statement A and
Statement A and A is true while is false while Statement B are false m
Statement B are Statement B Statement B is
true. m
is false. m
true. m

AY026 In a Java program, numArray 1, int


2, int
3,
4,
4
is an array initialized with int result=numArray result=numArr System.out.pri System.out.println(numArray[
values. Which of the following .size;
ay.length();
ntln(numArray[ numArray.length-1]); m
statement/statements, will you System.out.printl System.out.pri numArray.lengt
use to print the last int value n(result);
ntln(result); h]); m
stored in the array? m
m
m

AY027 Which of the following is NOT 1, switch (num) 2, int num = 3; 3, int num = 3; 4, switch (2)
a valid switch statement? m
{
switch
switch
{
case 1: (num)
(num)
System.out.printl
{
{
default:
n("Case 1");
System.out.println("Default
break;
case
case 3: Case");
case 2: 3:
System.out.pri
System.out.printl System.out.pri ntln("Case 3");
}
n("Case 2");
ntln("Case
m
break; 3");
continue;
case 3:
case
case 1:
System.out.printl 1:
System.out.pri
n("Case 3");
System.out.pri ntln("Case 1");
break; ntln("Case
default: 1");
continue;
System.out.printl
case
case 2:
n("Default
2:
System.out.pri
Case");
System.out.pri ntln("Case 2");
break; ntln("Case
}
2");
continue;
m
case
case 4:
4:
System.out.pri
System.out.pri ntln("Case 4");
ntln("Case
4");
}
m
}
m

AY028 Consider the following code:

1, The output
will display the
following:

2, The output 3, The output 4, There will be no output. m 2


will display
will display the
class Example
the following following:
{ public static void
infinitely:
main(String[] args)
The number is: 5
The number is:
{
int num=5;
The number is: 6 The number 5
do
{
The number is: 7 is: 5
m
The number is: 8 m
System.out.println("The
The number is: 9
number is: " + num);
The number is:
}
while (num < 10
10);
m
} }
Select the correct option for
above mentioned code. m

AY029 Consider the following


statements:
Statement A: In a switch
statement you can use the
return keyword instead of the
break keyword.
Statement B: In the switch
<expression> syntax, the
<expression> can evaluate to
a String value.
Select the correct option for
the preceding statements: m

1, Both
2, Statement 3, Statement A 4, Both Statement A and
Statement A and A is true while is false while Statement B are false. m
Statement B are Statement B Statement B is
true. m
is false. m
true. m

AY030 Consider the following


program:

1, 4-11 m

2, 2 m

3, -11 m

4, -3 m

class Example
{
public static void
main(String[] args)
{
int b = -11; b = b >>
2;
System.out.println(b);
}
}
What will be the output of the
above program?
m

AY031 Techunique Solutions is


1, Splash home 2, Menu home 3, Path-based 4, News-oriented home page 3
designing a website for a
page m
page m
home page m m
Goodways travels. One of the
requirements given to the
design team is that the
website should handle the
requirements of the
employees of Techunique,
travel agents and direct
customers separately. Apart
from that, the website should
give information related to the
new holiday packages
announced by Goodways. The
design team has decided to
create separate interfaces for
these three types of users.
Peter Williams, one of the
members of the design team,
has been given the task to
identify the home page
strategy for the website.
Which of the following home
page strategies should Peter
select for the travel website?
m

AY032 Joycee have developed a


1, Using white
website that allows the user to as background
view news of current affairs, color will make
entertainment, sports, and
the links
weather.
identifiable. m
Joycee kept the text style and
text size consistent throughout
the website. The website will
be accessed from mobile
phones. While designing the
website, Joycee used light
green as background color
and blue as text color. To
make the links identifiable, she
underlined the links and the
color of the visited links has
been set to purple. The
website is launched. When the
users started using the
website, they complained that
the links are not identifiable.
Identify which of the following
strategies should be selected
to rectify the problem? m
AY033 Newways software is
1, Menu home
designing an e-learning
page m
website for young students in
the age group of 10 to 12
years. Apart from providing
free learning opportunity, the
website will give information
related to the new tutorials
being launched by the
website. As the website is for
students, the design team is
focusing on keeping the lookand-feel of the website simple
but engaging. Currently, the
design team is working upon
the home page strategy for the
website. Which of the
following home page
strategies should be used by
the design team for the elearning website? m

2, Using black 3, Removing 4, Removing light green as


for
blue as text
background color will make
background color and
the links identifiable. m
color and blue purple as the
for visited
color for visited
links will make links will make
the links
the links
identifiable. m identifiable. m

2, News3, Path-based 4, Splash screen home page 4


oriented home home page m m
page m

AY034 John is designing a website 1, News2, Menu


3, Path-based 4, Splash screen Home page 2
for AT Services. The company oriented Home Home page m Home page m m
management wants the home page m
page to display the links of all
the 20 partner companies in
the home page. In addition,
the management does not
want John to create an
attractive home page because
it will primarily be used by the
employees of AT Services.
Identify the home page design
strategy that John should use.
m

AY035 Real software is developing a 1, The design


speech-based user interface team of Real
for blind people. However,
software should
speech based interface are
have used the
difficult to design and time
Sketching
given by the client is short. To technique
develop a functional interface because
without any errors, the
storyboard
company wants to first
technique would
evaluate the prototype. They only provide the
used the storyboard technique flow and
to demonstrate the
features of the
functionality of the application. interface. m
However, this technique was
unable to demonstrate the
interactive feature of the
application. Analyze and
provide solution for the above
scenario. m

2, The design 3, The design


team of Real team of Real
software
software
should have should have
used the
used the
Horizontal
Wizard of Oz
Prototyping technique
because
because
storyboard
storyboard
technique
technique
would only
would only
provide the provide the
flow of the
flow and
interface. m features of the
interface. m

4, The design team of Real 3


software should have used
the Vertical Prototyping
because storyboard
technique would only provide
the flow of the interface. m

AY036 Drivetech is in the process of 1, Conversing 2, Tangible


3, Direct
developing a speech-based should be used User Interface Manipulation
navigation system for the cars. to clearly show should be
should be
To check the functionality of the interaction of used to
used to clearly
the product, the company
the product with clearly show show the
uses the manipulating and
the system m
the interaction functionality of
navigating type of conceptual
of the product the product m
model. However, using this
with the
model the various features of
system m
the product could not be
visualized. Analyze the above
scenario and identify the
conceptual model that should
be used to give a fair idea
about the functionality of the
product. m

AY037 New Generation softwares is 1, Scenario


creating an application for the prototyping m
library management process.
To demonstrate the various
features and functionality of
the application, the company
used horizontal prototyping.
However, this technique did
not give detailed description of
the functionality of the
application. Analyze the
scenario and identify the
prototyping technique that
should be used by the
company. m

4, Ubiquitous Computing
should be used to show the
various ways of interacting
with the product m

2, Vertical
3, Sketching m 4, Wizard of Oz m
prototyping m

AY038 Red Sky IT Systems is


1, Scenario
designing a website for a
prototyping
news channel. To verify the
because it
requirements, Red Sky IT
covers both the
Systems has to develop a
features and the
prototype. The prototype must associated
show the navigation and flow functionalities of
of each news category, such the application.
as breaking news, sports, and m
weather.
Further, the website would
contain a subscription page.
The news channel has asked
Red Sky IT Systems to show
the detail subscription process
in the
prototype. Which of the
following prototyping
techniques should be used to
develop the prototype? m

2, Vertical
prototyping
because it
covers a set
of features
with in-depth
functionality.
m

3, Horizontal 4, Vertical Prototyping


Prototyping
because it covers all the
because it
features of the application
covers all the without their underlying
features of the functionality. m
application
without their
underlying
functionality. m

AY039 WebBizz got an offer to design 1,Storyboarding


a website for an entertainment because it
channel Znn. To verify the
describes each
requirements, WebBizz has to action of the
develop a prototype but they application
are running out of time. Due to sequentially. m
less manpower they could not
start developing the prototype
on time. Now, quickly they
have to explain through
prototype all the features the
websites. Further, Znn have
asked them to show them the
layout of the website. The
layout should explain the
positioning of various Web
page items, such as content,
graphics, and links.
Analyze the given factors and
identify which of the following
prototyping technique that
should be used to fulfill the
requirement. m

2, Wizard of 3, Sketching
Oz because it because it
is used to test explore the
an application design of the
without the
entire
existence of application
the
through visual
application. m brainstorming.
m

4, Horizontal prototyping
because it covers all the
features of the proposed
application. m

AY040 Which type of data gathering 1,


2, Naturalistic 3, Focus group 4, Interviews m
technique can be used to
Questionnaires observation m m
collect quantitive data? m
m

AY041 Which type of requirement


captures the system goals
with respect to effectiveness
and safety of a product? m

1, Usablity
2, Data
3, Functional 4, Non-functional
requirements m requirements requirements requirements m
m
m

AY042 Which of the following


1, Coherence m 2, Contextual 3, Participatory 4, Ethnography m
methods is used to collect and
design m
design m
interpret data from end users
to design an application? m

AY043 Which of the following


1, Non2, Functional 3, Data
4, User requirements m
requirements define the
functional
requirements requirements
constraints on the system and requirements m m
m
the conditions under which the
system must be developed? m

AY044 Which type of environmental 1, Physical


requirements addresses
environment m
questions related to the
hierarchy of the organization?
m

2,
3, Social
4, Technical environment m
Organizationa environment m
l environment
m

AY045 Which of the following should 1, Links m


be used for easy navigation
when the Web page is long?
m

2, Signature
graphics m

3, Header and 4, Jump to top buttons m


footer m

AY046 Which guideline of graphics


design is considered when
graphics are used for
communicating better than
text. m

1, Resemblance 2, Simplicity
m
m

AY047 One of the guidelines for


1,Web page
creating Web pages states
layout m
that if a graphic theme is used
it should be repeated in all the
Web pages throughout the
website. This guideline is
related to __________. m

3, Relevance 4, Size m
m

2, Web page 3, Visual


dimension m hierarchy m

4, Web page content m

AY048 Which of the following is the 1, The website 2, Use


3, Cascading 4, The use of drop-down lists 1
best practice for delivering the should be simple cookies
Style Sheets should be used for navigation.
web content to mobile
and shallow. m because most (CSS) and
m
phones? m
of the mobile frames should
phones do
be used for
support them. Web pages
m
developed for
mobile
phones. m

AY049 Which home page design


1, News2, Menu
3, Path-based 4, Splash screen Home page 3
strategy should be followed
oriented Home Home page m Home page m m
while designing a home page page m
for a large website? m

AY050 Ann is designing a website


1, Effectiveness 2, Efficiency
and he added a Web page on m
m
frequently asked questions
(FAQs). This Web page
displays a set of questions
and answers related to the
website, which will help the
users to browse and identify
the features of the website.
Identify by considering which
usability goal, Ann added that
FAQs Web page. m

3, Learnability 4, Utility m
m

AY051 Joe is designing a website for 1, Effectiveness 2, Efficiency


Johnson garments. One of the m
m
design considerations that Joe
considered while designing is
that the search facility should
display the results with less
than 60 seconds. Identify by
considering which usability
goal, Joe implemented that
consideration. m

3,
Memorability
m

4, Utility m

AY052 Christine is designing a


1, Supports
computer-based tutorial for
Creativity m
kids. To attract the kids, she
designed a visual impressive
interface. Identify by
considering which user
experience goal Christine
designed the computer-based
tutorial. m

2,
3, Helpful m
Aesthetically
Pleasing m

4, Enjoyable m

AY053 Sally is designing a reporting 1,Visibility m


tool. She added a preview
feature in the tool, which
allows the users to view all the
formatting options, while
formatting the report. Identify
by considering which
principles of interaction design
Sally incorporated this option.
m

2, Feedback 3, Constraints 4, Mapping m


m
m

AY054 Rebecca is designing an


1, Visibility m
application to maintain student
records. While designing the
fees record form, she
incorporates a feature that the
user will not be allowed to
enter more than four digits for
the student id field. Identify the
interaction design principle
that Rebecca is following while
incorporating this feature in
the fees record form. m

2, Feedback 3, Constraints 4, Mapping m


m
m

AY055 IT Tech Solutions has


designed a online game for
teenagers. After a month of
launch of the game, users
started complaining that when
they start the download
process, they are unable to
make out how long it will take
to download the application. It
takes two minutes to
download the application.
Which of the following
strategies should be used to
inform the user about the
download time? m

2, Download 3, An
time should hourglass
be specified in should be
the help file of used to inform
the
the user about
application. m the download
time. m

1, A progress
bar should be
used to inform
the user about
the download
time. m

4, A message box with the


message "Download
complete!!" after the
application has been
downloaded. m

AY056 Consider the following


program:
import java.util.*;
class Example
{
public static void main(String[]
args)
{
ArrayList list=getList();
Iterator iter=list.iterator();
while (iter.hasNext())
{
iter.next();
System.out.println(list);
}
}
static ArrayList getList()
{
ArrayList<String>
arrList=new
ArrayList<String>();
arrList.add("1");
arrList.add("2");
arrList.add("3");
arrList.add("4");
return arrList;
}
}
What will be the output on
executing the preceding code?
m

1, [1]
[2]
[3]
[4]
m

2, [1, 2, 3, 4] 3, [1][1][1][1]
m
[2][2][2][2]
[3][3][3][3]
[4][4][4][4]
m

4, [1, 2, 3, 4]
[1, 2, 3, 4]
[1, 2, 3, 4]
[1, 2, 3, 4]
m

AY057 Consider the following code


developed prior to the
introduction of generics and
autoboxing:

1, import
2, import
3,
java.util.*;
java.util.*;
import
public class
public class java.util.*;
Example
Example
public class
{
{
Example
import java.util.*;
public static void public static {
public class Example
main(String
void
public static
{
args[])
main(String void
public static void main(String {
args[])
main(String
args[])
{
args[])
{
ArrayList<Intege
{
ArrayList list=new ArrayList(); r> list=new
ArrayList<Inte
Integer num=new
ArrayList<Intege ger> list=new ArrayList<Inte
Integer(10);
r>();
ArrayList<Inte ger> list=new
list.add(0,num);
Integer
ger>();
ArrayList<Inte
Integer
num=new
list.add(10); ger>();
numObj=(Integer)list.get(0); Integer(10);
int
list.add(10);
int num2=numObj.intValue(); list.add(num); numObj=list.g
System.out.println(num2);
int
et(0);
System.out.pri
numObj=list.get(
ntln(list);
}
num);
System.out.pri
}
ntln(numObj); }
System.out.printl
}
Which of the following code n(numObj);
}
m
will you use to replace the
}
preceding code for
}
m
optimization using generics
}
and autoboxing.
m
Ensure that the code you use
select performs the same
function and produces the
same result as that of the
given code.
m

4, import java.util.*;
2
public class Example
{
public static void main(String
args[])
{
ArrayList<Integer> list=new
ArrayList<Integer>();
list.add("10");
String
num=(String)list.get(0);
System.out.println(num);
}
}
m

AY058 Consider the following code:


public class Example
{
public Example()
{
System.out.println("Inside
constructor.");
}
static
{
System.out.println("Inside
static block.");
}
public static void main(String
args[])
{
System.out.println("Inside
main method.");
}

1, Inside main
method.
Inside
constructor.
Inside static
block.
m

2, Inside main 3, Inside


method.
constructor.
Inside static Inside static
block.
block.
m
Inside main
method.
m

4, Inside static block.


Inside main method.
m

2, final m

4, private m

}
What will be the output on
executing the preceding code?
m
AY059 You must declare methods of 1, static m
an interface as
______________.
m

3, public m

AY060 Which of the following options 1, Error m


is the base class of all
checked and unchecked
exceptions in Java? m

2, Exception 3,
4, RuntimeException m
m
ArithmeticExce
ption m

AY061 Which of the following


1, final m
keywords ensures that a
method cannot be overridden?
m

2, protected m3, static m

4, abstract m

AY062 Which of the following


1,
2,
3,
4, ArithmeticException m
exceptions is thrown when youNumberFormatE NullPointerEx SecurityExcept
try to divide a number by 0? m xception m
ception m
ion m

AY063 Which of the following


formatting code formats the
arguments as a string?

1, %g m

2, %s m

3, %x m

4, %n m

AY064 Consider the following


statements:
Statement A: Variables
defined with static keyword
are called class variable.
Statement B: A static variable
is available from any instance
of a class.

1, Statement A is2, Statement


true while
A is false
Statement B is while
false. m
Statement B
is true. m

3, Both
4, Both Statement A and
Statement A Statement B are true. m
and Statement
B are false. m

1, Both
2, Statement 3, Statement A 4, Both Statement A and
Statement A and A is true while is false while Statement B are false. m
Statement B are Statement B Statement B is
true. m
is false. m
true. m

Select the correct option for


the preceding statements: m

AY065 Consider the following


statements:
Statement A: In a Java class,
you can extend a class
declared as final.
Statement B: In a Java class,
you can override public
methods declared as final.
Select the correct option for
the preceding statements: m

AY066 Consider the following


statements:
Statement A: There can be
multiple catch block after a try
block.
Statement B: The finally
clause defines a block of code
that is always executed
irrespective of an exception
being thrown or not.

1, Both
2, Statement 3, Statement A 4, Both Statement A and
Statement A and A is true while is false while Statement B are false. m
Statement B are Statement B Statement B is
true. m
is false. m
true. m

1, The num1
variable. m

Select the correct option for


the preceding statements: m

AY067 Consider the following code:


public class Example
{
public static int num1 = 4;
public int num2 = 5;
}
In the preceding code, which
one is a class variable? m

2, Both the
num1 and
num1
variables. m

3, The num2
variable. m

4, None of the variables m

AY068 You can use the FileReader


class to read ___________.

1, Characters m 2, Integers m 3, Streams m 4, Files m

1, HashSet m

AY069 Consider the following code:


import java.util.*;
public class Example
{
public static void
main(String [] args)
{
<Class Name> obj=
new <Class Name>();
obj.add("Alps");
obj.add("Alps");
System.out.println(obj);
}
}
Which of the following class
will you use in the place of
<Class Name> to execute the
program with the following
output:
[Alps]
m

2, LinkedList 3, Arraylist m 4, HashSetMap m


m

AY070 Consider the following code:


public class Example
{
public static void
main(String [] args)
{
try
{
String name =
args[1];

1, The code
executes with
the following
output:

2, The code 3, The code


exits with the exits without
following
any output. m
exception
message:

James m
java.lang.Arith
meticExceptio
n: 1 at
Example.main
(Example.java
:7) m

4, The code exits with the


3
following exception message:
java.lang.ArrayIndexOutOfBo
undsException: 1 at
Example.main(Example.java:
7) m

System.out.println(name);
}
catch(Exception ex)
{}
}
}
Select the correct option on
executing the code with the
following command:
java Example James
m
AY071 Consider the following code:
public class Example
{
final int i;
public static void
main(String[] args)
{
System.out.println(new
Example().i);
}
}
Select the correct option for
the preceding code:
m

1, The compiler 2, The code


will generate an will compile
error m
and run with
the following
output:
0m

3, The code 4, The code will compile and 1


will compile
run with the following output:
but generate a
runtime error. null m
m

AY072 Consider the following code:


import java.util.*;
public class Example
{
public static void
main(String[] args)
{
ArrayList<Integer> list =
new ArrayList<Integer>();
int num1 = 1;
int num2 = 2;
list.add(num1);
list.add(num2);
Iterator elements =
list.iterator();

1, The code will


not compile as it
tries to add int
values to an
ArrayList of type
Integer. m

2, The code
will compile
and execute
with the
following
output:
1
2m

3, The code 4, The code will compile and 2


will compile
execute with the following
but not
output:
execute as it
tries to add int num1
values to an num2 m
ArrayList of
type Integer. m

while(elements.hasNext()) {
System.out.println(elements.n
ext());
}
}
}
What will be the output of the
preceding code?
m
AY073 Consider the following code: 1, 1
3
public class Example
5m
{
public static void
main(String [] args)
{
try
{
System.out.println("1");
System.out.println(1/0);
System.out.println("2");
}
catch(ArithmeticException ex)
{
System.out.println("3");
}
catch(Exception ex)
{
System.out.println("4");
}
finally
{

2, 1
4
5m

3, 1
2
4
5m

4, 3
4
5m

System.out.println("5");
}
}
}
What will be the output on
executing the following code?
m

AY074 Consider the following code:


public class Example
{
public static void
main(String [] args)
{
int res = 0;
int [] arr= new int[]
{1,2,3,4,5};
for(int element : arr)
{
res +=element;
}
System.out.println(res);
}
}
What will be the output of the
following code:
m

1, 0 m

2, 15 m

3, 5 m

4, 10 m

AY075 Consider the following


Employee class:
public class Employee
{

1, The class will 2, The class


display the
will throw an
following output: exception opf
type
Henry
NullPointerEx
m
ception. m

3, The class
will execute
without any
output. m

4, The class will throw an


exception of type
SecurityException. m

4, Objects of the Error class


m

public String getName()


{
return "Henry";
}
}
Consider the following
Example class:
public class Example
{
Employee emp;
public static void main(String
args[])
{
System.out.println(emp.getNa
me());
}
}
What will be the result on
executing the Example class?
m
AY076 __________ are those that a 1, Checked
programmer is expected to
Exception m
handle in a program. m

2, Unchecked 3, Runtime
exception m exception m

AY077 You cannot override a


______________ method.

1, public m

2, abstract m 3, static m

4, protected m

AY078 Which of the following


exception will be thrown if a
program tries to read from a
file that does not exist?
m

1,
2,
3,
4, NumberFormatException m3
NullPointerExce SecurityExcep FileNotFoundE
ption m
tion m
xception m

AY079 A method in a Java class


1, throw m
contains code that might result
in an exception. Which of the
following keyword will you use
in the method to indicate that
the calling method should
handle the exception?

2, throws m

3, try m

4, this m

2, private m

3, public m

4, final m

AY080 To make a variable constant , 1, static m


you need to define the
variable with the _________
keyword m

AY081 Consider the following code:

1, class
Example2
abstract class Example1
extends
{
Example1
abstract void display();
{
void displayAll()
public static
{
void main(String
System.out.println("Hello"); [] args)
}
{
}
Example1 e1
= new
Which of the following code on Example1();
execution will display the
following output?
e1.displayAll();
}
Hello
}m
m

AY082 Consider the following code

2, class
3, class
4, class Example2 extends
Example2
Example2
Example1
extends
extends
{
Example1
Example1
public static void
{
{
main(String [] args)
public static void display() {
void
{
Example2.display();
main(String [] }
}
args)
public static }
{
void
m
Example1 main(String []
e2 = new
args)
Example2();
{
Example2
e2.displayAll() e2 = new
;
Example2();
}
}m
e2.displayAll();
}
}
m

1, The code on 2, The code


execution will
on execution
class Example
throw an
will throw an
{
exception of
exception of
public static void main(String [] type
type
args)
NumberFormatE ArithmeticExc
{
xception. m
eption. m
String var1 = args[0];
int var2 =
Integer.parseInt(var1);
System.out.println(var2);
}
}
Select the correct option when
you execute the preceding
code with the following
command:
java Example a
m

3, The code
on execution
will display
var2. m

4, The code on execution will 1


display var1. m

AY083 Consider the following two


classes:
public class Example1
{
public static int num;
static
{
num=5;
}
}

1, The
Example2 class
will execute
without any
output. m

2, The
Example2
class will
execute with
the following
output:
5m

3, The
4, The Example2 class will
Example2
not execute as it does not
class will not calls the constructor of the
compile as it Example 1 class. m
does not calls
the constructor
of the Example
1 class. m

public class Example2


{
public static void main(String[]
args)
{
System.out.println(Example1.n
um);
}
}
Select the correct option
regarding the preceding
classes.
m
AY084 Consider the following code:
import java.util.*;
public class Example{
public static void main(String
[]args)
{
try
{
System.out.println("Hello");
}
finally
{
System.out.println("Hello");
}
}
}
Select the correct option
regarding the preceding code.
m

1, The code will


not compile and
report that a
catch block is
missing. m

2, The code 3, The code


will compile will execute
but will throw with the
a runtime
following
expression. m output:
Hello m

4, The code will execute with 4


the following output:
Hello
Hello m

AY085 Consider the following code:


public class Example{
public static void main(String
[]args)
{
String str1=args[0];
String str2=args[1];
String str3=args[3];

1, 12Java m

2,
3, 12Java
4, The code will throw an
2
12Programmi Programming exception of type
ng m
Language m ArrayIndexOutOfBoundsExce
ption. m

System.out.println(str1+str2+st
r3);
}
What will be the output on
executing the preceding code
with the following command:
java Example 1 2 Java
Programming Language
}
m
AY086 To display a panel you must
add it to __________.
m

1, Another panel 2, A Frame m 3, A text


4, Any component m
m
component m

AY087 The default layout manager of 1, FlowLayout m 2,


3, GridLayout 4, NullLayout m
a panel is_________.
BorderLayout m
m
m

AY088 Every AWT component has a 1, setVisible() m 2, setSize() m 3, paint() m


____________method that
draws the specified
component on a container. m

4, draw() m

AY089 Which of the following method 1,


does the
mouseDragged(
MouseMotionListener
MouseEvent) m
interface contains?

2,
mouseExited(
MouseEvent)
m

3,
4,
1
mouseEntered mouseClicked(MouseEvent)
(MouseEvent) m
m

AY090 Which of the following event is 1, MouseEvent 2, KeyEvent


generated when you click a
m
m
button in a GUI form?
m

3, ItemEvent m4, ActionEvent m

AY091 Consider the following


statements:
Statement A : When you
resize a window containing
buttons assigned with
BorderLayout, the relative
positions of the button
changes.
Statement B: When you add a
component to an empty
window assigned with
BorderLayout, the window
adds the component to the
center region by default.

1, Statement A is2, Statement 3, Both


4, Both Statement A and
false while
A is true while Statement A Statement B are false. m
Statement B is statement B is and Statement
true. m
false m
B are true. m

Select the correct option for


the preceding statements.
m

AY092 Which of the following method 1, pack() m


will you call to set the size of
a Frame?
m

2, setVisible() 3, setSize() m 4, setLayout() m


m

AY093 Consider the following


statements:
Statement A : The code to
add a button object to the
center region of a frame using
border layout is:

1, Statement A is2, Statement


true while
A is false
Statement B is while
false. m
Statement B
is true. m

3, Both
4, Both Statement A and B
Statement A are false. m
and B are true.
m

frame.add(button, "Center");
Statement B: The code to add
a button object to the center
region of a frame using border
layout is:
frame.add(button,
BordeLayout.CENTER)
Select the correct option for
the preceding statements.
m
AY094 Which of the following method 1,
2,
3,
4, container.setLayout(null);
enables you to disable the
container.setLay container.layo container.layou m
layout manager for a
out(0); m
ut(null); m
t(0); m
container?
m

AY095 Which of the following layout 1, BorderLayout 2, FlowLayout 3, GridLayout 4, NullLayout m


manager enables you to
m
m
m
assign row and column
numbers to arrange
components? m

AY096 What will be the output of the 1, The statement 2, The


3, The
4, The statement will create a 2
following statement in a GUI will create a new statement will statement will new Frame window and
program?
Frame window create a new create a new display Hello at the left. m
and display
Frame
Frame window
Frame f = new Frame
Hello at the
window with a with a status
("Hello");
center. m
title bar
bar containing
m
containing the the Hello
Hello title. m status. m

AY097 Consider the following code:


Frame f = new
Frame("Frame");
MenuBar mb = new
MenuBar();

1,
2,
3, f.add(mb);
f.addMenubar(m f.setManubar( m
b); m
mb); m

4, f.set(mb); m

Which of the following code


will you use to add the menu
bar to the frame?
m

AY098 Consider the following code, 1, The code will


where MyListener is a listener add an action
class of action events:
listener to both
the menu bar
Frame f = new
and the File
Frame("Frame");
menu. m
MenuBar m1 = new
MenuBar();
Menu menu1 = new
Menu("File");
menu1.addActionListener(new
MyListener);
m1.add(menu1);
f.setMenuBar(m1);
Select the correct option
regarding the preceding code.
m

2, The code 3, The code 4, The code will add an action 2


will add an
will add an
listener to the menu bar. m
action listener action listener
to the File
to the frame. m
menu. m

AY099 What will be the output of the 1, The output


following code?
will display a
window with six
import java.awt.*;
buttons
public class Example
arranged in
{
three rows and
private Frame f;
two columns. m
private Button b1, b2, b3, b4,
b5, b6;
public Example()
{
f=new Frame("GridLayout
Demo");
b1=new Button("1");
b2=new Button("2");
b3=new Button("3");
b4=new Button("4");
b5=new Button("5");
b6=new Button("6");
}
public void display()
{
f.setLayout(new
GridLayout());
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(b6);
f.pack();
f.setVisible(true);
}
public static void
main(String[] args)
{
Example examp=new
Example();
examp.display();
}
}m

2, The output
will display a
window with
six buttons
arranged in
two rows and
three
columns. m

3, The output 4, The output will display a


will display a window with six buttons
window with arranged in one row. m
six buttons
arranged in
one column. m

AY100 Consider that you are creating 1, import


2, import
3, import
4, import java.awt.event.*;
1
a GUI application and you
java.awt.event.*; java.awt.event java.awt.event.
need an action listener to
.*;
*;
public class CustomHandler
handle events of type
public class
implements ActionListener{
ActionEvent. Which of the
CustomHandler public class public class
public static void main(String
following listener code will you implements
CustomHandl CustomHandle args[])
use? m
ActionListener{ er{
r implements
{
public void
public void ActionListener{ /*Process action here*/
actionPerformed actionPerform public void
}
(ActionEvent
ed(ActionEve actionPerform } m
evt)
nt evt)
ed()
{
{
{
/*Process
/*Process
/*Process
action here*/
action here*/ action here*/
}
}
}
}m
}m
}m

AY101 Consider the following code:

1, The code will 2, The code


not compile. m will compile
public class Example extends
but will not
Thread
execute. m
{
public void run()
{
System.out.println ("Hello");
}
public static void main (String
args[])
{
new Example();
}
}
Select the correct option
regarding the preceding code:
m

3, The code 4, The code will compile,


will compile, execute, but will not display
execute, and anything. m
display Hello
as the output.
m

AY102 Which of the following is NOT 1, Running m


a valid state of a thread? m

AY103 Consider the following


statements on threads:

2, Blocked m 3, Listening m 4, Dead m

1, Both
2, Statement 3, Statement A 4, Both Statement A and
Statement A and A is true while is false while Statement B are true. m
Statement B are Statement B Statement B is
Statement A: You can create a false. m
is false. m
true. m
new thread by extending the
Thread class.
Statement B: You can create a
new thread by implementing
the Runnable interface.
Select the correct option for
the preceding statements
m

AY104 Select the correct statement


that sets the priority of a
thread among a group of
threads to maximum. m

AY105 Consider the following code:

1,
2,
3,
4,
4
threadObj.getPri threadObj.set threadObj.setP threadObj.setPriority(THREA
ority(THREAD.M Priority(MAX_ riority(THREA D.MAX_PRIORITY); m
AX_PRIORITY); PRIORITY); D.PRIORITY);
m
m
m

1, The code will 2, The code


execute with the will execute
public class Example extends following output: without any
Thread
output. m
{
Hello m

3, The code
will execute
with the
following
output:

public static void main(String


args[])
{
for(int i=0;i<3;i++)
new Example().start();
}
public void run()
{
System.out.println("Hello");
}
}

Hello
Hello
Hello m

Select the correct option for


the preceding code.
m

4, The code will not execute. 3


m

AY106 In a Java multithreading


1, To give other 2, To start a 3, To terminate 4, To stop the current thread 1
program, under what
runnable threadsnew thread. m the current
for a specific time. m
circumstances will you call the a chance to
thread. m
yield() method of a thread?
execute. m
m

AY107 Consider the following code:

1, The code will 2, The code 3, The code 4, The code will display the
display the
will display
will not display following output:
public class Example extends following output: the following any output. m
Thread
output:
Hello
{
Hello m
Hello
public static void
Hello
Hello
main(String argv[])
Hello
Hello m
{
Hello
Example obj
Hello
= new Example();
Hello m
obj.run();
}
public void start()
{
for (int i = 0; i
<5; i++)
{
System.out.println("Hello");
}
}
}
What will be the output of the
preceding code?
m

AY108 Which of the following classes 1,


will you use to communicate FileInputStream
between threads? m
and
FileOutputStrea
mm

2,
3,
4, FilterInputStream and
PipedInputStr BufferedInputS FilterOutputStream m
eam and
tream and
PipedOutputS BufferedOutpu
tream m
tStream m

AY109 Which of the following is the 1,


2,
3,
4, ByteArrayOutputStream m 2
immediate superclass of the FileOutputStrea FilterOutputSt PipedOutputSt
DataOutputStream,
mm
ream m
ream m
BufferedOutputStream, and
PrintStream classes? m

AY110 Consider the following


statements:

1, Both
2, Statement 3, Statement A 4, Both Statement A and
Statement A and A is true while is false while Statement B are false. m
Statement B are Statement B Statement B is
Statement A: To implement a true. m
is false. m
true. m
TCP/IP server, you can use
the ServerSocket class of the
java.net package.
Statement B: a TCP/IP client
uses the Socket class of the
java.net package.

Select the correct option


regarding the preceding
statements.
m

AY111 Which of the following method 1, close() m


enables you to force writes
that an output stream
accumulates? m

2, write() m

3, flush() m

4, read() m

AY112 Which of the following will you 1, Reader m


use to read a stream of bytes
in a program?

2, Writer m

3, InputStream 4, OutputStream m
m

AY113 Which of the following class 1, FileReader m 2,


3,
4, PipedReader m
will you use to read the
StringReader FileInputStrea
content of a file as a stream of
m
mm
bytes?
m

AY114 A___________ stream


performs conversion on
another stream.

1, Filter m

2, Output m

3, Input m

4, Print m

2, yield() m

3, run() m

4, start() m

AY115 Which of the following method 1, notify() m


will you call to start a thread?
m

AY116 Which one of the following is a 1, -8080 m


valid TCP/IP port number?

2, 65535 m

3, 100000 m

4, -7070 m

AY117 Consider the following


statement:
Thread.sleep(x);
Select the correct option for
the value x.
m

1, An int value 2, A long


that specifies the value that
number of
specifies the
seconds for
number of
which the thread milliseconds
must be made for which the
inactive. m
thread must
be made
inactive. m

3, A float value 4, A float value that specifies 2


that specifies the number of milliseconds for
the number of which the thread must be
seconds for
made inactive. m
which the
thread must be
made inactive.
m

AY118 Consider the following


statements:

1, Statement A is2, Both


true while
Statement A
Statement B is and
Statement A: To start a thread false. m
Statement B
you must call the constructor
are true. m
of the Thread class.
Statement B: The Thread
class implements the
Runnable interface.

3, Statement A 4, Both Statement A and


is false while Statement B are false. m
Statement B is
true. m

1, Both
2, Statement 3, Statement A 4, Both Statement A and
Statement A and A is true while is false while Statement B are false. m
Statement B are Statement B Statement B is
true. m
is false. m
true. m

Select the correct options for


the preceding statements.
m

AY119 Consider the following


statements:
Statement A: TCP/IP port
numbers are 16 bit numbers.
Statement B: TCP/IP classes
are implemented using the
java.io package.
Select the correct options for
the preceding statements.
m

AY120 A TCP/IP server is running on 1, ServerSocket 2, Socket s1 3, Socket s1 = 4, Socket s1 = new


2
a computer with the IP
s1 = new
= new
new
Socket(127.168.0.10, 5430);
address 127.168.0.10 and
ServerSocket("1 Socket("127.1 ServerSocket(" m
listening to the 5430 port
27.168.0.10",
68.0.10",
127.168.0.10",
number.
5430); m
5430); m
5430); m
Which of the following
statement will you use in the
TCP/IP client code to establish
a connection with the server?
m

AY121 Consider the following code:

1, The code will


throw a runtime
import java.io.FileInputStream; exception. m
import
java.io.FileOutputStream;
import java.io.IOException;
public class Example {
public static void
main(String[] args) throws
IOException {
FileInputStream in = null;
FileOutputStream out =
null;
try {
in = new
FileInputStream("OutputFile.tx
t");
out = new
FileOutputStream("InputFile.tx
t");
int c;
while ((c = in.read()) !=
-1) {
out.write(c);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();

2, The code
will copy the
content of the
OutputFile.txt
file to the
InputFile.txt
file. m

3, The code 4, The code will execute


will copy the without any output. m
content of the
InputText.txt
file in to
OuputText.txt
file.
m

}
}
}
}
What will be the output of the
above code?
m

AY122 Consider the following code:

1, The code will 2, The code


not compile. m will compile,
import java.io.*;
execute, wait
class Example
for a key
{
press, and
public static void main(String
then exit. m
args[])
{
DataInputStream fi = new
DataInputStream(System.in);
try
{
fi.readChar();
}
catch(IOException e)
{
System.exit(0);
}
finally
{
System.out.println("Doing
finally");
}
}
}
Select the correct option for
the preceding code. m

3, The code 4, The code will execute and 3


will compile, exit immediately without
execute, wait output. m
for a key
press, prints
"Doing finally"
on a key
press, and
then exit.
m

AY123 Consider the following code:


public class Example {
public static void
main(String args[]) throws
InterruptedException {
String info[] = {
"Java",
"C++"
};
for (int i = 0; i <
info.length; i++) {

1, The code will


throw an
exception of
type
InterruptedExce
ption. m

2, The code 3, The code


will display
will display
Java and C+ only Java. m
+. m

1, import
java.io.*;
public class
Example
{
public static
void
main(String[]
args)
{

2, import
java.io.*;
public class
Example
{
public static
void
main(String[]
args)
{
String str;
try
{

4, The code will display only 2


C++. m

Thread.sleep(4000);
System.out.println(info[i]);
}
}
}
Select the correct option.
m
AY124 Consider an example.txt file
saved in your working
directory that contains the
following content:
User Name = Admin
Password = Administrator
Host = localhost

3, import
4, import java.io.*;
2
java.io.*;
public class Example
public class
{
Example
public static void
{
main(String[] args)
public static {
void
try
main(String[]
{
Which of the following code
args)
FileReader fr = new
will you use to read the
{
FileReader("example.txt");
content of the example.txt file
String str;
BufferedReader br = new
and display it on console?
try
try
BufferedReader(fr);
m
{
{
FileReader fr
FileReader
while (br.readLine()!=null)
= new
FileReader fr fr = new
FileReader("exa = new
FileReader(ex System.out.println(br.readLine
mple.txt");
FileReader("e ample.txt);
());
xample.txt");
BufferedReader
BufferedReade } catch (IOException e)
br = new
BufferedRead r br = new
{
BufferedWriter(fr er br = new BufferedReade
);
BufferedRead r(fr);
System.out.println(e.getMess
er(fr);
age());
System.out.printl
while ((str
}
n(br.display());
while ((str =
}
} catch
=
br.readLine()) m
(IOException e) br.readLine()) !=null)
{
!=null)
System.out.pri
System.out.printl System.out.pri ntln(str);
n(e.getMessage(ntln(str);
));
} catch

}
}
}
m

} catch
(IOException
(IOException e)
e)
{
{
System.out.pri
System.out.pri ntln(e.getMess
ntln(e.getMes age());
sage());
}
}
}
}
}
}
m
m

AY125 A Java multithreading program 1,


2, public void 3, public void
contains an operation()
synchronized(thi operation(){ synchronized
method. You need to ensure s)
synchronized( operation(){
that only a single thread can public void
this)
/*Method
access the operation() method operation(){
/*Method
Body*/
at a time. Which of the
/*Method Body*/ Body*/
}
following code will you use? m }
}
m
m
m

4, public synchronized void


operation(){
/*Method Body*/
}
m

AY126 Which of the following is the


key component of a data
provider? m

1, DataAdapter 2, DataTable 3,
4, DataRelationCollection m 1
m
m
DataTableColl
ection m

AY127 Which of the one following


components of a dataset
contains all the tables
retrieved from the
DataSource? m

1, DataTable m 2,
3,
4, DataColumnCollection m
DataTableColl DataRelationC
ection m
ollection m

AY128 Which one of the following


1,Connection m 2,
3, Command
components of a data provider
DataAdapter m
is used to transfer data to and
m
from a database? m

AY129 Which property of the


1,
2, RowFilter
DataView control is used to
GenerateMembe m
specify an
rm
expression/condition in a
string format used to filter the
records? m

4, DataReader m

3,
4, Modifiers m
RowStateFilter
m

AY130 Which of the following


parameters of
ConnectionString is used to
specify the Server login
account? m

1, Provider m

AY131 Consider the following code 1, Library refers


snippet:
to the name of
SqlConnection connection = the database m
new SqlConnection();
connection.ConnectionString
= "Data Source=
SourceDB;Initial
Catalog=Library; User
ID=administrator;
Password=password";
What does Library signify in
the preceeding code snippet?
m

2, Initial
Catalog m

3, Integrated
Security m

4, User ID m

2, Library
refers to the
Server login
account m

3, Library
4, Library refers to the
1
specifies the provider for the connection m
name of the
server, which
is used in an
open
connection m

AY132 Consider the following code 1, It specifies the 2, It specifies


snippet:
name of the
the name of
SqlConnection connection = server used in the server
new SqlConnection();
an open
login account
connection.ConnectionString connection m
m
= "Data Source=
SourceDB;Initial
Catalog=Library; User
ID=administrator;
Password=password";
What does SourceDB signify
in the preceding code snippet?
m

AY133 Williams has to write a code to 1, TextBox m


display the values of the
records from the database in
such a manner so that only
one value is displayed in each
control at a time. Identify the
control, which should be used.
m

3, It specifies 4, It specifies the name of the 1


the name of database m
the provider for
the connection
m

2, ListBox m 3, ComboBox 4, DataGrid m


m

AY134 Williams has to write a code to 1,


2, DataSource 3,
4, Items m
display all the employee codesDisplayMember m
DataBindings
from the Employees table in a m
m
ListBox control. Which of the
following options of the
ListBox control would enable
him to bind the column
containing the employee
codes of the Employees
table? m

AY135 John has to develop a small


code that would enable him to
find out the total number of
items present in the data
source being used. He has
used the BindingNavigator
control in his form. Which
control of the
BindingNavigator control
would enable him to
accomplish this task? m

1,
2,
3,
4,
2
bindingNavigatorbindingNaviga BindingSource bindingNavigatorMoveLastIte
PositionItem text torCountItem m
m button m
box m
text box m

AY136 Jim is assigned a task to


1, The code will 2, The code
develop a code to implement agive an error.
will give an
delete operation from the
This is because error. This is
Employee table present in a the
because the
database, HR. To accomplish ConnectionStrin parameters
this task, he has developed
g contains an
passed in the
the following code in which he incomplete
constructor of
deletes all the records from
number of
the
the Employee table where the parameters. To SqlCommand
employee code is 00005.
rectify this code, class are in
it is necessary to an incorrect
SqlConnection connection = mention the
sequence. m
new SqlConnection();
provider. m
connection.ConnectionString
= "Data Source=
SQLSERVER01;Initial
Catalog=HR; User ID=sa;
Password=password";
connection.Open();
SqlCommand cmd = new
SqlCommand(connection,"del
ete from Employee where
cEmployeeCode='000015'");
SqlDataReader myReader =
cmd.ExecuteReader();
myReader.read();
Identify whether the preceding
code gives the desired output
or not. m
AY137 John is assigned a task to
1, The code will
develop a window based
throw an
application in which the name exception. The
and department of an
term
employee is displayed on the employeecode
screen based on a particular should be
employee id. The details of the preceded with
employee are stored in the
an '@' sign. m
Employee table present in the
HR database. He has
developed a code to
implement the same. Refer to
the following partial code:
SqlConnection con =
new SqlConnection();
con.ConnectionString
= "Data Source=
SQLSERVER01; Initial
Catalog=HR; User ID=sa;
Password=niit#1234";
con.Open();
string
searchemployeecode;
searchemployeecode
= textbox1.Text;

2, The code
will give an
error. The
parameters
mentioned in
the
constructor of
the
SqlParameter
class are in
an incorrect
sequence. m

3, The code 4, The code will give the


will give an
desired output. m
error. This is
because the
constructor of
the
SqlCommand
class takes the
connection
string as a
parameter and
not the
Connection
object. m

3, The code 4, The code will give the


will give an
desired output. m
error.
Parameters is
the property of
the
SqlConnection
object and not
the
SqlCommand
object. m

String query =
"SELECT * FROM Employee
WHERE cemployeeCode =
employeecode";
SqlCommand cmd =
new SqlCommand(query,
con);
cmd.Parameters.Add(new
SqlParameter("employeecode
", searchemployeecode));
SqlDataReader dr =
cmd.ExecuteReader();
dr.Read();
MessageBox.Show(dr[1].ToStr
ing());
MessageBox.Show(dr[2].ToStr
ing());
Identify whether the preceding
code will give the desired
output or not. m
AY138 John is assigned a task to
1, The code will 2, The code
develop a window based
throw an
will give an
application in which the name exception. In the error. The
and department of an
term
parameters
employee is displayed on the employeecode, mentioned in
screen based on a particular '@' sign should the
employee id. The details of the be removed. m constructor of
employee are stored in the
the
Employee table present in the
SqlParameter
HR database. He has
class are in
developed a code to
an incorrect
implement the same. Refer to
sequence. m
the following partial code:
SqlConnection con =
new SqlConnection();
con.ConnectionString
= "Data Source=
SQLSERVER01; Initial
Catalog=HR; User ID=sa;
Password=niit#1234";
con.Open();
string
searchemployeecode;
searchemployeecode
= textbox1.Text;
String query =
"SELECT * FROM Employee
WHERE cemployeeCode =
@employeecode";
SqlCommand cmd =
new SqlCommand(query,

3, The code 4, The code will give the


will give an
desired output. m
error.
Parameters is
the property of
the
SqlConnection
object and not
the
SqlCommand
object. m

con);
cmd.Parameters.Add(new
SqlParameter("@employeeco
de", searchemployeecode));
SqlDataReader dr =
cmd.ExecuteReader();
dr.Read();
MessageBox.Show(dr[1].ToStr
ing());
MessageBox.Show(dr[2].ToStr
ing());
Identify whether the preceding
code will give the desired
output or not. m

AY139 John is assigned a task to


1, The code will 2, The code
develop a window based
throw an
will give an
application in which the name exception. In the error. The
and department of an
term
parameters
employee is displayed on the employeecode, mentioned in
screen based on a particular '@' sign should the
employee id. The details of the be removed. m constructor of
employee are stored in the
the
Employee table present in the
SqlParameter
HR database. He has
class are in
developed a code to
an incorrect
implement the same. Refer to
sequence. m
the following partial code:
SqlConnection con =
new SqlConnection();
con.ConnectionString
= "Data Source=
SQLSERVER01; Initial
Catalog=HR; User ID=sa;
Password=niit#1234";
con.Open();
string
searchemployeecode;
searchemployeecode
= textbox1.Text;
String query =
"SELECT * FROM Employee
WHERE cemployeeCode =
@employeecode";
SqlCommand cmd =
new SqlCommand(query,

3, The code 4, The code will give the


will give an
desired output. m
error.
Parameters is
the property of
the
SqlConnection
object and not
the
SqlCommand
object. m

con);
cmd.Parameters.Add(new
SqlParameter(searchemploye
ecode, "@employeecode"));
SqlDataReader dr =
cmd.ExecuteReader();
dr.Read();
MessageBox.Show(dr[1].ToStr
ing());
MessageBox.Show(dr[2].ToStr
ing());
Identify whether the preceding
code will give the desired
output or not. m

AY140 Jim works as a software


developer in MySofInc. Pvt.
Ltd. He has to develop a code
to display the employee id of
all the employees of his
organization in a ComboBox
control. The employee details
are present in the Employee
table int the HR database. He
has developed the following
code to accomplish this task:
SqlConnection con = new
SqlConnection();
con.ConnectionString = "Data
Source= SQLSERVER01;
Initial Catalog=HR; User
ID=sa; Password=password";
con.Open();
SqlCommand cmd = new
SqlCommand("select * from
employee", con);
cmd = dr.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr[0]);
}
con.Close();
Identify whether the preceding
code will give the desired

1, The code will


give an error.
The parameters
passed in the
SqlCommand
class are in an
incorrect
sequence. m

2, The code 3, The code 4, The code will give the


will give an
will give an
desired output. m
error. The line error. It is
of code cmd = necessary to
dr.ExecuteRe mention the
ader() is
provider in the
incorrect. m connection
string. m

output or not. m

AY141 Which of the following is true 1, Chances for


about a disconnected
data
environment? m
concurrency
issues are less
m

2, Allows one 3, Data is not 4, A constant connection is


application to always up to always required m
interact with date m
the data
source at a
time m

AY142 Which of the following


1,
2,
3,
4, Equals() m
methods of the DbCommand ExecuteNonQue ExecuteScala ExecuteReade
object executes a query and ry() m
r() m
r() m
returns the first column of the
first row in the result set
returned by the query? m

AY143 Which of the following


1, Select() m
methods of the DataRow
object accesses a row in a
table by its primary key value?
m

2, Find() m

3, Add() m

4, InsertAt() m

AY144 Which of the following values 1, CurrentRows 2,


3, None m
of the DataViewRowState
m
ModifiedCurre
enumeration is the default
nt m
enumeration value? m

AY145 Which of the following values 1, None m


of the Rule enumeration
throws an exception if the
parent DataRow object is
deleted or its unique key is
changed? m

4, OriginalRows m

2, Cascade m 3, SetDefault 4, SetNull m


m

AY146 John has to write a code in


1,
2,
3,
4, Equals() m
which he has to retrieve the ExecuteReader( ExecuteNonQ ExecuteScalar
number of rows affected
)m
uery() m
() m
whenever any transaction is
implemented in the database
through the front end. Which
function of the DbCommand
class would enable him to
accomplish this task? m

AY147 Consider a table containing 20 1, 20 m


records. Whenever any
modification is done in the
table through the front end,
the changes are sent to the
database in batches where
each batch consists of four
records. What value is set for
the UpdateBatchSize property
of the Update() method? m

2, 4 m

3, 5 m

4, 24 m

AY148 John has to develop a window 1, Add() m


based application which would
enable him to implement an
insert operation in a table at a
specified position. Which one
of the following methods of the
DataRow object would enable
him to accomplish this task? m

2, InsertAt() m 3, Find() m

4, Select() m

AY149 John has to develop a window 1, Find() m


based application which would
enable him to implement
delete operation in a table
from a specific position. Which
one of the following methods
of the DataRow object would
enable him to accomplish this
task? m

2, Remove() 3, RemoveAt() 4, Delete() m


m
m

AY150 Consider the following code


snippet:
DataView dv = new
DataView();
dv.RowFilter = "Price = 100";
What is the function of the
RowFilter property in the
preceding code snippet?
m

1, It filters those
records where
the value of
Price is 100 m

2, It filters
those records
where the
value of Price
is other than
100 m

3, It filters
those records
where the
value of Price
is 100 and
sorts them in
an ascending
order m

4, It filters those records


1
where the value of Price is
100 and controls the version
of the row m

AY151 MyProd Pvt. Ltd. is a leading 1, string


2, string
3, string
4, string productCode;
1
producer of hardware and
productCode;
productCode; productCode;
productCode =
software products. The details
textBox1.Text;
of all the products are
productCode = productCode productCode =
SqlCommand cmd =
maintained in a centralized
textBox1.Text; =
textBox1.Text; cn.CreateCommand();
database system. As a part of
textBox1.Text;
cmd.CommandType =
the development team,
SqlCommand
SqlCommand CommandType.Text;
Williams is assigned a task to cmd =
SqlCommand cmd =
cmd.CommandText =
develop a windows based
cn.CreateComm cmd =
cn.CreateCom "select * from ProductDetails
application in which the name and();
cn.CreateCo mand();
where ProductId=@Pode";
and the price of the product
mmand();
are displayed on entering the cmd.CommandT
cmd.Comman cmd.Parameters.Add(new
unique product id. The product ype =
cmd.Comman dType =
SqlParameter(productCode,
details are stored in the
CommandType. dType =
CommandTyp ("@Pode")));
ProductDetails table in the
Text;
CommandTyp e.Text;
SqlDataReader dr =
Products database.
e.Text;
cmd.ExecuteReader();
Identify the code that would cmd.CommandT
cmd.Comman
while (dr.Read())
enable him to accomplish this ext = "select * cmd.Comman dText = "select
{
task. Assume the connection from
dText =
* from
textBox2.Text =
to be already open where cn isProductDetails "select * from ProductDetails Convert.ToString((dr[1]));
the connection object. m
where
ProductDetail where
textBox3.Text =
ProductId=@Po s where
ProductId=@P Convert.ToString((dr[2]));
de";
ProductId=@ ode";
}m
Pode";
cmd.Parameters
cmd.Paramete
.Add(new
cmd.Paramet rs.Add(new
SqlParameter(" ers.Add(new SqlParameter(
@Pode",
SqlParameter "@Pode",
productCode)); ("@Pode",
productCode));
productCode))
SqlDataReader ;
textBox2.Text
dr =
=

cmd.ExecuteRe
ader();
while
(dr.Read())
{

textBox2.Text Convert.ToStri
=
ng((cmd.Execu
Convert.ToStri teScalar()));
ng(cmd.Execu
teNonQuery()) textBox3.Text
;
=
textBox2.Text =
Convert.ToStri
Convert.ToString textBox3.Text ng((cmd.Execu
((dr[1]));
=
teScalar())); m
Convert.ToStri
textBox3.Text = ng(cmd.Execu
Convert.ToString teNonQuery())
((dr[2]));
;m
}m

AY152 MyCall Ltd. is a upcoming call 1, string dCode; 2, string


3, string
4, string dCode;
4
centre. The details of all the
dCode = dCode;
dCode;
dCode =
employees are maintained in atextBox1.Text;
dCode
dCode textBox1.Text;
centralized database system.
=
=
SqlCommand cmd =
As a part of the development SqlCommand textBox1.Text; textBox1.Text; cn.CreateCommand();
team, Williams is assigned a cmd =
cmd.CommandType =
task to develop a windows
cn.CreateComm SqlCommand SqlCommand CommandType.Text;
based application in which
and();
cmd =
cmd =
cmd.CommandText =
whenever the user enters a
cn.CreateCo cn.CreateCom "select * from
department code in a TextBox cmd.CommandT mmand();
mand();
EmployeeDetails where
control, the employee id of all ype =
deptCode=@P";
the employees working in that CommandType. cmd.Comman cmd.Comman
particular department are
Text;
dType =
dType =
cmd.Parameters.Add(new
displayed in a combobox. The
CommandTyp CommandTyp SqlParameter("@P", dCode));
employee details are stored in cmd.CommandT e.Text;
e.Text;
SqlDataReader dr =
the EmployeeDetails table in ext = "select *
cmd.ExecuteReader();
the HR database. Identify the from
cmd.Comman cmd.Comman
while (dr.Read())
code that would enable him to EmployeeDetailsdText =
dText = "select
{
accomplish this task. Assume where
"select * from * from
the connection to be already deptCode=@P"; EmployeeDet EmployeeDeta comboBox1.Items.Add(dr[0]);
open where cn is the
ails where
ils where
}m
connection object. m
cmd.Parameters deptCode=@ deptCode=@P
.Add(new
P";
";
SqlParameter("
@P", dCode)); cmd.Paramet cmd.Paramete
ers.Add(new rs.Add(new
SqlDataReader SqlParameter SqlParameter(
dr =
("@P",
"@P",
cmd.ExecuteNo dCode));
dCode));
nQuery();
while
SqlDataRead SqlDataReade
(dr.Read())
er dr =
r dr;

cmd.Execute
while
Scalar();
(dr.Read())
comboBox1.Item
while
{
s.Add(dr[0]);
(dr.Read())
}m
{
comboBox1.Ite
ms.Add(dr[0]);
comboBox1.It
}m
ems.Add(dr[0]
);
}m

AY153 CalNetInfocom. Ltd. is a call 1, string


2, string
3, string
4, string employeeCode;
1
center company based in US. employeeCode; employeeCod employeeCodeemployeeCode =
Its centralized database
employeeCode e;
;
textBox1.Text;
system store the details of all = textBox1.Text; employeeCod employeeCodeSqlCommand cmd =
the employees. As a part of
SqlCommand e =
=
cn.CreateCommand();
the development team, John iscmd =
textBox1.Text; textBox1.Text; cmd.CommandType =
assigned a task to develop a cn.CreateComm SqlCommand SqlCommand CommandType.Text;
windows based application in and();
cmd =
cmd =
cmd.CommandText = "select
which the details of an
cmd.CommandT cn.CreateCo cn.CreateCom * from Employees where
employee are displayed on theype =
mmand();
mand();
empId=eCode";
screen on entering the unique CommandType. cmd.Comman cmd.Comman cmd.Parameters.Add(new
id of the employee. The details Text;
dType =
dType =
SqlParameter("eCode",
of the employees are stored in cmd.CommandT CommandTyp CommandTyp employeeCode));
an Employees table of the HR ext = "select * e.Text;
e.Text;
SqlDataReader dr =
database. Identify the code
from Employees cmd.Comman cmd.Comman cmd.ExecuteReader();
that would enable him to
where
dText =
dText = "select while (dr.Read())
accomplish this task. Assume empId=@eCode "select * from * from
{
the connection to be already ";
Employees Employees
textBox2.Text =
open where cn is the
cmd.Parameters where
where
Convert.ToString((dr[1]));
connection object. m
.Add(new
empId=@eCo empId=@eCo textBox3.Text =
SqlParameter(" de";
de";
Convert.ToString((dr[2]));
@eCode",
SqlDataRead cmd.Paramete } m
employeeCode)) er dr =
rs.Add(new
;
cmd.Execute SqlParameter(
SqlDataReader Reader();
employeeCode
dr =
while
,"@eCode"));
cmd.ExecuteRe (dr.Read())
SqlDataReade
ader();
{
r dr =
while (dr.Read())
cmd.ExecuteR
{
textBox2.Text eader();
textBox2.Text = =
while
Convert.ToString Convert.ToStri (dr.Read())

((dr[1]));
ng((dr[1]));
{
textBox3.Text =
textBox2.Text
Convert.ToString textBox3.Text =
((dr[2]));
=
Convert.ToStri
}m
Convert.ToStri ng((dr[1]));
ng((dr[2]));
textBox3.Text
}m
=
Convert.ToStri
ng((dr[2]));
}m

AY154 Marry has recently joined as a 1,


2,
3,
4, SqlDataAdapter adapter 2
tellecalling executive in a call SqlDataAdapter SqlDataAdapt SqlDataAdapte = new
centre CallNetInc. Ltd. Her
adapter = new er adapter = r adapter =
SqlDataAdapter("Select *
details need to be entered into SqlDataAdapter( new
new
from Employees",
the system. As a part of the
"Select * from SqlDataAdapt SqlDataAdapte connection);
development team, you need Employees",
er("Select * r("Select * from
SqlCommandBuilder
to create an application in
connection);
from
Employees", cmdBuilder = new
which the details of the
Employees", connection); SqlCommandBuilder(adapter)
employee being entered in the SqlCommandBuiconnection);
;
form gets saved in the
lder cmdBuilder
SqlCommandB
DataSet ds = new
database. The details of the = new
SqlCommand uilder
DataSet("Employees");
employee are stored in the
SqlCommandBuiBuilder
cmdBuilder =
adapter.Fill(ds,
Employees table in the HR
lder(adapter);
cmdBuilder = new
"Employees");
database. Identify the correct
new
SqlCommandB
DataRow row =
code to accomplish this task. DataSet ds =
SqlCommand uilder(adapter) ds.Tables["Employees"].New
Assume the connection to be new
Builder(adapt ;
Row();
already open where
DataSet("Emplo er);
row["empId"] =
connection is the connection yees");
DataSet ds = textBox1.Text;
object. m
DataSet ds = new
row["empName"] =
DataRow row = new
DataSet("Empl textBox2.Text;
ds.Tables["Empl DataSet("Emp oyees");
row["empSal"] =
oyees"].NewRo loyees");
textBox3.Text;
w();
adapter.Fill(ds,
adapter.Update(ds,
adapter.Fill(ds "Employees"); "Employees"); m
row["empId"] = ,
textBox1.Text; "Employees"); DataRow row
=
row["empName"] DataRow row ds.Tables["Em
= textBox2.Text; =
ployees"].New
ds.Tables["Em Row();
row["empSal"] = ployees"].New
textBox3.Text; Row();
row["empId"] =

textBox1.Text;
ds.Tables["Empl row["empId"]
oyees"].Rows.A =
row["empNam
dd(row);
textBox1.Text; e"] =
textBox2.Text;
adapter.Update( row["empNam
ds,
e"] =
row["empSal"]
"Employees"); m textBox2.Text; =
textBox3.Text;
row["empSal"]
=
ds.Tables["Em
textBox3.Text; ployees"].Row
s.Add(row); m
ds.Tables["Em
ployees"].Row
s.Add(row);
adapter.Updat
e(ds,
"Employees");
m

AY155 SysCalInc Ltd. is a call centre 1, string str;


2, string str; 3, string str;
4, string str;
1
company with its branches
str =
str =
str =
str =
spread all over the world. It
Console.ReadLi Console.Read Console.Read Console.ReadLine();
has got a centralized database ne();
Line();
Line();
string sSQL = "Select
management system whereby
string
string
string * from Employees";
the information about all the sSQL = "Select * sSQL =
sSQL = "Select
SqlDataAdapter da =
HR activities is maintained. As from
"Select * from * from
new SqlDataAdapter();
a part of the development
Employees";
Employees"; Employees";
da.SelectCommand =
team, John is assigned a task
new SqlCommand(sSQL,
to extract the details of all the SqlDataAdapter SqlDataAdapt SqlDataAdapte conn);
employees of a particular
da = new
er da = new r da = new
DataSet ds = new
department. The details of the SqlDataAdapter( SqlDataAdapt SqlDataAdapte DataSet();
employees are stores in the );
er();
r();
da.Fill(ds,
Employees table in the HR
"Employees");
database. Identify the code
da.SelectComm da.SelectCom da.SelectCom
DataTable dt =
that would enable him to
and = new
mand = new mand = new ds.Tables["Employees"];
accomplish this task. Assume SqlCommand(s SqlCommand( SqlCommand(
DataView dv = new
the connection to be already SQL, conn);
sSQL, conn); sSQL, conn); DataView("empDept = '" + str
open where conn is the
DataSet
+ "'", "empDept",
connection object. m
ds = new
DataSet ds = DataSet ds = DataViewRowState.CurrentR
DataSet();
new
new DataSet(); ows);
DataSet();
foreach
da.Fill(ds,
da.Fill(ds,
(DataRowView drv in dv)
"Employees"); da.Fill(ds,
"Employees");
{
"Employees");
for (int i = 0; i <
DataTable dt =
DataTable dt = dv.Table.Columns.Count; i++)
ds.Tables["Empl DataTable dt ds.Tables["Em
{
oyees"];
=
ployees"];
ds.Tables["Em
Console.WriteLine((drv[i]));
DataView dv = ployees"];
DataView dv =
}
new
new
}
DataView(dt,
DataView dv DataView(dt,
Console.ReadLine();

"empDept = '" + = new


"empDept = '" m
str + "'",
DataView(dt, + str + "'",
"empDept",
"empDept = '" "empDept");
DataViewRowSt + str + "'",
foreach
ate.CurrentRows "empDept", (DataRowView
);
DataViewRow drv in dv)
foreach State.Current
{
(DataRowView Rows);
for
drv in dv)
(int i = 0; i <
{
foreach (dv) dv.Table.Colu
for (int
{
mns.Count; i+
i = 0; i <
for +)
dv.Table.Column (int i = 0; i <
{
s.Count; i++)
dv.Table.Colu
{
mns.Count; i+ Console.Write
+)
Line((drv[i]));
Console.WriteLi
{
}
ne((drv[i]));
}
}
Console.Write
}
Line((drv[i])); Console.Read
}
Line(); m
Console.ReadLi
}
ne(); m
Console.Read
Line(); m
AY156 MyCalInc. Ltd.. is a
1, The method, 2, The
3, The method, 4, The method,
3
multinational call center
ExecuteScalar() method,
ExecuteScalar ExecuteScalar() will always
company whose branches are will always
ExecuteScala () will always return the value present in the
spread in different parts of the return the value r() will always return the
first column of the Employees
world. It has got a centralized present in the return the
value present table on the basis of the
database system wherein the first row and first value present in the first
employee id being entered.
details of all the employees
column of the
in the first row column of the The correct way is to use
are stored. As a part of the
Employees table and first
Employees
ExecuteNonQuery() method
development team, John is
irrespective of column of the table on the
as shown:
assigned a task to develop a the employee id Employees basis of the
windows based application in being entered. table
employee id textBox2.Text =
which the details of an
The correct way irrespective of being entered. Convert.ToString(cmd.Execut
employee are displayed on theis to use
the employee The correct
eNonQuery());
screen on entering the unique ExecuteNonQue id being
way is to use textBox3.Text =
id of the employee. He has
ry()
entered. The ExecuteReade Convert.ToString(cmd.Execut
developed a partial code in
method as
correct way is r() method as eNonQuery());
which the values of the
shown:
to use
shown:
m
second and third columns are
ExecuteRead
being displayed on entering textBox2.Text = er()
SqlDataReade
the employee id. The details of Convert.ToString method as
r dr =
the employees are stored in (cmd.ExecuteNo shown:
cmd.ExecuteR
an Employees table of the HR nQuery());
eader();
database. Refer to the
textBox3.Text = SqlDataRead
while
following code snippet:
Convert.ToString er dr =
(dr.Read())
(cmd.ExecuteNo cmd.Execute
{
string employeeCode;
nQuery());
Reader();
employeeCode =
m
while
textBox2.Text
textBox1.Text;
(dr.Read())
=
string connectionString =
{
Convert.ToStri
"Data
ng((dr[1]));
Source=SQLSERVER01;Initial
textBox2.Text

Catalog=HR;User
id=sa;Password=niit#1234";
SqlConnection cn =
new SqlConnection();
cn.ConnectionString =
connectionString;
cn.Open();
SqlCommand cmd =
cn.CreateCommand();
cmd.CommandType =
CommandType.Text;
cmd.CommandText =
"select * from Employees
where empId=@eCode";

=
textBox3.Text
Convert.ToStri =
ng((dr[1]));
Convert.ToStri
ng((dr[2]));
textBox3.Text
}
=
dr.Close(); m
Convert.ToStri
ng((dr[2]));
}
dr.Close(); m

cmd.Parameters.Add(new
SqlParameter("@eCode",empl
oyeeCode));
textBox2.Text =
Convert.ToString((cmd.Execut
eScalar()));
textBox3.Text =
Convert.ToString((cmd.Execut
eScalar()));
cn.Close();
However, the code does not
give the desired output.
Identify the problem in the
preceding code and provide a
solution for the same. m
AY157 MyCalInc. Ltd. is a
1, The code will
multinational call center
throw an
company whose branches are exception. It is
spread in different parts of the necessary to
world. It has got a centralized mention the
database system wherein the name of the
details of all the employees
provider in the
are stored. As a part of the
connection
development team, John is
string. m
assigned a task to develop a
windows based application in
which the details of an
employee are displayed on the
screen on entering the unique
id of the employee. He has
developed a partial code in
which the values of the first
two columns of an employee
are being displayed on
entering the employee id. The
details of the employees are
stored in an Employees table
of the HR database. Refer to
the following code snippet:

2, The code
will execute
but will not
give any
output. m

3, The code 4, The code will give the


will throw an desired output. m
exception. You
need to
mention the
parameters to
be passed in
the constructor
of
SqlParameter
class. m

string employeeCode;
employeeCode =
textBox1.Text;
string connectionString =
"Data
Source=SQLSERVER01;Initial
Catalog=HR;User
id=sa;Password=password";
SqlConnection cn = new
SqlConnection();
cn.ConnectionString =
connectionString;
cn.Open();
SqlCommand cmd =
cn.CreateCommand();
cmd.CommandType =
CommandType.Text;
cmd.CommandText = "select *
from Employees where
empId=@eCode";
SqlDataReader dr =
cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text =
Convert.ToString((dr[1]));
textBox3.Text =
Convert.ToString((dr[2]));
}
dr.Close();
cn.Close();
Identify whether the preceding
code will give the desired
output or not. m

AY158 MyProd Pvt. Ltd. is a leading 1, You need to 2, You cannot


producer of hardware and
set the
use a single
software products. The details MultipleActiveRe SqlDataRead
of all the products are
sultSets to true. er object to
maintained in a centralized
m
implement
database
more than
system. As a part of the
one operation
development team, Williams is
on a table. m
assigned a task to develop a
windows based application in
which the details of a product
on
the basis of a product Id is
being deleted from the
Products table. However,
before implementing a delete
operation, the details of the
product should
be displayed on the screen.
He has written the following
code to accomplish this task.
string productCode;
productCode =
textBox1.Text;
string connectionString
= "Data
Source=SQLSERVER01;Initial
Catalog=ProductsData;User
id=sa;Password=password";
SqlConnection cn =
new SqlConnection();
cn.ConnectionString =
connectionString;
cn.Open();
SqlCommand cmd =
cn.CreateCommand();
cmd.CommandType =
CommandType.Text;
cmd.CommandText =
"select * from Products where
ProductId=@pCode";
cmd.Parameters.Add(new
SqlParameter("@pCode",
productCode));
SqlDataReader dr =
cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text =
Convert.ToString((dr[1]));
textBox3.Text =
Convert.ToString((dr[2]));
}
SqlCommand cmd1 =

3, You need to 4, The parameters passed in 1


set the
the SqlParameter constructor
MultipleActive are an incorrect order. m
ResultSets to
false. m

cn.CreateCommand();
cmd1.CommandType
= CommandType.Text;
cmd1.CommandText =
"delete from Products where
productId=@pCode";
cmd1.Parameters.Add(new
SqlParameter("@pCode",
productCode));
SqlDataReader dr1 =
cmd1.ExecuteReader();
cn.Close();
However, on execution, an
exception occurs. Identify the
problem in the preceding
code. m

AY159 MyProd Pvt. Ltd. is a leading 1, You need to


producer of hardware and
set the MARS
software products. The details feature in the
of all the products are
connection
maintained in a centralized
string to false m
database
system. As a part of the
development team, Williams is
assigned a task to develop a
windows based application in
which the details of a product
on
the basis of a product Id is
being deleted from the
Products table. However,
before implementing a delete
operation, the details of the
product should
be displayed on the screen.
He has written the following
code to accomplish this task.
string productCode;
productCode =
textBox1.Text;
string connectionString
= "Data
Source=SQLSERVER01;Initial
Catalog=ProductsData;Multipl
eActiveResultSets=True;User
id=sa;Password=password";
SqlConnection cn =

2, You cannot
use a single
SqlDataRead
er object to
implement
more than
one operation
on a table m

3, You need to 4, The parameters passed in 3


assign
the SqlParameter constructor
parameterized are an incorrect order m
value for the
command
object cmd1 m

new SqlConnection();
cn.ConnectionString =
connectionString;
cn.Open();
SqlCommand cmd =
cn.CreateCommand();
cmd.CommandType =
CommandType.Text;
cmd.CommandText =
"select * from Products where
ProductId=@pCode";
cmd.Parameters.Add(new
SqlParameter("@pCode",
productCode));
SqlDataReader dr =
cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text =
Convert.ToString((dr[1]));
textBox3.Text =
Convert.ToString((dr[2]));
}
SqlCommand cmd1 =
cn.CreateCommand();
cmd1.CommandType
= CommandType.Text;
cmd1.CommandText =
"delete from Product where
productId=@pCode";
SqlDataReader dr1 =
cmd1.ExecuteReader();
cn.Close();
However, on execution, an
exception occurs. Identify the
problem in the preceding
code. m

AY160 John works as a software


1, An exception 2, The code
developer in MyProdInc. Ltd. will be thrown will execute
The company is involved in
because the
but will not
the large scale production of constructor of insert the
hardware and software items. the
product
The details of all the products SqlCommandBuidetails in the
are stored in a centralised
lder class takes database. m
database system. John is
the object of a
assigned a task to create an DataSet as a
application in which the details parameter. m
of the products need to be
saved in the database. The
product details are present in
the ProductDetails table of the
Products database. He has
written a partal code to
accomplish his task as shown:
SqlConnection
connection = new
SqlConnection();
connection.ConnectionString
= "Data
Source=SQLSERVER01;Initial
Catalog=Products;User
id=sa;Password=password";
connection.Open();
SqlDataAdapter
adapter = new
SqlDataAdapter("Select * from
Product_Details", connection);
SqlCommandBuilder
cmdBuilder = new
SqlCommandBuilder(adapter);
DataSet ds = new
DataSet("Product_Details");
adapter.Fill(ds,
"Product_Details");
DataRow row =
ds.Tables["Product_Details"].N
ewRow();
row["productId"] =
textBox1.Text;
row["productName"]
= textBox2.Text;
row["productPrice"] =
textBox3.Text;
ds.Tables["Product_Details"].R
ows.Add(row);
connection.Close();
What will be the output on
executing the preceding code?
m

3, The code 4, The details of the product


will give an
will get saved in the
error because database. m
the parameters
passed in the
constructor of
SqlDataAdatap
ter class are in
an incorrect
sequence. m

AY161 Which of the following


1, This property 2, This
3, This
4, This property states that
1
correctly defines atomicity? m states that either property
property states any change in data by a
all the
states that
that any data completed transaction
modifications
data is in a
modification remains permanently in effect
are performed or reliable state made by one in the database. m
none of them
after a
transaction
are performed. transaction is must be
m
completed
separated from
successfully the
to maintain
modifications
integrity of the made by the
data. m
other
transaction. m

AY162 How will you enable query


notification for the HR
database? m

1, ALTER
DATABASE HR
ENABLE
SERVICE_BRO
KER; m

2, ALTER
DATABASE
HR SET
ENABLE_BR
OKER; m

3, ALTER
4, ALTER DATABASE HR
2
DATABASE
ENABLE SERVICEBROKER;
HR SET
m
ENABLE_SER
VICEBROKER
;m

AY163 Which class is used to copy


data in bulk to SQL Server
tables? m

1, SqlBulkCopy 2,
3,
4, SqlCommand m
m
SqlDataRead SqlConnection
er m
m

AY164 How many parameters does 1, 3 m


the GetBytes method take? m

2, 5 m

3, 0 m

4, 1 m

AY165 How will you ensure that the 1, By specifying


UPDATETEXT function does the length of
not delete the existing data? mdata to be
deleted as 0. m

2, By
specifying the
length of data
to be deleted
as null. m

3, By
4, By specifying the length of 1
specifying the data to be deleted as None.
length of data m
to be deleted
as an empty
string. m

AY166 Consider the following code 1, Int m


snippet:
UPDATETEXT Student.Photo
@A @B @C @D
SqlParameter offsetParm =
command.Parameters.Add("@
B", SqlDbType.X); //command
is an object of SqlCommand

2, String m

3, Binary m

What does X represent? m

4, Image m

AY167 Consider the following code 1, String m


snippet to update an image in
a table:
UPDATETEXT Student.Photo
@A @B @C @D
SqlParameter ptrParm =
command.Parameters.Add("@
D", SqlDbType.X); //command
is an object of SqlCommand

2, Int m

3, Image m

4, Binary m

What does X represent? m

AY168 Consider the following code 1, byte, int, int,


snippet to read an image file: respectively m
file.Read(X, Y, Z); //file is an
object of the Filestream class.
What are the data types of X,
Y, and Z?
m

2, int, int,
3, byte, byte, 4, int, byte, int, respectively m 1
byte,
int,
respectively m respectively m

AY169 To update a photograph in a 1, The amount


table, you need to use the
of data to be
UPDATETEXT function.
deleted, the
Consider the following code pointer to the
snippet:UPDATETEXT
start of the
function that is assigned as a photograph, the
command text:
current offset to
command.CommandText="UP insert data, and
DATETEXT Emp.EmpPhoto the data being
@A @B @C @D";
sent to the
where Emp is the name of the database,
table and EmpPhoto is name respectively m
of the column.
Command is the object of
SqlCommand
What do @A, @B, @C, and
@D represent? m

2, The current 3, The current 4, The pointer to the start of 4


offset to insert offset to insert the photograph, the current
data, the
data, the
offset to insert data, amount
pointer to the pointer to the of data to be deleted, and the
start of the
start of the
data being sent to the
photograph, photograph, database, respectively m
the data being amount of data
sent to the
to be deleted,
database, and and the data
the amount of being sent to
data to be
the database,
deleted,
respectively m
respectively m

AY170 Consider the following code 1, Int m


snippet:
UPDATETEXT Student.Photo
@A @B @C @D
SqlParameter p =
command.Parameters.Add("@
A", SqlDbType.X, 16);
//command is an object of
SqlCommand

2, Binary m

In the preceding code snippet,


what does X represent? m

3, Image m

4, String m

AY171 You have been asked to


1, using
2,
3,
4, using (TransactionScope ts 1
create an application that will (TransactionSco TransactionSc TransactionSc = new TransactionScope())
open two connections and
pe ts = new
ope ts = new ope ts = new
{ using (SqlCommand
execute two command. The TransactionScop TransactionSc TransactionSc cmd = new
first command will insert a
e())
ope()
ope()
SqlCommand("INSERT
record in the HRusers table.
{
using
using
INTO
The other command deletes a
using
(SqlCommand (SqlCommand
record from the Department (SqlCommand cmd = new
cmd = new
HRusers(cUserName)VALUE
table. Which of the following cmd = new
SqlCommand( SqlCommand( S('Darren')", cn))
code snippet will allow you to SqlCommand("I "INSERT
"INSERT
{
perform the required task?
NSERT
INTO
INTO
int rowsUpdated =
Assume the connections to be
INTO
cmd.ExecuteNonQuery();
already open where cn and
HRusers(cUser HRusers(cUs HRusers(cUse
if (rowsUpdated > 0)
cn1 are the connection
Name)VALUES(' erName)VAL rName)VALUE
{
objects. m
Darren')", cn)) UES('Darren') S('Darren')",
using
{
", cn))
cn))
(SqlCommand cmd1 = new
int
{ int
{
SqlCommand(DELETE
rowsUpdated = rowsUpdated
int
Department
cmd.ExecuteNo =
rowsUpdated WHERE
nQuery();
cmd.Execute =
cDepartmentCode=1111,
if
NonQuery(); ExecuteNonQ cn1))
(rowsUpdated >
if
uery();
{
0)
(rowsUpdated
if
int
{
> 0)
(rowsUpdated rowsUpdated1 =
using
{
> 0)
cmd1.ExecuteNonQuery();
(SqlCommand
{
cn.Complete();
cmd1 = new
using
.}}}} m
SqlCommand("D (SqlCommand using
ELETE
cmd1 = new (SqlCommand
SqlCommand( cmd1 = new
Department
"DELETE
SqlCommand(
WHERE
"DELETE
cDepartmentCo Department
de=1111", cn1)) WHERE
Department
{
cDepartment WHERE
Code=1111", cDepartmentC
int
cn1))
ode=1111",
rowsUpdated1 =
cn))
cmd1.ExecuteN {
{
onQuery();
if int
int
(rowsUpdated1 rowsUpdated rowsUpdated1
> 0)
1=
=
cmd1.Execute cmd1.Execute
{
NonQuery(); NonQuery();
.}}} m
ts.Complete(); if
.}}}} m
(rowsUpdated
1 > 0)
{
ts.Complete();
.}}}} m

AY172 You need to create an


1, FileStream file 2, FileStream 3, FileStream 4, FileStream file = new
2
application that will insert an = new
file = new
file = new
FileStream(c,
image into an Images table of FileStream(c,
FileStream(c, FileStream(c, FileMode.OpenOrCreate,
Photographs database. Which FileMode.Open FileMode.Ope FileMode.Ope FileAccess.Read);
of the following code snippets OrCreate,
nOrCreate, nOrCreate,
byte[] r = new
will help you perform the
FileAccess.ReadFileAccess.Re FileAccess.Re byte[file.Length];
required task?
);
ad);
ad);
file.Read(r, 0,
byte[] r =
byte[] r
byte[] r System.Convert.ToInt32(file.L
Assume that c stores the
new
= new
= new
ength));
name of the image file and
byte[file.Length]; byte[file.Lengt byte[file.Lengt
file.Close();
connection is the Connection
h];
h];
string sql = "SELECT *
object.The connection has
file.Read(Syste
FROM Images";
been established. m
m.Convert.ToInt file.Read(r, 0, file.Read(0,r,S
SqlDataAdapter
32(file.Length)); System.Conv ystem.Convert. adapter = new
ert.ToInt32(file ToInt32(file.Le SqlDataAdapter(sql,
file.Close();
.Length));
ngth));
connection);
string sql
SqlCommandBuilder
= "SELECT *
file.Close(); file.Close();
cmdBuilder = new
FROM Images";
string
string SqlCommandBuilder(adapter)
sql =
sql = "SELECT ;
SqlDataAdapter "SELECT *
* FROM
DataSet ds = new
adapter = new FROM
Images";
DataSet("Images");
SqlDataAdapter( Images";
adapter.Fill(ds,
sql, connection);
SqlDataAdapte "Images");
SqlDataAdapt r adapter =
DataRow row =
SqlCommandBuier adapter = new
ds.Tables["Images"].NewRow
lder cmdBuilder new
SqlDataAdapte ();
= new
SqlDataAdapt r(sql,
row["imPhoto"] = r;
SqlCommandBuier(sql,
connection);
adapter.Update(ds,
lder(adapter);
connection);
"Images"); m
DataSet
SqlCommandB
ds = new
SqlCommand uilder
DataSet("Image Builder
cmdBuilder =
s");
cmdBuilder = new
new
SqlCommandB
adapter.Fill(ds, SqlCommand uilder(adapter)
"Images");
Builder(adapt ;
DataRow er);
row =
DataSet ds =
ds.Tables["Imag DataSet ds = new
es"].NewRow(); new
DataSet("Imag
DataSet("Ima es");
row["imPhoto"] = ges");
r;
adapter.Fill(ds,
adapter.Fill(ds "Images");
ds.Tables["Imag , "Images");
es"].Rows.Add(r
DataRow row
ow);
DataRow row =
=
ds.Tables["Ima
adapter.Update( ds.Tables["Im ges"].NewRow
ds, "Images"); m ages"].NewRo ();
w();
row["imPhoto"]
row["imPhoto" = r;
] = r;
ds.Tables["Ima

ds.Tables["Im ges"].Rows.Ad
ages"].Rows. d(row);
Add(row);
adapter.Updat
adapter.Updat e(ds,
e(ds,
"Images"); m
"Images"); m

AY173 Sven is working as a software 1,


2,
3,
4, SqlDataReader myReader 3
developer in QuickSolutions SqlDataReader SqlDataRead SqlDataReade =
Software Ltd. He has been
myReader =
er myReader r myReader =
asked to create an application
=
command.Exe command.ExecuteReader();
that will display the photo of command.Execu
cuteReader(C
while (myReader.Read())
an employee, stored in the
teReader();
command.Exe ommandBehav
{
imPhoto field of EMPLOYEES
while
cuteReader(C ior.SequentialA
file = new
table, whose employee code (myReader.Rea ommandBeha ccess);
FileStream(savedImageName
is E001. Which of the followingd())
vior.Sequentia
while
, FileMode.OpenOrCreate,
code snippet when appended
{ file =
lAccess);
(myReader.Re FileAccess.Write);
to the code given below will new
while
ad())
bw = new
help him perform the required FileStream(save (myReader.R
{
BinaryWriter(file);
task?
dImageName, ead())
file =
startIndex = 0;
Assume that connection has FileMode.Open
{
new
retval =
been established and
OrCreate,
file = FileStream(savmyReader.GetBytes(0,
connection is the Connection FileAccess.Write new
edImageName startIndex, outbyte, 0,
object.file and bw are objects );
FileStream(sa ,
bufferSize);
of FileStream and
bw =
vedImageNa FileMode.Ope
while (retval ==
BinaryWriter classes,
new
me,
nOrCreate,
bufferSize)
respectively
BinaryWriter(file) FileMode.Ope FileAccess.Wri
{
sring sql = "SELECT imPhoto ;
nOrCreate, te);
FROM EMPLOYEES WHERE
FileAccess.Wr
bw = bw.Write(outbyte);
cEmployeeCode='E001'";
startIndex = 0; ite);
new
bw.Flush();
int bufferSize = 100;
retval =
bw = BinaryWriter(fil
startIndex +=
byte[] outbyte = new
myReader.GetB new
e);
bufferSize;
byte[bufferSize];
ytes(startIndex, BinaryWriter(fi
retval =
long retval, startIndex = 0; outbyte,
le);
startIndex = 0; myReader.GetBytes(0,
string savedImageName = bufferSize);
retval startIndex, outbyte, 0,
" ";
while
startIndex = 0; =
bufferSize);
SqlCommand command = (retval ==
retval myReader.Get
}
new SqlCommand(sql,
bufferSize)
=
Bytes(0,
}
connection); m
myReader.Ge startIndex,
..

{ bw.Write(outbyt tBytes();
outbyte, 0,
} // Code for
e);
while bufferSize);
displaying image in the
(retval ==
while picture box
}m
bw.Flush();
bufferSize)
(retval ==
{
bufferSize)
startIndex +=
{
bufferSize;
bw.Write(outb
yte);
bw.Write(outby
retval =
te);
myReader.GetB bw.Flush();
ytes(startIndex,
bw.Flush();
outbyte,
startIndex +=
bufferSize);
bufferSize;
startIndex +=
}
bufferSize;
retval =
..
myReader.Ge retval =
} // Code tBytes();
myReader.Get
for displaying
} Bytes(0,
image in the
} startIndex,
picture box
outbyte, 0,
}m
..
bufferSize);
} //
}
Code for
}
displaying
image in the ..
picture box
} //
}m
Code for
displaying
image in the
picture box
}m
AY174 You have been asked to
1,
2,
3,
4, TransactionOptions options 4
create an application that will TransactionOpti TransactionO TransactionOp = new TransactionOptions();
insert a record each into the ons options =
ptions options tions options =
Departments table and the
new
= new
new
options.IsolationLevel =
HRUsers table of the HR
TransactionOpti TransactionO TransactionOp
database. You need to ensure ons();
ptions();
tions();
System.Transactions.Isolation
that dirty reads, nonLevel.Serializable; m
repeatable reads, and
options.Isolation options.Isolati options.Isolatio
phantom reads are avoided Level =
onLevel =
nLevel =
during the transaction. Which
System.Trans
of the following code snippet System.Transact actions.Isolati System.Transa
correctly does the required
ions.IsolationLev onLevel.Read ctions.Isolation
task? m
el.ReadCommitt Uncommitted; Level.Read; m
ed; m
m

AY175 A new employee, Linda Taylor, 1,


2,
3,
4, SqlTransaction tran = null; 1
has joined QuickSolutions
SqlTransaction SqlTransactio SqlTransaction
try
Software Ltd. Her details need tran = null;
n tran = null; tran = null;
{
to be added to an empdetails
try
try
try
//cn is an object of
table. This task should be
{
{
{
the SqlConnection class.
done through a transaction.
//cn is
//cn is
Which of the following code an object of the tran.BeginTra an object of
cn.BeginTransaction();
snippets will allow you to
SqlConnection nsaction();
the
SqlCommand cmd =
perform this task? m
class.
SqlConnection new SqlCommand("INSERT
tran = SqlCommand class.
INTO
cn.BeginTransac cmd = new
tran empdetails(ccode,cname,cad
tion();
SqlCommand( =
dress,cstate,ccountry,cDesign
"INSERT
cn.BeginTrans ation,cDepartment)VALUES(1
SqlCommand INTO
action();
101,'Linda
cmd = new
empdetails(cc
Taylor','Oxfordshire','London','
SqlCommand("I ode,cname,ca SqlCommand UK','Manager','Finance')", cn,
NSERT INTO
ddress,cstate, cmd = new
tran);
empdetails(ccod ccountry,cDes SqlCommand(
e,cname,caddre ignation,cDep "INSERT INTO cmd.ExecuteNonQuery();
ss,cstate,ccountr artment)VALU empdetails(cco
cn.Commit();
y,cDesignation,c ES(1101,'Lind de,cname,cad
Department)VAL a
dress,cstate,cc Console.WriteLine("Transacti
UES(1101,'Linda Taylor','Oxford ountry,cDesign on Committed\n");
Taylor','Oxfordsh shire','London' ation,cDepart
}
ire','London','UK' ,'UK','Manage ment)VALUES
catch (SqlException
,'Manager','Fina r','Finance')", (1101,'Linda ex)
nce')", cn, tran); cn, tran);
Taylor','Oxford
{
shire','London',
tran.Rollback();
cmd.ExecuteNo cmd.Execute 'UK','Manager',
nQuery();
NonQuery(); 'Finance')", cn, Console.WriteLine("Error tran);
TRANSACTION ROLLED
tran.Commit(); Commit();
BACK\n" + ex.Message);
cmd.ExecuteN
}
Console.WriteLi Console.Write onQuery();
m
ne("Transaction Line("Transac
Committed\n"); tion
cn.Commit();
}
Committed\n")
catch
;
Console.Write
(SqlException
}
Line("Transacti
ex)
catch on
{
(SqlException Committed\n");
ex)
}
tran.Rollback();
{
catch
(SqlException
Console.WriteLi Rollback();
ex)
ne("Error {
TRANSACTION Console.Write
ROLLED
Line("Error - cn.Rollback();
BACK\n" +
TRANSACTI
ex.Message);
ON ROLLED Console.Write
}
BACK\n" +
Line("Error m
ex.Message); TRANSACTIO
}
N ROLLED
m
BACK\n" +
ex.Message);
}

AY176 QuickSolutions Software Ltd. 1, The syntax of 2,


3,
4, The syntax of
2
stores the details of its
UPDATETEXT isUPDATETEX UPDATETEXT UPDATETEXT is incorrect. It
employees in an Employee
incorrect. It
T requires a requires a
should be:
table in a database called
should be:
pointer to the pointer to the UPDATETEXT
QuickSolutions. The details
UPDATETEXT binary field
binary field
Employee.Photo @Offset
include the photograph of the Employee.Photo being
being updated. @Pointer @Data null";
employees. The photograph of @Pointer
updated. To To get a
m
one employee whose
@Offset @Data get a pointer pointer to a
employee code is E009 needs null";
to a particular particular field
to be updated with a new
m
field of a
of a record in a
photograph. Peter is working
record in a
database, the
as a software developer in
database, the SQL Server
QuickSolutions Software Ltd.
SQL Server TEXTPTR
and he has been assigned this
TEXTPTR
function needs
task. Peter writes the following
function
to be called.
code in the click event of a
needs to be This can be
button to perform the required
called. This done in the
task:
can be done following way:
const int bufferSize =
in the
100;
following way: command.Co
byte[] buffer = new
mmandText =
byte[bufferSize];
command.Co "TEXTPTR(Sel
long currentIndex = 0;
mmandText = ect Photo from
byte[] photoPtr;
"Select
Employee
{
TEXTPTR(Ph where
//open the
oto) from
employeeCode
connection
Employee
='E009')";
using
where
m
(SqlCommand command =
employeeCod
connection.CreateCommand()
e='E009'";
)
m
{

command.CommandText =
"Select Photo from Employee
where
employeeCode='E009'";
photoPtr =
(byte[])command.ExecuteScal
ar();
}
using
(SqlCommand command =
connection.CreateCommand()
)
{
command.CommandText =
"UPDATETEXT
Employee.Photo @Pointer
@Offset null @Data";
..
..
}
However, when Peter
executes the code, he is
getting the exception "Invalid
text, ntext, or image value".
What might be causing this
problem? m
AY177 The records stored in the
1, using
2, using
3, using
4, using (SqlConnection sc = 1
Stores table of
(SqlConnection (SqlConnectio (SqlConnectio new
AdventureWorks database
sc = new
n sc = new
n sc = new
SqlConnection(connectionStri
have accidentally got deleted. SqlConnection(c SqlConnectio SqlConnection ng))
However, there is a backup
onnectionString) n(connectionS (connectionStri
{ sc.Open();
copy of this table called
)
tring))
ng))
SqlCommand
StoresBackup. You have
commandSourceData = new
written the following code in { sc.Open();
{ sc.Open(); { sc.Open(); SqlCommand("SELECT *
the click event of a button to
FROM StoresBackup;", sc);
copy the records from
SqlCommand SqlCommand SqlCommand
SqlDataReader
StoresBackup to Stores:
commandSourc commandSou commandSour reader =
using (SqlConnection eData = new
rceData =
ceData = new commandSourceData.Execut
sc = new
SqlCommand("S new
SqlCommand( eReader();
SqlConnection(connectionStri ELECT * FROM SqlCommand( "SELECT *
using
ng))
StoresBackup;", "SELECT *
FROM
(SqlConnection dc = new
{ sc.Open();
sc);
FROM
StoresBackup; SqlConnection(connectionStri
SqlCommand
StoresBackup ", sc);
ng))
commandSourceData = new SqlDataReader ;", sc);
{ dc.Open();
SqlCommand("SELECT *
reader =
SqlDataReade
using
FROM StoresBackup;", sc); commandSourc SqlDataRead r reader =
(SqlBulkCopy bulkCopy =
SqlDataReader
eData.ExecuteR er reader =
commandSour new SqlBulkCopy(dc))
reader =
eader();
commandSou ceData.Execut
commandSourceData.Execute
using rceData.Exec eReader();
{ bulkCopy.DestinationTable =
Reader();
(SqlConnection uteReader();
"Stores";
using
dc = new
using
(SqlConnection dc = new
SqlConnection(c using
(SqlConnectio bulkCopy.WriteToServer(read
SqlConnection(connectionStri onnectionString) (SqlConnectio n dc = new
er); } m

ng))

)
n dc = new
SqlConnection
{ dc.Open();
SqlConnectio (connectionStri
using
{ dc.Open();
n(connectionS ng))
(SqlBulkCopy bulkCopy = new
tring))
SqlBulkCopy())
using
{ dc.Open();
{
(SqlBulkCopy { dc.Open();
bulkCopy = new
using
bulkCopy.DestinationTableNa SqlBulkCopy(dc) using
(SqlBulkCopy
me = "Stores";
)
(SqlBulkCopy bulkCopy =
bulkCopy = new
bulkCopy.WriteToServer();
{ bulkCopy.Desti new
SqlBulkCopy())
}}
nationTableNam SqlBulkCopy(
e = "Stores";
dc))
{ bulkCopy.De
However, the preceding code
stinationTable
is not working. Analyze the
bulkCopy.WriteT { bulkCopy.De Name =
problem and identify which of oServer(reader); stinationTable "Stores";
the following code snippets
}m
Name =
will perform the required task?
"Stores";
bulkCopy.Write
m
ToServer(read
bulkCopy.Writ er); } m
eToServer(); }
m
AY178 Samuel needs to update the 1,
2,
3,
4, TransactionOptions
2
HRUsers table and the
TransactionOpti TransactionO TransactionOp options = new
Department table of the HR ons options;
ptions options tions options = TransactionOptions();
database using distributed
= new
new
transaction. The transaction options.Isolation TransactionO TransactionOp options.IsolationLevel =
should be such that volatile
Level =
ptions();
tions();
System.Transactions.Isolation
data cannot be read during theSystem.Transact
Level.ReadUncommitted;
transaction but can be
ions.IsolationLev options.Isolati options.Isolatio
using
modified. To perform this task, el.ReadCommitt onLevel =
nLevel =
(TransactionScope ts = new
Samuel writes the following
ed;
System.Trans System.Transa TransactionScope())
code:
using actions.Isolati ctions.Isolation
{ using
TransactionOptions
(TransactionSco onLevel.Read Level.ReadCo (SqlCommand cmd = new
options; options.IsolationLevel pe ts = new
Committed; mmitted;
SqlCommand("INSERT INTO
=
TransactionScop
using Department(cDepartmentCod
System.Transactions.Isolation e())
using
(options)
e) VALUES(2013)", cn))
Level.ReadUncommitted;
{ using (TransactionS
{ int
using (options)
(SqlCommand cope ts = new { using
rowsUpdated =
{ .
cmd = new
TransactionSc (SqlCommand cmd.ExecuteNonQuery();
using
SqlCommand("I ope())
cmd = new
if
(SqlCommand cmd = new
NSERT INTO
SqlCommand( (rowsUpdated > 0)
SqlCommand("INSERT INTO Department(cDe { using
"INSERT INTO
{using
Department(cDepartmentCod partmentCode) (SqlCommand Department(c (SqlCommand cmd1 = new
e) VALUES(2013)", cn))
VALUES(2013')" cmd = new
DepartmentCo SqlCommand("INSERT INTO
{ int
, cn))
SqlCommand( de)
HRusers(cUserName)
rowsUpdated =
"INSERT
VALUES(2013 VALUES('Hansel')", cn1))
cmd.ExecuteNonQuery();
{ int
INTO
)", cn))
{ int
if
rowsUpdated = Department(c
rowsUpdated1 =
(rowsUpdated > 0)
cmd.ExecuteNo DepartmentC { int
cmd1.ExecuteNonQuery();
{ using
nQuery();
ode)
rowsUpdated
if
(SqlCommand cmd1 = new
VALUES(201 =
(rowsUpdated1 > 0)
SqlCommand("INSERT INTO if (rowsUpdated 3)", cn))
cmd.ExecuteN
HRusers(cUserName)
> 0)
onQuery();
{ts.Complete();

VALUES('Hansel')", cn1))
{ int
{ int
{ using
rowsUpdated if
..}}}}} m
rowsUpdated1 =
(SqlCommand =
(rowsUpdated
cmd1.ExecuteNonQuery(); if cmd1 = new
cmd.Execute > 0)
(rowsUpdated1 >0)
SqlCommand("I NonQuery();
ts.Complete();
NSERT INTO
{ using
..}}}}
HRusers(cUser if
(SqlCommand
However, the code is not
Name)
(rowsUpdated cmd1 = new
serving the required purpose. VALUES('Hansel> 0)
SqlCommand(
Identify the problem and
'')", cn1))
"INSERT INTO
suggest a solution. Assume
{ { using
HRusers(cUse
that two connection objects cn int
(SqlCommand rName)
and cn1 have been created. m rowsUpdated1 = cmd1 = new VALUES('Hans
cmd1.ExecuteN SqlCommand( el')", cn1))
onQuery();
"INSERT
INTO
{int
if
HRusers(cUs rowsUpdated1
(rowsUpdated1 erName,cPas =
> 0)
sword)
cmd1.Execute
VALUES('Han NonQuery();
{ ts.Complete(); sel','Lord')",
cn1))
if
..}}}}} m
(rowsUpdated
{ int
1 > 0)
rowsUpdated
1=
{ ts.Complete()
cmd1.Execute ;
NonQuery();
}}}}}
if
m
(rowsUpdated
1 > 0)
{ ts.Complete
();
}}}} m

AY179 Samuel is working as a


1, Samuel
2, Samuel
3, Samuel
4, Samuel should make
4
software developer in
should make
should make should write following changes in the
QuickSolutions Software Ltd. following
following
the following code:
He needs to update the
changes in the changes in
code:
TransactionOptions
HRUsers table and the
code:
the code:
static void
options = new
Departments table of the HR
Main(string[] TransactionOptions();
database. The transaction
args)
should be such that volatile
TransactionOpti TransactionO
{
options.IsolationLevel =
data can be read but not
ons options =
ptions options
modified during the
new
= new
TransactionOp System.Transactions.Isolation
transaction. In addition, new TransactionOpti TransactionO tions options; Level.RepeatableRead;
data can be added during the ons();
ptions();
using
transaction. Samuel writes the
options.Isolatio (TransactionScope ts = new
following code snippet for that options.Isolation options.Isolati nLevel =
TransactionScope())
purpose:
Level =
onLevel =
{
TransactionOptions
System.Transa
//
options;
System.Transact System.Trans ctions.Isolation Code to update the HRUsers
ions.IsolationLev actions.Isolati Level.Repeata table and the Department
options.IsolationLevel =
el.ReadCommitt onLevel.Read bleRead;
table of the HR database
System.Transactions.Isolation ed;
Uncommitted;
using
}m
Level.ReadCommitted;
using
(options)
using (options)
(TransactionSco using
{
{
pe ts = new
(TransactionS
// Code to update TransactionScop cope ts = new
the HRUsers table and the
e())
TransactionSc // Code to
Department table of the HR
{
ope())
update the
database
{
HRUsers table
}
// Code to
and the
However, the code is not
update the
// Code to
Department
serving the required purpose. HRUsers table update the
table of the HR
Identify the problem and
and the
HRUsers
database
suggest a solution. m
Department
table and the
}m
table of the HR Department
database
table of the
}m
HR database
}m

AY180 The employee details of


1, private void 2, private void 3,private void 4,private void UpdateGrid() 3
QuickSolutions Software Ltd. UpdateGrid()
UpdateGrid() UpdateGrid()
{
are stored in an Employees
{
{
{
using (SqlCommand
table. Sarah is a software
...................
............... cmd = new SqlCommand(sql,
developer in QuickSolutions ..
..
cn))
Software Ltd. She has been
using
.
using
{ dep = new
assigned the task of creating (SqlCommand
using (SqlCommand SqlDependency();
an application that will cache cmd = new
(SqlCommand cmd = new
dep.OnChange +=
these details. The cache
SqlCommand(sq cmd = new
SqlCommand( dep_OnChange;
should get updated whenever l, cn))
SqlCommand( sql, cn))
using
there is some change in the
{
sql, cn))
{
(SqlDataReader rdr =
database. Sarah has written
dep =
{
dep = cmd.ExecuteReadercmd())
the following code to perform new
dep = new
{
this task:
SqlDependency( new
SqlDependenc
dt.Load(rdr);
//The connection object, cn
cmd);
SqlDependen y(cmd);
} } }
and SqlDependency object,
cy();
dep have already been
dep.OnChange
using dep.OnChang dataGridView1.Invoke((GridD
created
+=
(SqlDataRead e +=
elegate)delegate(DataTable
private void UpdateGrid() dep_OnChange; er rdr =
dep_OnChang table)
{ string sql = "SELECT
using
cmd.Execute e;
{ ..
cEmployeeCode FROM dbo. (SqlDataReader Reader())
using
}m
[Employees]";
rdr =
{
(SqlDataRead
DataTable dt = new
cmd.ExecuteRe
er rdr =
DataTable();
ader())
dt.Load(rdr); } cmd.ExecuteR
using (SqlCommand
{
}
}
eader())
cmd = new SqlCommand(sql,
cn))
dt.Load();}}}
dataGridView { dt.Load(rdr);
{dep = new
1.Invoke((Grid } }
}
SqlDependency();
dataGridView1( Delegate)dele
using (SqlDataReader GridDelegate)de gate(DataTabl dataGridView1
rdr = cmd.ExecuteReader()) legate(DataTabl e table)
.Invoke((GridD
{ dt.Load(rdr);}}
e table)
elegate)delega
{. te(DataTable
dataGridView1((GridDelegate) {.......................
}m
table)
delegate(DataTable table)
}m
{ ..................
{ dataGridView1.DataSource =
}m
table;}, dt);
}
private void
dep_OnChange(Object
sender,
SqlNotificationEventArgs e)
{
UpdateGrid();}}}
However, the code is not
working properly. Identify the
problem and suggest a
solution. m

AY181 Which of the following is not a 1, Durability is 2, Any change 3, Durability 4, Durability ensures that any 3
property of durability? m
ensured by
in data due to ensures that change in data by a
taking back ups a completed data is in a
completed transaction
of data and
transaction
reliable state remains permanently in effect
restoring
persists even after a
in the database. m
transaction logs. in the event of transaction is
m
a system
completed
failure. m
successfully to
maintain
integrity of the
data. m

AY182 Which class is used to provide 1,


2,
3,
4, SqlClientPermission m
security permissions to a user SqlDataAdapter SqlCommand SqlConnection
for executing SQL notification? m
m
m
m

AY183 How will you ensure that a


user has no access to a
resource while executing
query notifications? m

1, By setting the
value of
Permissionstate
to None m

2, By setting 3, By setting 4, By setting the value of


2
the value of the value of
Permissionstate to Restricted
PermissionSt PermissionStatm
ate to None m e to Restricted
m

AY184 Which namespace do you


1,
2,
3,
4,
1
need to include in order to
System.Security. System.Permi System.SecuritSystem.Permissions.Security
give permissions to a user so Permissions m ssions m
ym
m
that he is able to execute
query notifications? m

AY185 After calling which method, do 1, Commit() m


you need to execute a
command within a transaction,
set the connection property of
the command to a connection
running the appropriate
transaction, and then execute
the command? m

2,
3, Rollback() m4, EndTransaction() m
BeginTransact
ion() m

AY186 Which of the following


1, Encoding m
XmlWriterSettings property
gets or sets a value indicating
whether the
System.Xml.XmlWriter should
close the underlying stream or
System.IO.TextWriter when
the
System.Xml.XmlWriter.Close()
method is called? m

2,
3,
4, CloseOutput m
NewLineChar ConformanceL
sm
evel m

AY187 Which of the following


1,
2,
3,
4, WriteElementString() m
methods of the XmlTextWriter WriteStartDocu WriteStartEle WriteDeclarati
class creates an XML
ment() m
ment() m
on() m
declaration? m

AY188 Which of the following code


snippets retrieves the XML
representation of a dataset,
dataset1, and stores it in a
string, str? m

1, string
2, string
3, string
4, string
str=dataset1.Co str=dataset1. str=GetXml(da str=dataset1.GetXml(); m
nvert.GetXml; m GetXml; m
taset1); m

AY189 Which of the following is the


default option of
XmlWriteMode? m

1, Schemas m

2,
3,
4, DiffGram m
IgnoreSchem WriteSchema
am
m

AY190 Which of the following


methods of the
XmlTextReader class reads
the very next node from the
stream? m

1, Read() m

2,
3,
4, ReadString() m
MoveToNextA ReadNextElem
ttribute() m
ent() m

AY191 You have created an XML file 1, The Indent


2, The
3, The
4, The Indent property of
using XMLWriter. When you property of
IndentChars IndentChars NewLineOnAttributes class
open the XML file in Notepad, XmlWriterSetting property of
property of
has not been set to true m
you get the following output in s class has not XmlWriterSetti XmlWriterSetti
one line:
been set to true ngs class has ngs class has
<?xml version="1.0"
m
not been set not been set to
encoding="utf-8"?><!--Order
to true m
""m
Details of Q1-><OrderDetails><Order
OrderID="O001"><ProductNa
me>Toys</ProductName><Pri
ce>100</Price></Order><Ord
er
OrderID="O002"><ProductNa
me>Stationary</ProductName
><Price>30</Price></Order><
/OrderDetails>

What might be the possible


cause? m

AY192 Consider the following code, 1, An exception


which is written inside the click will be thrown
event of a button called
because
Operate:
Tables[0] will
return a NULL
XmlTextReader
value. m
ExternalCandidateReader =
new
XmlTextReader("C:\\ExternalC
andidate.xml");
XmlTextReader
InternalCandidateReader =
new
XmlTextReader("C:\\InternalC
andidate.xml");
DataSet
dsExtCandidate = new
DataSet();
dsExtCandidate.ReadXml(Ext
ernalCandidateReader);
DataSet
dsIntCandidate = new
DataSet();
dsIntCandidate.ReadXml(Inter
nalCandidateReader);
dsExtCandidate.Merge(dsIntC
andidate);
dsExtCandidate.WriteXml("C:\\

2, The
3, The
4, The contents of
2
contents of
contents of
dsIntCandidate, which
dsIntCandidat dsIntCandidate contains the
e, which
, which
InternalCandidate.xml file, will
contains the contains the be appended to
InternalCandi InternalCandid dsExtCandidate, which
date.xml file, ate.xml file, will contains the
will be
be appended ExternalCandidate.xml file. A
appended to to
new file CandidateDetails.xml
dsExtCandida dsExtCandidat file be created that will
te, which
e, which
contain the merged data. The
contains the contains the contents of dsIntCandidate
ExternalCandi ExternalCandi will be displayed in a
date.xml file. date.xml file. A DataGridView control. m
A new file
new file
CandidateDet CandidateDeta
ails.xml file be ils.xml file be
created that created that
will contain
will contain the
the merged merged data.
data. The
The
contents of
DataGridView
dsExtCandida control will not
te will be
display
displayed in a anything. m
DataGridView
control. m

CandidateDetails.xml");
DataSet dsDisplay =
new DataSet();
dsDisplay.ReadXml("C:\\Candi
dateDetails.xml",
XmlReadMode.InferSchema);
dataGridView1.DataSource =
dsDisplay.Tables[0].DefaultVie
w;
What will happen when the
Operate button is clicked? m

AY193 Which of the following


statements is true about the
InferSchema XmlReadMode
option? m

1, It examines 2, It ignores
the XML data
any inline
and selects the schema m
appropriate
option m

3, It loads the 4, It does not deduce the


XML data into schema according to the
the existing
structure of the XML data m
dataset
schema. m

AY194 Consider the following code 1,


2,
3,
4, ds.DefaultView.Tables[0] m 3
snippet, which fills a dataset ds.DefaultView ds.Tables.Def ds.Tables[0].D
with data stored in an
m
aultView m
efaultView m
Students.xml file:
DataSet ds = new DataSet();
ds.ReadXml("C:\\Students.xml
",
XmlReadMode.InferSchema);
dataGridView1.DataSource =
X;
In the preceding code, what
does X represent? m

AY195 Consider the following XML 1, The XSD file 2, The XML 3, The PRICE 4, The statement
4
file, products.xml:
is not incorrect. file is not well- element
xmlns="urn:product-schema"
<?xml version="1.0"?>
m
formed. m
cannot have a is missing in the XML file. m
<PRODUCTDATA>
negative value.
<PRODUCT>
m
<PRODUCTNAME>Barbie
Doll</PRODUCTNAME>
<PRICE>-200</PRICE>
<DESCRIPTION>Toy</DESC
RIPTION>
<QUANTITY>0</QUANTITY>
</PRODUCT>
</PRODUCTDATA>
Consider the schema file,
products.xsd:
<xsd:schema
xmlns:xsd="http://www.w3.org/
2001/XMLSchema"
xmlns="urn:product-schema"
elementFormDefault="qualifie
d"
targetNamespace="urn:produc
t-schema">
<xsd:element
name="PRODUCTDATA"
type="prdata"/>
<xsd:complexType
name="prdata">
<xsd:sequence>

<xsd:element
name="PRODUCT"
type="prdt"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType
name="prdt">
<xsd:sequence>
<xsd:element
name="PRODUCTNAME"
type="xsd:string"/>
<xsd:element
name="DESCRIPTION"
type="xsd:string"/>
<xsd:element
name="PRICE"
type="xsd:positiveInteger"/>
<xsd:element
name="QUANTITY"
type="xsd:nonNegativeInteger
"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
When you are validating the
XML file against the schema
using XmlReader, you are not
getting any output. What is the
possible cause? m
AY196 The employee details of
1, using
2, using
3, using
4, using (SqlConnection conn 2
QuickSolutions Software Ltd. (SqlConnection (SqlConnectio (SqlConnectio = new SqlConnection())
are stored in an XML format in conn = new
n conn = new n conn = new
{
an EMP table of an HR
SqlConnection())SqlConnectio SqlConnection
string
database. You are working as
{
n())
())
connectionString = "Data
a .NET developer in
string
{
{
Source=SQLSERVER01;Initia
QuickSolutions Software Ltd. connectionString
l Catalog=HR;User
You have been asked to
= "Data
string
string
ID=sa;Password=niit#1234";
create an application that will Source=SQLSE connectionStri connectionStri
retrieve these details and
RVER01;Initial ng = "Data
ng = "Data
conn.ConnectionString =
display them in a DataGrid
Catalog=HR;Us Source=SQLSSource=SQLS connectionString;
control. Which of the following er
ERVER01;Initi ERVER01;Initi
conn.Open();
code snippets will allow you to ID=sa;Password al
al
using
perform the required task? m =niit#1234";
Catalog=HR; Catalog=HR;U (SqlCommand cmd =
User
ser
conn.CreateCommand())
conn.Connection ID=sa;PasswoID=sa;Passwo
{
String =
rd=niit#1234"; rd=niit#1234";
connectionString
cmd.CommandText =
;
conn.Connecti conn.Connecti "SELECT * FROM EMP";
onString =
onString =
using
conn.Open();
connectionStri connectionStri (SqlDataReader rdr =
using ng;
ng;
cmd.ExecuteReader())
(SqlCommand
{
cmd =
conn.Open(); conn.Open();
while
conn.CreateCo
(rdr.Read())
mmand())
using
using
{

(SqlCommand (SqlCommand
cmd =
cmd =
SqlXml e =
cmd.CommandT conn.CreateC conn.CreateCo rdr.GetSqlXml(0);
ext = "SELECT * ommand())
mmand())
if (!e.IsNull)
FROM EMP";
{
{
{
// ds is the
using
cmd.Comman cmd.Comman object of DataSet
(SqlDataReader dText =
dText =
rdr =
"SELECT *
"SELECT *
ds.ReadXml(CreateReader());
cmd.ExecuteRe FROM EMP"; FROM EMP";
}
ader())
}
{
using
using
}
(SqlDataRead (SqlDataRead
}
while
er rdr =
er rdr =
(rdr.Read())
cmd.Execute cmd.ExecuteR dataGrid1.DataSource = ds;
{ Reader())
eader())
}m
{
{
SqlXml e =
while
rdr.GetSqlXml(0) (rdr.Read())
;
{
if (e.IsNull)

while
(rdr.Read())
{

SqlXml e =
SqlXml e =
rdr.GetSqlXml rdr.GetSqlXml(
// ds is the object (0);
);
of DataSet
if (!e.IsNull) if (!e.IsNull)
ds.ReadXml(e.C
reateReader()); {
{
}

// ds is the
} object of
}
DataSet

// ds is the
object of
DataSet

}
ds.ReadXml(e ds.ReadXml(e.
dataGrid1.DataS .CreateReade CreateReader(
ource = ds;
r());
));
}m
}
}
}

}
}
}

}
}

dataGrid1.Dat dataGrid1.Dat
aSource = ds; aSource = ds;
}m
}m

AY197 Which of the following code


snippets will allow you to
create an XML file of the
following format?
<?xml version="1.0"
encoding="utf-8"?>
<OrderDetails>
<Order OrderID="O001">
<Name>Toys</Name>
<Price>100</Price>
</Order>
<Order OrderID="O002">
<Name>Stationary</Name>
<Price>30</Price>
</Order>
</OrderDetails> m

1, using
2, using
3, using
(XmlWriter writer (XmlWriter
(XmlWriter
=
writer =
writer =
XmlWriter.Creat XmlWriter.Cre XmlWriter.Cre
e("C:\\OrderDeta ate("C:\\Order ate("C:\\Order
ils.xml"));
Details.xml")) Details.xml"))
{
{
{

4,using (XmlWriter writer =


2
XmlWriter.Create("C:\\OrderD
etails.xml"))
{
writer.WriteComment('Order
Details of Q1');

writer.WriteStart writer.WriteSt writer.WriteSta writer.WriteStartElement("Ord


Element("Order artElement("O rtElement('Ord erDetails");
Details");
rderDetails"); erDetails');
writer.WriteStartElement("Ord
writer.WriteStart writer.WriteSt writer.WriteSta er");
Element("Order" artElement("O rtElement("Ord
);
rder");
er");
writer.WriteAttributeString("Or
derID","O001");
writer.WriteAttrib writer.WriteAtt writer.WriteAttr
uteString("OrderIributeString(" ibuteString("Or writer.WriteElementString("Na
D","O001");
OrderID","O0 derID","O001") me", "Toys");
01");
;
writer.WriteElem
writer.WriteElementString("Pri
entString("Name writer.WriteElewriter.WriteEle ce", "100");
", "Toys");
mentString("N mentString("N
ame", "Toys"); ame", "Toys"); writer.WriteEndElement();
writer.WriteElem
entString("Price" writer.WriteElewriter.WriteEle writer.WriteStartElement("Ord
, "100");
mentString("P mentString("Pr er");
rice", "100"); ice", 100);
writer.WriteEndE
writer.WriteAttributeString("Or
lement();
writer.WriteEn writer.WriteEn derID", "O002");
dElement(); dElement();
writer.WriteStart
writer.WriteElementString("Na
Element("Order" writer.WriteSt writer.WriteSta me", "Stationary");
);
artElement("O rtElement("Ord
rder");
er");
writer.WriteElementString("Pri
writer.WriteAttrib
ce", "30");
uteString("OrderIwriter.WriteAtt writer.WriteAttr
D", "O002");
ributeString(" ibuteString("Or writer.WriteEndElement();
OrderID",
derID",
writer.WriteElem "O002");
"O002");
writer.WriteEndElement();
entString("Name
writer.Flush();
", "Stationary"); writer.WriteElewriter.WriteEle
}m
mentString("N mentString("N
writer.WriteElem ame",
ame",
entString("Price" "Stationary"); "Stationary");
, "30");
writer.WriteElewriter.WriteEle
writer.WriteEndE mentString("P mentString("Pr
lement();
rice", "30"); ice", 30);
writer.WriteEndE writer.WriteEn writer.WriteEn
lement();
dElement(); dElement();
writer.Flush();
}m

writer.WriteEn writer.WriteEn
dElement(); dElement();

writer.Flush(); writer.Flush();
}m
}m

AY198 You have to validate an XML


file myFile.xml against a
schema called myFile.xsd
using XmlReader. Which of
the following code snippets
correctly does this task? m

1,public static
void Main()
{
XmlSchemaSet
schemaSet =
new
XmlSchemaSet(
);

2, public static 3, public static 4, public static void Main()


3
void Main() void Main()
{
{
{
XmlSchemaSet schemaSet =
XmlSchemaSe new XmlSchemaSet();
XmlSchemaS t schemaSet =
et schemaSet new
schemaSet.Add("urn:myFile= new
XmlSchemaSe schema", C:\\myFile.xsd);
XmlSchemaS t();
XmlReaderSettings
et();
settings = new
schemaSet.Add(
schemaSet.Ad XmlReaderSettings();
"urn:myFileschemaSet.A d("urn:myFilesettings.ValidationType
schema",
dd("urn:myFil schema",
= ValidationType.Schema;
"C:\\myFile.xsd") e-schema", "C:\\myFile.xsd
settings.Schemas =
;
C:\\myFile.xsd ");
schemaSet;
);
XmlReaderSetti
XmlReaderSet settings.ValidationEventHandl
ngs settings = XmlReaderSe tings settings = er = new
new
ttings settings new
ValidationEventHandler(Valid
XmlReaderSetti = new
XmlReaderSet ationCallBack);
ngs();
XmlReaderSe tings();
XmlReader reader =
ttings();
XmlReader.Create(C:\\myFile.
settings.Validatio
settings.Validat xml, settings);
nType =
settings.Valid ionType =
while (reader.Read());
ValidationType.S ationType = ValidationType
Console.ReadLine();
chema;
ValidationTyp .Schema;
}
e.Schema;
settings.Schema
settings.Sche
private static void
s = schemaSet; settings.Sche mas =
ValidationCallBack(object
mas =
schemaSet; sender, ValidationEventArgs
settings.Validatio schemaSet;
e)
nEventHandler =
settings.Validat {
new
settings.Valid ionEventHandl

ValidationEvent ationEventHa er += new


Console.WriteLine("Errors:
Handler(Validati ndler += new ValidationEven {0}", e.Message);
onCallBack);
ValidationEve tHandler(Valid
}m
ntHandler(Vali ationCallBack);
XmlReader
dationCallBac
reader =
k);
XmlReader
XmlReader.Crea
reader =
te("C:\\myFile.x XmlReader XmlReader.Cr
ml", settings); reader =
eate("C:\\myFil
while
XmlReader.Cr e.xml",
(reader.Read()); eate("C:\\myFi settings);
le.xml",
while
Console.ReadLi settings);
(reader.Read()
ne();
while );
}
(reader.Read(
));
Console.Read
private
Line();
static void
Console.Read }
ValidationCallBa Line();
ck(object
}
private
sender,
static void
ValidationEvent
private ValidationCallB
Args e)
static void
ack(object
{
ValidationCall sender,
Back(object ValidationEven
Console.WriteLi sender,
tArgs e)
ne("Errors: {0}", ValidationEve
{
e.Message);
ntArgs e)
}m
{
Console.Write
Line("Errors:
Console.Write {0}",
Line("Errors: e.Message);
{0}",
}m
e.Message);
}m

AY199 You need to validate an XML


file myFile.xml against a
schema myFile.xsd using
XmlValidatingReader. Which
of the following code snippets
will allow you to do that? m

1, static void
Main(string[]
args)
{

2, static void 3, static void


Main(string[] Main(string[]
args)
args)
{
{

4, static void Main(string[]


1
args)
{
XmlTextReader reader
= new
XmlTextReader XmlTextRead XmlTextReade XmlTextReader("C:\\myFile.x
reader = new
er reader =
r reader = new ml");
XmlTextReader("new
XmlTextReade
XmlValidatingReader
C:\\myFile.xml"); XmlTextRead r("C:\\myFile.x validatingReader = new
er("C:\\myFile. ml");
XmlValidatingReader(reader);
XmlValidatingRe xml");
ader
XmlValidating validatingReader.ValidationTy
validatingReaderXmlValidating Reader
pe =
= new
Reader
validatingRead ValidationType.Schema("C:\\
XmlValidatingRe validatingRea er = new
myFile.xsd");
ader(reader);
der = new
XmlValidating
XmlValidating Reader(reader validatingReader.ValidationEv
validatingReaderReader(reade );
entHandler =new
.ValidationType r);
ValidationEventHandler(Valid
=
validatingRead ationHandler);
ValidationType.S reader.Validati er.ValidationTy
chema;
onType =
pe =
while(validatingReader.Read(
ValidationTyp ValidationType ));
validatingReadere.Schema;
.Schema("C:\\
}
.ValidationEvent
myFile.xsd");
public static void
Handler +=new validatingRea
ValidationHandler(Object
ValidationEvent der.Validation validatingRead sender, ValidationEventArgs
Handler(Validati EventHandler er.ValidationEv args)
onHandler);
=new
entHandler
{
ValidationEve +=new
while(validating ntHandler(Vali ValidationEven Console.WriteLine("Validation
Reader.Read()); dationHandler tHandler(Valid Error");
}
);
ationHandler);
public static
Console.WriteLine("\tSeverity:
void
while(validatin while(validatin {0}", args.Severity);
ValidationHandle gReader.Rea gReader.Read
r(Object sender, d());
());
Console.WriteLine("\tMessag
ValidationEvent
}
}
e :{0}", args.Message);
Args args)
public
public
}
{
static void
static void
m
ValidationHan ValidationHand
Console.WriteLi dler(Object
ler(Object
ne("Validation sender,
sender,
Error");
ValidationEve ValidationEven
ntArgs args) tArgs args)
Console.WriteLi
{
{
ne("\tSeverity:
{0}",
Console.Write Console.Write
args.Severity); Line("Validatio Line("Validatio
n Error");
n Error");
Console.WriteLi
ne("\tMessage : Console.Write Console.Write
{0}",
Line("\tSeverit Line("\tSeverity
args.Message); y:{0}",
:{0}",
}
args.Severity) args.Severity);
m
;

Console.Write
Console.Write Line("\tMessag
Line("\tMessa e :{0}",
ge :{0}",
args.Message)
args.Message ;
);
}
}
m
m

AY200 Consider the following code 1, XmlNode


2, XmlNode 3, XmlNode
4, XmlNode node =
3
snippet:
node =
node =
node =
doc.DocumentElement.FirstC
XmlDocument doc = new
doc.DocumentEl doc.Documen doc.Document hild;
XmlDocument();
ement.FirstChild tElement.First Element.FirstC
doc.LoadXml(("<BOOKDETAI ;
Child;
hild;
node.RemoveChild(node.First
LS><BOOK
Child);
BOOKID='B001'><BOOKNAM node.RemoveCh node.Remove node.Remove
XmlElement element
E>Angels and
ild(node.FirstChilChild(node.Fir Child(node.Fir =
Demons</BOOKNAME><AUT d);
stChild);
stChild);
doc.CreateElement("PRICE");
HOR>Dan
XmlText text =
Brown</AUTHOR></BOOK>< XmlElement
XmlElement XmlElement doc.CreateTextNode("20");
BOOK
element =
element =
element =
BOOKID='B002'><BOOKNAM doc.CreateElem doc.CreateEle doc.CreateEle doc.DocumentElement.Appen
E>Dr. Jekyll and Mr.
ent("PRICE"); ment("PRICE" ment("PRICE") dChild(element);
Hyde</BOOKNAME><AUTH
XmlText );
;
OR>Robert Louis
text =
doc.DocumentElement.LastC
Stevenson</AUTHOR></BOO doc.CreateTextN XmlText text = XmlText text = hild.AppendChild(node);
K></BOOKDETAILS>"));
ode("20");
doc.CreateTe doc.CreateText
xtNode("20"); Node("20");
doc.Save(Console.Out); m
Which of the following code doc.DocumentEl
snippets when appended to ement.AppendC doc.Documen doc.Document
the preceding snippet will
hild(element); tElement.App Element.Appe
produce the following XML file
endChild(nod ndChild(eleme
on the Console:
doc.DocumentEl e);
nt);
<BOOKDETAILS>
ement.FirstChild
<BOOK BOOKID="B001"> .AppendChild(te doc.Documen doc.Document
<AUTHOR>Dan
xt);
tElement.Last Element.LastC
Brown</AUTHOR>
Child.Append hild.AppendCh
</BOOK>
doc.Save(Conso Child(text);
ild(text);
<BOOK BOOKID="B002"> le.Out); m
<BOOKNAME>Dr. Jekyll
doc.Save(Con doc.Save(Con
and Mr. Hyde</BOOKNAME>
sole.Out); m sole.Out); m

<AUTHOR>Robert Louis
Stevenson</AUTHOR>
</BOOK>
<PRICE>20</PRICE>
</BOOKDETAILS>
m

You might also like