java compiler

119
3, Feedback 4, Constraints 2 2, Feedback 3, Constraints 4, Affordances 2 2, Star model 2 1, Data 3, Usability 4, User 3 3, Interviews 3 SMB 200 1 The __________ principle states that while designing an interactive product, the interfaces should have similar operations and should use similar elements for similar tasks. 1, Visibility 2, Consistency SMB 200 2 Which of the following principles of interactive design states that it is important to keep the users informed about their actions? 1, Visibility SMB 200 3 Which of the following options is a lifecycle model that is selected by designers when the project is small and they want to use a flexible lifecycle model? 1, Usability engineering model 3, Conceptual Model 4, User's Mental Model SMB 200 4 _________ requirements capture the system goals with respect to effectiveness, efficiency, safety, utility, learnability, and memorability of a product. 2, Environmental SMB 200 5 Which of the following data gathering techniques involves having a conversation with the participants where the researcher orally solicits responses? 1, Questionnair es 2, Focus groups 4, Naturalistic observation

Upload: boomzi

Post on 03-Dec-2014

67 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Java Compiler

1, Visibility 2, Consistency 3, Feedback 4, Constraints 2

1, Visibility 2, Feedback 3, Constraints 4, Affordances 2

2, Star model 2

1, Data 2, Environmental 3, Usability 4, User 3

2, Focus groups 3, Interviews 3

SMB2001

The __________ principle states that while designing an interactive product, the interfaces should have similar operations and should use similar elements for similar tasks.

SMB2002

Which of the following principles of interactive design states that it is important to keep the users informed about their actions?

SMB2003

Which of the following options is a lifecycle model that is selected by designers when the project is small and they want to use a flexible lifecycle model?

1, Usability engineering model

3, Conceptual Model

4, User's Mental Model

SMB2004

_________ requirements capture the system goals with respect to effectiveness, efficiency, safety, utility, learnability, and memorability of a product.

SMB2005

Which of the following data gathering techniques involves having a conversation with the participants where the researcher orally solicits responses?

1, Questionnaires

4, Naturalistic observation

Page 2: Java Compiler

1, Perception 2, Attention 3, Language 4, Memory 2

SMB2006

NewTech Book Store has launched its website to sell books to its customers around the world. The website displays thumbnails of books being sold instead of displaying the names of books in text. Which of the following cognition elements has been applied by NewTech in their website?

Page 3: Java Compiler

4

SMB2007

NewTech Book Store has launched its website to sell books to its registered users all over the world. The website provides a link to register new users. When a new user clicks the link to register himself/herself, the New User Registration page opens in a separate window. This page is then used to enter and submit the essential user details. After the site was launched, it was observed that the feature worked fine in Windows XP Operating System (OS). However, when the same link is clicked in Mac OS or Linux OS, the page is not displayed as the new window does not get opened.

In the preceding scenario, analyze and provide the requirements that have not been considered by NewTech while developing its website?

1, Functional requirements

2, User requirements

3, Data requirements

4, Non-functional requirements

Page 4: Java Compiler

3

4

SMB2008

A team of engineers at MobiDick, Inc. has developed a mobile phone. Before launching it in the market, they decided to test the usability and acceptance of the phone on a sample population. As per the feedback received, the team got to know that the phone is difficult to use and its features cannot be easily apprehended. Also, the user interface of the phone is very complicated. Because of this, the team will now have to redesign the mobile phone.

Analyze the situation and suggest which of the following implementations could have avoided this rework by the team?

1, The team should have designed the physical model before the conceptual model.

2, The team should have developed the users' mental model before physical model.

3, The team should have developed the conceptual model before physical model.

4, The team should have developed the star model before users' mental model.

SMB2009

Which of the following options is NOT a factor that is to be considered for selecting the appropriate prototyping technique?

1, Budget and time constraints

2, Navigation and flow

3, Look-and-feel of the application

4, Location and accessibility of stakeholders

Page 5: Java Compiler

3

2

3

SMB2010

Which of the following is NOT a correct guideline to be followed while designing a GUI for touch screens?

1, For better visual clarity, you should divide the screen into various functional areas.

2, Menu items should be at least 3 mm in size.

3, The size of the push button in a touch screen should be less than 2x2 cm and they should be spread out on the screen with a spacing of 10 mm.

4, 3x3 layout should be used to enter numbers.

SMB2011

Jim is creating a website for an organization. He needs to ensure that the links for Site Map, Contact Us, and Home should be displayed on top of all the pages of the website. Provide the strategy that Jim should adopt to display the links.

1, Jim should create mirror links.

2, Jim should create global links.

3, Jim should create local links.

4, Jim should create the links as a marquee.

SMB2012

Jim has been working upon a website of his organization to make sure that it gets displayed on handheld devices as well. After the launch it was observed that maximum percentage of users accessing the website over their mobile phones had to scroll down a number of screens before reaching the links pointing to relevant content. Jim's manager has now asked him to modify this new version of the website such that the users are able to find relevant content easily. Provide the correct Web viewing

1, Jim can use the linear migration display

2, Jim can use the original display

3, Jim can use the filtered display

4, Jim can use the splash screen display

Page 6: Java Compiler

1

SMB2013

Bryan needs to develop an intelligent software-based application. Before starting with the development, he wants to first identify the users' expectations from the application. His manager has asked him to implement the Wizard of Oz (WoZ) prototyping technique to accomplish the same. Provide the correct sequence of steps for implementing the same to Bryan.

1, The correct sequence of the working procedure for WoZ is: 1. A user sits in front of a screen that contains the rough design of the application. A developer sits behind the screen. A human typist sits in another room. 2. The user interacts with the screen by asking questions about the working of the application.3. The developer answers the user. 4. The human typist types the conversation.

2, The correct sequence of the working procedure for WoZ is: 1. A user interacts with the screen by asking questions about the working of the application.2. The human typist types the conversation. 3. This conversation is analyzed to gather feedback. 4. The feedback is shared with the designer, who then incorporates the changes in the design.

3, The correct sequence of the working procedure for WoZ is: 1. A user sits in front of a screen that contains the rough design of the application. A developer sits behind the screen. A human typist sits in another room. 2. The user interacts with the screen by asking questions about the working of the application.3. The developer answers the user. 4. The human typist types the conversation. 5. The designer incorporates the conversation in the design.

4, The correct sequence of the working procedure for WoZ is: 1. A developer sits in front of a screen that contains the rough design of the application. A user sits behind the screen.2. The developer interacts with the screen by asking questions about the working of the application.3. The user answers the developer. 4. The human typist types the conversation. 5. This conversation is analyzed to gather feedback. 6. The feedback is shared with the designer, who then incorporates the

Page 7: Java Compiler

1

SMB2014

Morrison needs to get the website developed by his team to be tested for usability. Morrison has certain predefined parameters for the evaluation. Therefore, he wants to get the heuristic evaluation performed for the website. Provide him with the sequence of stages for implementing the same.

1, Stage 1: In the first stage, the experts are briefed about what they are expected to do.Stage 2: In the second stage, experts may evaluate a product in two phases, look and feel of the product in the first phase and specific usability features in the second phase. Stage 3: In the third stage, experts come together to

2, Stage 1: In the first stage, experts may evaluate a product in two phases, look and feel of the product in the first phase and specific usability features in the second phase. Stage 2: In the second stage, the experts are then briefed about what they are expected to do.Stage 3: In the third stage, experts come together to share

3, Stage 1: In the first stage, the experts are briefed about what they are expected to do.Stage 2: In the second stage, experts come together to share their findings, which includes analyzing the problems encountered and suggesting appropriate solutions. Stage 3: In the third stage, experts may evaluate a product in two phases, look and feel of the product in the first

4, Stage 1: In the first stage, experts come together to share their findings, which includes analyzing the problems encountered and suggesting appropriate solutions.Stage 2: In the second stage, experts may evaluate a product in two phases, look and feel of the product in the first phase and specific usability features in the second phase. Stage 3: In the third stage, the experts are briefed about what they

Page 8: Java Compiler

1

SMB2015

A team of software engineers at NewTech Labs needs to develop a console-based operating system. The operating system should respond to the commands typed by the users in the console window. Before starting with the development, the manager wants a conceptual model to be developed by the team. You need to identify, from the following options, the type of conceptual model that should be developed for the operating system being developed.

1, The conceptual model should be instruction-based.

2, The conceptual model should be conversation-based.

3, The conceptual model should be based on direct manipulation.

4, The conceptual model should be exploring and browsing-based.

Page 9: Java Compiler

3

SMB2016

Alice needs to develop a conceptual model for a car game being developed by her team. The game requires the players to select race tracks, cars, and car specifications. The players can also select whether the gear mode for their selected car should be automatic or manual. In addition, the players can also change the color of their cars. Identify the model that best suits the game. In addition, provide the reason because of which Alice should develop that model.

1, Alice should develop an exploring and browsing-based model for the game because the game involves exploring and browsing for the car models.

2, Alice should develop an instruction-based model for the game because the user will be giving commands and controlling the game.

3, Alice should develop a manipulating and navigating-based model for the game because the game requires users to select, move, and drag elements of the game just as they would do in the physical world.

4, Alice should develop a conversation-based model for the game because the users are required to search for particular information while using the game.

Page 10: Java Compiler

4

SMB2017

While giving a lecture on principles of interactive design, John informed the participants that they could reduce the number of errors in an application by making the administrator-related features as inactive when a normal user works on the application. He further informed the participants that this is an implementation of the visibility principle of interactive design. Analyze whether the knowledge imparted by John regarding the design principle is correct. If not, provide the correct information that John should have given to the participants?

1, Yes, the principle specified by John correctly identifies the knowledge imparted to the participants.

2, No. The principle that reflects the knowledge imparted by John is the Consistency principle.

3, No. The principle that reflects the knowledge imparted by John is the Affordances principle.

4, No. The principle that reflects the knowledge imparted by John is the Constraints principle.

Page 11: Java Compiler

2

SMB2018

Joanna is creating an application that displays the current time to the users. In addition to displaying the time, she wants to give the users the flexibility of viewing either an analog clock or a digital clock. However, she needs to ensure that the time displayed in either of the interface is always correct. She has decided to use Vector graphics to implement this functionality in the application. Analyze if Joanna will be able to accomplish the requirement. If not, provide from the following options, the feature that will enable her to implement the same.

1, Yes. The required functionality can be implemented by using Vector graphics.

2, No. The required functionality can be implemented by using Lookless controls in the application.

3, No. The required functionality can be implemented by using the Grid layout control in the application.

4, No. The required functionality can be implemented by using Canvas layout in the application.

Page 12: Java Compiler

1, Grid layout 2, Dock panel 3, Stack panel 4, Canvas layout 4

SMB2019

You are creating a Web application that displays various wildlife images to the users. One page may display 4 to 5 images to the users. To avoid overlapping of the images on the page, you have decided to place them by specifying x and y coordinates. Which of the following layouts will you use to accomplish the same?

Page 13: Java Compiler

4, Group interview 1

2

SMB2020

Jenny is required to conduct an interview for a number of participants. She needs to gather data regarding personal details and academic qualifications of each of the participants. She has a set of questions which she will be asking in a particular sequence from each participant. Identify the type of interview that Jenny is implementing in the current scenario.

1, Structured interview

2, Unstructured interview

3, Semi-structured interview

SMB2021

Which of the following model is used when the user wants to search for particular information or wants to discuss an issue?

1, Instruction-based model

2, Conversation-based model

3, Manipulating and navigating-based model

4, Exploring and browsing-based model

Page 14: Java Compiler

1, storyboard 2, sketching 3, Wizard of Oz 1

1, Selection 2, Text entry 3, Operable 4, Canvas 1

1, grid 2, canvas 3, dock panel 4, stack panel 2

3, Video camera 4

SMB2022

The _________ prototyping technique describes each action sequentially.

4, computer-based simulation

SMB2023

_________ screen controls can be used to set attributes, properties, or values.

SMB2024

In _______ layout, controls are placed in the form of x and y coordinates.

SMB2025

Which of the following options is NOT a direct observation technique?

1, Notes and a still camera

2, Audio recording and a still camera

4, Interaction logging

Page 15: Java Compiler

1, super 2, this 3, abstract 4, static 2

1, .java file 2, .class file 3, .jar file 4, .mf file 2

1, public 2, private 3, default 4, protected 2

SMB2026

Which of the following keywords is used to resolve ambiguity between instance variables and parameters? In addition, it is also used to pass the current object as a parameter to another method?

SMB2027

Which of the following files contains the code for the Java Virtual Machine (JVM)?

SMB2028

Which of the following keyword declares that the attribute is accessible only to the methods within the same class?

Page 16: Java Compiler

2, char ch = "S"; 3, Char ch = 'S'; 4, char ch = 'S'; 4

1, Hi.java 2, Hello.java 3, MyApp.java 4, Welcome.java 3

SMB2029

Which of the following options is used to declare and initialize a character variable?

1, Char ch = "S";

SMB2030

You have written the following code to create a java program:class Hi{ public void japp(){ System.out.println("Java Application");}}

class Hello{ public void disp(){ System.out.println("Display");}}public class MyApp { public static void main(String[] args) { Hello obj = new Hello(); Hi obj1 = new Hi(); obj.disp(); obj1.japp(); } }Now, you need to save the preceding code. Which of the following name will you use to save the preceding code as a java file?

Page 17: Java Compiler

2, Inheritance 3, Encapsulation 4, Abstraction 3

2

1, thisOne 2, this 3, -One 4, 5One 1

SMB2031

Which of the following refers to the methodology of hiding certain elements of the implementation of a class but providing a public interface for the client software?

1, Polymorphism

SMB2032

A constructor is defined with in a java class which takes int as an argument. What will be the output, if you instantiate the class object without passing any parameter?

1, It will invoke the construct defined within the class.

2, It will generate compile time error.

3, It will automatically invoke the default constructor.

4, It will generate runtime error.

SMB2033

You need to declare a variable in a java class. Which of the following identifiers will you use to accomplish the desired task?

Page 18: Java Compiler

1, -classpath 2, -sourcepath 3, -extdirs 4, -d 4

SMB2034

