You are on page 1of 119

AY001

Which of the following process converts Java programming language code to a set of bytecodes?

1, Bytecode verification

2, Compilation

3, Class loading

4,Execution

AY002

Which of the following values is a type of the boolean data type? m

1, 'true' m 2, "true"

3, true
4, boolean

AY003

Your program needs to use the App class present in the foo.bar package. Which of the following
statements imports the class to your program? m

1, import App; m

2, imports foo..bar.App; m

3, import foo.bar.*; m
4, import foo.*; 3

AY004

Consider the following statements:


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:
1, Stetement A is true while Statement B is false. 2, Both Statement A and Statement B are true.
3, Statement A is false while Statement B is true. 4, Both Statement A and
Statement B are false.

AY005

Consider the following statements:


Statement A: A constructor must have the same name as that of the class.
Statement B: The return type of a constructor must be void.
Select the correct option for the preceding statements:
1, Both Statement A and Statement B are true. 2, Both Statement A and Statement B are false. 3,
Statement A is true while Statement B is false.4, Statement A is false while
Statement B is true. 3

AY006

Select the correct integer length for the int data type.

1, 8 bits

2, 16 bits

3, 32 bits
4, 64 bits
3

AY007

Which of the following is a valid Java identifier?

1, $const

2, const m

3, long 4, new

AY008

The _____________ option of the compiler enables you to compile class files to a different
directory than that of the source files.
1, -cp

2, -source

3, -g

4, -d 4

AY009

Select the correct option that shows the command to execute the MyApp Java class.

1, java class=MyApp 2, javac MyApp.java 3, java MyApp.java 4, java MyApp m


4

AY010

To compile and execute Java programs, you need to set the PATH environment variable to
___________________.
1, The working directory that contains the source files of the program. 2, The java_root/lib
directory, where java_root is the installation directory of the Java technology software. 3, The
java_root/bin directory, where java_root is the installation directory of theJava technology
software. 4, The installation directory of the Java technology software.

3
AY011

________ is the default value of the double datatype:


1, 1

2, 0.0D 3, 1.0D 4, null

AY012

The _________ variables of a class are created when the class is loaded and continues to exist as
long as the class is loaded.
1, static

2, member

3, local 4, instance

AY013

All Java classes directly or indirectly extends the _______ class.

1, Main 2, Class

3, String

4, Object

AY014
In a Java program, a Manager 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?

1, super();
2, Employee();

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

AY015

Consider the following code:


public class Example
{
public static void main(String args[])
{
String [] direction = {"East","West","North","South"};
System.out.println(direction[4]);
}
}
What will be the outcome when the preceding code is executed?
1, The code will execute and display South as the output. 2, The code will throw a runtime
exception. 3, The code will execute and display North as the output. 4, The code will execute
but will not display any output.

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?

1, 0

2, 4 3, 5

4, 6

AY017

Consider the following code:

public class Example{


public static void main (String args []) {
String str;
str = str+"Hello world";
System.out.println(str);
}
}
What will be the outcome on compiling and executing the preceding code?
1, The code will execute with the output Hello world Hello world 2, The code will execute with
theoutput Hello world 3, The code will not compile 4, The code will compel but will not
execute.3

AY018

Which of the following options will you use to determine the number of elements that an array
contains?

1, size
2, length()

3, length

4, size() m

AY019

Which of the following options is a short-circuit logical operator?


1, &&&& 2, && m

3, | m

4, ! 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?
1, The code will execute and display null.

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

AY021

Which of the following code will compile, execute, and display the word Hello?
1, public class Example
{
public static void main(String args[])
{
int num1;
int num2;
if(num1==num2)
{
System.out.println("Hello");
}
}
}
2, public class Example
{
public static void main(String args[])
{
String str1=new String("Hello");// correct but cant cmpare
String str2=new String("Hello");

if(str1==str2)
{
System.out.println("Hello");
}
}
}
3, public class Example
{
public static void main(String args[])
{
String str1="Hello";
String str2="Hello";
if(str1==str2)
{
System.out.println("Hello");
}
}
}
4, public class Example
{
public static void main(String args[])
{
String str1="hello";
String str2="Hello";
if(str1.equals(str2)) // correct comparing
{
System.out.println("Hello");
}
}
} 3

AY022

Consider the following code:


public class Example
{
public static void main(String args[])
{
String [] names = {"Linux","Unix","Windows","Mac OS"};
for(String list : names )
System.out.println(list);
}
}
Select the correct option for the preceding code?
1, The code will execute but will not display any output.

2, The code will not compile. 3, The code will execute and display Linux, Unix,
Windows, and Mac OS.
4, The code will compile but will throw an exception on execution.

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:

1, Both Statement A and Statement B are true.

2, Statement A is true while Statement B is false.


3, Statement A is false while Statement B is true.

4, Both Statement A and Statement B are false.


2

AY024

Consider the following class declaration:


class Example
{
/* class body*/
}
Which of the following statements is true regarding the preceding class?
1, The Example class is accessible to all classes

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

3, The Example class is not accessible to any classes

4, The Example class is accessible to its subclasses.

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:

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

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

AY026
In a Java program, numArray is an array initialized with int values.
Which of the following statement/statements, will you use to print the last int value stored in the
array?

1, int result=numArray.size;
System.out.println(result);

2, int result=numArray.length();
System.out.println(result);

3, System.out.println(numArray[numArray.length]);

4, System.out.println(numArray[numArray.length-1]);

AY027

Which of the following is NOT a valid switch statement?

1, switch (num)
{
case 1: System.out.println("Case 1");
break;
case 2: System.out.println("Case 2");
break;
case 3: System.out.println("Case 3");
break;
default: System.out.println("Default Case");
break;
}
2, int num = 3;
switch (num)
{
case 3: System.out.println("Case 3");
case 1: System.out.println("Case 1");
case 2: System.out.println("Case 2");
case 4: System.out.println("Case 4");

}
3, int num = 3;
switch (num)
{
case 3: System.out.println("Case 3");
continue;
case 1: System.out.println("Case 1");
continue;
case 2: System.out.println("Case 2");
continue;
case 4: System.out.println("Case 4");

4, switch (2)
{
default: System.out.println("Default Case");
} 3

AY028

Consider the following code:


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

1, The output will display the following:


The number is: 5
The number is: 6
The number is: 7
The number is: 8
The number is: 9
The number is: 10
2, The output will display the following infinitely:
The number is: 5
3, The output will display the following:
The number is: 5
4, There will be no output.

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:
1, Both Statement A and Statement B are true.

2, Statement A is true while Statement B is false.

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

4, Both Statement A and Statement B are false.

AY030

Consider the following program:


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?
1, 4-11 m

2, 2 m
3, -11 m

4, -3 m

AY031

Techunique Solutions is designing a website for a 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?

1, Splash home page

2, Menu home page

3, Path-based home page

4, News-oriented home page

AY032

Joycee have developed a website that allows the user to view news of current affairs,
entertainment, sports, and weather. 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?
1, Using white as background color will make the links identifiable.

2, Using black for background color and blue for visited links will make the links identifiable.

3, Removing blue as text color and purple as the color for visited links will make the links
identifiable. 4, Removing light green as background color will make the links identifiable.

AY033

Newways software is designing an e-learning 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 look-and-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 e-learning website?

1, Menu home page

2, News-oriented home page m

3, Path-based home page

4, Splash screen home page

AY034

John is designing a website for AT Services. The company management wants the home 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.

1, News-oriented Home page

2, Menu Home page

3, Path-based Home page


4, Splash screen Home page

AY035

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

1, The design team of Real software should have used the Sketching technique because
storyboard technique would only provide the flow and features of the interface.. 2, The design
team of Real software should have used the Horizontal Prototyping because storyboard technique
would only provide the flow of the interface. 3, The design team of Real software should have
used the Wizard of Oz technique because storyboard technique would only provide the flow and
features of the interface. 4, The design team of Real software should have used the Vertical
Prototyping because storyboard technique would only provide the flow of the interface.

AY036

Drivetech is in the process of developing a speech-based navigation system for the cars. To
check the functionality of the product, the company uses the manipulating and navigating type of
conceptual model. However, using this model the various features of 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.
1, Conversing should be used to clearly show the interaction of the product with the system

2, Tangible User Interface should be used to clearly show the interaction of the product with the
system

3, Direct Manipulation should be used to clearly show the functionality of the product

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

AY037

New Generation softwares is creating an application for the 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.

1, Scenario prototyping

2, Vertical prototyping

3, Sketching

4, Wizard of Oz

AY038

Red Sky IT Systems is designing a website for a news channel. To verify the requirements, Red
Sky IT Systems has to develop a prototype. The prototype must show the navigation and flow of
each news category, such as breaking news, sports, and 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?
1, Scenario prototyping because it covers both the features and the associated functionalities of
the application.

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

3, Horizontal Prototyping because it covers all the features of the application without their
underlying functionality.

4, Vertical Prototyping because it covers all the features of the application without their
underlying functionality.
1

AY039

WebBizz got an offer to design a website for an entertainment channel Znn. To verify the
requirements, WebBizz has to develop a prototype but they are running out of time. Due to 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.
1,Storyboarding because it describes each action of the application sequentially. 2, Wizard of
Oz because it is used to test an application without the existence of the application.

3,Sketching because it explore the design of the entire application through visual brainstorming.

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

AY040

Which type of data gathering technique can be used to collect quantitive data?

1, Questionnaires

2, Naturalistic observation

3, Focus group 4, Interviews 1

AY041

Which type of requirement captures the system goals with respect to effectiveness and safety of a
product?

1, Usablity requirements

2, Data requirements m

3, Functional requirements

4, Non-functional requirements
1

AY042

Which of the following methods is used to collect and interpret data from end users to design an
application?
1, Coherence

2, Contextual design 3, Participatory design 4, Ethnography 2

AY043

Which of the following requirements define the constraints on the system and the conditions
under which the system must be developed?
1, Non-functional requirements 2, Functional requirements

3, Data requirements

4, User requirements

AY044

Which type of environmental requirements addresses questions related to the hierarchy of the
organization?
1, Physical environment

2, Organizational environment

3, Social environment

4, Technical environment
2

AY045

Which of the following should be used for easy navigation when the Web page is long? 1, Links

2, Signature graphics 3, Header and footer

4, Jump to top buttons

AY046

Which guideline of graphics design is considered when graphics are used for communicating
better than text.
1, Resemblance

2, Simplicity

3, Relevance

4, Size

AY047

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

3, Visual hierarchy 4, Web page content 1

AY048

Which of the following is the best practice for delivering the web content to mobile phones?

1, The website should be simple and shallow.

2, Use cookies because most of the mobile phones do support them.

3, Cascading Style Sheets (CSS) and frames should be used for Web pages developed for mobile
phones. 4, The use of drop-down lists should be used for navigation.
1

AY049

Which home page design strategy should be followed while designing a home page for a large
website?
1, News-oriented Home page 2, Menu Home page

3, Path-based Home page

4, Splash screen Home page

AY050

Ann is designing a website and he added a Web page on 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.
1, Effectiveness

2, Efficiency

3, Learnability

4, Utility

AY051

Joe is designing a website for Johnson garments. One of the 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
1, Effectiveness

2, Efficiency m

3, Memorability m

4, Utility m

AY052

Christine is designing a computer-based tutorial for 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

1, Supports Creativity m

2, Aesthetically Pleasing m

3, Helpful m 4, Enjoyable 2

AY053

Sally is designing a reporting 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

1,Visibility m

2, Feedback m

3, Constraints m

4, Mapping m

AY054

Rebecca is designing an 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
1, Visibility m

2, Feedback m

3, Constraints m

4, Mapping 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

1, A progress bar should be used to inform the user about the download time. 2, Download time
should be specified in the help file of the application. m

3, An hourglass 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.

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?
1, [1]
[2]
[3]
[4]

2, [1, 2, 3, 4]

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

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

AY057

Consider the following code developed prior to the introduction of generics and autoboxing:
import java.util.*;
public class Example
{
public static void main(String args[])
{
ArrayList list=new ArrayList();
Integer num=new Integer(10);
list.add(0,num);
Integer numObj=(Integer)list.get(0);
int num2=numObj.intValue();
System.out.println(num2);

}
}
Which of the following code will you use to replace the preceding code for optimization using
generics and autoboxing.
Ensure that the code you use select performs the same function and produces the same result as
that of the given code.

1, import java.util.*;
public class Example
{
public static void main(String args[])
{
ArrayList<Integer> list=new ArrayList<Integer>();
Integer num=new Integer(10);
list.add(num);
int numObj=list.get(num);
System.out.println(numObj);
}
}
2, import java.util.*;
public class Example
{
public static void main(String args[])
{
ArrayList<Integer> list=new ArrayList<Integer>();
list.add(10);
int numObj=list.get(0);
System.out.println(numObj);
}
}
3,
import java.util.*;
public class Example
{
public static void main(String args[])
{
ArrayList<Integer> list=new ArrayList<Integer>();
list.add(10);
System.out.println(list);
}
}
4, import java.util.*;
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);
}
}

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.");
}

}
What will be the output on executing the preceding code?
1, Inside main method.Inside constructor.Inside static block.
2, Inside main method.Inside static block.
3, Inside constructor.Inside static blockInside main method.
4, Inside static block.Inside main method.
4

