Saturday, June 20, 2009

Understand the Sun Certified Java Developer Exam Process


OK, so now you know everything about the language. But can you actually build

something in it? You’ll hear that argument from some who’ve never taken (or passed)

the programmer’s exam. Obviously, they don’t understand how darn difficult the

programmer’s exam actually is, but nonetheless there is something to the claim that,

“just because you know how the compiler and VM work does not mean you can

develope software.” The Developer exam, which is unique in the IT exam world,

lets you answer that question (most often posed by a prospective employer).

In the Developer exam, you get to put your code where your mouth is by developing

a software application. In fact, the Developer exam isn’t even a multiple-choice test

but rather a project that you build, given a (somewhat sketchy) specification. You’re

told what to build, with some general guidelines, and then it’s up to you to implement

and deliver the program. You have an unlimited amount of time in which to finish

the project (as of this writing), but there is a short follow-up essay exam (taken at an

authorized testing center, just as the Programmer exam is). The follow-up questions

are largely used to verify that it was you (not your hotshot programmer brother-in-law

who owed you big time) who did the work. In other words, the follow-up exam asks

essay questions that only the project developer could answer (for example, “Justify

your design choice on…”).

First, we’ll lay out the facts of the exam—how it works, how you do it, etc., and

then we’ll dive into what you need to know to pass it. Keep in mind that the actual

knowledge you need to pass cannot be stuffed into a book this size, even if we made

the book big enough to crush a car. Being a programmer is one thing, but being a

developer is quite another. And you can’t become a developer just by memorizing

some facts. Study and memorization can work for passing the Programmer’s exam—

but that’s OK because the programmer’s exam is designed to verify that you’re smart

and that you really know the language. A prospective employer doesn’t have to train

you in Java if you’ve passed the programmer’s exam. But if your employer wants

to verify that you can follow a spec and implement a well-designed, maintainable,

correct application, then you need either previous experience successfully building

one or more Java applications or you need to pass the SCJD.

The next seven chapters (in other words, the rest of the book) show you what

you’ll need to know and do to pass the exam, but it’s up to you to do the heavy

lifting. And unless you’re already well-versed in some of the topics (Swing, Threads,

RMI, etc.) then you’ll need to do some outside reading and practice in those

technologies. We’re focusing here on what the exam assessors are looking for in

your finished project.

How Does It Work?

The exam has two parts, The Assignment and The Essay. You must successfully pass

both parts to become certified.

The Assignment

Once you register for the Developer’s exam, you’re given instructions for downloading

your assignment. There are many possible assignments that you might get. The

assignment is a 9- or 10-page document with instructions for completing the project.

Instructions include both the application specification and requirements for

implementation and delivery. It also includes notes about how the application

will be marked (evaluated, graded, assessed).

The Essay

Once you’ve submitted your assignment, you should immediately register for the

essay portion of the certification. You can’t register until after you’ve submitted your

completed assignment, but the sooner the better once you have submitted it. You

really want to take the essay portion while the application you just completed is still

fresh in your mind. The essay portion will feel somewhat familiar to you—it takes

place in an authorized Prometric testing center, just as the Programmer’s exam does.

You have 90 minutes to complete the essay portion, and it normally involves just a

handful (about five) questions.

The Assessment

Once you’ve submitted both your assignment and the follow-up essay, the two

pieces will be sent to the assessor for grading. It might be four weeks or so before

you learn the results.

Understand the Sun Certified Java Developer Exam Process

Are You a Good Candidate?

If you haven’t yet passed the Programmer’s (SCJP) exam, then stop right now and go

get certified. You must pass the Programmer’s exam before you’re allowed to register

for the Developer exam. So we figure that you’ll read the first part of the book, take

the Programmer’s exam (passing, of course), then come back at some point and start

reading this part. That means by the time you’re reading this part, this book should

already be dog-eared, marked-up, scratched, bent, and possibly dusty (from that dry

spell between taking the Programmer’s exam and going for the Developer exam).

If you got to this paragraph, then we assume you’re already a Sun Certified Java

Programmer. But are you ready for the Developer exam? Well, the good news is that

you don’t need to be ready when you register for the exam. You’ve got plenty of time

to complete the assignment once you download it. So unlike the Programmer’s

exam, you don’t have to wait until you’re at top form for passing the exam. You can

download the assignment, analyze what you’ll need to learn to complete it, and then

get to work. Sun (and most candidates) estimates that it takes between 90 and 120

hours of solid work to complete the exam, and that assumes you’re already familiar

with all the necessary technologies (networking, database, threads/locking, Swing,

etc.). Some people work for three weeks straight, as if the project were their full-time

job. Others work on it when they can, in their spare time, and might take several

months to actually finish it. Of course, there’s always the chance that you download

it and discover you’re way over your head and unlikely to get up-to-speed within a

year. But if you’ve passed the Programmer’s exam and you’re willing to commit the

time to work on it (plus whatever additional time you need to learn any required

technologies you’re not familiar with), then we say go for it…if you’ve got the

money (we’ll get to that in the next section).

Having said all that, we don’t recommend registering until you’ve read the rest of

this book. It’ll give you a better idea of what’s really involved, and you might decide

to wait a while if you’re still a beginner at some of these technologies. But if you’re

comfortable with at least three of the following, chances are you’re ready to at least

download the assignment:

Swing and GUI design

Networking issues: sockets and RMI

Database issues: searching and record-locking

Writing clear, maintainable code

OO design and development

How Much Does It Cost?

All you need is $250 (US dollars) and you’re in business…for the first part. The

SCJD is in two parts, remember: the exam assignment (the specification that you

download, implement, and submit) and the follow-up essay. The follow-up exam is

an additional $150. So you’re looking at $400 total to get your certification. There’s

no partial certification, so submitting your exam doesn’t get you anywhere unless

you successfully take the follow-up exam. In other words, you can’t be certified

without spending the $400.

How Long Does It Take?