While compiling a java program, you need to reroute the class files to another directory. Which of the following options of the javac command will you use to accomplish the desired task?

Page 19: Java Compiler

1

SMB2035

Identify the reference variable in the MyApp class in the following code snippet:

class Hello{ private int d=1; private int m=1; public Hello(int day, int month) { System.out.println("day:"+day); System.out.println("Month:"+month); } }

public class MyApp { public static void main(String[] args) { int i,j; Hello obj = new Hello(5,10); } }

1, The variable obj is a reference variable in the MyApp class.

2, The variable i is a reference variable in the MyApp class.

3, The variable d is a reference variable in the MyApp class.

4, There is no reference variable in the MyApp class.

Page 20: Java Compiler

2

SMB2036

Consider the following code:

class Example { public void display() { System.out.println("Display in base class."); } } public class example1 extends Example{ public void display() { super.display(); System.out.println("Display in derived class."); } public static void main(String[] args) { example1 s = new example1(); s.display(); } }

Identify the output of the preceding code.

1, The output of the given code is:

Display in derived class.

2, The output of the given code is:

Display in base class.Display in derived class.

3, The output of the given code is:

Display in derived class.Display in base class.

4, The output of the given code is:

Display in base class.

Page 21: Java Compiler

1

1

SMB2037

While writing a Java code you need to declare an integer array that can hold 10 elements. Which of the following options will you use to accomplish the desired task?

1, int[] a = new int[10];

2, int[10] a = new int[];

3, int[] a = new int[9];

4, int[9] a = new int[];

SMB2038

Which of the following options refers to method overloading in Java?

1, 1. The functions should have same name.2. The functions can have different return type.3. The functions should have different argument list.4. The functions should be defined in the same class.

2, 1. The functions should have same name.2. The functions can have different return type.3. The functions should have different argument list.4. The functions can be defined in the different class.

3, 1. The functions should have same name.2. The functions can have same return type.3. The functions can have same argument list.4. The functions should be defined in the same class.

4, 1. The functions should have same name.2. The functions can have different return type.3. The functions can have same argument list.4. The functions can be defined in the different class.

Page 22: Java Compiler

1, super 2, abstract 3, static 4, virtual 1

SMB2039

You have created a base class STUDENT, and a derived class STUD_DETAILS in a java program. Now, you want to use the STUD_DETAILS class to invoke the constructor of the STUDENT class. Identify the correct keyword that you should use to accomplish the desired task?

Page 23: Java Compiler

2

SMB2040

Consider the following code snippet that contains two string s1 and s2, which contains the value NIIT and Niit respectively:

String s1="NIIT";String s2="Niit";

Identify the correct statement to compare the two given string values in the preceding statements.

1, System.out.println(s1=s2);

2, System.out.println(s1.equals(s2));

3, System.out.println(s1==s2);

4, System.out.println(s1.equal(s2));

Page 24: Java Compiler

1

SMB2041

Sam has been assigned a task to create a Java application to create a heterogeneous collection, in which all the items have a common ancestor class.Identify the correct code that Sam should use to accomplish the desired task.

1, public class poly_demo {

public static void main(String[] args) {Object [] obj=new Object[3];obj[0]=new Double(1.1d);obj[1]=new Integer(1);obj[2]=new Float(1.0f); }}

2, public class poly_demo {

public static void main(String[] args) {Date[] obj = new Date[2];obj[0] = new Date(23,4,2009);obj[1] = new Date(23,5,2009); }}

3, public class poly_demo {

public static void main(String[] args) {Date[] obj = new Date[2];obj[0] = new Object(23,4,2009);obj[1] = new Date(23,5,2009); }}

4, public class poly_demo {

public static void main(String[] args) {Object [] obj=new Object[3];obj[0]=new Object(1.1d);obj[1]=new Object(1);obj[2]=new Object(1.0f); }}

Page 25: Java Compiler

1

SMB2042

Consider the following code snippet:

public class enh_demo { int sum(int[] a){ * * *} public static void main(String args[]) { int[] i={1,2,3}; enh_demo obj= new enh_demo(); obj.sum(i); } }

Sam has been assigned a task to write the method definition of the sum method. The sum method should use enhance for loop such that it displays the sum of the values given in the array. Identify the correct code that Sam should use to accomplish the desired task.

1, int sum(int[] a) { int res = 0; for (int i : a) res += i; System.out.println(res); return res; }

2, int sum(int[] a) { int res = 0; for (int i : res) res += i; System.out.println(res); return res; }

3, int sum(int[] a) { int res = 0; for (int i : a) res += a; System.out.println(res); return res; }

4, int sum(int[] a) { int res = 0; for (int i : res) res += a; System.out.println(res); return res; }

Page 26: Java Compiler

3

SMB2043

Sam has been assigned a task to write a java program to print the even numbers between 0 to 10 and their sum. Identify the correct code that Sam should use to accomplish the desired task.

1, public class Loop_demo { public static void main(String [] args){ int sum=0; int i; for(i=0; i<10; i++){ if(i%2==0) { System.out.println(i); } sum=sum+i; } System.out.println("Sum of all even numbers:"+sum); } }

2, public class Loop_demo { public static void main(String [] args){ int sum=0; int i; for(i=0; i<10; i++){ if(i%2!=0) { System.out.println(i); sum=sum+i; }} System.out.println("Sum of all even numbers:"+sum); } }

3, public class Loop_demo { public static void main(String [] args){ int sum=0; int i; for(i=0; i<=10; i++){ if(i%2==0) { System.out.println(i); sum=sum+i; }} System.out.println("Sum of all even numbers:"+sum); } }

4, public class Loop_demo { public static void main(String [] args){ int sum=0; int i; for(i=0; i<10; i++){ if(i%2!=0) { System.out.println(i); } sum=sum+i; } System.out.println("Sum of all even numbers:"+sum); } }

Page 27: Java Compiler

1

SMB2044

Consider the following code:

public class mdim_demo { public static void main(String [] args){ int arr[][] = new int[4][]; arr[0] = new int[1]; arr[1] = new int[2]; arr[2] = new int[3]; arr[4] = new int[4]; int i,j,k = 0; for(i=0; i<4; i++) for(j=0; j<i+1; j++) { arr[i][j] = k; k++; } for(i=0; i<3; i++) { for(j=0; j<i+1; j++) System.out.print(arr[i][j]); System.out.println(); } }}

Identify the output of the preceding code.

1, It will generate a runtime error.

2, It will generate the following output:

01 23 4 5

3, It will generate the following output:

01 23 4

4,It will generate a compile time error.

Page 28: Java Compiler

2

2, new operator 1

SMB2045

Consider the following code:class acc{ int a; private int b; void setvalue(int i){ b=i; } int getvalue(){ return b; }}public class acc_demo {public static void main(String [] args){ acc obj = new acc(); obj.a =11; obj.setvalue(33); System.out.println("Value of a:" + obj.a); System.out.println("Value of b using:"+obj.getvalue()); }}Identify the output of the preceding code.

1, It will generate a compile time error as b has private access.

2, It will display the values assigned to a and b.

3, It will generate a runtime error.

4, It will display only the value assigned to a.

SMB2046

Which of the following options is used to compare an object to a specified class type?

1, instanceof operator

3, Comparison operators

4, Bitwise operators

Page 29: Java Compiler

1

2

SMB2047

After creating an array, how can you use the same reference variable to refer to an entirely new array?

1, int[] myArray = new int[6];myArray = new int[10];

2, int myArray = new int[6];myArray = new int[10];

3, int[] myArray = new int(6);myArray = new int(10);

4, int myArray = new int(6);myArray = new int(10);

SMB2048

Consider the following java program:

public class branching { public static void main(String[] args) { int i=0; int j=0; int k=0; if(i<3) { if(j<3) { if(k<3) { System.out.println("BRANCHING STATEMENT"); } } } } }

Identify the correct output of the preceding program.

1, It will generate a runtime exception.

2, The code will compile and will print BRANCHING STATEMENT.

3, The code will compile but will not generate any output.

4, It will generate a compile time error.

Page 30: Java Compiler

2

1, 0L 2, null 3, '\u0000' 4, 0 3

SMB2049

Consider the following code snippet:

public class op_demo { public static void main (String args []) { String str="Hi"; * * * System.out.println(str); }}Sam has been assigned a task to modify the preceding code such that the given value of str is concatenated with "HOW ARE YOU?", and gives the following output:

Hi How Are You?

Identify the correct operator and statement that Sam should use to accomplish the desired task.

1, str = str +" "+'How are you?';

2, str = str +" "+"How are

you?";3, str = str +" "+ How are you?;

4, str = str + How are you?;

SMB2050

Which of the following options gives the default value for a variable of a char data type?

Page 31: Java Compiler

1, 256 2, -256 3, 64 4, -64 1

1, private 2, protected 3, default 4, public 3

SMB2051

The two operands a and b are assigned the values 128 and 1 respectively. What will be the result if left shift operation is performed on the given operands a and b?

SMB2052

You have created a method add() with in a class STUDENT. You want that the add() should only be accessible to the classes that belongs to the same package as that of a STUDENT class. Which of the following access modifiers will you use to accomplish the desired task?

Page 32: Java Compiler

2, Method 3, Object 4, Variable 3

1

SMB2053

Which of the following options cannot have a polymorphic behavior?

1, Access Modifiers

SMB2054

Consider the following code:

class demo { private int x=1; public void setValue() { int x=4, y=5; this.x = x+y; setNewValue(10); } public void setNewValue(int x) { int y=8; this.x = x+y; System.out.println(x); System.out.println(y); }}public class var_sc_demo{ public static void main(String[] args) { demo obj = new demo(); obj.setValue(); }}Identify the output of the preceding code.

1, The output of the given code is:

108

2, The output of the given code is:

128

3, It will generate a compile time error as x is a private variable.

4, It will generate a runtime error.

Page 33: Java Compiler

1

4

SMB2055

Consider the following code:

import java.lang.*;class copy{ char[] a={'N','I','I','T'}; char[] b = {'C','o','u','r','s','e'}; public void copyArr() { * * * }}public class arr_cpy { public static void main(String[] args) { copy obj = new copy(); obj.copyArr(); } }

Sam has been assigned a task to update the preceding code such that it copies the value of the array a to array b using the arraycopy function. In addition, he has to print the resultant. Identify the correct code snippet that Sam should use to accomplish the desired result.

1, System.arraycopy(a,0,b,0,a.length); for(int i=0;i<b.length;i++)System.out.println(b[i]);

2, System.arraycopy(a,0,b,0,b.length); for(int i=0;i<b.length;i++)System.out.println(b[i]);

3, System.arraycopy(0,a,0,b,b.length); for(int i=0;i<b.length;i++)System.out.println(b[i]);

4, System.arraycopy(0,a,0,b,a.length); for(int i=0;i<b.length;i++)System.out.println(b[i]);

SMB2056

Which of the following options is correct in reference to the final keyword?

1, The main() method in java is a final method because JVM does not create an instance of the class when executing the main method.

2, The final method can be overridden.

3, The final class can be subclassed.

4, The blank final instance variable must be assigned in a constructor.

Page 34: Java Compiler

1

SMB2057

Sam has been assigned a task to create a Java application that allows him to add the elements in an array list and display the sum of the values in the elements provided in the list. Identify the correct code snippet that Sam should use to accomplish the desired task.

1,public static void main(String [] args) { int sum=0; ArrayList<Integer> list = new ArrayList<Integer>(); int val[]={1,2,3,4,5}; for(int i=0;i<val.length;i++) { list.add(i,val[i]); sum=sum+list.get(i); } System.out.println(sum);}

2,public static void main(String [] args) { int sum=0; ArrayList list = new ArrayList<Integer>(); int val[]={1,2,3,4,5}; for(int i=0;i<val.length;i++) { list.add(i,val[i]); sum=sum+list.get(i); } System.out.println(sum);}

3,public static void main(String [] args) { int total=0; List list = new List(); int val[]={1,2,3,4,5}; for(int i=0;i<val.length;i++) { list.add(i,val[i]); sum=sum+list.get(i); } System.out.println(sum);}

4,public static void main(String [] args) { int total=0; ArrayList list = new List(); int val[]={1,2,3,4,5}; for(int i=0;i<val.length;i++) { list.add(i,val[i]); sum=sum+list.get(i); } System.out.println(sum);}

Page 35: Java Compiler

1

SMB2058

Consider the following code:

public class ex_demo {public static void main(String args[]) {int sum = 0;for ( int i = 0; i < args.length; i++ ) {sum += Integer.parseInt(args[i]);}System.out.println("Sum = " + sum);}}

The preceding code displays the sum of the values passed through a command line and fails if any of the argument is not integer. Identify the correct code to handle the exception generated if any of the argument passed is not an integer.

1, public class ex_demo {public static void main(String args[]) {try {int sum = 0;for ( int i = 0; i < args.length; i++ ) {sum += Integer.parseInt(args[i]);}System.out.println("Sum = " + sum);} catch (NumberFormatException n) { System.err.println("One of the command-line " + "arguments is not an integer."); }}}

2, public class ex_demo {public static void main(String args[]) {try {int sum = 0;for ( int i = 0; i < args.length; i++ ) {sum += Integer.parseInt(args[i]);}System.out.println("Sum = " + sum);} catch (NullPointerException n) { System.err.println("One of the command-line " + "arguments is not an integer."); }}}

3, public class ex_demo {public static void main(String args[]) {try {int sum = 0;for ( int i = 0; i < args.length; i++ ) {sum += Integer.parseInt(args[i]);}System.out.println("Sum = " + sum);} catch (ArithmeticException n) { System.err.println("One of the command-line " + "arguments is not an integer."); }}}

4, public class ex_demo {public static void main(String args[]) {try {int sum = 0;for ( int i = 0; i < args.length; i++ ) {sum += Integer.parseInt(args[i]);}System.out.println("Sum = " + sum);} catch (EOFException n) { System.err.println("One of the command-line " + "arguments is not an integer."); }}}

Page 36: Java Compiler

1, One 2, Two 3, Three 4, Four 1

1, final 2, static 3, abstract 4, protected 1

1, %g 2, %x 3, %s 4, %% 1

SMB2059