AY059

You must declare methods of an interface as ______________.


1, static m

2, final m

3, public m

4, private m

AY060

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

1, Error m 2, Exception m

3, ArithmeticException m

4, RuntimeException 2

AY061

Which of the following keywords ensures that a method cannot be overridden? m

1, final m

2, protected m

3, static m

4, abstract m

AY062

Which of the following exceptions is thrown when you try to divide a number by 0? m

1, NumberFormatException m
2, NullPointerException m

3, SecurityException m

4, ArithmeticException 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 2

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.
Select the correct option for the preceding statements:
1, Statement A is true while Statement B is false. m

2, Statement A is false whileStatement B is true. 3, Both Statement A and Statement B are false.
m

4, Both Statement A and Statement B are true.

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

1, Both Statement A and Statement B are true. m


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

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

4, Both Statement A and Statement B are false. 4

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.
Select the correct option for the preceding statements:

1, Both Statement A and Statement B are true. m

2, Statement A is true while Statement B is false.

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

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

1, The num1 variable. m

2, Both the num1 and num1 variables.

3, The num2 variable. m

4, None of the variables

AY068

You can use the FileReader class to read ___________.


1, Characters m

2, Integers m

3, Streams m

4, Files 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]
1, HashSet m

2, LinkedList m

3, Arraylist m

4, HashSetMap

AY070

Consider the following code:


public class Example
{
public static void main(String [] args)
{
try
{
String name = args[1];
System.out.println(name);
}
catch(Exception ex){}
}
}
Select the correct option on executing the code with the following command:
java Example James
1, The code executes with the following output:
James

2, The code exits with the following exception message:


java.lang.ArithmeticException: 1 at Example.main(Example.java:7) m

3, The code exits without any output.

4, The code exits with the following exception message:


java.lang.ArrayIndexOutOfBoundsException: 1 at Example.main(Example.java:7)

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:
1, The compiler will generate an error m 2, The code will compile and run with the following
output:0 3, The code will compile but generate a runtime error. 4, The code will compile and
run with the following output:null

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();
while(elements.hasNext()) {
System.out.println(elements.next());
}
}
}
What will be the output of the preceding code?
1, The code will not compile as it tries to add int values to an ArrayList of type Integer. 2, The
code will compile and execute with the following output:1 2 3, The code will compile but not
execute as it tries to add int values to an ArrayList of type Integer.

4, The code will compile and execute with the following output:
num1
num2
2

AY073

Consider the following code:


public class Example
{
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
{
System.out.println("5");
}
}
}

What will be the output on executing the following code?


1, 135 m

2, 145 m

3, 1245 m

4, 345 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:
1, 0 m

2, 15 m

3, 5 m

4, 10 m

AY075

Consider the following Employee class:


public class Employee

{
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.getName());
}
}
What will be the result on executing the Example class?
1, The class will display the following output:Henry
2, The class will throw an exception opf type NullPointerException. 3, The class will execute
without any output. 4, The class will throw an exception of type SecurityException.

AY076

__________ are those that a programmer is expected to handle in a program. m

1, Checked Exception m

2, Unchecked exception m

3, Runtime exception 4, Objects of the Error class 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?
1, NullPointerException m

2, SecurityException m
3, FileNotFoundException m

4, NumberFormatException m

AY079

A method in a Java class 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?
1, throw m

2, throws m

3, try m

4, this m

AY080

To make a variable constant , you need to define the variable with the _________ keyword m

1, static m

2, private m

3, public m 4, final

AY081

Consider the following code:


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

2, class Example2 extends Example1


{
public static void main(String [] args)
{
Example1 e2 = new Example2();
e2.displayAll();
}
}

3, class Example2 extends Example1


{
void display()
{
}
public static void main(String [] args)
{
Example2 e2 = new Example2();
e2.displayAll();
}
}

4, class Example2 extends Example1


{
public static void main(String [] args)
{
Example2.display();
}
}
3

AY082

Consider the following code


class Example
{
public static void main(String [] args)
{
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
1, The code on execution will throw an exception of type NumberFormatException.

2, The code on execution will throw an exception of type ArithmeticException. m

3, The code on execution will display var2.

4, The code on execution will display var1.

AY083

Consider the following two classes:


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

public class Example2


{
public static void main(String[] args)
{
System.out.println(Example1.num);
}
}
Select the correct option regarding the preceding classes.
1, The Example2 class will execute without any output. m

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

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

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

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.
1, The code will not compile and report that a catch block is missing. m

2, The code will compile but will throw a runtime expression. m

3, The code will execute with the following output:Hello 4, The code will execute with the
following output:Hello Hello

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];
System.out.println(str1+str2+str3);
}
What will be the output on executing the preceding code with the following command:
java Example 1 2 Java Programming Language
}1, 12Java m

2, 12Programming m

3, 12Java Programming Language m

4, The code will throw an exception of type ArrayIndexOutOfBoundsException. m

AY086

To display a panel you must add it to __________.


1, Another panel m

2, A Frame m

3, A text component m

4, Any component 2

AY087

The default layout manager of a panel is_________.


1, FlowLayout m

2, BorderLayout m

3, GridLayout m

4, NullLayout m

AY088

Every AWT component has a ____________method that draws the specified component on a
container. m
1, setVisible() m

2, setSize() m

3, paint() m

4, draw() m

AY089

Which of the following method does the MouseMotionListener interface contains?


1, mouseDragged(MouseEvent) m

2, mouseExited(MouseEvent) m

3, mouseEntered(MouseEvent) m

4, mouseClicked(MouseEvent) m

AY090

Which of the following event is generated when you click a button in a GUI form?
1, MouseEvent m

2, KeyEvent m

3, ItemEvent m

4, 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.
Select the correct option for the preceding statements.
1, Statement A is false while Statement B is true. m

2, Statement A is true while statement B is false m

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

AY092

Which of the following method will you call to set the size of a Frame?
1, pack() m

2, setVisible() m

3, setSize() m

4, setLayout()

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:
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.
1, Statement A is true while Statement B is false. m

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

AY094

Which of the following method enables you to disable the layout manager for a container?
1, container.setLayout(0); m

2, container.layout(null); m

3, container.layout(0); m

4, container.setLayout(null);

AY095

Which of the following layout manager enables you to assign row and column numbers to
arrange components? m

1, BorderLayout m

2, FlowLayout m

3, GridLayout m

4, NullLayout m

AY096

What will be the output of the following statement in a GUI program?


Frame f = new Frame ("Hello");
1, The statement will create a new Frame window and display Hello at the center. m
2, The statement will create a new Frame window with a title bar containing the Hello title. m

3, The statement will create a new Frame window with a status bar containing the Hello status. m

4, The statement will create a new Frame window and display Hello at the left. m

AY097

Consider the following code:


Frame f = new Frame("Frame");
MenuBar mb = new MenuBar();
Which of the following code will you use to add the menu bar to the frame?
1, f.addMenubar(mb); m

2, f.setManubar(mb); m

3, f.add(mb); m

4, f.set(mb); 2

AY098

Consider the following code, where MyListener is a listener class of action events:
Frame f = new Frame("Frame");
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.
1, The code will add an action listener to both the menu bar and the File menu. m

2, The code will add an action listener to the File menu. m

3, The code will add an action listener to the frame. m

4, The code will add an action listener to the menu bar.

AY099

What will be the output of the following code?


import java.awt.*;
public class Example
{
private Frame f;
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();
}
}

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

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

3, The output will display a window with six buttons arranged in one column. m

4, The output will display a window with six buttons arranged in one row. m

AY100

Consider that you are creating a GUI application and you need an action listener to handle events
of type ActionEvent. Which of the following listener code will you use? m
1, import java.awt.event.*;
public class CustomHandler implements ActionListener{
public void actionPerformed(ActionEvent evt)
{
/*Process action here*/
}
}

2, import java.awt.event.*;

public class CustomHandler{


public void actionPerformed(ActionEvent evt)
{
/*Process action here*/
}
}
3, import java.awt.event.*;
public class CustomHandler implements ActionListener{
public void actionPerformed()
{
/*Process action here*/
}
}

4, import java.awt.event.*;
public class CustomHandler implements ActionListener{
public static void main(String args[])
{
/*Process action here*/
}
}