As of this writing, there is no time limit specified for completing the assignment

once you’ve downloaded it, but we don’t advise waiting more than a year, as the

requirements could change. Plus, there’s a new requirement (although these

requirements could change at any time so check the Sun website frequently at

http://suned.sun.com for updates) that you must not use a version of Java that is

deemed “out of date.” The current definition of out of date is that your version must

not have been superceded by a new production version for more than 18 months by

the time you make your submission. What that means is that if your version has

been out for less than 18 months, you’re fine. If your version is older than 18

months (in other words, its official public release was more than 18 months ago),

then the version released directly after your version must be less than 18 months old.

So don’t take forever is what we’re saying, or you could find yourself rewriting your

application. It’s not good enough for your program to run on newer versions; you

need to indicate in your exam which version you’ve compiled and tested on.

What’s the Exam Deliverable?

Chapter 17 covers this in picky detail, but the short version is: a JAR file. As of this

writing, you must submit the entire application, including compiled working classes,

source code, and documentation in a single JAR file. Your assignment instructions

will specify exactly how you must submit it and the most important rule is that you

must not deviate in any way from the submission instructions.

Can I Develop with an IDE?

You can, but everything you submit must be your own creation. In other words,

no auto-generated code. So use an IDE as an editor but not as a GUI-building tool

Understand the Sun Certified Java Developer Exam Process

or something that implements your networking. And whatever you do, be sure to

test on a machine other than your development machine! When using an IDE

(or not, but there’s more of a danger when using an IDE) you can end up being

sheltered and protected from things like classpath issues, which allow your program

to run fine on your machine and then blow up (OK, just fail to run) at runtime on

another system.

How Is It Graded?

Once you’ve completed both the assignment and the essay exam, an assessor takes

both pieces and performs the assessment. Your project is first assumed to be correct

and is given a starting point value (currently 155 points, but this could change).

Then points are deducted through a variety of audits. For example, you might get

12 points deducted for issues with your coding conventions, and perhaps another 15

(out of a possible, say, 18 points) for problems with your record-locking or search

algorithm. That subtracts 27 from your starting total of 155, and leaves you with

128 points. Currently, the exam requires 124 points to pass, so you’d be good with

128. Your instructions will give you an idea of the relative importance of certain

evaluation (audit) criteria, but you won’t know the specific values for specific

violations. DISCLAIMER: the point values mentioned here are merely examples of

how the exam is graded; they are not the actual point values used in the assessment.

The only thing you will know with certainty is the relative importance of different

aspects of your project. We’ll give you one clue right now, though: code readability/

clarity and threading/locking will be extremely important. You’ll almost certainly

find these two areas carrying the most weight on your assignment instructions.

What Are the Exam Assessors Thinking?

OK, we aren’t mind readers, and for all we know the assessors are thinking about

last night’s Bellbottom Bowling party as they mark your exam. But we do know one

thing: they aren’t looking to see how clever an algorithm designer you are! If anything,

it’s just the opposite. When you think of the Developer exam, don’t think Lone

Ranger. Instead, think Team Player. And don’t even think about showing off your

programming prowess by revising the specification to do something even better and

cooler than what’s asked for. There’s a saying we have in the software world, and it

will serve you well to remember it while building your Developer project: “Code as

if the next guy to maintain it is a homicidal maniac who knows where you live.”

The exam assessors aren’t thinking like my-algorithm-is-bigger-than-yours

code mavericks. They aren’t looking for the next great breakthrough in

record-locking. They aren’t even looking for new, creative implementations.

They are looking for development that says, “I’m a thoughtful programmer. I

care about maintainability. Readability is very important to me. I want everyone

to understand what’s going on with the least amount of effort. I write careful,

correct code. My code might not be the snappiest, and it might even incur an

extra few bytes in order to make something less complex, but my logic is simple,

my code and my design are clear and implement the specification perfectly, I

didn’t reinvent the wheel anywhere, and gosh—wouldn’t you just love to have

me on your team?” If your project submission says all that about you, you’re

in great shape.

The exam assessor looks at your code first from an entirely selfish perspective by

asking, “Is this easy for me to evaluate?” Chapters 16 and 17 offer insight into what

you need to do to make the assessor’s job easier. Trust us on this one—they’d rather

be at the beach (or skiing, mountain-biking, taking a Martha Stewart crafts workshop)

than spending unnecessary time figuring out how to get your assignment working.

Beginning with the “refreshed” exam assignments at the end of 2002, the requirements

changed to make the submission rules much more strict, in order to benefit the assessor.

If at any time you neglect to follow even a single submission requirement—say, the

directory structure of your project puts the user documentation in a different

folder—you’ll be failed on the spot. The assessor won’t make any allowances for

misplaced files, even if the program still runs perfectly. Don’t make them go looking

for something.

Another aspect of making the assessor’s life easier is what you’ll learn in Chapters

11 and 12. The little things really matter! For example, while you might think—if

you indent your code four spaces—that an occasional three-space indentation here

and there is OK, what’s the harm in that? The harm is in readability, and while a

couple of inconsistencies in indentations might not be a big deal, adhering to the

Java Coding Conventions is absolutely crucial for others looking at your code…

especially the assessor.

We’ve seen people fail the exam because they put the curly braces on the line

below the method declaration rather than immediately following the declaration

(on the same line), violating the official Java Coding Conventions. While this

infraction alone probably might not cause you to fail, the points deducted for code

convention violations might be the ones that sink you where you otherwise might

have squeaked by. You don’t get to make very many mistakes in this exam. Just

because your manager or your co-workers are tolerant of a little sloppiness here and

there, the assessor won’t be. Reread the preceding Exam Watch, copy it down on a

post-it note, and stick it onto your bathroom mirror. Each morning, say it to

yourself, “I’m a thoughtful programmer. I care…” (except say the whole thing).

What Are the Exam Assessors NOT Thinking?

If your solution works—according to the spec—then even if the algorithms might

be tweaked just a little more for efficiency, you probably won’t be marked down—

especially if the code is clear, maintainable, and gets the job done correctly. They’re

also not looking for one particular solution. There is no one right way to implement

your assignment. There are a gazillion wrong ways, however, and we’ll be looking at

some of those throughout the rest of the book. But here’s one that’s guaranteed to

kill you (both on the exam and in the real world): deadlock. Remember, we talked

about threads in Chapter 8, and you’d better take it all very seriously. If there’s even

a chance that your design could lead to deadlock (it doesn’t have to actually cause

deadlock right before the assessor’s eyes) then you can probably kiss that $400 goodbye.

The bottom line is that they’re not looking for The Perfect Solution. But they’re

also not looking for innovative new approaches, regardless of how clever, when

well-known patterns or other solutions exist. They’re especially not looking for you

to reinvent the wheel or write your own, say, new and improved set of classes to

replace the perfectly working core library packages.

What’s the Assignment Like?

We can’t give you a real assignment from the actual exam, of course, but here are a

couple of examples to give you the flavor of what the specification might look like.

And don’t be thinking these are outlandish examples; wait ‘til you see the real ones.

WindRider Horse Cruises

WindRider Horse Cruises (WHC) offers a variety of unique vacation trips, all on

horseback. Copying the cruise ship model, WHC has 4-day, 7-day, and 14-day

cruises that include all the food, drinks, and partying you can handle. (Which, after

four straight days on a horse won’t be much.) WindRider has grown steadily from a

two-person outfit offering one cruise a month to a busy operation with several cruises

running simultaneously in different parts of the world. But while the business has

Understand the Sun Certified Java Developer Exam Process grown, their cruise booking software hasn’t kept pace. The WindRider CEO is

acting as the company’s IT director, but he has some quirks. He insists on keeping

the entire application—including the database server—homegrown. In other words,

he doesn’t want to buy or use a database server written by anyone but his trusted

friend Wilbur. Sadly, Wilbur sustained an injury while fulfilling his other

WindRider duties (training horses to tolerate the disco music) and that’s where you

come in. Your job is to build the new WindRider booking software. One restriction

is that you must use the WindRider’s existing data file format. All cruise records

must stay in that format because the accounting part of the company still has

software that requires that format, and you’re only updating the booking software.

Customers must be able to call in to one of the four booking offices and request

a cruise. A customer service representative then uses the new booking application

(the one you’re going to write) to search for and then book an appropriate cruise to

meet that customer’s needs. Although the data file lives on one machine, back at the

head office, the three other booking offices (and possibly more in the future) need

to be able to access it over a standard TCP/IP network. So there’s a danger that two

customer service agents could be trying to book the same cruise slot at the same

time. (A cruise slot is like a ‘cabin’ on a real seafaring cruise. So any given cruise

might have anywhere between 6 to 12 slots, and each slot represents a record in the

data file.) You’ll have to make sure that this doesn’t happen! Overbooking would be

a Really Bad Thing. (Especially for the horse.)

So the people who interact with the actual software are the customer service

agents. But it’s the actual cruise customers who are making the requests. For example, a

customer might phone up and say, “I’d like a 4- or 7-day Horse Cruise sometime in

August 2003, in the United States.” The customer service agent must then use the

system to perform a search for that customer’s needs. The application needs to provide

a list of all possible matching cruises and then also allow the agent to reserve (book)

a cruise slot for that customer.

You must use a Swing GUI, and WindRider’s CEO just happens to be dating a

Computer-Human Interaction specialist, so you can bet she’ll be looking for all the

right characteristics of a usable GUI.

For networking, you have the choice between RMI and using regular old Java

TCP sockets (with serialized objects). It’s really up to you to make that decision, but

you’d better be prepared to explain why you chose what you chose.

The data file format is a little ugly, not comma-delimited or anything, just a

bunch of fixed-length fields. And you must stick to this data file exactly. We’ll send

it to you so you can see exactly how it’s formatted and start working with it in your

development. You can’t change a thing about what goes into a record. You can’t add

a field, can’t reformat the data…nothing. Your job is simply to build the actual

database server that accesses the data file to allow for searching, booking, adding new

cruises, etc. Oh, and don’t forget about those concurrent user issues—you must lock

these records in some way during use.

From his hospital bed, Wilbur sketched out what the database interface should

be, and you need to follow this exactly (although you can add more, but you must at

least provide these two methods in your public interface to the database server).

public void updateRecord(String[] recordData, int whichRecord) throws

LockedRecordException, NoSuchRecordException;

public int[] findByCustomerCriteria(Criteria criteriaObject);

But then you still need to add the methods for deleting, locking, etc. And you’ll

have to create the custom Exceptions and decide what should go in the Criteria class

(the thing you’re going to use to search the database).

Your job, ultimately, is to deliver the following:

The customer service GUI application that they use to search and book

records in the database.

The actual database server application—the thing that actually gets into the

data file and takes care of locking, etc. This is most likely the piece the GUI

interacts with.

Networking functionality so that multiple users can access this, remotely.

Confused?

That’s part of the idea. You need to think through the problems, think about new

problems not addressed in this spec, and figure out how to solve them, even in the

face of incomplete information. The real world isn’t perfect. Specs never seem to be

complete. And the person you need to ask for clarification never seems to be at his

desk when you call. Oh, and there’s nobody—and we do mean nobody—who will

reassure you that you’re on the right track by implementing a particular solution.

You’re just going to have to roll your sleeves up and answer your own “what about

?” questions.

And boy oh boy are there issues. Both raised and unraised by this specification.

The majority of the rest of this book raises those issues and gives you a lot to think

about. We can’t give you solutions—there aren’t any right solutions, remember—and

it wouldn’t be ethical to work out all the issues here. That’s the whole point of the

Developer exam! The actual coding is quite straightforward and fairly simple. It’s not

like you’re writing the world’s greatest neural network or artificial life program. But

thinking about the true business issues—about what the customer might need, what

the customer service agents need, and what the business itself needs, and then planning

and implementing a solution—are what this certification is all about. You’ll thank us

one day. And don’t forget, if you get frustrated, just remember how much you like us

for getting you through the Programmer certification. Which we did, or of course

you wouldn’t be reading this far into the book!

Overview of the Developer Exam Chapters

We’re going to cover a lot of ground here, some at a high level and some a little

lower. The high-level areas are the places where you need to design solutions and

discover potential problems. Locking issues, for example, are handled at a high level.

We’ll raise issues to get you thinking, but you’ll have to come up with your own

designs—after all, we have no way of knowing what your exact assignment will be.

The lower-level areas are reserved for things you must do throughout your entire

application—such as coding standards, OO design, documentation, etc., and for

tools such as javadoc and Jar. We also cover GUI usability in some depth, but it will

be up to you to work out the implementations. The following is a chapter-by-chapter

look at what we cover in the rest of the book:

MCP 70-536 Recent Exam questions


1)