Consider the following code snippet:

public class a{ static int i=0; public static void main(String[] a) {}}

How many copies of the variable i would be created, if you have created four objects of class a?

SMB2060

If you apply ____ keyword to a class, the class cannot be subclassed.

SMB2061

Which of the following formatting codes in java uses scientific notations?

Page 37: Java Compiler

1

SMB2062

Consider the following code:

interface Color {public void Red();public void Green();public void Yellow();}

Sam has created the preceding interface. Now he has to create a class that implements the preceding interface. Identify the correct code that Sam should use to accomplish the desired task.

1, public class intrf_demo implements Color{public void Red(){System.out.println("Stop");}public void Green(){System.out.println("GO");}public void Yellow(){ System.out.println("PAUSE");}public static void main(String[] args) { intrf_demo a= new intrf_demo(); a.Red(); a.Green(); a.Yellow();

2, public class intrf_demo implements Color{public void Red(){System.out.println("Stop");}public void Green(){System.out.println("GO");}

public static void main(String[] args) { intrf_demo a= new intrf_demo(); a.Red(); a.Green(); a.Yellow(); }}

3, class intrf_demo implements Color{public void Red(){System.out.println("Stop");}public void Yellow(){ System.out.println("PAUSE");}public static void main(String[] args) { intrf_demo a= new intrf_demo(); a.Red(); a.Green(); a.Yellow(); }}

4, class intrf_demo implements Color{public void Red(){System.out.println("Stop");}public void Green(){System.out.println("GO");}public static void main(String[] args) { intrf_demo a= new intrf_demo(); a.Red(); a.Green(); a.Yellow(); }}

Page 38: Java Compiler

1

SMB2063

Consider the following code:

import java.util.*;public class itr_demo { public static void main(String[] args) { HashSet s=getValue(); Iterator iter=s.iterator(); while (iter.hasNext()) { iter.next(); System.out.println(s); } }

static HashSet getValue() { HashSet<String> arrList=new HashSet<String>(); arrList.add("1"); arrList.add("2"); arrList.add("3"); arrList.add("4"); return arrList; } }Identify the output of the given code.

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

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

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

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

Page 39: Java Compiler

1

SMB2064

Consider the following code snippet:

abstract class a{ public abstract double sum(); public abstract double mul();

}

public class b extends a{double a =40; double b=20; double c=0; public double mul() { c=b*a; System.out.println(c); return c; }

} Identify the correct output of the preceding code snippet.

1, It will generate a compile time error stating b is not an abstract class and does not override the sum method.

2, It will throw a runtime exception.

3, It will generate a compile time error stating b class inherit class a.

4, It will compile and execute successfully.

Page 40: Java Compiler

1, java demo 2, java demo file 3, java -ea demo 4, java -ea test file1 3

SMB2065

Consider the following code:

public class demo{ public static void main(String args[]) { assert args.length-1==0; }}

Sam has been assigned a task to turn on the assertion for the preceding code. Identify which of the following commands will Sam use to achieve this task.

Page 41: Java Compiler

1

3, IOException 4, AssertionError 1

SMB2066

Consider the following code:

enum Days {SUNDAY(1), MONDAY(2), TUESDAY(3);Days(int d) {this.d = d;}private int d;public int getdays() {return d;}}

class demo1{* * *}Sam has been assigned a task to create a class that will print the values for the preceding enum and gives the following output:SUNDAY 1MONDAY 2TUESDAY 3Identify the correct code that Sam should use to accomplish the desired task.

1, class demo1 {Days num;public static void main(String[] args) {demo1 obj = new demo1();for(Days dy: Days.values())System.out.println(dy + " " + dy.getdays());}}

2, class demo1 {Days num;public static void main(String[] args) {demo1 obj = new demo1();obj.num = Days.SUNDAY;demo1 obj1 = new demo1();for(Days dy: Days.values())System.out.println(obj1.num.getdays()); }}

3, class demo1 {Days num;public static void main(String[] args) {demo1 obj = new demo1();obj.num = Days.SUNDAY;System.out.println(obj.num.getdays()); demo1 obj1 = new demo1();obj.num = Days.MONDAY;System.out.println(obj1.num.getdays()); demo1 obj2 = new demo1();obj.num = Days.TUESDAY;System.out.println(obj.num.getdays()); }}

4, class demo1 {Days num;public static void main(String[] args) {demo1 obj = new demo1();obj.num = Days.SUNDAY;demo1 obj1 = new demo1();obj.num = Days.MONDAY;demo1 obj2 = new demo1();obj.num = Days.TUESDAY;System.out.println(obj.num.getdays()); }}

SMB2067

Which of the following class is the base class used for the unchecked exceptions that arise as a result of program bugs?

1, RuntimeException

2, VirtualMachineError

Page 42: Java Compiler

1, static 2, final 3, abstract 4, protected 1

1, static 2, extends 3, implements 4, abstract 3

1, final 2, abstract 3, static 4, public 3

SMB2068

Which of the following keywords makes a variable accessible from any instance of the class?

SMB2069

Which of the following keywords enable the class to use the methods of an interface?

SMB2070

Sam is creating a Java application. He wants to create a method that should be invoked without creating an instance of the object at the runtime.Identify the keyword to be used to satisfy the preceding scenario needed in main method?

Page 43: Java Compiler

1, finally 2, final 3, throws 4, throw 1

3, getProperty() 4, setProperty() 2

1, assert 2, finally 3, throw 4, throws 1

SMB2071

The __________ clause defines a block of code that always executes, regardless of whether an exception was caught.

SMB2072

Which of the following methods returns the system property object?

1, setProperties()

2, getProperties()

SMB2073

Which of the following keywords is used to test the programmer's assumptions during development without writing exception handlers for an exception?

Page 44: Java Compiler

1

SMB2074

If the superclass method throws an IOException, then which of the following statement is correct in reference to the exceptions that can be thrown by the overriding method?

1, It will not throw an exception of its own super class, such as Exception.

2, It will not allow you to declare any other exception in the throws clause.

3, It will not throw FileNotFoundException exception.

4, It will not throw an IllegalArgumentException exception.

Page 45: Java Compiler

1

2

SMB2075

Consider the following code snippet:

public class ServerTimedOutException extends Exception{ private int port; public ServerTimedOutException(String message, int port) { super(message); this.port;}public int getport(){ return port;}}Sam has written a client-server Java program. In the client code, he tries to connect to the server and expect the server to respond within five seconds.Now he wants that if the server does not respond within the specified time, the code should throw a user defined exception ServerTimedOutException. Identify the correct code snippet that Sam should use to accomplish the desired task.

1, public void MyException(String servname) throws ServerTimedOutException{ boolean success; int p = 80; success = open(servname,p); if(! success) { throw new ServerTimedOutException("Not able to connect",p);}}

2, public void MyException(String servname) throw ServerTimedOutException{ boolean success; int p = 80; success = open(servname,p); if(! success) { throws new ServerTimedOutException("Not able to connect",p);}}

3, public void MyException(String servname) throws ServerTimedOutException{ boolean success; int p = 80; success = open(servname,p); if(! success) { throw ServerTimedOutException("Not able to connect",p);}}

4, public void MyException(String servname) throw ServerTimedOutException{ boolean success; int p = 80; success = open(servname,p); if(! success) { throws ServerTimedOutException("Not able to connect",p);}}

SMB2076

Which of the following exceptions is the result of a divide-by-zero operation for integers?

1, NumberFormatException

2, ArithmeticException

3, IllegalArgumentException

4, NullPointerException

Page 46: Java Compiler

2

SMB2077

Consider the following statements:

Statement A: Set is an unordered collection which allows duplicate values.Statement B: List is an ordered collection that does not allow duplicate values.

Which of the following is correct in reference to the preceding statements?

1, Both statement A and B are true.

2, Both statement A and B are false.

3, Statement A is true, and statement B is false.

4, Statement A is false, and statement B is true.

Page 47: Java Compiler

1

SMB2078

Anthony has been assigned a task to create a Java application that accepts the command-line argument either as a standalone tokens or as quoted strings.Identify the correct code that Anthony should use to accept and print the command-line arguments.

1, public class command { public static void main(String[] args) { for(int i=0;i<args.length;i++) System.out.println("args["+i+"] is " +args[i]); }

}

2, public class command { public static void main(String[] args) { while((args=in.readLine())!=null) System.out.println("args["+i+"] is " +args[i]); }

}

3, public class command { public static void main(String[] args) { for(int i=0;i<args.length;i++) InputStreamReader i = new InputStreamReader(args); System.out.println("args["+i+"] is " +args[i]); }

}

4, public class command { public static void main(String[] args) { InputStreamReader i = new InputStreamReader(args); while((args=in.readLine())!=null) System.out.println("args["+i+"] is " +args[i]); }

}

Page 48: Java Compiler

4

SMB2079

Consider the following code:

import java.util.Properties;import java.util.Enumeration;

public class prop_demo { public static void main(String[] args) { Properties props = System.getProperties(); Enumeration propNames = props.propertyNames(); while(propNames.hasMoreElements()) { String pName = (String) propNames.nextElement(); String prop = props.getProperty(pName); System.out.println(propNames+" "+prop);}

} }Identify the output of the preceding code.

1, It generates a runtime error.

2, It generates a compile time error.

3, It retrieves the property value.

4, It retrieves the property name and value pair.

Page 49: Java Compiler

1

SMB2080

Consider the following code:

class EMP{ String empName; public void display() { System.out.println(empName); } } public class err_cat { EMP e[]; public err_cat() { for(int i=0;i!= 2;i++) { e[i] = new EMP(); } e[0].empName="Hello"; } public static void main(String args[]) { err_cat empObj; empObj = new err_cat(); }}Identify the output of the preceding code.

1, It will generate a NullPointer Exception.

2, It will generate StackOverFlowError.

3, It will generate a IllegalArgumentException.

4, It will generate OutOfMemoryError.

Page 50: Java Compiler

1

SMB2081

Consider the following statements:

Statement A: The Error class is the base class for unchecked errors.Statement B: The RuntimeException class is the base class that is used for unchecked exceptions that might arise as a result of program bug.

Which of the following is correct in reference to the preceding statements?

1, Both statement A and B are true.

2, Both statement A and B are false.

3, Statement A is true, and statement B is false.

4, Statement A is false, and statement B is true.

Page 51: Java Compiler

2

3

SMB2082

Consider the following code:

public class asser_demo { static int n = 1;static int getnum() { return n--; }public static void main(String [] args) { int x; for (int i =0; i>5; i++) { x = getnum(); assert x == 0; System.out.println(x); } }}Identify the output of the preceding code.

1, It will give the following output:

12345

2, It will execute successfully but no output will be generated.

3, It will generate the following output:

54321

4, It will generate a runtime error.

SMB2083

Which of the following options is correct in reference to the System.err variable of the java.lang.System class?

1, It is an InputStream object that refers (initially) to the user's keyboard.

2, It is a PrintStream object that refers (initially) to the user's keyboard.

3, It is a PrintStream object that refers (initially) to the terminal window that launched the Java technology application.

4, It is an InputStream object that refers (initially) to the terminal window that launched the Java technology application.

Page 52: Java Compiler

1

SMB2084

Consider the following code:

import java.io.*;

public class demo{ public static void main(String[] args) { String s; * * *}}Sam has been assigned a task to read String information from the console standard input. Identify the correct code snippet that Sam should use to accomplish the desired task.

1, InputStreamReader i = new InputStreamReader(System.in);BufferedReader in = new BufferedReader(i);

2, InputReader i = new InputReader(System.in);BufferedReader in = new BufferedReader(i);

3, BufferedReader in = new BufferedReader(System.in);InputStreamReader i = new InputStreamReader(in);

4, BufferedReader in = new BufferedReader(System.in);InputReader i = new InputReader(System.i);

Page 53: Java Compiler

1

SMB2085

Consider the following code snippet:

import java.util.*;

public class demo{ public static void main(String[] args) { * * * System.out.println(l); }}Sam has been assigned a task to create a Java application to create an ordered collection in which duplicate values are permitted. Identify the correct code snippet that Sam should use to accomplish the desired task.

1, List l = new ArrayList();l.add("ONE");l.add(new Integer(4));l.add("ONE");

2, Set l = new HashSet();l.add("ONE");l.add(new Integer(4));l.add("ONE");

3, List l = new List();l.add("ONE");l.add(new Integer(4));l.add("ONE");

4, Set l = new Set();l.add("ONE");l.add(new Integer(4));l.add("ONE");

Page 54: Java Compiler

4, ItemListener 1

1, FlowLayout 2, BorderLayout 3, CardLayout 4, GridLayout 2

1, setlayout() 2, pack() 3, add() 4, setVisible() 2

1, Dialog 2, Frame 3, Panel 4, Canvas 1

SMB2086

While building a Java GUI application, you need to create an item within a menu. Which of the following listener will you implement that can be associated with the MenuItem component?

1, ActionListener

2, AdjustmentListerner

3, ComponentListener

SMB2087

Which of the following layout managers is the default layout manager for the Frame and Dialog classes?

SMB2088

The _______ method tells the frame to set a size that neatly encloses the components that it contains.

SMB2089

Which of the following AWT components is a top-level window with a title and a border?

Page 55: Java Compiler

1

1, Component 3, Insets 4, Event 1

SMB2090

Which of the following methods belongs to the ContainerListener interface?

1, componentAdded()

2, componentMoved()

3, componentHidden()

4, componentShown()

SMB2091

The Container class is an abstract subclass of ____________.

2, MenuComponent

Page 56: Java Compiler

1

SMB2092

import java.awt.*;

public class jfc_demo{ private Frame f; private Button b; public jfc_demo() { f = new Frame("GUI"); b = new Button("Add"); } public void disp() { f.setSize(200,200); f.setLayout(null); b.setSize(50,50); f.add(b); f.setVisible(true); }

public static void main(String args[]){ jfc_demo obj = new jfc_demo(); obj.disp();

}}

1, Step 1: Use the right imports: import javax.swing.*;Step 2: Use the right component names JFrame and JButton.Step 3: Address content pane issues: JFrame.getContentPane().add(Component)

2, Step 1: Use the right imports: import java.swing.*;Step 2: Use the right comonent names Jframe and Jbutton.Step 3: Address content pane issues: JFrame.getContentPane().add(Component)

3, Step 1: Use the right imports: import javax.swing.*;Step 2: Use the right comonent names Jframe and Jbutton.Step 3: Address content pane issues: JFrame.add(Component).getContentPane()

4, Step 1: Use the right imports: import java.swing.*;Step 2: Use the right comonent names JFrame and JButton.Step 3: Address content pane issues: JFrame.add(Component).getContentPane()

Page 57: Java Compiler

1

SMB2093

Sam has been assigned a task to create a frame of size 100, 100 which has a background of blue color. In addition, the frame should display "Login" as a title. Identify the correct code that Sam should use to accomplish the desired task.

1, import java.awt.*;

public class MyFrame extends Frame{ Panel p; public MyFrame() { super("Login"); p=new Panel(); add(p); setSize(100,100); setVisible(true); } public static void main(String s[]) { new MyFrame(); }}

2, import javax.awt.*;

public class MyFrame extends Frame{ Panel p; public MyFrame() { super("Login"); p=new Panel(); add(p); setSize(100,100); setVisible(true); } public static void main(String s[]) { new MyFrame(); }}

3, import java.Awt.*;

public class MyFrame extends Frame{ Panel p; public MyFrame() { super("Login"); p=new Panel(); add(p); setSize(100,100); setVisible(true); } public static void main(String s[]) { new MyFrame(); }}

4, import javax.Awt.*;

public class MyFrame extends Frame{ Panel p; public MyFrame() { super("Login"); p=new Panel(); add(p); setSize(100,100); setVisible(true); } public static void main(String s[]) { new MyFrame(); }}

Page 58: Java Compiler

1

SMB2094

Sam has been assigned a task to create a Java GUI application that create a frame having following properties:

Width = 50Height = 60Back ground Color = RedTitle = "WELCOME"

Identify the correct code snippet that Sam should use to accomplish the desired task.

1, public class frm_demo { private Frame f; public frm_demo(String title) { f=new Frame("Welcome"); } public void launch() { f.setSize(50,60); f.setBackground(Color.red); f.setVisible(true); } }

2, public class frm_demo { private Frame f; public frm_demo(String title) { f=new Frame("Welcome"); } public void launch() { f.setSize(60,50); f.setBackground(Color.red); f.setVisible(true); } }}

3, public class frm_demo { private Frame f; public frm_demo(String title) { f=new Frame("Welcome"); } public void launch() { f.setSize(50,60); f.setBackground.Color(RED); f.setVisible(true); } }

4, public class frm_demo { private Frame f; public frm_demo(String title) { f=new Frame("Welcome"); } public void launch() { f.setSize(60,50); f.setBackground.Color(RED); f.setVisible(true); } }}