1
AY101

Consider the following code:


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

4, The code will compile, execute, but will not display anything.

AY102

Which of the following is NOT a valid state of a thread?


1, Running m

2, Blocked m

3, Listening m

4, Dead m

AY103

Consider the following statements on threads:


Statement A: You can create a 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
1, Both Statement A and Statement B are false. m

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

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

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


4

AY104

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

1, threadObj.getPriority(THREAD.MAX_PRIORITY); m

2, threadObj.setPriority(MAX_PRIORITY); m

3, threadObj.setPriority(THREAD.PRIORITY); m

4, threadObj.setPriority(THREAD.MAX_PRIORITY);

AY105

Consider the following code:


public class Example extends Thread
{
public static void main(String args[])
{
for(int i=0;i<3;i++)
new Example().start();
}
public void run()
{
System.out.println("Hello");
}
}
Select the correct option for the preceding code.
1, The code will execute with the following output:Hello m

2, The code will execute without any output. m

3, The code will execute with the following output:


Hello
Hello
Hello

4, The code will not execute. m

AY106

In a Java multithreading program, under what circumstances will you call the yield() method of a
thread?
1, To give other runnable threads a chance to execute. m

2, To start a new thread. m

3, To terminate the current thread. m

4, To stop the current thread for a specific time. m

1
AY107

Consider the following code:


public class Example extends Thread
{
public static void main(String argv[])
{
Example obj = new Example();
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?
1, The code will display the following outputHello m

2, The code will display the following output:Hello


Hello
Hello
Hello
Hello

3, The code will not display any output. m

4, The code will display the following output:


Hello
Hello
Hello
Hello

AY108

Which of the following classes will you use to communicate between threads? m

1, FileInputStream and FileOutputStream m

2, PipedInputStream and PipedOutputStream m

3, BufferedInputStream and BufferedOutputStream m

4, FilterInputStream and FilterOutputStream m

AY109
Which of the following is the immediate superclass of the DataOutputStream,
BufferedOutputStream, and PrintStream classes? m

1, FileOutputStream m

2, FilterOutputStream m

3, PipedOutputStream m

4, ByteArrayOutputStream

AY110

Consider the following statements:


Statement A: To implement a 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.
1, Both Statement A and Statement B are true. m

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

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

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


1

AY111

Which of the following method enables you to force writes that an output stream accumulates? m

1, close() m

2, write() m

3, flush() m

4, read() 3

AY112

Which of the following will you use to read a stream of bytes in a program?
1, Reader m

2, Writer m

3, InputStream m

4, OutputStream

AY113

Which of the following class will you use to read the content of a file as a stream of bytes?
1, FileReader m

2, StringReader m

3, FileInputStream m

4, PipedReader 3

AY114
A___________ stream performs conversion on another stream.
1, Filter m

2, Output m

3, Input m

4, Print m

AY115

Which of the following method will you call to start a thread?


1, notify() m

2, yield() m

3, run() m

4, start() m

AY116

Which one of the following is a valid TCP/IP port number


1, -8080 m

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.
1, An int value that specifies the number of seconds for which the thread must be made inactive.

2, A long value that specifies the number of milliseconds for which the thread must be made
inactive. m

3, A float value that specifies the number of seconds for which the thread must be made inactive.
m
4, A float value that specifies the number of milliseconds for which the thread must be made
inactive.

AY118

Consider the following statements:


Statement A: To start a thread you must call the constructor of the Thread class.
Statement B: The Thread class implements the Runnable interface.
Select the correct options for the preceding statements.
1, Statement A is true while Statement B is false. m

2, Both Statement A and Statement B are true. m

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

4, Both Statement A and Statement B are false. 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.
1, Both Statement A and Statement B are true. m

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

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

4, Both Statement A and Statement B false.


2

AY120

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

2, Socket s1 = new Socket("127.168.0.10", 5430); m

3, Socket s1 = new ServerSocket("127.168.0.10", 5430); 4, Socket s1 = new


Socket(127.168.0.10, 5430); m

AY121

Consider the following code:


import java.io.FileInputStream;
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.txt");
out = new FileOutputStream("InputFile.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
}
What will be the output of the above code?
1, The code will throw a runtime exception. m

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

3, The code will copy the content of the InputText.txt file in to OuputText.txt file.
4, The code will execute without any output. m

AY122

Consider the following code:


import java.io.*;
class Example
{
public static void main(String 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

1, The code will not compile. m

2, The code will compile, execute, wait for a key press, and then exit. m

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

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++) {
Thread.sleep(4000);
System.out.println(info[i]);
}
}
}
Select the correct option.
1, The code will throw an exception of type InterruptedException. m

2, The code will display Java and C++.

3, The code will display only Java. m

4, The code will display only C++.

AY124

Consider an example.txt file saved in your working directory that contains the following content:
User Name = Admin
Password = Administrator
Host = localhost
Which of the following code will you use to read the content of the example.txt file and display
it on console?
1, import java.io.*;
public class Example
{
public static void main(String[] args)
{
try
{
FileReader fr = new FileReader("example.txt");
BufferedReader br = new BufferedWriter(fr);
System.out.println(br.display());
} catch (IOException e)
{
System.out.println(e.getMessage());
}
}
}
2, import java.io.*;
public class Example
{
public static void main(String[] args)
{
String str;
try
{
FileReader fr = new FileReader("example.txt");
BufferedReader br = new BufferedReader(fr);
while ((str = br.readLine()) !=null)
System.out.println(str);
} catch (IOException e)
{
System.out.println(e.getMessage());
}
}
}
3, import java.io.*;
public class Example
{
public static void main(String[] args)
{
String str;
try
{
FileReader fr = new FileReader(example.txt);
BufferedReader br = new BufferedReader(fr);
while ((str = br.readLine()) !=null)
System.out.println(str);
} catch (IOException e)
{
System.out.println(e.getMessage());
}
}
}

4, import java.io.*;
public class Example
{
public static void main(String[] args)
{
try
{
FileReader fr = new FileReader("example.txt");
BufferedReader br = new BufferedReader(fr);
while (br.readLine()!=null)
System.out.println(br.readLine());
} catch (IOException e)
{
System.out.println(e.getMessage());
}
}

AY125

A Java multithreading program contains an operation() method. You need to ensure that only a
single thread can access the operation() method at a time. Which of the following code will you
use?

1, synchronized(this)
public void operation(){
/*Method Body*/
}
2, public void operation(){
synchronized(this)
/*Method Body*/
}
3, public void synchronized operation(){
/*Method Body*/
}
4, public synchronized void operation(){
/*Method Body*/
}

AY126

Which of the following is the key component of a data provider? m

1, DataAdapter m

2, DataTable m

3, DataTableCollection m

4, DataRelationCollection 1

AY127

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

1, DataTable m

2, DataTableCollection m

3, DataRelationCollection m

4, DataColumnCollection m
2

AY128

Which one of the following components of a data provider is used to transfer data to and from a
database? m

1,Connection m

2, DataAdapter m

3, Command m

4, DataReader m

AY129

Which property of the DataView control is used to specify an expression/condition in a string


format used to filter the records? m

1, GenerateMember m

2, RowFilter m

3, RowStateFilter m

4, Modifiers 2

AY130

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

1, Provider m

2, Initial Catalog m

3, Integrated Security m
4, User ID 4

AY131

Consider the following code snippet:


SqlConnection connection = 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

1, Library refers to the name of the database m

2, Library refers to the Server login account m

3, Library specifies the name of the server, which is used in an open connection m

4, Library refers to the provider for the connection m

AY132

Consider the following code snippet:


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

1, It specifies the name of the server used in an open connection m

2, It specifies the name of the server login account m

3, It specifies the name of the provider for the connection m

4, It specifies the name of the database m

AY133
Williams has to write a code to 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

1, TextBox m

2, ListBox m

3, ComboBox m

4, DataGrid m

AY134

Williams has to write a code to display all the employee codes from the Employees table in a
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

1, DisplayMember m

2, DataSource m

3, DataBindings m

4, Items 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, bindingNavigatorPositionItem text box m

2, bindingNavigatorCountItem text box m

3, BindingSource m

4, bindingNavigatorMoveLastItem button m

AY136
Jim is assigned a task to develop a code to implement a delete operation from the Employee table
present in a database, HR. To accomplish this task, he has developed the following code in
which he deletes all the records from the Employee table where the employee code is 00005.
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Data Source= SQLSERVER01;Initial Catalog=HR; User ID=sa;
Password=password";
connection.Open();
SqlCommand cmd = new SqlCommand(connection,"delete from Employee where
cEmployeeCode='000015'");
SqlDataReader myReader = cmd.ExecuteReader();
myReader.read();
Identify whether the preceding code gives the desired output or not. m

1, The code will give an error. This is because the ConnectionString contains an incomplete
number of parameters. To rectify this code, it is necessary to mention the provider. m

2, The code will give an error. This is because the parameters passed in the constructor of the
SqlCommand class are in an incorrect sequence. m

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

4, The code will give the desired output. m

AY137

John is assigned a task to develop a window based application in which the name and department
of an employee is displayed on the screen based on a particular employee id. The details of the
employee are stored in the 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;
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].ToString());
MessageBox.Show(dr[2].ToString());
Identify whether the preceding code will give the desired output or not. m

1, The code will throw an exception. The term employeecode should be preceded with an '@'
sign. m

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 will give an error. Parameters is the property of the SqlConnection object and not the
SqlCommand object. m

4, The code will give the desired output. m

AY138

John is assigned a task to develop a window based application in which the name and department
of an employee is displayed on the screen based on a particular employee id. The details of the
employee are stored in the 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;
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].ToString());
MessageBox.Show(dr[2].ToString());
Identify whether the preceding code will give the desired output or not. m

1, The code will throw an exception. In the term employeecode, '@' sign should be removed. m

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 will give an error. Parameters is the property of the SqlConnection object and not the
SqlCommand object. m

4, The code will give the desired output. m

AY139

John is assigned a task to develop a window based application in which the name and department
of an employee is displayed on the screen based on a particular employee id. The details of the
employee are stored in the 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;
String query = "SELECT * FROM Employee WHERE cemployeeCode =
@employeecode";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.Add(new SqlParameter(searchemployeecode, "@employeecode"));
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
MessageBox.Show(dr[1].ToString());
MessageBox.Show(dr[2].ToString());
Identify whether the preceding code will give the desired output or not. m

1, The code will throw an exception. In the term employeecode, '@' sign should be removed. m

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 will give an error. Parameters is the property of the SqlConnection object and not the
SqlCommand object. m

4, The code will give the desired output. m


2

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 output or not. m

1, The code will give an error. The parameters passed in the SqlCommand class are in an
incorrect sequence. m

2, The code will give an error. The line of code cmd = dr.ExecuteReader() is incorrect. m