You are writing a custom dictionary. The custom-dictionary class is named MyDictionary. You need to ensure that the dictionary is type safe.

Which code segment should you use?

A.

class MyDictionary : Dictionary

B.

class MyDictionary : HashTable

C.

class MyDictionary : IDictionary

D.

class MyDictionary { ... }

Dictionary t = new Dictionary();

MyDictionary dictionary = (MyDictionary)t;

2)

You write a class named Employee that includes the following code segment.

public class Employee {

string employeeId, employeeName, jobTitleName;

public string GetName() { return employeeName;

}

public string GetTitle() {

return jobTitleName;

}

You need to expose this class to COM in a type library. The COM interface must also facilitate forward-compatibility across new versions of the Employee class. You need to choose a method for generating the COM interface.

What should you do?

A.

Add the following attribute to the class definition.

[ClassInterface(ClassInterfaceType.None)]

public class Employee {

B.

Add the following attribute to the class definition.

[ClassInterface(ClassInterfaceType.AutoDual)]

public class Employee {

C.

Add the following attribute to the class definition.

[ComVisible(true)]

public class Employee {

D.

Define an interface for the class and add the following attribute to the class definition.

[ClassInterface(ClassInterfaceType.None)]

public class Employee : IEmployee

{

3)

You are working on a debug build of an application.

You need to find the line of code that caused an exception to be thrown. Which property of the Exception class should you use to achieve this goal?

A.

Data

B.

Message

C.

StackTrace

D.

Source

4)

You need to write a code segment that performs the following tasks:

* Retrieves the name of each paused service.

* Passes the name to the Add method of Collection1.

Which code segment should you use?

A.

ManagementObjectSearcher searcher =

new ManagementObjectSearcher(

"Select * from Win32_Service where State = ‘Paused’");

for each (ManagementObject svc in searcher.Get()) {

Collection1.Add(svc["DisplayName"]);

}

B.

ManagementObjectSearcher searcher =

new ManagementObjectSearcher(

"Select * from Win32_Service", "State = ‘Paused’");

for each (ManagementObject svc in searcher.Get()) {

Collection1.Add(svc["DisplayName"]);

}

C.

ManagementObjectSearcher searcher =

new ManagementObjectSearcher(

"Select * from Win32_Service");

for each (ManagementObject svc in searcher.Get()) {

if ((String) svc["State"] == "'Paused'") {

Collection1.Add(svc["DisplayName"]);

}}

D.

ManagementObjectSearcher searcher = new ManagementObjectSearcher();

searcher.Scope = new ManagementScope("Win32_Service");

for each (ManagementObject svc in searcher.Get()) {

if ((String)svc["State"] == "Paused") {

Collection1.Add(svc["DisplayName"]);

}}

5)

You are developing an application that dynamically loads assemblies from an application directory.

You need to write a code segment that loads an assembly named Braindumps1.dll into the current application domain. Which code segment should you use?

A.

AppDomain domain = AppDomain.CurrentDomain;

string myPath = Path.Combine(domain.BaseDirectory, "Braindumps1.dll");

Assembly asm = Assembly.LoadFrom(myPath);

B.

AppDomain domain = AppDomain.CurrentDomain;

string myPath = Path.Combine(domain.BaseDirectory, "Braindumps1.dll");

Assembly asm = Assembly.Load(myPath);

C.

AppDomain domain = AppDomain.CurrentDomain;

string myPath = Path.Combine(domain.DynamicDirectory, "Braindumps1.dll");

Assembly asm = AppDomain.CurrentDomain.Load(myPath);

D.

AppDomain domain = AppDomain.CurrentDomain;

Assembly asm = domain.GetData("Braindumps1.dll");

6)

You are testing a newly developed method named PersistToDB. This method accepts a parameter of type EventLogEntry. This method does not return a value. You need to create a code segment that helps you to test the method. The code segment must read entries from the application log of local computers and then pass the entries on to the PersistToDB method. The code block must pass only events of type Error or Warning from the source MySource to the PersistToDB method. Which code segment should you use?

A.

EventLog myLog = new EventLog("Application", ".");

for each (EventLogEntry entry in myLog.Entries) {

if (entry.Source == "MySource") {

PersistToDB(entry);

}}

B.

EventLog myLog = new EventLog("Application", ".");

myLog.Source = "MySource";

for each (EventLogEntry entry in myLog.Entries) {

if (entry.EntryType == (EventLogEntryType::Error &

EventLogEntryType::Warning)) {

PersistToDB(entry);

}}

C.

EventLog myLog = new EventLog("Application", ".");

for each (EventLogEntry entry in myLog.Entries) {

if (entry.Source == "MySource") {

if (entry.EntryType == EventLogEntryType::Error ||

entry.EntryType == EventLogEntryType::Warning) {

PersistToDB(entry);

}

}}

D.

EventLog myLog = new EventLog("Application", ".");

myLog.Source = "MySource";

for each (EventLogEntry entry in myLog.Entries) {

if (entry.EntryType == EventLogEntryType::Error ||

entry.EntryType == EventLogEntryType::Warning) {

PersistToDB(entry);

}}

7)

