Professional Documents
Culture Documents
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
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
AY005
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
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.
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
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
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
AY016
On execution how many times the above code will display the Hello word?
1, 0
2, 4 3, 5
4, 6
AY017
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
3, | m
4, ! m
AY020
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
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
AY024
2, The Example class is accessible to the classes within the same package
AY025
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
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
AY029
AY030
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?
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?
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.
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.
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
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
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
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
AY048
Which of the following is the best practice for delivering the web content to mobile phones?
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
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
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
}
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
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
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
2, %s m
3, %x m
4, %n 2
AY064
2, Statement A is false whileStatement B is true. 3, Both Statement A and Statement B are false.
m
AY065
AY066
3, Statement A is false while Statement B is true. 4, Both Statement A and Statement B are
false.
AY067
AY068
2, Integers m
3, Streams m
4, Files m
AY069
2, LinkedList m
3, Arraylist m
4, HashSetMap
AY070
AY071
AY072
4, The code will compile and execute with the following output:
num1
num2
2
AY073
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
{
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
1, Checked Exception m
2, Unchecked exception m
AY077
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
AY082
AY083
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
3, The code will execute with the following output:Hello 4, The code will execute with the
following output:Hello Hello
AY085
2, 12Programming m
AY086
2, A Frame m
3, A text component m
4, Any component 2
AY087
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
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
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
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
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
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
AY099
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.*;
4, import java.awt.event.*;
public class CustomHandler implements ActionListener{
public static void main(String args[])
{
/*Process action here*/
}
}
1
AY101
4, The code will compile, execute, but will not display anything.
AY102
2, Blocked m
3, Listening m
4, Dead m
AY103
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
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
1
AY107
AY108
Which of the following classes will you use to communicate between threads? 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
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
2, yield() m
3, run() m
4, start() m
AY116
2, 65535 m
3, 100000 m
4, -7070 m
AY117
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
AY119
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
AY121
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
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
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
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
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
3, Library specifies the name of the server, which is used in an open connection m
AY132
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
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
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
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
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
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
AY141
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
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
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
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
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
2, You cannot use a single SqlDataReader object to implement more than one operation on a
table. 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
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
AY161
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
AY163
1, SqlBulkCopy m
2, SqlDataReader m
3, SqlConnection m
4, SqlCommand 1
AY164
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
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
1, String m
2, Int m
3, Image m
4, Binary 3
AY168
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
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
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
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
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
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
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
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
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:
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
AY179
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
AY181
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
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
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;
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
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
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
SqlXml e = rdr.GetSqlXml(0);
if (e.IsNull)
{
// ds is the object of DataSet
ds.ReadXml(e.CreateReader());
}
}
}
}
dataGrid1.DataSource = ds;
}
SqlXml e = rdr.GetSqlXml(0);
if (!e.IsNull)
{
// ds is the object of DataSet
ds.ReadXml(e.CreateReader());
}
}
}
}
dataGrid1.DataSource = ds;
}
SqlXml e = rdr.GetSqlXml();
if (!e.IsNull)
{
// ds is the object of DataSet
ds.ReadXml(e.CreateReader());
}
}
}
}
dataGrid1.DataSource = ds;
}
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
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
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
AY200