3, The code will give an error. It is necessary to mention the provider in the connection string. m

4, The code will give the desired output. m

AY141

Which of the following is true about a disconnected environment? m


1, Chances for data concurrency issues are less m

2, Allows one application to interact with the data source at a time m

3, Data is not always up to date m


4, A constant connection is always required m

AY142

Which of the following methods of the DbCommand object executes a query and returns the first
column of the first row in the result set returned by the query? m

1, ExecuteNonQuery() 2, ExecuteScalar() 3, ExecuteReader()

4, Equals() m

AY143

Which of the following methods of the DataRow object accesses a row in a table by its primary
key value? m

1, Select() m

2, Find() m

3, Add() m

4, InsertAt() m

AY144

Which of the following values of the DataViewRowState enumeration is the default enumeration
value? m

1, CurrentRows m

2, ModifiedCurrent m

3, None m
4, OriginalRows

AY145

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

1, None m

2, Cascade m

3, SetDefault m

4, SetNull m

AY146

John has to write a code in which he has to retrieve the number of rows affected 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

1, ExecuteReader() 2, ExecuteNonQuery() m

3, ExecuteScalar() m

4, Equals() 2

AY147

Consider a table containing 20 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?

1, 20 m

2, 4 m

3, 5 m

4, 24 m
2

AY148

John has to develop a window 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

1, Add() m

2, InsertAt() m

3, Find() m

4, Select() m

AY149

John has to develop a window 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?
1, Find() m

2, Remove() m

3, RemoveAt() m

4, Delete() 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?
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 where the value of Price is 100 and controls the version of the row m

AY151

MyProd Pvt. Ltd. is a leading producer of hardware and software products. The details of all the
products are maintained in a centralized database system. As a part of the development team,
Williams is assigned a task to develop a windows based application in which the name and the
price of the product are displayed on entering the unique product id. The product details are
stored in the ProductDetails table in the Products database.
Identify the code that would enable him to accomplish this task. Assume the connection to be
already open where cn is the connection object. m

1, string productCode;
productCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from ProductDetails where ProductId=@Pode";
cmd.Parameters.Add(new SqlParameter("@Pode", productCode));
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text = Convert.ToString((dr[1]));
textBox3.Text = Convert.ToString((dr[2]));
}

2, string productCode;
productCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from ProductDetails where ProductId=@Pode";
cmd.Parameters.Add(new SqlParameter("@Pode", productCode));
textBox2.Text = Convert.ToString(cmd.ExecuteNonQuery());
textBox3.Text = Convert.ToString(cmd.ExecuteNonQuery()); m

3, string productCode;
productCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from ProductDetails where ProductId=@Pode";
cmd.Parameters.Add(new SqlParameter("@Pode", productCode));
textBox2.Text = Convert.ToString((cmd.ExecuteScalar()));
textBox3.Text = Convert.ToString((cmd.ExecuteScalar())); m

4, string productCode;
productCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd..CommandType = CommandType.Text;
cmd.CommandText = "select * from ProductDetails where ProductId=@Pode";
cmd.Parameters.Add(new SqlParameter(productCode, ("@Pode")));
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text = Convert.ToString((dr[1]));
textBox3.Text = Convert.ToString((dr[2]));
}m

AY152

MyCall Ltd. is a upcoming call centre. The details of all the employees are maintained in a
centralized database system. As a part of the development team, Williams is assigned a task to
develop a windows based application in which whenever the user enters a department code in a
TextBox control, the employee id of all the employees working in that particular department are
displayed in a combobox. The employee details are stored in the EmployeeDetails table in the
HR database. Identify the code that would enable him to accomplish this task. Assume the
connection to be already open where cn is the connection object. m

1, string dCode;
dCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from EmployeeDetails where deptCode=@P";
cmd.Parameters.Add(new SqlParameter("@P", dCode));
SqlDataReader dr = cmd.ExecuteNonQuery();
while (dr.Read())
{
comboBox1.Items.Add(dr[0]);
}m

2, string dCode;
dCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from EmployeeDetails where deptCode=@P";
cmd.Parameters.Add(new SqlParameter("@P", dCode));
SqlDataReader dr = cmd.ExecuteScalar();
while (dr.Read())
{
comboBox1.Items.Add(dr[0]);
}m

3, string dCode;
dCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from EmployeeDetails where deptCode=@P";
cmd.Parameters.Add(new SqlParameter("@P", dCode));
SqlDataReader dr;
while (dr.Read())
{
comboBox1.Items.Add(dr[0]);
}m

4, string dCode;
dCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from EmployeeDetails where deptCode=@P";
cmd.Parameters.Add(new SqlParameter("@P", dCode));
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr[0]);
}m

4
AY153
CalNetInfocom. Ltd. is a call center company based in US. Its centralized database system store
the details of all the employees. As a part of the development team, John is 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. The details of the employees are stored in an
Employees table of the HR database. Identify the code that would enable him to accomplish this
task. Assume the connection to be already open where cn is the connection object. m

1, string employeeCode;
employeeCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Employees where empId=@eCode";
cmd.Parameters.Add(new SqlParameter("@eCode", employeeCode));
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text = Convert.ToString((dr[1]));
textBox3.Text = Convert.ToString((dr[2]));
}m

2, string employeeCode;
employeeCode = textBox1.Text;
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]));
}m

3, string employeeCode;
employeeCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Employees where empId=@eCode";
cmd.Parameters.Add(new SqlParameter(employeeCode,"@eCode"));
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text = Convert.ToString((dr[1]));
textBox3.Text = Convert.ToString((dr[2]));
}m
4, string employeeCode;
employeeCode = textBox1.Text;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Employees where empId=eCode";
cmd.Parameters.Add(new SqlParameter("eCode", employeeCode));
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text = Convert.ToString((dr[1]));
textBox3.Text = Convert.ToString((dr[2]));
}m

AY154

Marry has recently joined as a tellecalling executive in a call centre CallNetInc. Ltd. Her details
need to be entered into the system. As a part of the development team, you need to create an
application in which the details of the employee being entered in the form gets saved in the
database. The details of the employee are stored in the Employees table in the HR database.
Identify the correct code to accomplish this task. Assume the connection to be already open
where connection is the connection object. m

1, SqlDataAdapter adapter = new SqlDataAdapter("Select * from Employees", connection);


SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet("Employees");
DataRow row = ds.Tables["Employees"].NewRow();
row["empId"] = textBox1.Text;
row["empName"] = textBox2..Text;
row["empSal"] = textBox3.Text;
ds.Tables["Employees"].Rows.Add(row);
adapter.Update(ds, "Employees"); m

2, SqlDataAdapter adapter = new SqlDataAdapter("Select * from Employees", connection);


SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet("Employees");
adapter.Fill(ds, "Employees");
DataRow row = ds.Tables["Employees"].NewRow();
row["empId"] = textBox1.Text;
row["empName"] = textBox2.Text;
row["empSal"] = textBox3.Text;
ds.Tables["Employees"].Rows.Add(row);
adapter.Update(ds, "Employees"); m

3, SqlDataAdapter adapter = new SqlDataAdapter("Select * from Employees", connection);


SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet("Employees");
adapter.Fill(ds, "Employees");
DataRow row = ds.Tables["Employees"].NewRow();
row["empId"] = textBox1.Text;
row["empName"] = textBox2.Text;
row["empSal"] = textBox3.Text;
ds.Tables["Employees"].Rows.Add(row); m

4, SqlDataAdapter adapter = new SqlDataAdapter("Select * from Employees", connection);


SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet("Employees");
adapter.Fill(ds, "Employees");
DataRow row = ds.Tables["Employees"].NewRow();
row["empId"] = textBox1.Text;
row["empName"] = textBox2.Text;
row["empSal"] = textBox3.Text;
adapter.Update(ds, "Employees"); m

AY155

SysCalInc Ltd. is a call centre company with its branches spread all over the world. It has got a
centralized database management system whereby the information about all the HR activities is
maintained. As a part of the development team, John is assigned a task to extract the details of all
the employees of a particular department. The details of the employees are stores in the
Employees table in the HR database. Identify the code that would enable him to accomplish this
task. Assume the connection to be already open where conn is the connection object. m

1, string str;
str = Console.ReadLine();
string sSQL = "Select * from Employees";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sSQL, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Employees");
DataTable dt = ds.Tables["Employees"];
DataView dv = new DataView(dt, "empDept = '" + str + "'", "empDept",
DataViewRowState.CurrentRows);
foreach (DataRowView drv in dv)
{
for (int i = 0; i < dv.Table.Columns.Count; i++)
{
Console.WriteLine((drv[i]));
}
}
Console.ReadLine(); m

2, string str;
str = Console.ReadLine();
string sSQL = "Select * from Employees";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sSQL, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Employees");
DataTable dt = ds.Tables["Employees"];
DataView dv = new DataView(dt, "empDept = '" + str + "'", "empDept",
DataViewRowState.CurrentRows);
foreach (dv)
{
for (int i = 0; i < dv.Table.Columns.Count; i++)
{
Console.WriteLine((drv[i]));
}
}
Console.ReadLine(); m

3, string str;
str = Console.ReadLine();
string sSQL = "Select * from Employees";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sSQL, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Employees");
DataTable dt = ds.Tables["Employees"];
DataView dv = new DataView(dt, "empDept = '" + str + "'", "empDept");
foreach (DataRowView drv in dv)
{
for (int i = 0; i < dv.Table.Columns..Count; i++)
{
Console.WriteLine((drv[i]));
}
}
Console.ReadLine(); m

4, string str;
str = Console.ReadLine();
string sSQL = "Select * from Employees";
SqlDataAdapter da = new SqlDataAdapter();
da..SelectCommand = new SqlCommand(sSQL, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Employees");
DataTable dt = ds.Tables["Employees"];
DataView dv = new DataView("empDept = '" + str + "'", "empDept",
DataViewRowState.CurrentRows);
foreach (DataRowView drv in dv)
{
for (int i = 0; i < dv.Table.Columns.Count; i++)
{
Console.WriteLine((drv[i]));
}
}
Console.ReadLine(); m

AY156

MyCalInc. Ltd. is a multinational call center company whose branches are spread in different
parts of the world. It has got a centralized database system wherein the details of all the
employees are stored. As a part of the development team, John is 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 second and third columns 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:

string employeeCode;
employeeCode = textBox1.Text;
string connectionString = "Data Source=SQLSERVER01;Initial 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";
cmd.Parameters.Add(new SqlParameter("@eCode",employeeCode));
textBox2.Text = Convert.ToString((cmd.ExecuteScalar()));
textBox3.Text = Convert.ToString((cmd.ExecuteScalar()));
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

1, The method, ExecuteScalar() will always return the value present in the first row and first
column of the Employees table irrespective of the employee id being entered. The correct way is
to use ExecuteNonQuery()
method as shown:

textBox2.Text = Convert.ToString(cmd.ExecuteNonQuery());
textBox3.Text = Convert.ToString(cmd.ExecuteNonQuery());
m

2, The method, ExecuteScalar() will always return the value present in the first row and first
column of the Employees table irrespective of the employee id being entered. The correct way is
to use ExecuteReader()
method as shown:
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text = Convert..ToString((dr[1]));
textBox3.Text = Convert.ToString((dr[2]));
}
dr.Close(); m