You are developing an application for a client residing in Hong Kong.

You need to display negative currency values by using a minus sign. Which code segment should you use?

A.

NumberFormatInfo culture = new CultureInfo("zh-HK")::NumberFormat;

culture.NumberNegativePattern = 1;

return numberToPrint.ToString("C", culture);

B.

NumberFormatInfo culture = new CultureInfo("zh-HK")::NumberFormat;

culture.CurrencyNegativePattern = 1;

return numberToPrint.ToString("C", culture);

C.

CultureInfo culture = new CultureInfo("zh-HK");

return numberToPrint.ToString("-(0)", culture);

D.

CultureInfo culture = new CultureInfo("zh-HK");

return numberToPrint.ToString("()", culture);

8)

Your application uses two threads, named threadOne and threadTwo.

You need to modify the code to prevent the execution of threadOne until threadTwo completes

execution.

What should you do?

A.

Configure threadOne to run at a lower priority.

B.

Configure threadTwo to run at a higher priority.

C.

Use a WaitCallback delegate to synchronize the threads.

D.

Call the Sleep method of threadOne.

E.

Call the SpinLock method of threadOne.

9)

You are writing an application that uses SOAP to exchange data with other applications.

You use a Department class that inherits from ArrayList to send objects to another application.

The Department object is named dept.