Page 59: Java Compiler

1, getSource() 3, getModifiers() 4, getAnnotation() 1

4, CardLayout 1

SMB2095

While creating a Java GUI application, you want to obtain the reference of the object that has generated the event. Which of the following methods will you use to accomplish this task?

2, getActioncommand()

SMB2096

Consider the following values, used to align the components within a container:

LEFT, RIGHT, and CENTER.

Which of the following layout manager uses the preceding values to set the alignment of the components?

1, FlowLayout Manager

2, GridBagLayout Manager

3, GridLayout Manager

Page 60: Java Compiler

1

SMB2097

You need to implement a grid layout containing 5 rows and 2 columns. In addition, you need to ensure that the gaps between each column is 10 and the gap between each row is 15. Which of the following code snippet will you use to accomplish the desired task?

1,GridLayout gl=new GridLayout(5, 2,10,15);

2, GridLayout gl=new GridLayout(2, 5,10,15);

3, GridLayout gl=new GridLayout(2, 5,15,10);

4, GridLayout gl=new GridLayout(5, 2,15,10);

Page 61: Java Compiler

2

SMB2098

Consider the following code snippet:

import java.awt.*;import java.awt.event.*;

public class demo implements MouseListener{ private Frame f; private TextField t; public demo() { f = new Frame("WELCOME"); t = new TextField(20);} * * * }

Sam has created a class which implements MouseListener interface. Identify the methods that should be defined within the preceding class.

1, mouseDragged(MouseEvent)mouseMoved(MouseEvent)

2, mousePressed(MouseEvent)mouseReleased(MouseEvent)mouseEntered(MouseEvent)mouseExited(MouseEvent)mouseClicked(MouseEvent)

3, mousePressed(MouseEvent)mouseReleased(MouseEvent)mouseEntered(MouseEvent)mouseExited(MouseEvent)mouseClicked(MouseEvent)mouseDragged(MouseEvent)mouseMoved(MouseEvent)

4, mouseExited(MouseEvent)mouseClicked(MouseEvent)mouseDragged(MouseEvent)mouseMoved(MouseEvent)

Page 62: Java Compiler

1, f.pack(); 2, f.add(); 3, f.setLayout(); 4, f.setSize(); 1

2

SMB2099

Consider the following code snippet:

import java.awt.*;public class LayoutExample {private Frame f;private Button b1;private Button b2;public LayoutExample() {f = new Frame("GUI example");b1 = new Button("Press Me"); b2 = new Button("Don't press Me");}public void launchFrame() { f.setLayout(new FlowLayout()); f.add(b1); f.add(b2); f.setVisible(true); } public static void main(String args[]) { LayoutExample guiWindow = new LayoutExample(); guiWindow.launchFrame();}}

Sam has been assigned a task to modify the preceding code such that it tells the frame to set a size that neatly encloses the components that it contains.Identify the method that Sam should use to accomplish the desired task.

SMB2100

Which of the following is correct in reference to a panel in Java?

1, A Frame is a type of panel with a title and corners that can be resized.

2, A panel must be placed into a window.

3, A panel is a type of component.

4, A panel is a free-standing native window on the display that is independent of other containers.

Page 63: Java Compiler

1

1

SMB2101

Which of the following is correct in reference to the FileOutputStream class?

1, The FileOutputStream constructor, overwrites the already existing output file.

2, The FileOutputStream constructor, appends the already existing output file.

3, The FileOutputStream constructor, prompts an error if the output file already exists.

4, The FileOutputStream constructor, creates a new file with any name if the output file already exists.

SMB2102

Sam has been assigned a task to create a TCP/IP client. Identify the correct code snippet to accomplish the desired task.