3, The method, ExecuteScalar() will always return the value present in the first column of the
Employees table on the basis of the employee id being entered. The correct way is to use
ExecuteReader() method as shown:
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text = Convert.ToString((dr[1]));
textBox3.Text = Convert.ToString((dr[2]));
}
dr.Close(); m

4, The method, ExecuteScalar() will always return the value present in the first column of the
Employees table on the basis of the employee id being entered. The correct way is to use
ExecuteNonQuery() method as shown:

textBox2.Text = Convert.ToString(cmd.ExecuteNonQuery());
textBox3.Text = Convert.ToString(cmd.ExecuteNonQuery());

AY157

MyCalInc. Ltd. is a multinational call center company whose branches are spread in different
parts of the world. It has got a centralized database system wherein the details of all the
employees are stored. As a part of the development team, John is 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:

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

1, The code will throw an exception. It is necessary to mention the name of the provider in the
connection string. 2, The code will execute but will not give any output. m

3, The code will throw an exception. You need to mention the parameters to be passed in the
constructor of SqlParameter class. m

4, The code will give the desired output. m

AY158

MyProd Pvt. Ltd. is a leading producer of hardware and software products. The details of all the
products are maintained in a centralized 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;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 = 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

1, You need to set the MultipleActiveResultSets to true. m

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

3, You need to set the MultipleActiveResultSets to false. m

4, The parameters passed in the SqlParameter constructor are an incorrect order. m

AY159

MyProd Pvt. Ltd. is a leading producer of hardware and software products. The details of all the
products are maintained in a centralized 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;MultipleActiveResultSets=True;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 = 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

1, You need to set the MARS feature in the connection string to false m

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

3, You need to assign parameterized value for the command object cmd1 m

4, The parameters passed in the SqlParameter constructor are an incorrect order m

AY160

John works as a software developer in MyProdInc. Ltd. The company is involved in the large
scale production of hardware and software items. The details of all the products are stored in a
centralised database system. John is assigned a task to create an application in which the details
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"].NewRow();
row["productId"] = textBox1.Text;
row["productName"] = textBox2.Text;
row["productPrice"] = textBox3.Text;
ds.Tables["Product_Details"].Rows.Add(row);
connection.Close();
What will be the output on executing the preceding code? m

1, An exception will be thrown because the constructor of the SqlCommandBuilder class takes
the object of a DataSet as a parameter. m
2, The code will execute but will not insert the product details in the database. 3, The code will
give an error because the parameters passed in the constructor of SqlDataAdatapter class are in
an incorrect sequence. m

4, The details of the product will get saved in the database. m

AY161

Which of the following correctly defines atomicity? m

1, This property states that either all the modifications are performed or none of them are
performed. m

2, This property states that data is in a reliable state after a transaction is completed successfully
to maintain integrity of the data. m

3, This property states that any data modification made by one transaction must be separated
from the modifications made by the other transaction. m

4, This property states that any change in data by a completed transaction remains permanently
in effect in the database. m

AY162

How will you enable query notification for the HR database? m

1, ALTER DATABASE HR ENABLE SERVICE_BROKER; m

2, ALTER DATABASE HR SET ENABLE_BROKER; m

3, ALTER DATABASE HR SET ENABLE_SERVICEBROKER; m

4, ALTER DATABASE HR ENABLE SERVICEBROKER; m


2

AY163

Which class is used to copy data in bulk to SQL Server tables? m

1, SqlBulkCopy m

2, SqlDataReader m

3, SqlConnection m

4, SqlCommand 1

AY164

How many parameters does the GetBytes method take? m

1, 3 m

2, 5 m

3, 0 m

4, 1 m

AY165

How will you ensure that the UPDATETEXT function does not delete the existing data? 1, By
specifying the length of data to be deleted as 0. m

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

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

AY166
Consider the following code snippet:
UPDATETEXT Student.Photo @A @B @C @D
SqlParameter offsetParm = command.Parameters.Add("@B", SqlDbType.X); //command is an
object of SqlCommand
What does X represent? m

1, Int m

2, String m

3, Binary m

4, Image 1

AY167

Consider the following code 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
What does X represent? m

1, String m

2, Int m

3, Image m

4, Binary 3

AY168

Consider the following code snippet to read an image file:


file.Read(X, Y, Z); //file is an object of the Filestream class.
What are the data types of X, Y, and Z?
1, byte, int, int, respectively m

2, int, int, byte, respectively m

3, byte, byte, int, respectively m

4, int, byte, int, respectively m


1

AY169

To update a photograph in a table, you need to use the UPDATETEXT function. Consider the
following code snippet:UPDATETEXT function that is assigned as a command text:
command.CommandText="UPDATETEXT Emp.EmpPhoto @A @B @C @D";
where Emp is the name of the table and EmpPhoto is name of the column.
Command is the object of SqlCommand
What do @A, @B, @C, and @D represent? m

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

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

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

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

AY170

Consider the following code snippet:


UPDATETEXT Student.Photo @A @B @C @D
SqlParameter p = command.Parameters.Add("@A", SqlDbType.X, 16); //command is an object
of SqlCommand
In the preceding code snippet, what does X represent? m

1, Int m

2, Binary m

3, Image 4, String m

AY171

You have been asked to create an application that will open two connections and execute two
command. The first command will insert a record in the HRusers table. The other command
deletes a record from the Department table. Which of the following code snippet will allow you
to perform the required task? Assume the connections to be already open where cn and cn1 are
the connection objects. m

1, using (TransactionScope ts = new TransactionScope())