You need to ensure that the application serializes the Department object for transport by using SOAP. Which code should you use?

A.

SoapFormatter formatter = new SoapFormatter();

byte[] buffer = new byte[dept.Capacity];

MemoryStream stream = new MemoryStream(buffer);

Foreach (object o in dept) {

formatter.Serialize(stream, o);

}

B.

SoapFormatter formatter = new SoapFormatter();

byte[] buffer = new byte[dept.Capacity];

MemoryStream stream = new MemoryStream(buffer);

formatter.Serialize(stream, dept);

C.

SoapFormatter formatter = new SoapFormatter();

MemoryStream stream = new MemoryStream();

foreach (object o in dept) {

Formatter.Serialize(stream, o);

}

D.

SoapFormatter formatter = new SoapFormatter();

MemoryStream stream = new MemoryStream();

formatter.Serialize(stream, dept);

10)

You need to write a code segment that will create a common language runtime (CLR) unit of isolation within an application. Which code segment should you use?

A.

AppDomainSetup mySetup = AppDomain::CurrentDomain::SetuupInformation;

mySetup.ShadowCopyFiles = "true";

B.

System::Diagnostics::Process myProcess;

myProcess = new System::Diagnostics::Process();

C.

AppDomain domain;

domain = AppDomain::CreateDomain("BraindumpsDomain");

D.

System::ComponentModel::Component myComponent;

myComponent = new System::ComponentModel::Component();

11)

You are developing an application that will use custom authentication and role-based security.

You need to write a code segment to make the runtime assign an unauthenticated principal object to each running thread.

Which code segment should you use?

A.

AppDomain domain = AppDomain::CurrentDomain;

domain.SetPrincipalPolicy(PrincipalPolicy::WindowsPrincipal);

B.

AppDomain domain = AppDomain::CurrentDomain;

domain.SetThreadPrincipal(new WindowsPrincipal(nullptr));

C.

AppDomain domain = AppDomain::CurrentDomain;

Domain.SetAppDomainPolicy(PolicyLevel::CreateAppDomainLevel());

D.

AppDomain domain = AppDomain::CurrentDomain;

Domain.SetPrincipalPolicy(PrincipalPolicy::UnauthenticatedPrincipal);

12)

You need to write a code segment that transfers the contents of a byte array named dataToSend by using a NetworkStream object named netStream. You need to use a cache of size 8,192 bytes. Which code segment should you use?

A.

MemoryStream memStream = new MemoryStream(8192);

memStream.Write(dataToSend, 0, (int) netStream.Length);

B.

MemoryStream memStream = new MemoryStream(8192);

netStream.Write(dataToSend, 0, (int) memStream.Length);

C.

BufferedStream bufStream = new BufferedStream(netStream, 8192);

bufStream.Write(dataToSend, 0, dataToSend.Length);

D.

BufferedStream bufStream = new BufferedStream(netStream);

bufStream.Write(dataToSend, 0, 8192);

13)

You are writing a method to compress an array of bytes. The bytes to be compressed are passed to the method in a parameter named document.

You need to compress the contents of the incoming parameter.

Which code segment should you use?

A.

MemoryStream inStream = new MemoryStream(document);

GZipStream zipStream = new GZipStream(inStream, CompressionMode.Compress);

byte[] result = new Byte[document.Length];

zipStream.Write(result, 0, result.Length);

return result;

B.

MemoryStream Stream = new MemoryStream(document);

GZipStream zipStream = new GZipStream(stream, CompressionMode.Compress);

zipStream.Write(document, 0, document.Length);

zipStream.Close();

return stream.ToArray();

C.

MemoryStream outStream = new MemoryStream();

GZipStream zipStream = new GZipStream(outStream, CompressionMode.Compress);

zipStream.Write(document, 0, document.Length);

zipStream.Close();

return outStream.ToArray();

D.

MemoryStream inStream = new MemoryStream(document);

GZipStream zipStream = new GZipStream(inStream, CompressionMode.Compress);

MemoryStream outStream = new MemoryStream();

int b;

while ((b = zipStream.ReadByte()) != -1) {

outStream.WriteByte((byte)b);

}

return outStream.ToArray();

14)

You need to select a class that is optimized for key-based item retrieval from both small and large collections. Which class should you choose?

A.

OrderedDictionary class

B.

HybridDictionary class

C.

ListDictionary class

D.

Hashtable class

15)