1, public class MyClient {public static void main(String args[]) {Socket s = null;try {s = new Socket("127.0.0.1",5432);} catch (IOException e) {e.printStackTrace();}}

2, public class MyClient {public static void main(String args[]) {Socket s = null;try {s = new Socket(5432);} catch (IOException e) {e.printStackTrace();}}

3, public class MyClient {public static void main(String args[]) {ServerSocket s = null;try {s = new ServerSocket("127.0.0.1",5432);} catch (IOException e) {e.printStackTrace();}}

4, public class MyClient {public static void main(String args[]) {ServerSocket s = null;try {s = new ServerSocket(5432);} catch (IOException e) {e.printStackTrace();}}

Page 64: Java Compiler

4

SMB2103

Consider the following code snippet:

import java.io.*; public class strm_demo { public static void main(String[] args) throws IOException { try { FileInputStream in = new FileInputStream("C:\\a.txt"); System.out.println("File found at the given location."); } catch(Exception ex) { ex.printStackTrace(); } }}

Identify the output of the preceding code, assuming that the a.txt file already exists at the given location.

1, It will generate a run time error.

2, It will generate a compile time error.

3, It will not display any result.

4, It will display the following output:

File found at the given location.

Page 65: Java Compiler

3

SMB2104

Consider the following code:

import java.io.*;

public class strm_demo { public static void main(String[] args) throws IOException { try {

FileReader obj = new FileReader("C:\\a.txt"); char [] buffer = new char[128]; int c; c = obj.read(buffer); c = obj.read(buffer); System.out.println(c); } catch(Exception ex) { ex.printStackTrace(); } }}

Identify the output of the preceding code considering that the a.txt file does not exists in C drive.

1, It will display the following output:

-1

2, It will generate a compile time error.

3, It will throw a runtime exception.

4, It will compile successfully and will not display any output.

Page 66: Java Compiler

1

SMB2105

Consider the following code snippet:

System.out.println("Enter the Designation:");* * *ReadString = bufferStream.readLine();

Sam has been assigned a task to modify the given code snippet such that it forces the write operation to clear any accumilated data on the output stream. Identify the correct method that Sam should use to accomplish the desired task.

1, System.out.flush();

2, System.out.reset();

3, System.out.mark();

4, System.out.markSupported();

Page 67: Java Compiler

1

SMB2106

Sam is creating a Java application. He has created an object of the Connection interface to establish a connection of the Java application with a database using the getConnection() method with a single parameter.

Identify the correct syntax for a JDBC URL that Sam should pass as a parameter to the getConnection().

1, <protocol>:<subprotocol>:<subname>

2, <protocol>:<subprotocol>

3, <protocol>:<subname>

4, <protocol>:<subname>:<subprotocol>

Page 68: Java Compiler

2

SMB2107

Sam has created a Java application that allows to access information stored in a database "AUTH_DETAILS". Now, Sam has been assigned a task to create a code that modifies the state to CA where city is Oakland in the Authors table in the AUTH_DETAILS database using the PreparedStatement object. Identify the correct code snippet that Sam should use to accomplish the desire task.

1, String str=" "; PreparedStatement ps = con.prepareStatement(str);ps.setString(1, "CA");ps.setString(2, "Oakland");int rt=ps.executeUpdate();

2, String str = "UPDATE Authors SET state= ? WHERE city= ? ";PreparedStatement ps = con.prepareStatement(str);ps.setString(1, "CA");ps.setString(2, "Oakland");int rt=ps.executeUpdate();

3, String str = " ";PreparedStatement ps = con.prepareStatement(UPDATE Authors SET state= ? WHERE city= ?);ps.setString(1, "CA");ps.setString(2, "Oakland");int rt=ps.Update();

4, String str = "UPDATE Authors SET state= ? WHERE city= ? ";PreparedStatement ps = con.prepareStatement(str);ps.setString(1, "CA");ps.setString(2, "Oakland");int rt=ps.Update();

Page 69: Java Compiler

1

SMB2108

Sam is creating a java program that implements stacks. He has to create a method having following features:1) The method should protect the shared buffer so that no two users are able to access the method simultaneously.2) If the stack is empty in the method, the executing thread must wait.

Identify the correct code snippet for the method that Sam should use to accomplish the desired task.

1, public synchronized char pop(){ char ch;while(buffer.size()==0){try{this.wait();}catch(InterruptedException e){}ch = buffer.remove(buffer.size()-1);return c;}

2, public char pop(){ char ch;while(buffer.size()==0){try{this.wait();}catch(InterruptedException e){}ch = buffer.remove(buffer.size()-1);return c;}

3, public final char pop(){ char ch;while(buffer.size()==0){try{this.wait();}catch(InterruptedException e){}ch = buffer.remove(buffer.size()-1);return c;}

4, public static char pop(){ char ch;while(buffer.size()==0){try{this.wait();}catch(InterruptedException e){}ch = buffer.remove(buffer.size()-1);return c;}

Page 70: Java Compiler

3

SMB2109

Consider the following code:

public class th_demo extends Thread{int i=0;public static run(){ while(i<10){

System.out.println("i="+i);} i++; }

public static void main(String[] args){ Thread t = new th_demo(); t.start();}}

Identify the correct output of the preceding code snippet.

1, It will generate a compile time error as the th_demo class is not implementing the Runnable interface.

2, It will compile successfully and on calling start, it will print the value of i from 0 to 9.

3, It will not compile because the method run cannot have static keyword as a return type.

4, It will compile successfully and on calling start, it will print the value of i=0 infinitely.

Page 71: Java Compiler

1, commit() 2, rollback() 3, executeUpdate() 1

1

1, java.lang 2, java.util 3, java.awt 4, java.io 1

SMB2110

While creating a Java application, you need to reflect the changes made by the transactions in a database. Which of the following method will you use to accomplish the desired task?

4, PrepareStatement()

SMB2111

While creating a TCP/IP server application, you need to register your service on port 5232. Which of the following code snippet will you use to accomplish the desired task?

1, ServerSocket s = new ServerSocket(5432);

2, Socket s = new Socket("127.0.0.1",5432);

3, Socket s = new Socket(5432);

4, ServerSocket s = new ServerSocket("127.0.0.1",5432);

SMB2112

Which of the following packages is used to access Thread class?

Page 72: Java Compiler

1

SMB2113

Consider the following code:

public class thread_demo extends Thread{ public static void main(String args[]) { for(int i=0;i<5;i++) new thread_demo().start(); }public void run() { System.out.println("Hello"); }}

Analyze the preceding code and identify the correct output for the given code.

1, It will print Hello five times.

2, It will generate a runtime error.

3, It will generate a compile time error.

4, It will compile, and execute successfully but will not generate any output.

Page 73: Java Compiler

2, Thread.join() 3, Thread.sleep(); 4, Thread.wait() 1

SMB2114

While creating a thread in a Java application, you want to use a method that allows you to give other runnable threads a chance to execute. If other threads are runnable, the calling thread should be placed into the runnable pool and allows another runnable thread to run. Which of the following methods of the Thread class will help you in accomplishing the desired task?

1, Thread.yield()

Page 74: Java Compiler

1

1, forName() 3, absolute() 1

SMB2115

Consider the following code:

import java.sql.*;public class AuthorsInfo{public static void main(String args[]){try{ String str="SELECT * FROM Authors WHERE city LIKE 'S%'";

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");Connection con = DriverManager.getConnection("jdbc:sqlserver://sqlserver01; databaseName=Library;user=user1;password=password#1234");Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(str); System.out.println("Author ID\tAuthor Name\tCity");while (rs.next()){String id=rs.getString("au_id");String name=rs.getString("au_name");String city=rs.getString("city");System.out.print(id+"\t");if (name.length() <=7) System.out.print(name+"\t\t");

1, It retrieve information (author id, name, address, city, and state) about the authors who are living in the city where the city name begins with the letter "S".

2, It retrieve information (author id, name, address, city, and state) about all the authors.

3, It will generate a runtime exception due to database access error.

4, It will generate a compile time error as the user needs to import javax.sql package.

SMB2116

Which of the following methods is used to load the JDBC driver and registers it?

2, getConnection()

4, createStatement()

Page 75: Java Compiler

2, ResultSet 3, Connection 4, Statement 1

1

1

SMB2117

The _______ object allows you to pass runtime parameters to the SQL statements using the placeholders.

1, PreparedStatement

SMB2118

Which of the following methods of ResultSetMetaData interface retrieves the title of a table column corresponding to the index passed as a parameter to the method?

1, getColumnLabel()

2, getColumnName()

3, getColumnCount()

4, getColumnType()

SMB2119

Which of the following fields of the ResultSet interface specifies that the cursor of the ResultSet object is scrollable and it does not reflect changes in the data made by other users?

1, TYPE_SCROLL_INSENSITIVE

2, TYPE_SCROLL_SENSITIVE

3, CONCUR_READ_ONLY

4, CONCUR_UPDATABLE

Page 76: Java Compiler

1

1, accept() 2, Socket() 3, readUTF() 4, getInputStream() 1

1, Byte 2, Processing 3, Node 4, Character 4

1, Byte stream 2, Node stream 3, Filter stream 3

4, java.lang.Error 1

SMB2120

Which of the following drivers is called the Type 1 driver?

1, JDBC-ODBC Bridge driver

2, Native-API Partly-Java driver

3, JDBC-Net Pure-Java driver

4, Native Protocol Pure-Java driver

SMB2121

When the client requests a connection, the server opens the socket connection with the ________ method.

SMB2122

The PipedReader class is a type of _______ stream.

SMB2123

Which of the following streams performs conversion on another stream?

4, Character stream

SMB2124

Which of the following classes contains the wait and notify methods?

1, java.lang.Object

2, java.lang.Thread

3, java.lang.Exception

Page 77: Java Compiler

1

W3C stands for ___________________. 3

1, Connection 2, DataReader 3, Command 4, DataAdapter 2

1, Provider 3, Data Source 4, Initial Catalog 4

SMB2125

Which of the following is correct in reference to the getSQLState() method of the SQLException class?

1, It returns X/Open error code.

2, It returns the next exception in the chain of exceptions.

3, It loads the JDBC driver and registers the driver with the DriverManager.

4, It is used to create a Connection object.

SMB2126

1, World Wide Consortium

2, World Web Consortium

3, World Wide Web Consortium

4, World Web Wide Consortium

SMB2127

You want to retrieve data from a data source in a read-only and forward-only mode. Which of the following components of a data provider will you use?

SMB2128

Which of the following parameters of the connection string is used to specify the name of a database?

2, Integrated Security

Page 78: Java Compiler

2, System.Data 3, System.Data.Sql 1

3

SMB2129

Which of the following namespaces would you include in your program to use the functionality of the SqlConnection class?

1, System.Data.SqlClient

4, System.Data.SqlTypes

SMB2130

You are creating an application to retrieve data from a database in a read-only and forward-only mode. For this, you have written the following code snippet:

SqlConnection connection = new SqlConnection();connection.ConnectionString = "Data Source= SQLSERVER01; Initial Catalog=HR; User ID=sa; Password=niit#1234";connection.Open();SqlCommand cmd = new SqlCommand("select * from monthlysalary");SqlDataReader myReader = cmd.ExecuteReader();

However, on execution, the code snippet is throwing a compilation error. Analyze the code snippet and identify the error.

1, Instead of ExecuteReader(), the ExecuteNonQuery() method should be used.

2, The myReader object should be initialized, as shown in the following code snippet:SqlDataReader myReader = new SqlDataReader();

3, The SqlCommand constructor should have the query and the connection object as the parameter. It should be written as:

SqlCommand cmd = new SqlCommand("select * from monthlysalary", connection);

4, The connection string should also include the Integrated Security parameter and it should be set to true.

Page 79: Java Compiler

1

2, Enlist 3, Pooling 1

SMB2131

Sam has written the following code snippet to illustrate how the StateChange event is initialized during a connection:

connection.StateChange += new StateChangeEventHandler(OnStateChange);protected static void OnStateChange(object sender, StateChangeEventArgs args) { Console.WriteLine("The current Connection state has changed from {0} to {1}.", OriginalState, CurrentState); }

However, when he compiled the code snippet, it threw an error. Analyze the code snippet and identify the correct code.

1, connection.StateChange += new StateChangeEventHandler(OnStateChange);protected static void OnStateChange(object sender, StateChangeEventArgs args) { Console.WriteLine("The current Connection state has changed from {0} to {1}.", args.OriginalState, args.CurrentState); }

2, connection.StateChange += new StateChangeEventHandler(OnStateChange);protected static void OnStateChange(object sender, StateChangeEventArgs args) { Console.WriteLine("The current Connection state has changed from {0} to {1}.", sender.OriginalState, sender.CurrentState); }

3, connection.StateChange += new StateChangeEventHandler(OnStateChange);protected static void OnStateChange(object sender, StateChangeEventArgs args) { Console.WriteLine("The current Connection state has changed from {0} to {1}.", args.OriginalState, sender.CurrentState); }

4, connection.StateChange += new StateChangeEventHandler(OnStateChange);protected static void OnStateChange(object sender, StateChangeEventArgs args) { Console.WriteLine("The current Connection state has changed from {0} to {1}.", sender.OriginalState, args.CurrentState); }

SMB2132

Which of the following parameters indicates that the database connection will be reset when the connection is removed from the pool?

1, Connection reset

4, Connection timeout

Page 80: Java Compiler

1, 1000 2, 100 3, 50 4, 200 2

4

SMB2133

What would be the value of the Max pool size parameter if you have not explicitly specified any value?

SMB2134

Sam is implementing connection pooling. He wants that the pooler opens a new connection instead of attempting to acquire a connection from the pool.For this, he has written the following code:

SqlConnection connection = new SqlConnection();connection.ConnectionString = "Data Source=SQLSERVER01;user ID=sa; password=niit#1234;Initial Catalog=HR;Connection Timeout = 20; Pooling = true";connection.Open();

However, he found that the code does not fulfill the requirement. Analyze the code and provide a solution.

1, The timeout should be increased so that the pooler can open a new connection.

2, The Max pool size parameter should be included in the connection string.

3, The Min pool size parameter should be included in the connection string.

4, The pooling parameter should be set to false.

Page 81: Java Compiler

1, Locked 2, Name 3, Tag 4, Text 4

1

4

SMB2135

Which of the following properties of a TextBox control is used to bind the value of a column in the dataset?

SMB2136

You want to bind a ComboBox control to a specific data element. Which of the following properties will you use?

1, The DisplayMember property

2, The DataSource property

3, The Items property

4, The Text property

SMB2137

Which of the following benefits is NOT provided by stored procedures?

1, precompiled execution

2, reduced network traffic

3, efficient reuse of code

4, reduced bandwidth

Page 82: Java Compiler

1

SMB2138

John has to develop an application that enables the users to retrieve the details of an employee from a database based on a employee code. He has written the following code snippet:

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 monthlySalary WHERE cemployeeCode = @employeecode";SqlCommand cmd = new SqlCommand(query, con);

SqlDataReader dr = cmd.ExecuteReader();

However, when he executed the code, it threw an error. Analyze the code and provide the solution.

1, After creating the command object, the parameters need to be added, as shown in the code snippet:cmd.Parameters.Add(new SqlParameter("@employeecode", searchemployeecode));

2, After creating the command object, the parameters need to be added, as shown in the code snippet:cmd.Parameters.Add("@employeecode", searchemployeecode);

3, After creating the command object, the parameters need to be added, as shown in the code snippet:cmd.AddParameters(new SqlParameter("@employeecode", searchemployeecode));

4, After creating the command object, the parameters need to be added, as shown in the code snippet:cmd.AddParameters("@employeecode", searchemployeecode);

Page 83: Java Compiler

2, RowFilter 3, Sort 4, Modifiers 2

SMB2139

Which of the following properties of the DataView control enables you to specify an expression/condition in a string format for filtering the records?

1, RowStateFilter

Page 84: Java Compiler

3

1, DataAdapter 2, DataReader 3, Connection 4, Dataset 4

SMB2140

Sam wants to execute TableAdapter queries on the Click event of the ToolStripButton control. He wants to populate the data from the Sales datatable of the adventureWorks dataset. For this, he has written the following code snippet:

private void ToolStripButton_Click(object sender, EventArgs e){ try { this.internalCandidateTableAdapter.FillBy(this.adventureWorksDataSet.Sales); }catch (System.Exception ex){ System.Windows.Forms.MessageBox.Show(ex.Message); }}

However, the code snippet is throwing an error. Analyze the code snippet and provide the solution.

1, private void ToolStripButton_Click(object sender, EventArgs e){ try { this.internalCandidateTableAdapter.Fill(this.adventureWorksDataSet.Sales); }catch (System.Exception ex){ System.Windows.Forms.MessageBox.Show(ex.Message); }}

2, private void ToolStripButton_Click(object sender, EventArgs e){ try { this.internalCandidateTableAdapter.Sales(this.adventureWorksDataSet.Fill); }catch (System.Exception ex){ System.Windows.Forms.MessageBox.Show(ex.Message); }}

3, private void ToolStripButton_Click(object sender, EventArgs e){ try { this.internalCandidateTableAdapter.FillBy(this.adventureWorksDataSet.Sales); }catch (System.Exception ex){ System.Windows.Forms.MessageBox.Show(ex.Message); }}

4, private void ToolStripButton_Click(object sender, EventArgs e){ try { this.internalCandidateTableAdapter.FilledBy(this.adventureWorksDataSet.Sales); }catch (System.Exception ex){ System.Windows.Forms.MessageBox.Show(ex.Message); }}

SMB2141

Which of the following objects is NOT contained in the Connected classes?

Page 85: Java Compiler

2, Parameters 3, Transaction 4, Site 1

4, DeleteCommand 2

1, Cascade 2, None 3, SetDefault 4, SetNull 1

SMB2142

Which of the following properties of the DbCommand object indicates or specifies how the CommandText property is interpreted?

1, CommandType

SMB2143

Which of the following properties of a DataAdapter object refers to a DML statement or a stored procedure to retrieve data from a dataset?

1, InsertCommand

2, SelectCommand

3, UpdateCommand

SMB2144

Which of the following Rule enumeration values deletes or updates the child DataRow object when the Parent DataRow object is deleted or its unique key is changed?

Page 86: Java Compiler

2, CurrentRows 3, OriginalRows 4, ModifiedCurrent 4

1

SMB2145

Which of the following enumeration values of the DataViewRowState enumeration retrieves the current row version of all modified rows?

1, ModifiedOriginal

SMB2146

Consider the following statements:Statement A: In the connected environment the data is always current and updated.Statement B: Connected environment leads to network congestion.

Which of the following options are correct in context of 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 and Statement B is false.

4, Statement B is true and Statement A is false.

Page 87: Java Compiler

2

1

4

3

SMB2147

How will you check whether the specified DbParameter object instances are same?

1, By using the Equals() method of the DbParameter object

2, By using the RefereneceEquals() method of the DbParameter object

3, By using the GetType() method of the DbParameter object

4, By using the GetHashCode() method of the DbParameter object

SMB2148

How will you determine the number of rows affected in the last batch?

1, By adding a RowUpdated event to the SqlDataAdapter object.

2, By adding a RowUpdated() method to the SqlDataAdapter object.

3, By adding a Updated event to the SqlDataAdapter object.

4, By adding a Updated() method to the SqlDataAdapter object.

SMB2149

Sam wants to merge dataset ds1 with dataset ds. Which of the following code snippet will he use to perform the desired task?

1, ds.Merge(dsMissingSchemaAction.Add);

2, ds.Merge(ds1, 0, MissingSchemaAction.Add);

3, ds.Merge(ds1, false, MissingSchemaAction.Add);

4, ds.Merge(ds1, true, MissingSchemaAction.Add);

SMB2150

How will you specify a sorting order on a particular column of a DataView object?

1, By using the Sort() method of the DataView object

2, By using the ApplyDefaultSort property of the DataView object

3, By using the Sort property of the DataView object

4, By using the ApplyDefaultSort() method of the DataView object

Page 88: Java Compiler

2

SMB2151

You want to create a Windows form to display the details of an employee with Employee ID 3150. You want to fetch the data by sending SQL command to the database with the help of the DbCommand object. Which of the following code snippets will you write to achieve the desired task?

1, string connectionString = "Data Source=SQLSERVER01;Initial Catalog=Employee;User id=sa;Password=niit#1234";

SqlConnection cn = new SqlConnection();cn.ConnectionString = connectionString;cn.Open();

SqlCommand cmd = cn.CreateCommand();

cmd.CommandText = "select * from Employees where Emp_ID=3150";

connectionString = "Data Source=SQLSERVER01;Initial Catalog=Employee;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

connectionString = "Data Source=SQLSERVER01;Initial Catalog=Employee;User id=sa;Password=niit#1234";

SqlConnection cn = new SqlConnection();cn.ConnectionString = connectionString;

SqlCommand cmd = cn.CreateCommand(); cmd.CommandType = CommandType.Text;

cmd.CommandText = "select * from Employees where Emp_ID=3150"; cmd.ExecuteNonQuery();

connectionString = "Data Source=SQLSERVER01;Initial Catalog=Employee;User id=sa;Password=niit#1234";

SqlConnection cn = new SqlConnection();cn.ConnectionString = connectionString;cn.Open();

SqlCommand cmd = new SQLCommand(); cmd.CommandType = CommandType.Text;

cmd.CommandText = "select * from Employees where Emp_ID=3150"; cmd.ExecuteNonQuery();

Page 89: Java Compiler

1

SMB2152

You want to retrieve all details from the Departments database by using the SqlDataAdapter object. Which of the following code snippets will you use?

1, SqlConnection cn = new SqlConnection();cn.ConnectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234";

DataSet DataSet1 = new DataSet();SqlDataAdapter da = new SqlDataAdapter();

SqlCommand cmd=new SqlCommand("Select * from Departments", cn);da.SelectCommand = cmd;

SqlConnection cn = new SqlConnection();cn.ConnectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234";

DataSet DataSet1 = new DataSet();SqlDataAdapter da = new SqlDataAdapter();

SqlCommand cmd=new SqlCommand("Select * from Departments", cn);da.SelectCommand = cmd;

DataSet1.Fill(da);

3, SqlConnection cn = new SqlConnection();cn.ConnectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234";

DataSet DataSet1 = new DataSet();SqlDataAdapter da = da.CreateSqlDataAdapter();

SqlCommand cmd=new SqlCommand("Select * from Departments", cn);da.SelectCommand = cmd;

da.Fill(DataSet1);

4, SqlConnection cn = new SqlConnection();cn.ConnectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234";

DataSet DataSet1 = new DataSet();SqlDataAdapter da = new SqlDataAdapter();

SqlCommand cmd=new SqlCommand("Select * from Departments");

da.Fill(DataSet1);

Page 90: Java Compiler

4

SMB2153

Sam wants to add two tables, Department and Employee, in a single dataset. He also wants to create a relation between the tables on a common field that is Department ID. In addition, he wants to add the tables' relation information in the dataset. Which of the following code snippets will allow him to do so?

ds.Tables.Add("Department");dt.Columns.Add("Department ID", typeof(string));dt.Columns.Add("Department Name", typeof(string));dt.Columns.Add("Region", typeof(string));

DataTable dt1 = ds.Tables.Add("Employee");dt1.Columns.Add("Department ID", typeof(string));dt1.Columns.Add("Employee ID", typeof(string));dt1.Columns.Add("Employee Name", typeof(string));

DataTable dt = ds.Tables.Add("Department");dt.Columns.Add("Department ID", typeof(string));dt.Columns.Add("Department Name", typeof(string));dt.Columns.Add("Region", typeof(string));

DataTable dt1 = ds.Tables.Add("Employee");dt1.Columns.Add("Department ID", typeof(string));dt1.Columns.Add("Employee ID", typeof(string));dt1.Columns.Add("Employee Name", typeof(string));

3, DataSet ds = new DataSet();

DataTable dt = ds.Tables.Add("Department");dt.Columns.Add("Department ID", typeof(string));dt.Columns.Add("Department Name", typeof(string));dt.Columns.Add("Region", typeof(string));

DataTable dt1 = ds.Tables.Add("Employee");dt1.Columns.Add("Employee ID", typeof(string));dt1.Columns.Add("Employee Name", typeof(string));

dt.PrimaryKey = new DataColumn[]{dt.Columns["Department ID"]};

DataTable dt = ds.Tables.Add("Department");dt.Columns.Add("Department ID", typeof(string));dt.Columns.Add("Department Name", typeof(string));dt.Columns.Add("Region", typeof(string));

DataTable dt1 = ds.Tables.Add("Employee");dt1.Columns.Add("Department ID", typeof(string));dt1.Columns.Add("Employee ID", typeof(string));dt1.Columns.Add("Employee Name", typeof(string));

dt.PrimaryKey = new DataColumn[]{dt.Columns["Department ID"]};

Page 91: Java Compiler

1

1

SMB2154

Sam wants to filter and delete the records from a DataView where the year is greater than 1995. Which of the following code snippets will he use to achieve the same?

1, DataView dv = new DataView();dv.RowFilter = "Year > 1995";dv.RowStateFilter = DataViewRowState.Deleted;

2, DataView dv = dv.CreateDataView();dv.RowFilter = "Year > 1995";dv.RowStateFilter = DataViewRowState.Deleted;

3, DataView dv = new DataView();dv.RowFilter = "Year > 1995";dv.RowStateFilter = DataViewRowState.Delete;

4, DataView dv = dv.CreateDataView();dv.RowFilter = "Year > 1995";dv.RowStateFilter = DataViewRowState.Delete;

SMB2155

John wants to sort two columns, Salary and Year. He wants to sort the Salary column in the ascending order and the Year column in the descending order. Which of the following code snippets allows him to do so?

1, DataView dv = new DataView(); dv.Sort = "Salary ASC, Year DESC";

2, DataView dv = dv.CreateDataView(); dv.Sort = "Salary ASC, Year DESC";

3, DataView dv = new DataView(); dv.Sort = "Salary Ascending, Year Descending";

4, DataView dv = dv.CreateDataView(); dv.Sort = "Salary Ascending, Year Descending";

Page 92: Java Compiler

1

SMB2156

Peter has created an application in which he wants that a user should select an employee code from a combo box and the details of the selected employee are retrieved from the database. He has written the following code snippet in the application:

string val = comboBox1.Text.ToString();

string constr = "Data Source=SQLSERVER01;User ID=sa;password=niit#1234;Initial Catalog=HR";SqlConnection con = new SqlConnection();con.ConnectionString = constr;con.Open();

string str = "select * from employees where ccode=@val";SqlCommand cmd = new SqlCommand(str, con);cmd.CommandType = CommandType.Text;

SqlParameter sql;sql.Value = val;

However, when he executed the code snippet, an error occurred. Analyze the code snippet and provide the correct code snippet.

string constr = "Data Source=SQLSERVER01;User ID=sa;password=niit#1234;Initial Catalog=HR";SqlConnection con = new SqlConnection();con.ConnectionString = constr;con.Open();

string str = "select * from employees where ccode=@val";SqlCommand cmd = new SqlCommand(str, con);cmd.CommandType = CommandType.Text;

comboBox1.Text.ToString();

string constr = "Data Source=SQLSERVER01;User ID=sa;password=niit#1234;Initial Catalog=HR";SqlConnection con = new SqlConnection();con.ConnectionString = constr;con.Open();

string str = "select * from employees where ccode=@val";SqlCommand cmd = new SqlCommand(str, con);cmd.CommandType = CommandType.Text;

3, string val = comboBox1.Text.ToString();

string constr = "Data Source=SQLSERVER01;User ID=sa;password=niit#1234;Initial Catalog=HR";SqlConnection con = new SqlConnection();con.ConnectionString = constr;con.Open();

string str = "select * from employees where ccode=@val";SqlCommand cmd = new SqlCommand(str);cmd.CommandType = CommandType.Text;

SqlParameter sql;

4, string val = comboBox1.Text.ToString();

string constr = "Data Source=SQLSERVER01;User ID=sa;password=niit#1234;Initial Catalog=HR";SqlConnection con = new SqlConnection();con.ConnectionString = constr;con.Open();

string str = "select * from employees where ccode=@val";SqlCommand cmd = new SqlCommand(str, con);cmd.CommandType = CommandType.Text;

Page 93: Java Compiler

4

SMB2157

Peter has created a console application in which he is retrieving data in read-only forward-only mode from the Employee table of the AdventureWorks database. For this, he has written the following code snippet:

string connectionString = "Data Source=SQLSERVER01;Initial Catalog=AdventureWorks;User id=sa;Password=niit#1234";string sSQL = "SELECT * FROM HumanResources.Employee";SqlConnection cn = new SqlConnection(connectionString);cn.Open();

SqlCommand cmd = new SqlCommand(sSQL, cn);SqlDataReader dr;while (dr.Read()){ Console.WriteLine(dr[0] + "" + dr[1]);}cn.Close();

However, when Peter executed the application, it threw an error. Analyze the code snippet and provide the correct code snippet.

1, string connectionString = "Data Source=SQLSERVER01;Initial Catalog=AdventureWorks;User id=sa;Password=niit#1234";string sSQL = "SELECT * FROM HumanResources.Employee";SqlConnection cn = new SqlConnection(connectionString);cn.Open();

SqlCommand cmd = new SqlCommand(sSQL, cn);SqlDataReader dr = new SqlDataReader();while (dr.Read())

= "Data Source=SQLSERVER01;Initial Catalog=AdventureWorks;User id=sa;Password=niit#1234";string sSQL = "SELECT * FROM HumanResources.Employee";SqlConnection cn = new SqlConnection(connectionString);cn.Open();

SqlCommand cmd = new SqlCommand(sSQL, cn);SqlDataReader dr = cmd.Execute();while (dr.Read()){ Console.WriteLine(dr[0] + "" + dr[1]);

"Data Source=SQLSERVER01;Initial Catalog=AdventureWorks;User id=sa;Password=niit#1234";string sSQL = "SELECT * FROM HumanResources.Employee";SqlConnection cn = new SqlConnection(connectionString);cn.Open();

SqlCommand cmd = new SqlCommand(sSQL, cn);SqlDataReader dr = cmd.ExecuteReader();while (dr.ExecuteReader()){ Console.WriteLine(dr[0] + "" + dr[1]);

connectionString = "Data Source=SQLSERVER01;Initial Catalog=AdventureWorks;User id=sa;Password=niit#1234";string sSQL = "SELECT * FROM HumanResources.Employee";SqlConnection cn = new SqlConnection(connectionString);cn.Open();

SqlCommand cmd = new SqlCommand(sSQL, cn);SqlDataReader dr = cmd.ExecuteReader();while (dr.Read()){ Console.WriteLine(dr[0] + "" + dr[1]);

Page 94: Java Compiler

2

SMB2158

Peter has created an application to add records in a table and update the database. For this, he has written the following code snippet:

SqlConnection connection = new SqlConnection();connection.ConnectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234";connection.Open();

SqlDataAdapter adapter = new SqlDataAdapter("Select * from Employees", connection);SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(connection);DataSet ds = new DataSet("Employees");adapter.Fill(ds, "Employees");

DataRow row = ds.Tables["Employees"].NewRow();row["cEmployeeCode"] = "000018";row["vFirstName"] = "Peter";row["vLastName"] = "Martin";

ds.Tables["Employees"].Rows.Add(row);adapter.Update(ds, "Employees");connection.Close();

new SqlConnection();connection.ConnectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234";connection.Open();

SqlDataAdapter adapter = new SqlDataAdapter("Select * from Employees", connection);SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);DataSet ds = new DataSet("Employees");

SqlConnection connection = new SqlConnection();connection.ConnectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234";connection.Open();

SqlDataAdapter adapter = new SqlDataAdapter("Select * from Employees", connection);SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);DataSet ds = new DataSet("Employees");

3, SqlConnection connection = new SqlConnection();connection.ConnectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234";connection.Open();

SqlDataAdapter adapter = new SqlDataAdapter("Select * from Employees", connection);SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);DataSet ds = new DataSet("Employees");ds.Fill(adapter, "Employees");

DataRow row = ds.Tables["Employees"].NewRow();

connection = new SqlConnection();connection.ConnectionString = "Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234";connection.Open();

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();

Page 95: Java Compiler

3

SMB2159

Sam is creating an application in which he needs to merge the data available in one DataSet with another DataSet. For this, he has written the following code snippet in the application:

SqlConnection cn = new SqlConnection("Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234");SqlCommand cmd = cn.CreateCommand();cmd.CommandText = "SELECT * FROM Department";SqlDataAdapter da = cn.CreateDataAdapter();da.SelectCommand = cmd;

DataSet ds = new DataSet();cn.Open();da.Fill(ds, "Department");cmd.CommandText = "SELECT * FROM Country";

DataSet ds1 = new DataSet();da.Fill(ds1, "Country");cn.Close();

ds.Merge(ds1, true, MissingSchemaAction.Add);

SqlConnection cn = new SqlConnection("Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234");SqlCommand cmd = cn.CreateCommand();cmd.CommandText = "SELECT * FROM Department";SqlDataAdapter da = new SqlDataAdapter();da.SelectCommand = cmd;

DataSet ds = new DataSet();cn.Open();da.Fill(ds, "Department");

2, SqlConnection cn = new SqlConnection("Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234");SqlCommand cmd = cn.CreateCommand();cmd.CommandText = "SELECT * FROM Department";SqlDataAdapter da = new SqlDataAdapter();da.SelectCommand = cmd;

DataSet ds = new DataSet();cn.Open();da.Fill(ds, "Department");

cn = new SqlConnection("Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234");SqlCommand cmd = cn.CreateCommand();cmd.CommandText = "SELECT * FROM Department";SqlDataAdapter da = new SqlDataAdapter();da.SelectCommand = cmd;

DataSet ds = new DataSet();cn.Open();da.Fill(ds, "Department");cmd.CommandText = "SELECT * FROM Country";

cn = new SqlConnection("Data Source=SQLSERVER01;Initial Catalog=HR;User id=sa;Password=niit#1234");SqlCommand cmd = cn.CreateCommand();cmd.CommandText = "SELECT * FROM Department";SqlDataAdapter da = new SqlDataAdapter();da.SelectCommand = cmd;

DataSet ds = new DataSet();cn.Open();da.Fill(ds, "Department");cmd.CommandText = "SELECT * FROM Country";

Page 96: Java Compiler

1

1

SMB2160

want to view the employee codes of the employees who are married. For this, you need to filter the data based on the marital status of employees. You have written the following code snippet to filter the data:

string connectionString = "Data Source=SQLSERVER01;Initial Catalog=AdventureWorks;User id=sa;Password=niit#1234";string sSQL = "Select * From HumanResources.Employee";SqlConnection conn = new SqlConnection(connectionString);

SqlDataAdapter da = new SqlDataAdapter();da.SelectCommand = new SqlCommand(sSQL,conn);DataSet ds = new DataSet();

da.Fill(ds, "HumanResources.Employee");DataTable dt = ds.Tables["HumanResources.Employee"];

DataView dv = ds.CreateDataView(dt, "MaritalStatus = 'M'", "MaritalStatus", DataViewRowState.CurrentRows);

On execution, the application throws an error. Analyze the code snippet and provide the solution.

Source=SQLSERVER01;Initial Catalog=AdventureWorks;User id=sa;Password=niit#1234";string sSQL = "Select * From HumanResources.Employee";SqlConnection conn = new SqlConnection(connectionString);

SqlDataAdapter da = new SqlDataAdapter();da.SelectCommand = new SqlCommand(sSQL,conn);DataSet ds = new DataSet();

da.Fill(ds, "HumanResources.Employee");

connectionString = "Data Source=SQLSERVER01;Initial Catalog=AdventureWorks;User id=sa;Password=niit#1234";string sSQL = "Select * From HumanResources.Employee";SqlConnection conn = new SqlConnection(connectionString);

SqlDataAdapter da = new SqlDataAdapter();da.SelectCommand = new SqlCommand(sSQL);DataSet ds = new DataSet();

da.Fill(ds, "HumanResources.Employee");

connectionString = "Data Source=SQLSERVER01;Initial Catalog=AdventureWorks;User id=sa;Password=niit#1234";string sSQL = "Select * From HumanResources.Employee";SqlConnection conn = new SqlConnection(connectionString);

SqlDataAdapter da = new SqlDataAdapter();da.SelectCommand = new SqlCommand(sSQL,conn);DataSet ds = da. CreateNewDataSet();

da.Fill(ds, "HumanResources.Employee");

connectionString = "Data Source=SQLSERVER01;Initial Catalog=AdventureWorks;User id=sa;Password=niit#1234";string sSQL = "Select * From HumanResources.Employee";SqlConnection conn = new SqlConnection(connectionString);

SqlDataAdapter da = new SqlDataAdapter();da.SelectCommand = new SqlCommand(sSQL,conn);DataSet ds = da.CreateNewDataSet();

da.Fill(ds, "HumanResources.Employee");

SMB2161

Which of the following options allows the DataReader class to handle columns, which store large binary data?

1, The SequentialAccess property

2, The ExecuteReader() method

3, The GetBytes() method

4, The SingleRow property

Page 97: Java Compiler

1, Pointer 2, Offset 3, Delete_Length 4, Data 2

3

1, SqlCopyBulk 2, SqlCommand 3, SqlConnection 4, SqlBulkCopy 4

1

2

SMB2162

Which of the following options is the starting position of the update in the syntax of the UPDATETEXT function?

SMB2163

Which of the following WriteToServer() method copies all rows from the DataRow array to a destination table?

1, SqlBulkCopy.WriteToServer (DataTable)

2, SqlBulkCopy.WriteToServer (IDataReader)

3, SqlBulkCopy.WriteToServer (DataRow[])

4, SqlBulkCopy.WriteToServer (DataTable, DataRowState)

SMB2164

The __________ class is used for bulk copy of records.

SMB2165

Which of the following namespaces will you include to use the PermissionState enumeration?

1, System.Security.Permissions

2, System.Security.Policy

3, System.Security.AccessControl

4, System.Security.Authentication

SMB2166

Which of the following classes will you use to execute SQL notifications?

1, The SqlClientPermission class

2, The SqlDependency class

3, The SqlBulkCopy class

4, The DataAdapter class

Page 98: Java Compiler

1, Durability 2, Consistency 3, Atomicity 4, Isolation 4

2, System.Data 3, System.Data.Sql 1

1, Rollback() 2, Commit() 2

SMB2167

Which of the following properties of a transaction states that any data modification made by one transaction must be independent from the modifications made by the other transaction?

SMB2168

A local transaction is created and managed within the ____________ namespace.

1, System.Transactions

4, System.Data.SqlClient

SMB2169

Which of the following methods is called when a transaction is successfully completed?

3, BeginTransaction()

4, ExecuteNonQuery()

Page 99: Java Compiler

1, Snapshot 1

1

SMB2170

Which of the following isolation levels is used when accuracy is required on long-running queries and multi-statement transactions, but no updates are performed on the data?

2, Repeatable Read

3, Read Committed with Snapshots

4, Read Committed with Locks

SMB2171

You are using a DbCommand object, command, in your application. You want to change the behavior of the command object to a sequential stream when you execute the ExecuteReader() method. Which of the following code snippet allows you to do so?

1, command.ExecuteReader(CommandBehavior.SequentialAccess);

2, command.ExecuteReader(Behavior.SequentialAccess);

3, command.ExecuteReader(CommandBehavior(SequentialAccess));

4, command.ExecuteReader(CommandBehavior.SequentialAccess(command));

Page 100: Java Compiler

3

2

4

SMB2172

Identify the correct syntax of the UPDATETEXT function.

1, UPDATETEXT <Table_Name>.<Column_Name> <Data> <Pointer> <Offset> <Delete_Length>

2, UPDATETEXT <Table_Name>.<Column_Name> <Offset> <Pointer> <Delete_Length> <Data>

3, UPDATETEXT <Table_Name>.<Column_Name> <Pointer> <Offset> <Delete_Length> <Data>

4, UPDATETEXT <Table_Name>.<Column_Name> <Offset> <Delete_Length> <Pointer> <Data>

SMB2173

You need to enable a Service Broker for a SQL Server database. Which of the following SQL statements will you use?

1, ALTER DATABASE DATABASE_NAME SET ENABLE.BROKER;

2, ALTER DATABASE DATABASE_NAME SET ENABLE_BROKER;

3, ALTER DATABASE DATABASE_NAME SET BROKER.ENABLE;

4, ALTER DATABASE DATABASE_NAME SET BROKER_ENABLE;

SMB2174

You want to create and perform local transactions against a single data source. Which of the following options provide you with the methods for doing so?

1, The SqlConnection Class

2, The IDataReader interface

3, The SqlCommand class

4, The IDbTransaction interface

Page 101: Java Compiler

1

SMB2175

You are creating an application that implements transactions. In the application, you want that the queries running inside one transaction are affected by the committed changes in another transaction. Which of the following types of transaction isolation levels will you use?

1, Read Uncommitted

2, Read Committed with Locks

3, Read Committed with Snapshots

4, Repeatable Read

Page 102: Java Compiler

1

SMB2176

You are creating an application for a hospital. The application should enable the management of the hospital to view the photographs of all the patients and store them in a file. The details of all the patients including the photographs are stored in a database. Which of the following code snippet will you write to achieve the required functionality?

1,private void store_Click(object sender, EventArgs e){ //connection is the valid connection object and command is the valid command object FileStream fs; BinaryWriter bw; int bufferSize = 100; byte[] outbyte = new byte[bufferSize]; long retval; long startIndex = 0; string patientID = ""; connection.Open(); SqlDataReader myReader = command.Exec

store_Click(object sender, EventArgs e){ //connection is the valid connection object and command is the valid command object FileStream fs; BinaryWriter bw; int bufferSize = 100; byte[] outbyte = new byte[bufferSize]; long retval; long startIndex = 0; string patientID = ""; connection.Open();

SqlDataReader myReader = command.Execu

sender, EventArgs e){ //connection is the valid connection object and command is the valid command object FileStream fs; BinaryWriter bw; int bufferSize = 100; byte[] outbyte = new byte[bufferSize]; long retval; long startIndex = 0; string patientID = ""; connection.Open();

SqlDataReader myReader = command.ExecuteReader(Command.SequentialAccess); while (myReader.Read()){

sender, EventArgs e){ //connection is the valid connection object and command is the valid command object FileStream fs; BinaryWriter bw; int bufferSize = 100; byte[] outbyte = new byte[bufferSize]; long retval; long startIndex = 0; string patientID = ""; connection.Open(); SqlDataReader myReader = command.ExecuteReader(CommandBehavior.Access(Sequential)); while (myReader.Read()) {

Page 103: Java Compiler

2

SMB2177

You are creating an application in which you have to write BLOB value to the database. To optimize the usage of system resources, you are writing the BLOB to the database in chunks. Which of the following code snippets will you write to achieve the required functionality?

file = new FileStream(curFileName, FileMode.OpenOrCreate, FileAccess.Read);byte[] rawdata = new byte[file.Length];file.Read(rawdata, 0, System.Convert.ToInt32(file.Length));file.Close();string sql = "SELECT * FROM PATIENTS";

SqlConnection connection = new SqlConnection();connection.ConnectionString = connectionString;

FileStream(curFileName, FileMode.OpenOrCreate, FileAccess.Read);byte[] rawdata = new byte[file.Length];file.Read(rawdata, 0, System.Convert.ToInt32(file.Length));file.Close();string sql = "SELECT * FROM PATIENTS";

SqlConnection connection = new SqlConnection();connection.ConnectionString = connectionString;connection.Open();

ame, FileMode.OpenOrCreate);byte[] rawdata = new byte[file.Length];file.Read(rawdata, 0, System.Convert.ToInt32(file.Length));file.Close();string sql = "SELECT * FROM PATIENTS";

SqlConnection connection = new SqlConnection();connection.ConnectionString = connectionString;connection.Open();

SqlDataAdapter adapter = new SqlDataAdapter(sql);SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);

4, FileStream file = new FileStream(curFileName, FileMode.OpenOrCreate, FileAccess.Read);byte[] rawdata = new byte[file.Length];file.Read(rawdata, 0, System.Convert.ToInt32(file.Length));file.Close();string sql = "SELECT * FROM PATIENTS";

SqlConnection connection = new SqlConnection();connection.ConnectionString = connectionString;connection.Open();

SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);

Page 104: Java Compiler

3

SMB2178

You have to perform the bulk copy operation. Identify the correct sequence of steps to perform the bulk copy operation.

1, 1. Connect to the source server to get the data to be copied. 2. Create a SqlBulkCopy object. 3. Connect to the destination server.4. Set the DestinationTableName property to the name of the target table.5. Call the WriteToServer() method.

2, 1. Connect to the source server to get the data to be copied. 2. Call the WriteToServer() method. 3. Connect to the destination server.4. Create a SqlBulkCopy object. 5. Set the DestinationTableName property to the name of the target table.

3, 1. Connect to the source server to get the data to be copied. 2. Connect to the destination server.3. Create a SqlBulkCopy object. 4. Set the DestinationTableName property to the name of the target table.5. Call the WriteToServer() method.

4, 1. Create a SqlBulkCopy object. 2. Connect to the source server to get the data to be copied. 3. Call the WriteToServer() method. 4. Connect to the destination server.5. Set the DestinationTableName property to the name of the target table.

Page 105: Java Compiler

4

SMB2179

Sam is creating an application in which a transaction has been created by passing a connection to the HR database. The BeginTransaction() method is called and a SQL command is passed that will insert one record in the empdetails table. If the transaction successfully executes the command, the Commit() method will be called otherwise the Rollback() method will be called. Sam could not complete the code as he has to take leave due to health problems. He has written the following code snippet:

static void Main(string[] args) { string connectString = "Initial Catalog=HR;Data Source=SQLSERVER01;User id=sa;Password=niit#1234"; SqlConnection cn = new SqlConnection(); cn.ConnectionString = connectString; cn.Open(); SqlTransaction tran = null; Being a member of the same development team as Sam was, you need to complete the code. Which of the following code snippets will you write to complete the preceding code?

tran = cn.BeginTransaction(); SqlCommand cmd = new SqlCommand("INSERT INTO empdetails(ccode,cname,caddress,cstate,ccountry, cDesignation,cDepartment)VALUES(1101,'Linda Taylor','Oxfordshire','London','UK','Manager', 'Finance')", cn, tran); cmd.ExecuteQuery(); tran.Commit(); Console.WriteLine("Transaction Committed\n");

tran = cn.BeginTransaction(); SqlCommand cmd = tran.CreateSqlCommand("INSERT INTO empdetails(ccode,cname,caddress,cstate,ccountry, cDesignation,cDepartment)VALUES(1101,'Linda Taylor','Oxfordshire','London','UK','Manager', 'Finance')", cn, tran); cmd.ExecuteNonQuery(); tran.Commit(); Console.WriteLine("Transaction Committed\n");

3,try { tran = cn.BeginTransaction(); SqlCommand cmd = new SqlCommand("INSERT INTO empdetails(ccode,cname,caddress,cstate,ccountry, cDesignation,cDepartment)VALUES(1101,'Linda Taylor','Oxfordshire','London','UK','Manager', 'Finance')", cn, tran); cmd.ExecuteNonQuery(); tran.Commit(); Console.WriteLine("Transaction Committed\n"); }

4,try { tran = cn.BeginTransaction(); SqlCommand cmd = new SqlCommand("INSERT INTO empdetails(ccode,cname,caddress,cstate,ccountry, cDesignation,cDepartment)VALUES(1101,'Linda Taylor','Oxfordshire','London','UK','Manager', 'Finance')", cn, tran); cmd.ExecuteNonQuery(); tran.Commit(); Console.WriteLine("Transaction Committed\n"); }

Page 106: Java Compiler

3

SMB2180

You are creating an application in which you are performing a bulk copy operation where the details of the Employee table are to be copied into the EmployeeBackUp table. For this,You have got the following partial code that has to be completed:static void Main(string[] args) { using (TransactionScope ts = new TransactionScope()) { string connectionString = GetConnectionString(); using (SqlConnection cn = new SqlConnection(connectionString)) { cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandText = "DELETE dbo.EmployeeBackUp"; cmd.ExecuteNonQuery(); SqlCommand cmd1 = new SqlCommand(); cmd1.Connection = cn; cmd1.CommandText = "INSERT INTO EmployeeBackUp (cEmployeeCode,vFirstName,vLastName)VALUES(000005,'David','Cooper')"; cmd1.ExecuteNonQuery();

1,SqlCommand rowCount = new SqlCommand("SELECT COUNT(*) FROM dbo.EmployeeBackUp",cn); long countStart = System.Convert.ToInt32(rowCount.Execute()); Console.WriteLine("Starting row count = {0}", countStart); SqlCommand commandSourceData = new SqlCommand("SELECT cEmployeeCode,vFirstName,vLastName FROM Employees",

SqlCommand("SELECT COUNT(*) FROM dbo.EmployeeBackUp",cn); long countStart = System.Convert.ToInt32(rowCount.ExecuteScalar()); Console.WriteLine("Starting row count = {0}", countStart); SqlCommand commandSourceData = new SqlCommand("SELECT cEmployeeCode,vFirstName,vLastName FROM Employees", cn); SqlDataReader reader = commandSource

3,SqlCommand rowCount = new SqlCommand("SELECT COUNT(*) FROM dbo.EmployeeBackUp",cn); long countStart = System.Convert.ToInt32(rowCount.ExecuteScalar()); Console.WriteLine("Starting row count = {0}", countStart); SqlCommand commandSourceData = new SqlCommand("SELECT cEmployeeCode,vFirstName,vLastName FROM Employees", cn); SqlDataReader reader = commandSourceData.ExecuteReader()

4,SqlCommand rowCount = new SqlCommand("SELECT COUNT(*) FROM dbo.EmployeeBackUp",cn); long countStart = System.Convert.ToInt32(rowCount.ExecuteScalar()); Console.WriteLine("Starting row count = {0}", countStart); SqlCommand commandSourceData = new SqlCommand("SELECT cEmployeeCode,vFirstName,vLastName FROM Employees", cn); SqlDataReader reader = commandSourceData.ExecuteReader

Page 107: Java Compiler

1

SMB2181

Sam is creating an application for a hospital. The application should create a backup copy of the Patients table. He has written the following code snippet to copy data from the Patients table to the Patients_backUp table:Line 1: using (SqlConnection sourceConnection = new SqlConnection(connectionString))Line 2:{ sourceConnection.Open();Line 3: SqlCommand commandSourceData = new SqlCommand("SELECT * FROM Patients;", sourceConnection);Line 4: SqlDataReader reader = commandSourceData.ExecuteReader();Line 5: using (SqlConnection destinationConnection = new SqlConnection(connectionString))Line 6: { destinationConnection.Open();Line 7: using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnection))Line 8: { bulkCopy.DestinationTableName = "Patients_backUp"; tryLine 9: {bulkCopy.WriteToServer(reader);}Line 10: catch (Exception ex)Line 11: {Console.WriteLine(ex.Message);}

1,Line 7: using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnection)) has error. It should be:using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection))

2,Line 9: {bulkCopy.WriteToServer(reader);} has error. It should be:{bulkCopy.Write(reader);}

3,Line 9: {bulkCopy.WriteToServer(reader);} has error. It should be:{bulkCopy.WriteTo(reader);}

4,Line 7: using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnection)) has error. It should be:using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sourceConnection))

Page 108: Java Compiler

3

SMB2182

Sam wants a client-side code to execute SQL notification. For this, the client-side code requires necessary permissions. To provide the required permissions to the client-side code, Sam has written the following code snippet:

private bool CanRequestNotifications(){ Permissions permission = new Permissions(PermissionState.Unrestricted); try { permission.Demand(); return true; } catch (System.Exception) { return false; }}However, when he executed the preceding code snippet, he found that it is throwing an error. Analyze the code snippet and provide the correct code.

1, private bool CanRequestNotifications(){ ClientPermissions permission = new ClientPermissions(PermissionState.Unrestricted); try { permission.Demand(); return true; } catch (System.Exception) { return false; }}

2, private bool CanRequestNotifications(){ SqlClientPermission permission = new SqlClientPermission(Permissions.Unrestricted); try { permission.Demand(); return true; } catch (System.Exception) { return false; }}

3, private bool CanRequestNotifications(){ SqlClientPermission permission = new SqlClientPermission(PermissionState.Unrestricted); try { permission.Demand(); return true; } catch (System.Exception) { return false; }}

4, private bool CanRequestNotifications(){ ClientPermission permission = new ClientPermission(Permissions.Unrestricted); try { permission.Demand(); return true; } catch (System.Exception) { return false; }}

Page 109: Java Compiler

2

SMB2183

Peter wants to execute SQL notifications in his application. For this, he has written the following code snippet in the application:

public partial class Form1 : Form{1. private string connectionString = "Data Source=SQLSERVER01;Initial Catalog=BomSaudeHospital;Pooling=False;User id=sa;Password=niit#1234";2. private delegate void GridDelegate(DataTable table);3. private SqlDependency dep; public Form1() {4. InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e){5. SqlDependency.StartDependency(connectionString);6. UpdateGrid();}

However, when he executed the application, he found that the preceding code snippet has an error. Identify the line that has error and provide the correct code snippet.

1, Line 3 has an error. The code should be:

Line 3: private SqlDependency;

2, Line 5 has an error. The code should be:

Line 5: SqlDependency.Start(connectionString);

3, Line 2 has an error. The code should be:

Line 2: private void GridDelegate(DataTable table);

4, Line 5 has an error. The code should be:

Line 5: dep.Start(connectionString);

Page 110: Java Compiler

4

SMB2184

Robert is creating an application in which the BeginTransaction() method is called and a SQL command is passed that will insert one record in the empdetails table. If the particular transaction successfully executes the changes should be committed otherwise the changes should be rolled back. He has written the following code snippet in the application:Line 1: string connectString = "Initial Catalog=HR;Data Source=SQLSERVER01;User id=sa;Password=niit#1234";Line 2: SqlConnection cn = CreateSqlConnection();Line 3: cn.ConnectionString = connectString;Line 4: cn.Open();Line 5: SqlTransaction tran = null; try{Line 6: tran = cn.BeginTransactions();Line 7: SqlCommand cmd = new SqlCommand("INSERT INTO empdetails(ccode,cname,caddress)VALUES(1101,'Linda Taylor','Oxfordshire')", cn, tran);Line 8: cmd.ExecuteNonQuery();Line 9: tran.Commit();Line 10: Console.WriteLine("Transaction Committed\n"); }

1,Line 2: SqlConnection cn = CreateSqlConnection(); has error. It should be:SqlConnection cn = new SqlConnection();

2, Line 8: cmd.ExecuteNonQuery(); has errors. It should be:cmd.ExecuteQuery();

3,Line 6: tran = cn.BeginTransactions(); have errors. It should be:tran = cn.BeginTransaction();

4,Line 2: SqlConnection cn = CreateSqlConnection(); and Line 6: tran = cn.BeginTransactions(); have errors. These should be:SqlConnection cn = new SqlConnection(); andtran = cn.BeginTransaction();

Page 111: Java Compiler

1

SMB2185

Rebecca has written the following code snippet to demonstrate the use of managing distributed transactions:class Program { static void Main(string[] args) {1. using (TransactionScope ts = new TransactionScope()) {2. using(SqlConnection cn = new SqlConnection("Initial Catalog=HR;Data Source=SQLSERVER01;User id=sa;Password=niit#1234")) {3. cn.Open();4. using (SqlCommand cmd = new SqlCommand("INSERT INTO HRusers(cUserName,cPassword)VALUES('Darren', 'Cooper')", cn)) {5. int rowsUpdated = cmd.Execute();6. if (rowsUpdated > 0) {7. using(SqlConnection cn1 = new SqlConnection("Initial Catalog=HR;Data Source=SQLSERVER01;User id=sa;Password=niit#1234")) {

1, Line 5 and Line 12 are causing the error. The correct code should be:Line 5: int rowsUpdated = cmd.ExecuteNonQuery();Line 12: ts.Complete();

2, Line 5 is causing the error. The correct code should be:Line 5: int rowsUpdated = cmd.ExecuteQuery();

3, Line 1 is causing the error. The correct code should be:Line 1: using (TransactionScope ts = new TransactionScope.CreateTransaction())

4, Line 5 and Line 10 are causing the error. The correct code should be:Line 5: int rowsUpdated = cmd.ExecuteQuery();Line 10: int rowsUpdated1 = cmd1.Execute();

Page 112: Java Compiler

2, CloseOutput 3, CheckCharacters 4, Encoding 1

3, ValidationType 4, Schemas 2

1, XmlWriter 4, XmlConvert 3

SMB2186

Which of the following properties of the XmlWriterSettings class gets or sets the level of compliance with which the System.Xml.XmlWriter complies?

1, ConformanceLevel

SMB2187

Which of the following properties of the XmlReaderSettings class gets or sets a value indicating whether to do character checking or not?

1, ConformanceLevel

2, CheckCharacters

SMB2188

The ____________ class uses the ValidationEventHandler() callback method that is called when a validation error occurs.

2, XmlWriterSettings

3, XmlValidatingReader

Page 113: Java Compiler

2, XmlDocument 3, XmlNodeList 4

3, System.Xml 4

1, XmlWriter 3, XmlConvert 4, XmlTextWriter 1

1, XmlWriter 4, XmlConvert 3

SMB2189

In the .NET Framework, NamedNodeMap is implemented by the ______________ class.

1, XmlTextReader

4, XmlNamedNodeMap

SMB2190

Which of the following namespaces contains the SqlXml class?

1, System.Xml.XPath

2, System.Xml.Schema

4, System.Data.SqlTypes

SMB2191

You want to provide non-cached, forward-only, and write-only access to XML data. Which of the following classes enables you to achieve this?

2, XmlWriterSettings

SMB2192

You want to determine whether the XmlReader instance imposes validation or not. Which of the following classes enables you to do this?

2, XmlWriterSettings

3, XmlReaderSettings

Page 114: Java Compiler

1, hasErrors 2, parentID 3, hasChanges 4, id 3

2

2, InferSchema 3, Auto 4, DiffGram 1

SMB2193

You want to identify a row in the <DataInstance> block as modified. Which of the following attributes enables you to do this?

SMB2194

You are writing a code in which you need to put all the attributes of an element node into a collection. Which of the following options enables you to achieve this?

1, The NextSibling property

2, The XmlElement.Attributes property

3, The GetAttribute() method

4, The GetAttributeNode() method

SMB2195

You want to ignore inline schemas and load the XML data into the existing dataset schema. Which of the following XmlReadMode Options enables you to do so?

1, IgnoreSchema

Page 115: Java Compiler

1

SMB2196

You need to create a program that creates an XML file, OrderDetails.xml, by using the XmlWriter class in .NET. Which of the following code snippets enables you to perform the task?

Main(string[] args) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineOnAttributes = true; using (XmlWriter writer = XmlWriter.Create("C:\\OrderDetails.xml", settings)) { writer.WriteComment("Order Details of

2, static void Main(string[] args) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = "*"; settings.NewLineOnAttributes = true; using (XmlWriter writer = XmlWriter.Create("C:\\OrderDetails.xml")) { writer.WriteComment("Order Details of

Main(string[] args) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineOnAttributes = true; using (XmlWriter writer = XmlWriter.Create("C:\OrderDetails.xml", settings)) { writer.WriteComment("Order Details of Velocidade Inc."); writer.WriteStartElement("OrderDetails");

Main(string[] args) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewAttributes = true; using (XmlWriter writer = XmlWriter.Create(@"C:\\OrderDetails.xml", settings)) { writer.WriteComment("Order Details of Velocidade Inc."); writer.WriteStartElementNode("OrderDetails");

Page 116: Java Compiler

1

SMB2197

You are creating an application in which you need to read an XML document, books.xml, and display the content of the document to the reader. Which of the following code snippets will you use to read the document?

{ XmlReader reader = null; try { XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; reader = XmlReader.Create("C:\\books.xml", settings); while (reader.Read()) { reader.MoveToElement(); Console.WriteLine("XmlReader Properties

Main(string[] args) { XmlReader reader = null; try { XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; reader = XmlReader.Create("C:\\books.xml", settings); while (reader.Read()) { reader.MoveToElement(); Console.WriteLine("XmlReader Properties

{ XmlReader reader = null; try { XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; reader = XmlReader.Create("C:\\books.xml", settings); while (reader.Read()) { reader.MoveToElement(); Console.WriteLine("XmlReader Properties Test"); Console.WriteLine("===================");

XmlReader reader = null; try { XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; reader = XmlReader.CreateDocument("C:\\books.xml", settings); while (reader.Read()) { reader.MoveToElement(); Console.WriteLine("XmlReader Properties Test"); Console.WriteLine("===================");

Page 117: Java Compiler

3

SMB2198

You need to create a program that validates the products.xml file against the products.xsd file. Which of the following code snippets enables you to do so?

{ class Program { static void Main(string[] args) { XmlTextReader reader = new XmlTextReader("C:\\products.xml"); XmlValidatingReader validatingReader = new XmlValidatingReader(reader); validatingReader.ValidationType = ValidationType.Schema; validatingReader.ValidationEventHandler

validatingXmlDocument{ class Program { static void Main(string[] args) { XmlTextReader reader = new XmlTextReader("C:\products.xml"); XmlValidatingReader validatingReader = new XmlValidatingReader(reader); validatingReader.ValidationType = ValidationType.Schema; validatingReader.ValidationEventHandler +=new

ment{ class Program { static void Main(string[] args) { XmlTextReader reader = new XmlTextReader("C:\\products.xml"); XmlValidatingReader validatingReader = new XmlValidatingReader(reader); validatingReader.ValidationType = ValidationType.Schema; validatingReader.ValidationEventHandler +=new ValidationEventHandler(ValidationHandler); while(validatingReader.Read());

ment{ class Program { static void Main(string[] args) { XmlTextReader reader = new XmlTextReader("C:\\products.xml"); XmlValidatingReader validatingReader = new XmlValidatingReader(reader); validatingReader.ValidationType = ValidationType.Schema; validatingReader.ValidationEventHandler +=new ValidationEventHandler(ValidationHandler); while(validatingReader.Reading());

Page 118: Java Compiler

3

SMB2199

Predict the output of 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>"));

XmlNode node = doc.DocumentElement.FirstChild;

node.RemoveChild(node.FirstChild);doc.Save(Console.Out);Console.ReadLine();

1, The first BOOK BOOKID element is removed.

2, The code will not delete any element.

3, The BOOKNAME element of the first BOOK element is removed.

4, The code will give an error.

Page 119: Java Compiler

2

SMB2200

You have created a table named Students, by using the following SQL queries:CREATE TABLE Students(Marks xml)INSERT Students VALUES('<Marks><English>85</English><Math>100</Math></Marks>')INSERT Students VALUES('<Marks><English>83</English><Math>96</Math></Marks>')

Now, you need to create a program that retrieves the records stored in Students table and display them in a DataGrid control. Which of the following code snippets enables you to perform the desired task.

1,private void cmdRetrieve_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); //connectionString is the connection string using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = connectionString; conn.Open(); using (SqlCommand cmd = conn.CreateCommand())

cmdRetrieve_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); //connectionString is the connection string using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = connectionString; conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "SELECT * FROM

object sender, EventArgs e) { DataSet ds = new DataSet(); //connectionString is the connection string using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = connectionString; conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "SELECT * FROM Students"; using (SqlDataReader rdr = cmd.ExecuteReade

cmdRetrieve_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); //connectionString is the connection string using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = connectionString; conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "SELECT * FROM Students"; using (SqlDataReader rdr = cmd.ExecuteRead