{
using (SqlCommand cmd = new SqlCommand("INSERT
INTO
HRusers(cUserName)VALUES('Darren')", cn))
{
int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated > 0)
{
using (SqlCommand cmd1 = new SqlCommand("DELETE
Department WHERE cDepartmentCode=1111", cn1)) {
int rowsUpdated1 = cmd1.ExecuteNonQuery();
if (rowsUpdated1 > 0)
{
ts.Complete();….}}}} m

2, TransactionScope ts = new TransactionScope()


using (SqlCommand cmd = new SqlCommand("INSERT
INTO
HRusers(cUserName)VALUES('Darren')", cn))
{ int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated > 0)
{
using (SqlCommand cmd1 = new SqlCommand("DELETE
Department WHERE cDepartmentCode=1111", cn1))
{
int rowsUpdated1 = cmd1.ExecuteNonQuery();
if (rowsUpdated1 > 0)
{
ts.Complete();
….}}}} m

3, TransactionScope ts = new TransactionScope()


using (SqlCommand cmd = new SqlCommand("INSERT
INTO
HRusers(cUserName)VALUES('Darren')", cn))
{
int rowsUpdated = ExecuteNonQuery();
if (rowsUpdated > 0)
{
using (SqlCommand cmd1 = new SqlCommand("DELETE
Department WHERE cDepartmentCode=1111", cn))
{
int rowsUpdated1 = cmd1.ExecuteNonQuery();
….}}} m

4, using (TransactionScope ts = new TransactionScope())


{ using (SqlCommand cmd = new SqlCommand("INSERT
INTO
HRusers(cUserName)VALUES('Darren')", cn))
{
int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated > 0)
{
using (SqlCommand cmd1 = new SqlCommand(DELETE
Department WHERE cDepartmentCode=1111, cn1))
{
int rowsUpdated1 = cmd1.ExecuteNonQuery();
cn.Complete();
….}}}} m

AY172

You need to create an application that will insert an image into an Images table of Photographs
database. Which of the following code snippets will help you perform the required task?
Assume that c stores the name of the image file and connection is the Connection object.The
connection has been established. m

1, FileStream file = new FileStream(c, FileMode.OpenOrCreate, FileAccess.Read);


byte[] r = new byte[file.Length];
file.Read(System.Convert.ToInt32(file.Length));
file.Close();
string sql = "SELECT * FROM Images";
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet("Images");
adapter.Fill(ds, "Images");
DataRow row = ds.Tables["Images"].NewRow();
row["imPhoto"] = r;
ds.Tables["Images"].Rows.Add(row);
adapter.Update(ds, "Images"); m

2, FileStream file = new FileStream(c, FileMode.OpenOrCreate, FileAccess.Read);


byte[] r = new byte[file.Length];
file.Read(r, 0, System.Convert.ToInt32(file.Length));
file.Close();
string sql = "SELECT * FROM Images";
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet("Images");
adapter.Fill(ds, "Images");
DataRow row = ds.Tables["Images"].NewRow();
row["imPhoto"] = r;
ds.Tables["Images"].Rows.Add(row);
adapter.Update(ds, "Images"); m

3, FileStream file = new FileStream(c, FileMode.OpenOrCreate, FileAccess.Read);


byte[] r = new byte[file.Length];
file.Read(0,r,System.Convert.ToInt32(file.Length));
file.Close();
string sql = "SELECT * FROM Images";
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet("Images");
adapter.Fill(ds, "Images");
DataRow row = ds.Tables["Images"].NewRow();
row["imPhoto"] = r;
ds.Tables["Images"].Rows.Add(row);
adapter.Update(ds, "Images"); m

4, FileStream file = new FileStream(c, FileMode.OpenOrCreate, FileAccess.Read);


byte[] r = new byte[file.Length];
file.Read(r, 0, System.Convert.ToInt32(file.Length));
file.Close();
string sql = "SELECT * FROM Images";
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet("Images");
adapter.Fill(ds, "Images");
DataRow row = ds.Tables["Images"].NewRow();
row["imPhoto"] = r;
adapter.Update(ds, "Images"); m

AY173

Sven is working as a software developer in QuickSolutions Software Ltd. He has been asked to
create an application that will display the photo of an employee, stored in the imPhoto field of
EMPLOYEES table, whose employee code is E001. Which of the following code snippet when
appended to the code given below will help him perform the required task?
Assume that connection has been established and connection is the Connection object.file and
bw are objects of FileStream and BinaryWriter classes, respectively
sring sql = "SELECT imPhoto FROM EMPLOYEES WHERE cEmployeeCode='E001'";
int bufferSize = 100;
byte[] outbyte = new byte[bufferSize];
long retval, startIndex = 0;
string savedImageName = " ";
SqlCommand command = new SqlCommand(sql, connection); m

1, SqlDataReader myReader =
command.ExecuteReader();
while (myReader.Read())
{ file = new FileStream(savedImageName, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(file);
startIndex = 0;
retval = myReader.GetBytes(startIndex, outbyte, bufferSize);
while (retval == bufferSize)
{ bw.Write(outbyte);
bw.Flush();
startIndex += bufferSize;
retval = myReader.GetBytes(startIndex, outbyte, bufferSize);
}
…..
} // Code for displaying image in the picture box }m

2, SqlDataReader myReader =
command.ExecuteReader(CommandBehavior.SequentialAccess);
while (myReader.Read())
{
file = new FileStream(savedImageName, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(file);
startIndex = 0;
retval = myReader..GetBytes();
while (retval == bufferSize)
{
bw.Write(outbyte);
bw.Flush();
startIndex += bufferSize;
retval = myReader.GetBytes();
}
}
…..
} // Code for displaying image in the picture box }m

3, SqlDataReader myReader =
command.ExecuteReader(CommandBehavior.SequentialAccess);
while (myReader.Read())
{
file = new FileStream(savedImageName, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(file);
startIndex = 0;
retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
while (retval == bufferSize)
{
bw.Write(outbyte);
bw.Flush();
startIndex += bufferSize;
retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
}
}
…..
} // Code for displaying image in the picture box }m

4, SqlDataReader myReader = command.ExecuteReader();


while (myReader.Read())
{
file = new FileStream(savedImageName, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(file);
startIndex = 0;
retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
while (retval == bufferSize)
{
bw.Write(outbyte);
bw.Flush();
startIndex += bufferSize;
retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
}
}
…..
} // Code for displaying image in the picture box }m

AY174

You have been asked to create an application that will insert a record each into the Departments
table and the HRUsers table of the HR database. You need to ensure that dirty reads, non-
repeatable reads, and phantom reads are avoided during the transaction. Which of the following
code snippet correctly does the required task? m

1, TransactionOptions options = new TransactionOptions();


options.IsolationLevel =
System.Transactions.IsolationLevel.ReadCommitted; m

2, TransactionOptions options = new TransactionOptions();


options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted; m

3, TransactionOptions options = new TransactionOptions();


options.IsolationLevel =
System.Transactions.IsolationLevel.Read; m

4, TransactionOptions options = new TransactionOptions();


options.IsolationLevel =
System.Transactions.IsolationLevel.Serializable; m

AY175

A new employee, Linda Taylor, has joined QuickSolutions Software Ltd. Her details need to be
added to an empdetails table. This task should be done through a transaction. Which of the
following code snippets will allow you to perform this task? m

1, SqlTransaction tran = null;


try
{
//cn is an object of the SqlConnection class.
tran = cn.BeginTransaction();
SqlCommand cmd = new SqlCommand("INSERT INTO
empdetails(ccode,cname,caddress,cstate,ccountry,cDesignation,cDepartment)VALUES(1101,'Li
nda Taylor','Oxfordshire','London','UK','Manager','Finance')", cn, tran);
cmd.ExecuteNonQuery();
tran.Commit();
Console.WriteLine("Transaction Committed\n");
}
catch (SqlException ex)
{
tran.Rollback();
Console.WriteLine("Error - TRANSACTION ROLLED BACK\n" + ex.Message);
}

2, SqlTransaction tran = null;


try
{
tran.BeginTransaction();
SqlCommand cmd = new SqlCommand("INSERT INTO
empdetails(ccode,cname,caddress,cstate,ccountry,cDesignation,cDepartment)VALUES(1101,'Li
nda Taylor','Oxfordshire','London','UK','Manager','Finance')", cn, tran);
cmd.ExecuteNonQuery();
Commit();
Console.WriteLine("Transaction Committed\n");
}
catch (SqlException ex)
{
Rollback();
Console.WriteLine("Error - TRANSACTION ROLLED BACK\n" + ex.Message);
}

3, SqlTransaction tran = null;


try
{
//cn is an object of the SqlConnection class.
tran = cn.BeginTransaction();
SqlCommand cmd = new SqlCommand("INSERT INTO
empdetails(ccode,cname,caddress,cstate,ccountry,cDesignation,cDepartment)VALUES(1101,'Li
nda Taylor','Oxfordshire','London','UK','Manager','Finance')", cn, tran);
cmd.ExecuteNonQuery();
cn.Commit();
Console.WriteLine("Transaction Committed\n");
}
catch (SqlException ex)
{
cn.Rollback();
Console.WriteLine("Error - TRANSACTION ROLLED BACK\n" + ex.Message);
}

4, SqlTransaction tran = null;


try
{
//cn is an object of the SqlConnection class.
cn.BeginTransaction();
SqlCommand cmd = new SqlCommand("INSERT INTO
empdetails(ccode,cname,caddress,cstate,ccountry,cDesignation,cDepartment)VALUES(1101,'Li
nda Taylor','Oxfordshire','London','UK','Manager','Finance')", cn, tran);
cmd.ExecuteNonQuery();
cn.Commit();
Console.WriteLine("Transaction Committed\n");
}
catch (SqlException ex)
{
tran.Rollback();
Console.WriteLine("Error - TRANSACTION ROLLED BACK\n" + ex.Message);
}

AY176

QuickSolutions Software Ltd. stores the details of its employees in an Employee table in a
database called QuickSolutions. The details include the photograph of the employees. The
photograph of one employee whose employee code is E009 needs to be updated with a new
photograph. Peter is working as a software developer in QuickSolutions Software Ltd. and he has
been assigned this task. Peter writes the following code in the click event of a button to perform
the required task:
const int bufferSize = 100;
byte[] buffer = new byte[bufferSize];
long currentIndex = 0;
byte[] photoPtr;
{
//open the connection
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "Select Photo from Employee where
employeeCode='E009'";
photoPtr = (byte[])command.ExecuteScalar();
}
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

1, The syntax of UPDATETEXT is incorrect. It should be:UPDATETEXT Employee.Photo


@Pointer @Offset @Data null";
2, UPDATETEXT requires a pointer to the binary field being updated. To get a pointer to a
particular field of a record in a database, the SQL Server TEXTPTR function needs to be called.
This can be done in the following way:command.CommandText = "Select TEXTPTR(Photo)
from Employee where employeeCode='E009'";
3, UPDATETEXT requires a pointer to the binary field being updated. To get a pointer to a
particular field of a record in a database, the SQL Server TEXTPTR function needs to be called.
This can be done in the following way:command.CommandText = "TEXTPTR(Select Photo
from Employee where employeeCode='E009')";
4, The syntax of UPDATETEXT is incorrect. It should be:
UPDATETEXT Employee..Photo @Offset @Pointer @Data null";

AY177

The records stored in the Stores table of AdventureWorks database have accidentally got deleted.
However, there is a backup copy of this table called StoresBackup. You have written the
following code in the click event of a button to copy the records from StoresBackup to Stores:
using (SqlConnection sc = new SqlConnection(connectionString))
{ sc.Open();
SqlCommand commandSourceData = new SqlCommand("SELECT * FROM
StoresBackup;", sc);
SqlDataReader reader = commandSourceData.ExecuteReader();
using (SqlConnection dc = new SqlConnection(connectionString))
{ dc.Open();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy())
{
bulkCopy.DestinationTableName = "Stores";
bulkCopy.WriteToServer();
}}
However, the preceding code is not working. Analyze the problem and identify which of the
following code snippets will perform the required task? m

1, using (SqlConnection sc = new SqlConnection(connectionString))


{ sc.Open();
SqlCommand commandSourceData = new SqlCommand("SELECT * FROM
StoresBackup;", sc);
SqlDataReader reader = commandSourceData.ExecuteReader();
using (SqlConnection dc = new SqlConnection(connectionString))
{ dc.Open();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(dc))
{ bulkCopy.DestinationTableName = "Stores";
bulkCopy.WriteToServer(reader); } m

2, using (SqlConnection sc = new SqlConnection(connectionString))


{ sc.Open();
SqlCommand commandSourceData = new SqlCommand("SELECT * FROM
StoresBackup;", sc);
SqlDataReader reader = commandSourceData.ExecuteReader();
using (SqlConnection dc = new SqlConnection(connectionString))
{ dc.Open();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(dc))
{ bulkCopy.DestinationTableName = "Stores";
bulkCopy.WriteToServer(); } m

3, using (SqlConnection sc = new SqlConnection(connectionString))


{ sc.Open();
SqlCommand commandSourceData = new SqlCommand("SELECT * FROM
StoresBackup;", sc);
SqlDataReader reader = commandSourceData.ExecuteReader();
using (SqlConnection dc = new SqlConnection(connectionString))
{ dc.Open();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy())
{ bulkCopy.DestinationTableName = "Stores";
bulkCopy.WriteToServer(reader); } m
4, using (SqlConnection sc = new SqlConnection(connectionString))
{ sc.Open();
SqlCommand commandSourceData = new SqlCommand("SELECT * FROM
StoresBackup;", sc);
SqlDataReader reader = commandSourceData.ExecuteReader();
using (SqlConnection dc = new SqlConnection(connectionString))
{ dc.Open();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(dc))
{ bulkCopy.DestinationTable = "Stores";
bulkCopy.WriteToServer(reader); } m

AY178

Samuel needs to update the HRUsers table and the Department table of the HR database using
distributed transaction. The transaction should be such that volatile data cannot be read during
the transaction but can be modified. To perform this task, Samuel writes the following code:

TransactionOptions options; options.IsolationLevel =


System.Transactions..IsolationLevel.ReadUncommitted;
using (options)
{ ….
using (SqlCommand cmd = new SqlCommand("INSERT INTO
Department(cDepartmentCode) VALUES(2013)", cn))
{ int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated > 0)
{ using (SqlCommand cmd1 = new SqlCommand("INSERT INTO
HRusers(cUserName) VALUES('Hansel')", cn1))
{ int rowsUpdated1 = cmd1.ExecuteNonQuery(); if (rowsUpdated1 >0)
ts.Complete();
…..}}}}
However, the code is not serving the required purpose. Identify the problem and suggest a
solution. Assume that two connection objects cn and cn1 have been created. m

1, TransactionOptions options;
options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
using (TransactionScope ts = new TransactionScope())
{ using (SqlCommand cmd = new SqlCommand("INSERT INTO
Department(cDepartmentCode) VALUES(2013')", cn))
{ int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated > 0)
{ using (SqlCommand cmd1 = new SqlCommand("INSERT INTO
HRusers(cUserName) VALUES('Hansel'')", cn1))
{ int rowsUpdated1 = cmd1..ExecuteNonQuery();
if (rowsUpdated1 > 0)
{ ts.Complete();
…..}}}}} m

2, TransactionOptions options = new TransactionOptions();


options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
using (TransactionScope ts = new TransactionScope())
{ using (SqlCommand cmd = new SqlCommand("INSERT INTO
Department(cDepartmentCode) VALUES(2013)", cn))
{ int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated > 0)
{ using (SqlCommand cmd1 = new SqlCommand("INSERT INTO
HRusers(cUserName,cPassword) VALUES('Hansel','Lord')", cn1))
{ int rowsUpdated1 = cmd1.ExecuteNonQuery();
if (rowsUpdated1 > 0)
{ ts.Complete();
……}}}} m

3, TransactionOptions options = new TransactionOptions();


options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
using (options)
{ using (SqlCommand cmd = new SqlCommand("INSERT INTO
Department(cDepartmentCode) VALUES(2013)", cn))
{ int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated > 0)
{ using (SqlCommand cmd1 = new SqlCommand("INSERT INTO
HRusers(cUserName) VALUES('Hansel')", cn1))
{int rowsUpdated1 = cmd1.ExecuteNonQuery();
if (rowsUpdated1 > 0)
{ ts.Complete();
……………}}}}} m

4, TransactionOptions options = new TransactionOptions();


options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
using (TransactionScope ts = new TransactionScope())
{ using (SqlCommand cmd = new SqlCommand("INSERT INTO
Department(cDepartmentCode) VALUES(2013)", cn))
{ int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated > 0)
{using (SqlCommand cmd1 = new SqlCommand("INSERT INTO
HRusers(cUserName) VALUES('Hansel')", cn1))
{ int rowsUpdated1 = cmd1.ExecuteNonQuery();
if (rowsUpdated1 > 0)
{ts.Complete();
……………..}}}}}

AY179

Samuel is working as a software developer in QuickSolutions Software Ltd. He needs to update


the HRUsers table and the Departments table of the HR database. The transaction should be such
that volatile data can be read but not modified during the transaction. In addition, new data can
be added during the transaction. Samuel writes the following code snippet for that purpose:
TransactionOptions options;
options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
using (options)
{
// Code to update the HRUsers table and the Department table of the HR database
}
However, the code is not serving the required purpose. Identify the problem and suggest a
solution.. m

1, Samuel should make following changes in the code:


TransactionOptions options = new TransactionOptions();
options.IsolationLevel =
System.Transactions.IsolationLevel.ReadCommitted;
using (TransactionScope ts = new TransactionScope())
{
// Code to update the HRUsers table and the Department table of the
HR database
}m

2, Samuel should make following changes in the code:


TransactionOptions options = new TransactionOptions();
options.IsolationLevel =
System.Transactions.IsolationLevel.ReadUncommitted;
using (TransactionScope ts = new TransactionScope())
{
// Code to update the HRUsers table and the Department table of the HR
database
}m
3, Samuel should write the following code:
static void Main(string[] args)
{
TransactionOptions options;
options.IsolationLevel =
System.Transactions.IsolationLevel.RepeatableRead;
using (options)
{
// Code to update the HRUsers table and the Department table of the HR
database
}m

4, Samuel should make following changes in the code:


TransactionOptions options = new TransactionOptions();
options.IsolationLevel =
System.Transactions.IsolationLevel.RepeatableRead;
using (TransactionScope ts = new TransactionScope())
{
// Code to update the HRUsers table and the Department table of the
HR database
}m

AY180

The employee details of QuickSolutions Software Ltd. are stored in an Employees table. Sarah is
a software developer in QuickSolutions Software Ltd. She has been assigned the task of creating
an application that will cache these details. The cache should get updated whenever there is some
change in the database. Sarah has written the following code to perform this task:
//The connection object, cn and SqlDependency object, dep have already been created
private void UpdateGrid()
{ string sql = "SELECT cEmployeeCode FROM dbo.[Employees]";
DataTable dt = new DataTable();
using (SqlCommand cmd = new SqlCommand(sql, cn))
{dep = new SqlDependency();
using (SqlDataReader rdr = cmd.ExecuteReader())
{ dt.Load(rdr);}}
dataGridView1((GridDelegate)delegate(DataTable table)
{ dataGridView1.DataSource = 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

1, private void UpdateGrid()


{
.....................
using (SqlCommand cmd = new SqlCommand(sql, cn))
{
dep = new SqlDependency(cmd);
dep.OnChange += dep_OnChange;
using (SqlDataReader rdr = cmd.ExecuteReader())
{
dt.Load();}}}
dataGridView1(GridDelegate)delegate(DataTable table)
{.......................
}m

2, private void UpdateGrid()


{
…………………….
using (SqlCommand cmd = new SqlCommand(sql, cn))
{
dep = new SqlDependency();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
dt.Load(rdr); } } }
dataGridView1.Invoke((GridDelegate)delegate(DataTable table)
{…………….
}m

3,private void UpdateGrid()


{
.................
using (SqlCommand cmd = new SqlCommand(sql, cn))
{
dep = new SqlDependency(cmd);
dep.OnChange += dep_OnChange;
using (SqlDataReader rdr = cmd.ExecuteReader())
{ dt.Load(rdr); } } }
dataGridView1.Invoke((GridDelegate)delegate(DataTable table)
{ ...................
}m

4,private void UpdateGrid()


{
using (SqlCommand cmd = new SqlCommand(sql, cn))
{ dep = new SqlDependency();
dep.OnChange += dep_OnChange;
using (SqlDataReader rdr = cmd.ExecuteReadercmd())
{
dt.Load(rdr);
} } }
dataGridView1.Invoke((GridDelegate)delegate(DataTable table)
{ …………………..
}m

AY181

Which of the following is not a property of durability? m

1, Durability is ensured by taking back ups of data and restoring transaction logs. m

2, Any change in data due to a completed transaction persists even in the event of a system
failure. m

3, Durability ensures that data is in a reliable state after a transaction is completed successfully to
maintain integrity of the data. m

4, Durability ensures that any change in data by a completed transaction remains permanently in
effect in the database. m

AY182

Which class is used to provide security permissions to a user for executing SQL notification? m
1, SqlDataAdapter 2, SqlCommand

3, SqlConnection 4, SqlClientPermission 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 the value of PermissionState to None m

3, By setting the value of PermissionState to Restricted m

4, By setting the value of Permissionstate to Restricted m

AY184

Which namespace do you need to include in order to give permissions to a user so that he is able
to execute query notifications? m

1, System.Security.Permissions m

2, System.Permissions m

3, System.Security m

4, System.Permissions.Security m

AY185
After calling which method, do 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

1, Commit() m

2, BeginTransaction() m

3, Rollback() m

4, EndTransaction() 2

AY186

Which of the following 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

1, Encoding m

2, NewLineChars m

3, ConformanceLevel m

4, CloseOutput 4

AY187

Which of the following methods of the XmlTextWriter class creates an XML declaration? 1,
WriteStartDocument() m

2, WriteStartElement() m

3, WriteDeclaration() m

4, WriteElementString() 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 str=dataset1.Convert.GetXml; m

2, string str=dataset1.GetXml; m

3, string str=GetXml(dataset1); m

4, string str=dataset1.GetXml(); m

AY189

Which of the following is the default option of XmlWriteMode? m

1, Schemas m

2, IgnoreSchema m

3, WriteSchema

4, DiffGram m

AY190

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

1, Read() m

2, MoveToNextAttribute() m

3, ReadNextElement() m

4, ReadString() 1

AY191

You have created an XML file using XMLWriter. When you open the XML file in Notepad, you
get the following output in one line:
<?xml version="1.0" encoding="utf-8"?><!--Order Details of Q1--><OrderDetails><Order
OrderID="O001"><ProductName>Toys</ProductName><Price>100</Price></Order><Order
OrderID="O002"><ProductName>Stationary</ProductName><Price>30</Price></Order></Ord
erDetails>
What might be the possible cause? m

1, The Indent property of XmlWriterSettings class has not been set to true m

2, The IndentChars property of XmlWriterSettings class has not been set to true m

3, The IndentChars property of XmlWriterSettings class has not been set to " " 4, The Indent
property of NewLineOnAttributes class has not been set to true

AY192

Consider the following code, which is written inside the click event of a button called Operate:
XmlTextReader ExternalCandidateReader = new
XmlTextReader("C:\\ExternalCandidate.xml");
XmlTextReader InternalCandidateReader = new
XmlTextReader("C:\\InternalCandidate.xml");
DataSet dsExtCandidate = new DataSet();
dsExtCandidate.ReadXml(ExternalCandidateReader);
DataSet dsIntCandidate = new DataSet();
dsIntCandidate.ReadXml(InternalCandidateReader);
dsExtCandidate.Merge(dsIntCandidate);
dsExtCandidate.WriteXml("C:\\CandidateDetails.xml");
DataSet dsDisplay = new DataSet();
dsDisplay.ReadXml("C:\\CandidateDetails.xml", XmlReadMode.InferSchema);
dataGridView1.DataSource = dsDisplay.Tables[0].DefaultView;

What will happen when the Operate button is clicked? m

1, An exception will be thrown because Tables[0] will return a NULL value. m

2, The contents of dsIntCandidate, which contains the InternalCandidate.xml file, will be


appended to dsExtCandidate, which contains the ExternalCandidate.xml file. A new file
CandidateDetails.xml file be created that will contain the merged data. The contents of
dsExtCandidate will be displayed in a DataGridView control. 3, The contents of
dsIntCandidate, which contains the InternalCandidate.xml file, will be appended to
dsExtCandidate, which contains the ExternalCandidate.xml file.. A new file
CandidateDetails.xml file be created that will contain the merged data. The DataGridView
control will not display anything. m

4, The contents of dsIntCandidate, which contains the InternalCandidate.xml file, will be


appended to dsExtCandidate, which contains the ExternalCandidate.xml file. A new file
CandidateDetails.xml file be created that will contain the merged data. The contents of
dsIntCandidate will be displayed in a DataGridView control. m

AY193

Which of the following statements is true about the InferSchema XmlReadMode option? 1, It
examines the XML data and selects the appropriate option m

2, It ignores any inline schema m

3, It loads the XML data into the existing dataset schema. m

4, It does not deduce the schema according to the structure of the XML data m

AY194

Consider the following code snippet, which fills a dataset with data stored in an 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

1, ds.DefaultView m

2, ds.Tables.DefaultView m

3, ds.Tables[0].DefaultView

4, ds.DefaultView.Tables[0]
3

AY195

Consider the following XML file, products.xml:


<?xml version="1.0"?>
<PRODUCTDATA>
<PRODUCT>
<PRODUCTNAME>Barbie Doll</PRODUCTNAME>
<PRICE>-200</PRICE>
<DESCRIPTION>Toy</DESCRIPTION>
<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="qualified" targetNamespace="urn:product-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

1, The XSD file is not incorrect. m

2, The XML file is not well-formed. m

3, The PRICE element cannot have a negative value. m

4, The statement xmlns="urn:product-schema" is missing in the XML file. m


4

AY196

The employee details of QuickSolutions Software Ltd. are stored in an XML format in an EMP
table of an HR database. You are working as a .NET developer in QuickSolutions Software Ltd.
You have been asked to create an application that will retrieve these details and display them in a
DataGrid control. Which of the following code snippets will allow you to perform the required
task? m

1, using (SqlConnection conn = new SqlConnection())


{
string connectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User
ID=sa;Password=niit#1234";
conn.ConnectionString = connectionString;
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM EMP";
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{

SqlXml e = rdr.GetSqlXml(0);
if (e.IsNull)
{
// ds is the object of DataSet
ds.ReadXml(e.CreateReader());
}
}
}
}
dataGrid1.DataSource = ds;
}

2, using (SqlConnection conn = new SqlConnection())


{
string connectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User
ID=sa;Password=niit#1234";
conn.ConnectionString = connectionString;
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM EMP";
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{

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

3, using (SqlConnection conn = new SqlConnection())


{
string connectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User
ID=sa;Password=niit#1234";
conn.ConnectionString = connectionString;
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM EMP";
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{

SqlXml e = rdr.GetSqlXml();
if (!e.IsNull)
{
// ds is the object of DataSet
ds.ReadXml(e.CreateReader());
}
}
}
}
dataGrid1.DataSource = ds;
}

4, using (SqlConnection conn = new SqlConnection())


{
string connectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User
ID=sa;Password=niit#1234";
conn.ConnectionString = connectionString;
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM EMP";
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{

SqlXml e = rdr.GetSqlXml(0);
if (!e.IsNull)
{
// ds is the object of DataSet
ds.ReadXml(CreateReader());
}
}
}
}
dataGrid1.DataSource = ds;
}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 (XmlWriter writer = XmlWriter.Create("C:\\OrderDetails.xml"));


{
writer.WriteStartElement("OrderDetails");
writer.WriteStartElement("Order");
writer.WriteAttributeString("OrderID","O001");
writer.WriteElementString("Name", "Toys");
writer.WriteElementString("Price", "100");
writer.WriteEndElement();
writer.WriteStartElement("Order");
writer.WriteAttributeString("OrderID", "O002");
writer.WriteElementString("Name", "Stationary");
writer.WriteElementString("Price", "30");
writer.WriteEndElement();
writer.WriteEndElement();
writer.Flush();
}m

2, using (XmlWriter writer = XmlWriter.Create("C:\\OrderDetails.xml"))


{
writer.WriteStartElement("OrderDetails");
writer.WriteStartElement("Order");
writer.WriteAttributeString("OrderID","O001");
writer.WriteElementString("Name", "Toys");
writer.WriteElementString("Price", "100");
writer.WriteEndElement();
writer.WriteStartElement("Order");
writer.WriteAttributeString("OrderID", "O002");
writer.WriteElementString("Name", "Stationary");
writer.WriteElementString("Price", "30");
writer..WriteEndElement();
writer.WriteEndElement();
writer.Flush();
}m

3, using (XmlWriter writer = XmlWriter.Create("C:\\OrderDetails.xml"))


{
writer.WriteStartElement('OrderDetails');
writer.WriteStartElement("Order");
writer.WriteAttributeString("OrderID","O001");
writer.WriteElementString("Name", "Toys");
writer.WriteElementString("Price", 100);
writer.WriteEndElement();
writer.WriteStartElement("Order");
writer.WriteAttributeString("OrderID", "O002");
writer.WriteElementString("Name", "Stationary");
writer.WriteElementString("Price", 30);
writer.WriteEndElement();
writer.WriteEndElement();
writer.Flush();
}m

4,using (XmlWriter writer = XmlWriter.Create("C:\\OrderDetails.xml"))


{
writer.WriteComment('Order Details of Q1');
writer.WriteStartElement("OrderDetails");
writer.WriteStartElement("Order");
writer.WriteAttributeString("OrderID","O001");
writer.WriteElementString("Name", "Toys");
writer.WriteElementString("Price", "100");
writer.WriteEndElement();
writer.WriteStartElement("Order");
writer.WriteAttributeString("OrderID", "O002");
writer.WriteElementString("Name", "Stationary");
writer.WriteElementString("Price", "30");
writer.WriteEndElement();
writer.WriteEndElement();
writer.Flush();
}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();
schemaSet.Add("urn:myFile-schema", "C:\\myFile.xsd");
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = schemaSet;
settings.ValidationEventHandler = new ValidationEventHandler(ValidationCallBack);
XmlReader reader = XmlReader.Create("C:\\myFile.xml", settings);
while (reader.Read());
Console.ReadLine();
}
private static void ValidationCallBack(object sender, ValidationEventArgs e)
{
Console.WriteLine("Errors: {0}", e.Message);
}m

2, public static void Main()


{
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("urn:myFile-schema", C:\\myFile.xsd);
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = schemaSet;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
XmlReader reader = XmlReader.Create("C:\\myFile.xml", settings);
while (reader.Read());
Console.ReadLine();
}
private static void ValidationCallBack(object sender, ValidationEventArgs e)
{
Console.WriteLine("Errors: {0}", e.Message);
}m

3, public static void Main()


{
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("urn:myFile-schema", "C:\\myFile.xsd");
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = schemaSet;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
XmlReader reader = XmlReader.Create("C:\\myFile.xml", settings);
while (reader.Read());
Console.ReadLine();
}
private static void ValidationCallBack(object sender, ValidationEventArgs e)
{
Console.WriteLine("Errors: {0}", e.Message);
}m

4, public static void Main()


{
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("urn:myFile-schema", C:\\myFile.xsd);
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = schemaSet;
settings.ValidationEventHandler = new ValidationEventHandler(ValidationCallBack);
XmlReader reader = XmlReader.Create(C:\\myFile.xml, settings);
while (reader.Read());
Console.ReadLine();
}
private static void ValidationCallBack(object sender, ValidationEventArgs e)
{
Console.WriteLine("Errors: {0}", 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)


{
XmlTextReader reader = new XmlTextReader("C:\\myFile.xml");
XmlValidatingReader validatingReader = new XmlValidatingReader(reader);
validatingReader.ValidationType = ValidationType.Schema;
validatingReader..ValidationEventHandler +=new
ValidationEventHandler(ValidationHandler);
while(validatingReader.Read());
}
public static void ValidationHandler(Object sender, ValidationEventArgs args)
{
Console.WriteLine("Validation Error");
Console.WriteLine("\tSeverity:{0}", args.Severity);
Console.WriteLine("\tMessage :{0}", args.Message);
}
2, static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader("C:\\myFile.xml");
XmlValidatingReader validatingReader = new XmlValidatingReader(reader);
reader..ValidationType = ValidationType.Schema;
validatingReader.ValidationEventHandler =new
ValidationEventHandler(ValidationHandler);
while(validatingReader.Read());
}
public static void ValidationHandler(Object sender, ValidationEventArgs args)
{
Console.WriteLine("Validation Error");
Console.WriteLine("\tSeverity:{0}", args.Severity);
Console.WriteLine("\tMessage :{0}", args.Message);
}
3, static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader("C:\\myFile.xml");
XmlValidatingReader validatingReader = new XmlValidatingReader(reader);
validatingReader.ValidationType = ValidationType.Schema("C:\\myFile.xsd");
validatingReader.ValidationEventHandler +=new
ValidationEventHandler(ValidationHandler);
while(validatingReader.Read());
}
public static void ValidationHandler(Object sender, ValidationEventArgs args)
{
Console.WriteLine("Validation Error");
Console.WriteLine("\tSeverity:{0}", args.Severity);
Console.WriteLine("\tMessage :{0}", args.Message);
}
4, static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader("C:\\myFile.xml");
XmlValidatingReader validatingReader = new XmlValidatingReader(reader);
validatingReader.ValidationType = ValidationType.Schema("C:\\myFile.xsd");
validatingReader.ValidationEventHandler =new
ValidationEventHandler(ValidationHandler);
while(validatingReader.Read());
}
public static void ValidationHandler(Object sender, ValidationEventArgs args)
{
Console.WriteLine("Validation Error");
Console.WriteLine("\tSeverity:{0}", args.Severity);
Console.WriteLine("\tMessage :{0}", args.Message);
}

AY200

Consider the following code snippet:


XmlDocument doc = new XmlDocument();
doc.LoadXml(("<BOOKDETAILS><BOOK BOOKID='B001'><BOOKNAME>Angels and
Demons</BOOKNAME><AUTHOR>Dan Brown</AUTHOR></BOOK><BOOK
BOOKID='B002'><BOOKNAME>Dr. Jekyll and Mr.
Hyde</BOOKNAME><AUTHOR>Robert Louis
Stevenson</AUTHOR></BOOK></BOOKDETAILS>"));
Which of the following code snippets when appended to the preceding snippet will produce the
following XML file on the Console:
<BOOKDETAILS>
<BOOK BOOKID="B001">
<AUTHOR>Dan Brown</AUTHOR>
</BOOK>
<BOOK BOOKID="B002">
<BOOKNAME>Dr.. Jekyll and Mr. Hyde</BOOKNAME>
<AUTHOR>Robert Louis Stevenson</AUTHOR>
</BOOK>
<PRICE>20</PRICE>
</BOOKDETAILS>

1, XmlNode node = doc.DocumentElement.FirstChild;


node.RemoveChild(node.FirstChild);
XmlElement element = doc.CreateElement("PRICE");
XmlText text = doc.CreateTextNode("20");
doc.DocumentElement.AppendChild(element);
doc.DocumentElement.FirstChild.AppendChild(text);
doc.Save(Console.Out); m
2, XmlNode node = doc.DocumentElement.FirstChild;
node.RemoveChild(node.FirstChild);
XmlElement element = doc.CreateElement("PRICE");
XmlText text = doc.CreateTextNode("20");
doc.DocumentElement.AppendChild(node);
doc.DocumentElement.LastChild.AppendChild(text);
doc.Save(Console.Out); m

3, XmlNode node = doc.DocumentElement.FirstChild;


node.RemoveChild(node.FirstChild);
XmlElement element = doc.CreateElement("PRICE");
XmlText text = doc.CreateTextNode("20");
doc.DocumentElement.AppendChild(element);
doc.DocumentElement.LastChild.AppendChild(text);
doc.Save(Console.Out); m

4, XmlNode node = doc.DocumentElement.FirstChild;


node.RemoveChild(node.FirstChild);
XmlElement element = doc.CreateElement("PRICE");
XmlText text = doc.CreateTextNode("20");
doc.DocumentElement.AppendChild(element);
doc.DocumentElement.LastChild.AppendChild(node);
doc.Save(Console.Out); m

You might also like