You create a class library that contains the class hierarchy defined in the following code segment.

(Line numbers are included for reference only.)

01. public ref class Employee {

02.

03. public :

04. String Name;

05. };

06.

07. public ref class Manager : public Employee {

08.

09.public :

10.int Level;

11. };

12.

13. public ref class Group {

14.

15. public :

16. array Employees;

17. };

You create an instance of the Group class. You populate the fields of the instance. When you attempt to serialize the instance by using

the Serialize method of the XmlSerializer class, you receive InvalidOperationException.

You also receive the following error message: "There was an error generating the XML document."

You need to modify the code segment so that you can successfully serialize instances of the Group class by using the XmlSerializer class. You also need to ensure that the XML output contains an element for all public fields in the class hierarchy. What should you do?

A.

Insert the following code between lines 14 and 15 of the code segment:

[XmlArrayItem(Type = __typeof(Employee))]

[XmlArrayItem(Type = __typeof(Manager))]

B.

Insert the following code between lines 14 and 15 of the code segment:

[XmlElement(Type = __typeof(Employees))]

C.

Insert the following code between lines 14 and 15 of the code segment:

[XmlArray(ElementName="Employees")]

D.

Insert the following code between lines 3 and 4 of the code segment:

[XmlElement(Type = __typeof(Employee))]

andInsert the following code segment between lines 8 and 9 of the code segment:

[XmlElement(Type = __typeof(Manager))]

16)

You create an application that stores information about your customers who reside in various regions. You are developing internal utilities for this application.

You need to gather regional information about your customers in Canada.

Which code segment should you use?

A.

for each (CultureInfo culture in CultureInfo::GetCultures(CultureTypes::SpecificCultures)) {

// Output the region information...}

B.

CultureInfo cultureInfo = new CultureInfo("CA");

// Output the region information...

C.

RegionInfo regionInfo = new RegionInfo("CA

// Output the region information...

D.

RegionInfo regionInfo = new RegionInfo("");

if(regionInfo.Name == "CA"){

// Output the region information...}

17)

You need to generate a report that lists language codes and region codes.

Which code segment should you use?

A.

for each (CultureInfo culture in

CultureInfo::GetCultures(CultureTypes::SpecificCultures)) {

// Output the culture information...}

B.

CultureInfo culture = new CultureInfo("");

CultureTypes types = culture.CultureTypes;

// Output the culture information...

C.

for each (CultureInfo culture in

CultureInfo::GetCultures(CultureTypes::NeutralCultures)) {

// Output the culture information...}

D.

for each (CultureInfo culture in

CultureInfo::GetCultures(CultureTypes::ReplacementCultures)) {

// Output the culture information...}

18)

You need to identify a type that meets the following criteria: ?

Is always a number.?

Is not greater than 65,535. Which type should you choose?

A.

System.UInt16

B.

int

C.

System.String

D.

System.IntPtr

19)

You are writing code for user authentication and authorization. The username, password, and roles are stored in your application data store.

You need to establish a user security context that will be used for authorization checks such as IsInRole. You write the following code segment to authorize the user.

if (!TestPassword(userName, password))

throw new Exception("could not authenticate user");

String[] userRolesArray =

LookupUserRoles(userName);

You need to complete this code so that it establishes the user

security context. Which code segment should you use?

A.

GenericIdentity ident = new GenericIdentity(userName);

GenericPrincipal currentUser = New GenericPrincipal(ident, userRolesArray);

Thread.CurrentPrincipal = currentUser;

B.

WindowsIdentity ident = new WindowsIdentity(userName);

WindowsPrincipal currentUser = new WindowsPrincipal(ident);

Thread.CurrentPrincipal = currentUser;

C.

NTAccount userNTName = new NTAccount(userName);

GenericIdentity ident = new GenericIdentity(userNTName.Value);

GenericPrincipal currentUser = new GenericPrincipal(ident, userRolesArray);

Thread.CurrentPrincipal = currentUser;

D.

IntPtr token = IntPtr.Zero;

token = LogonUserUsingInterop(username, encryptedPassword);

WindowsImpersonationContext ctx = WindowsIdentity.Impersonate(token);

20)

You are creating a strong-named assembly named Braindumps1 that will be used in multiple applications. Braindumps1 will be rebuilt frequently during the development cycle. You need to ensure that each time the assembly is rebuilt it works correctly with each application that uses it.

You need to configure the computer on which you develop Braindumps1 such that each application uses the latest build of Braindumps1.

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

A.

Create a DEVPATH environment variable that points to the build output directory for the strong-named assembly.

B.

Add the following XML element to the machine configuration file:

C.

Add the following XML element to the machine configuration file:

publicKeyToken="32ab4ba45e0a69a1"

language="en-US" version="*.*.*.*" />

D.

Add the following XML element to the configuration file of each application that uses the strong-named assembly:

E.

Add the following XML element to the configuration file of each application that uses the strong-named assembly:

publicKeyToken="32ab4ba45e0a69a1"

language="en-US" version="*.*.*.*" />

21)

You need to return the contents of an isolated storage file as a string. The file is machine-scoped and is named Settings.dat. Which code segment should you use?

A.

IsolatedStorageFileStream isoStream;

isoStream = new IsolatedStorageFileStream("Settings.dat", FileMode::Open);

String result = (new StreamReader(isoStream)).ReadToEnd();

B.

IsolatedStorageFile isoFile;

isoFile = IsolatedStorageFile::GetMachineStoreForAssembly();

IsolatedStorageFileStream isoStream;

isoStream = new IsolatedStorageFileStream("Settings.dat", FileMode::Open, isoFile);

String result = (new StreamReader(isoStream)).ReadToEnd();

C.

IsolatedStorageFileStream isoStream;

isoStream = new IsolatedStorageFileStream("Settings.dat", FileMode::Open);

String result = isoStream.ToString();

D.

IsolatedStorageFile isoFile;

isoFile = IsolatedStorageFile::GetMachineStoreForAssemblly();

IsolatedStorageFileStream isoStream;

isoStream = new IsolatedStorageFileStream("Settings.dat", FileMode::Open, isoFile);

String result = isoStream.ToString();

22)

You are defining a class named BraindumpsClass that contains several child objects.

BraindumpsClass contains a method named ProcessChildren that performs actions on the child objects. BraindumpsClass objects will be serializable.

You need to ensure that the ProcessChildren method is executed after the BraindumpsClass object and all its child objects are reconstructed.

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

A.

Apply the OnDeserializing attribute to the ProcessChildren method.

B.

Specify that BraindumpsClass implements the IDeserializationCallback interface.

C.

Specify that BraindumpsClass inherits from the ObjectManager class.

D.

Apply the OnSerialized attribute to the ProcessChildren method.

E.

Create a GetObjectData method that calls ProcessChildren.

F.

Create an OnDeserialization method that calls ProcessChildren.

23)

You develop a service application that needs to be deployed. Your network administrator creates a specific user account for your service application. You need to configure your service application to run in the context of this specific user account. What should you do?

A.

Prior to installation, set the StartType property of the ServiceInstaller class.

B.

Prior to installation, set the Account, Username, and Password properties of the ServiceProcessInstaller class.

C.

Use the CONFIG option of the net.exe command-line tool to install the service.

D.

Use the installutil.exe command-line tool to install the service.

24)

You need to write a multicast delegate that accepts a DateTime argument and returns a Boolean value. Which code segment should you use?

A.

public delegate int PowerDeviceOn(bool, DateTime);

B.

public delegate bool PowerDeviceOn(Object, EventArgs);

C.

public delegate void PowerDeviceOn(DateTime);

D.

public delegate bool PowerDeviceOn(DateTime);

25)

You are writing an application that uses isolated storage to store user preferences. The application uses multiple assemblies. Multiple users will use this application on the same computer. You need to create a directory named Preferences in the isolated storage area that is

scoped to the current Microsoft Windows identity and assembly.

Which code segment should you use?

A.

IsolatedStorageFile store;

store = IsolatedStorageFile::GetUserStoreForAssembly();

store.CreateDirectory("Preferences");

B.

IsolatedStorageFile store;

store = IsolatedStorageFile::GetMachineStoreForAssembly();

store.CreateDirectory("Preferences");

C.

IsolatedStorageFile store;

store = IsolatedStorageFile::GetUserStoreForDomain();

store.CreateDirectory("Preferences");

D.

IsolatedStorageFile store;

store = IsolatedStorageFile::GetMachineStoreForApplication();

store.CreateDirectory("Preferences");

26)

You are using the Microsoft Visual Studio 2005 IDE to examine the output of a method that returns a string. You assign the output of the method to a string variable named fName. You need to write a code segment that prints the following on a single line The message: "Test Failed: " The value of fName if the value of fName does not equal "Braindumps" You also need to ensure that the code segment simultaneously facilitates uninterrupted execution of the application. Which code segment should you use?

A.

Debug::Assert(fName == "Braindumps", "Test Failed: ", fName);

B.

Debug::WriteLinelf(fName != "Braindumps", fName, "Test Failed");

C.

if (fName != "Braindumps") {

Debug::Print("Test Failed: ");

Debug::Print(fName);

}

D.

if (fName != "Braindumps") {

Debug::WriteLine("Test Failed: ");

Debug::WriteLine(fName);

}

27)

You are developing a method that searches a string for a substring. The method will be localized to Italy.

Your method accepts the following parameters: The string to be searched, which is named searchListThe string for which to search, which is named searchValue You need to write the code. Which code segment should you use?

A.

return searchList.IndexOf(searchValue);

B.

CompareInfo comparer = new CultureInfo("it-IT")::CompareInfo;

return comparer.Compare(searchList, search Value);

C.

CultureInfo comarer = new CultureInfo("it-IT");

if (searchList.IndexOf(searchValue) > 0) {

return true;

} else {

return false;

}

D.

CompareInfo comparer = new CultureInfo("it-IT")::CompareInfo;

if (comparer.IndexOf(searchList, searchValue) > 0) {

return true;

} else {

return false;

28)

You are creating an application that retrieves values from a custom section of the application configuration file. The custom section uses XML as shown in the following block.

You need to write a code segment to define a class named Role. You need to ensure that the Role class is initialized with values that are retrieved from the custom section of the configuration file. Which code segment should you use?

A.

public class Role : ConfigurationElement {

internal string_ElementName = "name";

[ConfigurationProperty("role")]

public string Name {

get {

return ((string)base["role"]);

}

}

}

B.

public class Role : ConfigurationElement {

internal string_ElementName = "role";

[ConfigurationProperty("name", RequiredValue = true)]

public string Name {

get {

return ((string)base["name"]);

}

}

}

C.

public class Role : ConfigurationElement {

internal string_ElementName = "role";

private String_name;

[ConfigurationProperty("name")]

public string Name {

get {

return_name;

}

}

}

D.

public class Role : ConfigurationElement {

internal string_ElementName = "name";

private String_name;

[ConfigurationProperty("role", RequiredValue = true)]

public string Name {

get {

return_name;

}

}

}

29)

You are developing a method to encrypt sensitive data with the Data Encryption Standard (DES) algorithm. Your method accepts the following parameters:

The byte array to be encrypted, which is named messageAn encryption key, which is named keyAn initialization vector, which is named iv

You need to encrypt the data. You also need to write the encrypted data to a MemoryStream object.

Which code segment should you use?

A.

DES des = new DESCryptoServiceProvider();

des.BlockSize = message.Length;

ICryptoTransform crypto = des.CreateEncryptor(key, iv);

MemoryStream cipherStream = new MemoryStream();

CryptoStream cryptoStream = new CryptoStream(cipherStream,

crypto, CryptoStreamMode.Write);

cryptoStream.Write(message, 0, message.Length);

B.

DES des = new DESCryptoServiceProvider();

ICryptoTransform crypto = des.CreateDecryptor(key, iv);

MemoryStream cipherStream = new MemoryStream();

CryptoStream cryptoStream = new CryptoStream(cipherStream,

crypto, CryptoStreamMode.Write);

cryptoStream.Write(message, 0, message.Length);

C.

DES des = new DESCryptoServiceProvider();

ICryptoTransform crypto = des.CreateEncryptor();

MemoryStream cipherStream = new MemoryStream();

CryptoStream cryptoStream = new CryptoStream(cipherStream,

crypto, CryptoStreamMode.Write);

cryptoStream.Write(message, 0, message.Length);

D.

DES des = new DESCryptoServiceProvider();

ICryptoTransform crypto = des.CreateEncryptor(key, iv);

MemoryStream cipherStream = new MemoryStream();

CryptoStream cryptoStream = new CryptoStream(cipherStream,

crypto, CryptoStreamMode.Write);

cryptoStream.Write(message, 0, message.Length);

30)

You are developing a utility screen for a new client application. The utility screen displays a thermometer that conveys the current status of processes being carried out by the application.

You need to draw a rectangle on the screen to serve as the background of the thermometer as shown in the exhibit. The rectangle must be filled with gradient shading.

Which code segment should you choose?

Exhibit:

A.

Rectangle rectangle = new Rectangle(10, 10, 450, 25);

LinearGradientBrush rectangleBrush = new LinearGradientBrush(rectangle, Color.AliceBlue, Color.CornflowerBlue, LinearGradientMode.ForwardDiagonal);

Pen rectanglePen = new Pen(rectangleBrush);

Graphics g = this.CreateGraphics();

g.DrawRectangle(rectanglePen, rectangle);

B.

Rectangle rectangle = new Rectangle(10, 10, 450, 25);

LinearGradientBrush rectangleBrush = new LinearGradientBrush(rectangle, Color.AliceBlue, Color.CornflowerBlue,

LinearGradientMode.ForwardDiagonal);

Pen rectanglePen = new Pen(rectangleBrush);

Graphics g = this.CreateGraphics();

g.FillRectangle(rectangleBrush, rectangle);

C.

RectangleF rectangle = new RectangleF(10f, 10f, 450f, 25f);

Point[] points = new Point[] {new Point(0, 0), new Point(110, 145)};

LinearGradientBrush rectangelBrush = new LinearGradientBrush(rectangle, Color.AliceBlue, Color.CornflowerBlue, LinearGradientMode.ForwardDiagonal);

Pen rectanglePen = new Pen(rectangleBrush);

Graphics g = this.CreateGraphics();

g.DrawPolygon(rectanglePen, points);

D.

RectangleF rectangle = new RectangleF(10f, 10f, 450f, 25f);

SolidBrush rectangleBrush = new SolidBrush(Color.AliceBlue);

Pen rectanglePen = new Pen(rectangleBrush);

Graphics g = this.CreateGraphics();

g.DrawRectangle(rectangleBrush, rectangle);

31)

You write the following code to implement the BraindumpsClass.MyMethod function.

public class BraindumpsClass {

public int MyMethod(int arg) {

return arg;

}}

You need to call the BraindumpsClass.MyMethod function dynamically from an unrelated class in your assembly. Which code segment should you use?

A.

BraindumpsClass myClass = new BraindumpsClass();

Type t = BraindumpsClass::typeid;

MethodInfom = t.GetMethod("MyMethod");

int i = (int)m.Invoke(this, new array {1});

B.

BraindumpsClass myClass = new BraindumpsClass();

Type t = BraindumpsClass::typeid;

MethodInfom = t.GetMethod("MyMethod");

int i = (int)m.Invoke(myClass, new array {1});

C.

BraindumpsClass myClass = new BraindumpsClass();

Type t = BraindumpsClass::typeid;

MethodInfom = t.GetMethod("BraindumpsClass.MyMethod");

int i = (int)m.Invoke(myClass, new array {1});

D.

Type t =Type::GetType("BraindumpsClass");

MethodInfom = t.GetMethod("MyMethod");

int i = (int)m.Invoke(this, new array {1});

32)

You are creating an application that lists processes on remote computers. The application requires a method that performs the following tasks: Accept the remote computer name as a string parameter named strComputer.Return an ArrayList object that contains the names of all processes that are running on that computer. You need to write a code segment that retrieves the name of each process that is running on the remote computer and adds the name to the ArrayList object. Which code segment should you use?

A.

ArrayList al = new ArrayList();

array procs = Process::GetProcessesByName(StrComputer);

for each (Process proc in procs) {

al.Add(proc);

}

B.

ArrayList al = new ArrayList();

array procs = Process::GetProcesses(StrComputer);

for each (Process proc in procs) {

al.Add(proc);

}

C.

ArrayList al = new ArrayList();

array procs = Process::GetProcessesByName(StrComputer);

for each (Process proc in procs) {

al.Add(proc.ProcessName);

}

D.

ArrayList al = new ArrayList();

array procs = Process::GetProcesses(StrComputer);

for each (Process proc in procs) {

al.Add(proc.ProcessName);

}

33)

You write the following custom exception class named CustomException.

public class CustomException : ApplicationException {

public static int COR_E_ARGUMENT = unchecked((int)0x80070057);

public CustomException(string msg) : base(msg) {

HResult = COR_E_ARGUMENT;

}}

You need to write a code segment that will use the CustomException class to immediately return control to the COM caller. You also need to ensure that the caller has access to the error code. Which code segment should you use?

A.

return Marshal.GetExceptionForHR(CustomException.COR_E_ARGUMENT);

B.

return CustomException.COR_E_ARGUMENT;

C.

Marshal.ThrowExceptionForHR(CustomException.COR_E_ARGUMENT);

D.

throw new CustomException("Argument is out of bounds");