Interview Questions (Scott Hanselman) & Answers (Muhammad Adnan Amanaullah) :)
Let’s answer Scott Hanselman interview questions.
First of all, I
would like to clear, purpose of this post is only educational/sharing
knowledge. May be i am wrong and i would love if any1 of you correct me
through commenting to this post with authentic references. i will
really appreciate the contributors.
Many days back
I saw Scott hanselman website and kept reading his many other blogs and
I found a list of interview questions which he said, he asked usually
and he thinks should be known by .net guys at different levels. I got
many (some wrote and answered as well) interview questions and put them
at single platform just for knowledge sharing @ http://interviewquestion.wordpress.com
. Actually I always like to be part of interviews questions so I
decided to write answer of them according to my little knowledge.
I can say now,
it’s really great learning/evaluation experience when I was
thinking/writing their answers as to just skim them is another thing
than to answer them.
Hmmm now let me
tell you I didn’t answer 100% and didn’t know answer 100% as well so I
just tell you how much I answered by my brain and how much I couldn’t.
I have divided answers in three categories. 1 I knew (with following emoticon)
. 2 I didn’t know with this emoticon
. 3 I know but not sure with this emoticon
so took either help or wrote according to my littleeeeeee knowledge.
At the end of
each question I have mentioned emoticon to mention which I knew and …
if you are interested to know which I knew or not, it would help you to
know rather pinging me on msn
Let me make stats for my knowledge vs questions
Total Questions: 84
I knew: 61 (I think if I dind’t count wrong)
I was not sure about 16
I didn’t know 7
What Great .NET Developers Ought To Know
Everyone who writes code
- Describe the difference between a Thread and a Process?
- Thread is minimum
unit for processor to execute. Collections of threads make process. By
dividing process into threads, processor achieves multi tasking (by
running threads concurrently not parallel). Threads can share memory
but processes can’t share memory. Threads can communicate with each
other of same process without any middle layer but process can’t they
required inter process communication kind of thingy.
- What is a Windows Service and how does its lifecycle differ from a “standard” EXE?
- Windows service is
windows based background process which has no user interface like any
other service (aka daemon in UNIX based environment). Windows service
needs to be installed before executing unlike EXE. Windows service used
to perform such tasks which doesn’t required user interaction but
system status based events like performing tasks at specific intervals
or at different state of system like alarm user when disk is about to
get full to clean up. Windows service is controlled by Service control
manager (SCM) and it started automatically even user didn’t login to
his/her windows account (as SCM already has account credentials so SCM
knows if system start which service needs to start and by which
account), where as EXE is controlled by OS and runs only when user get
login using windows account.
- What is the maximum amount of memory any
single process on Windows can address? Is this different than the
maximum virtual memory for the system? How would this affect a system
design?
- Single process on windows can address different
amount of memory as it depends upon systems (32bit/64bit processor) and
OS as well. Yes process memory consumption size can be different from
maximum virtual memory size. If software/process code is written by
keeping 64 bit processor (as 64 bit processor support more than double
memory) then it won’t be able to run that process on 32 bit system.
- What is the difference between an EXE and a DLL?
- Exe is executable and independent program/process
to run which has its own reserved memory space whereas DLL (Dynamic
Link Library) is neither executable and not even independent, it used
by other DLL/program.
- What is strong-typing versus weak-typing? Which is preferred? Why?
- Strong typing means a person who has great typing skills and that chat do too much chatting
just joking. Strong typing means when code compiles, type rules
enforced strictly according to their data assigned to them whereas weak
typing is quite opposite of this definition. JavaScript/C/C++ is weak
typing but .net based languages are strongly typed. Strong typing is
preferred by means of less run time errors risk and efficient during
execution of program but not during compile time. - Corillian’s product is a “Component
Container.” Name at least 3 component containers that ship now with the
Windows Server Family.
- I am not sure either I understood this question
in correct way. I think answer would be Windows Shell, Windows
Explorer, IIS (happy guessing)
- What is a PID? How is it useful when troubleshooting a system?
- PID is Process ID
which is unique to identify any process within a system. Whilst
troubleshooting we can kill process through its PID.
- How many processes can listen on a single TCP/IP port?
- I think single process can only hold handler of
any port at a time means can listen on single port. Once I got error
when I ran my web application as another application (skype) was using
that port. It make sense as well, ports are like doors if two people
talk on specific door and third one comes up then no privacy
(divorce ratio would be dramatically raised) - What is the GAC? What problem does it solve?
- GAC stands for Global Access Cache where
shareable/public assemblies (DLL) stored to be used by multiple
programs. It gives a shared platform for programs to use single
assembly and can store same assembly (of same name) with different
versions and can help to solve DLL HELL.
Mid-Level .NET Developer
· Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.
· ——————————????????????
· Describe what an Interface is and how it’s different from a Class.
· An
interface is strictly a Contract without implementation means interface
can only declare properties or methods. Class can have implementation
of its methods, can have different level of access identifiers whereas
interface’s properties or methods can have only public access
identifier and can implement class and multiple interfaces.
· What is Reflection?
Reflection is mechanism to load dynamically assembly at runtime and
using assembly Meta data can access its namespace, class and their
properties, methods and even events.
· What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?
· Remoting
assumes the other end is .NET. This is because .NET remoting using SOAP
uses the SoapFormatter to serialize data. SoapFormatter embeds the type
information required to deserialize the object into the message itself.
This requires that the client and the server must have access to this
assembly. Remoting believes in the .NET Type System. Remoting believes
in sharing types and assemblies. Remoting can support DCOM style Client
Activated Objects which are stateful. The use of CAOs though have to be
carefully thought about because CAOs cannot be load balanced. ASMX
model does not assume that the other end is .NET. ASMX uses
XmlSerializer to serialize data. Xmlserailizer believes that the XML
Type System, that is the XSD is superior and works on serializing data
conforming to a schema. In other words XML Web Services believe in
sharing schema and contracts over types and assemblies. This makes the
Web Services interoperable. ASMX services are usually stateless. Ref
· Are the type system represented by XmlSchema and the CLS isomorphic?
· No, there
is some impedence mismtach. That’s the reason you ned IXmlSerializable
to help the XmlSerializer. XSD is not a type system in the traditional
sense. Ref
· Conceptually, what is the difference between early-binding and late-binding?
· Early
binding means compiler get information of type calling/path execution
during compilation of code and in late binding compiler doesn’t get
that information but this information determined at runtime/execution
time.
· Is using Assembly.Load a static reference or dynamic reference?
· Its dynamic load (Reflection)
· When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?
· Difference
is only about binding. LoadFrom is flexible and if it doesn’t get
assembly where it was pointing then it can be redirect to another path
on the other hand LoadFile points/depends upon strictly to
reference/path of the assembly defined, don’t redirect in case of
failure.
· What is an Asssembly Qualified Name? Is it a filename? How is it different?
· Assembly
qualified name contains assembly name, version, token key whereas
filename is simple file name physically on file system. Assembly names
store as Meta data as is very important by means of defining scope.
· Is this valid? Assembly.Load(”foo.dll”)
· Ofcouse NOT
as its file name not Assembly qualified name which is required.
· How is a strongly-named assembly different from one that isn’t strongly-named?
· Strongly
named assembly have strong names due to public token key so can be
stored in GAC (shared environment) and can be referred by multiple
programs whereas non-strongly name can’t be stored in GAC.
· Can DateTimes be null?
· Before
.net 2.0 it was not possible as datetime/integer… are struct/value
types which can’t be null but due to nullable types now its possible.
· What is the JIT? What is NGEN? What are limitations and benefits of each?
· I
remember, once I was being interviewed at very big name (company),
interviewer asked me about .net IL compilation… I start telling and
talked about JIT as well after listening me he said hmmm JIT exist in
Java technologies not .net technologies, I said no I read about it and
it does but he kept negating me so I got quite and said Ok. Anyhow JIT
stands for Just in time compiler it compiles code into native code to
execute by processor in three different techniques. It compiles code
just before code required to be run which makes execution little slow
(depends) so to avoid that we use NGEN which converts IL into native
code like JIT but during deployment. It comes with large image which
also includes that codes compiled version which is not being calling
frequently.
· How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?
· Object
life time divides into three different generations, 1 short term and 2
long terms so manage accordingly. Non deterministic finalization means
GC calls finalize method of object not right after object goes out of
scope rather when GC got idle time to prioritize it.
· What is the difference between Finalize() and Dispose()?
· Finalize called by GC and Dispose called by programmer to free up resources.
· How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?
· Using
statement is quite handy and makes code quite efficient as right after
end of using statement object created/declared in that statement
disposed automatically means dispose method get called in deterministic
way to free up memory. IDisposible is interface which classes
implements to dispose unmanaged resources in deterministic manner.
· What does this useful command line do? tasklist /m “mscor*”
· It will list down all the processes that have loaded modules which start from mscor… hosting by the .net environment.
· What is the difference between in-proc and out-of-proc? J
· As
name implies in proc means loading in the same process memory domain of
invoker/host, it is fast technique but less reliable than out proc in
case of any fault/exception occurs. Out proc is opposite to in proc
definition and as loading out of the host process so is not depending
and could be safe in host process failure for some reason.
· What technology enables out-of-proc communication in .NET?
· .net remoting through marshalling
· When you’re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?
· Aspnet_wp.exe in case of winxp and win2k but w3pw.exe in case of win2k3.
Senior Developers/Architects
· What’s wrong with a line like this? DateTime.Parse(myString);
· There
is nothing wrong necessarily but could be wrong means no error no
exception but some logical error like unexpected result could be
produce due to lack of locale/culture info.
· What are PDBs? Where must they be located for debugging to work?
· PDB
stands for Program database store debugging symbols and meta
information for debugging. Normally they are located at bin or debug
folder.
· What is cyclomatic complexity and why is it important?
· —————————–????????????????????
· Write a standard lock() plus “double check” to create a critical section around a variable access.
· Object objLock; bool isLocked = true; if (isLocked) {lock(objLock){if (isLocked) {//bingooooo}}}}
· What is FullTrust? Do GAC’ed assemblies have FullTrust?
· FullTrust means newly happily marriage
and in .net it means Assembly have full access of system resources
(which is quite dangerous and in shared hosting domain only medium
trust level is allowed). YES GACed assemblies have fulltrust.
· What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?
· It
let user know what your code/program required to do so and either it’s
allowed to do operation or not so it becomes user friendly by means of
security permissions.
· What does this do? gacutil /l | find /i “Corillian”
· I
knew about gacutil only not about any other parameters but I think I
can guess so I think gacutil /l means list of assemblies in GAC (as
gacutil used to install/uninstall assemblies in gac and I did that
operation ONLY) find /I “Corrilian” seems to look for Corillian named
assemblies and not sure about /I but I think in other commands it means
ignore case hope it means same here too
· What does this do? sn -t foo.dll
· SN
stands for strong name and used to generate strong names of assemblies
but not sure about –t param here but my searching told me its for Token
Key.
· What ports must be open for DCOM over a firewall? What is the purpose of Port 135?
· DCOM
is distributed COM technology which used to remote procedure call and
it used port 135 by default. 135 is port of Remote procedure call
Service and as DCOM is OO based RPC mechanism so no wonder about it
by the way good question can kill any 1J
· Contrast OOP and SOA. What are tenets of each?
· OOP
tenets are Polymorphism, inheritance, abstraction…. And SOA tenets
would be (not much sure) as it based on services so discovering/access,
interoperatibility, security, distributeable
· How does the XmlSerializer work? What ACL permissions does a process using it require?
· XmlSerializer
used read/write interfaces to deserialize/serialize respectively xml
based data so it’s understood that it uses reflection.
· Why is catch(Exception) almost always a bad idea?
· Catch(exception)
is always a time consuming and somehow it means programmer
knows/expecting there would/can be some exception so better approach is
to use checks as much as programmer can rather catch exception but
ofcourse its unavoidable.
· What is the difference between Debug.Write and Trace.Write? When should each be used?
· As
names implies .write means printing something and debug would be used
whilst debugging and Trace is useable at release mode and according to
my knowledge during release mode if debug statement is used it would be
ignored gracefully so chill.
· What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?
· Debug
build contains debug symbols in (pdb) files and debugging related meta
information which release build doesn’t that’s why more compact and
efficient.
· Does JITting occur per-assembly or per-method? How does this affect the working set?
· JITing
occue per method as NGEN make image of whole assembly at once. JITing
degrade efficiency if method is very highly coupled means dependent
upon other methods (call/invoke other methods which were not JIT)
· Contrast the use of an abstract base class against an interface?
· Aaaaah typical interview question but thanks there is something typical scott asked
. abstract
class can have implementation of methods at different access levels
whereas interface can have only declarations of methods and must be
public, abstract class is inheritable. I think interesting and bit
difficult contract would be between PURE abstract class and interface.
Sounds good?
· What is the difference between a.Equals(b) and a == b?
· Equals checks type as well as it compares on heap to objects whereas == doesn’t, it just check value on stack.
· In the context of a comparison, what is object identity versus object equivalence?
· Identity means two references on stack point to same address of heap whereas object equivalence means objects has same value.
· How would one do a deep copy in .NET?
· Normally
I hate typical interview questions as this but in this (scott) case I
am more than happy to hear. Anyhow Implement ICloneable simple.
· What is boxing?
· To convert value type into reference type is called boxing.
· Is string a value type or a reference type?
· It’s
not even again typical interview question but also for heaven sake
scott it’s not suppose to be known by some senior/architect level of
.net guru. Anyhow string is reference type due to its any length of
size.
· What is the significance of the “PropertySpecified” pattern used by the XmlSerializer? What problem does it attempt to solve?
· ————————?????????????
· Why are out parameters a bad idea in .NET? Are they?
· Ofcourse
they are not encouraging as out keyword is somehow violating the rule
of returning single value which keep function easy to readable and
debuggable as we know only there is single point to return value and
somehow caller can send any vulnerable value which always should be
validate. Anyhow there are many solutions like using array (if return
values are of same type or ENUM if feasible or Collection or Class with
multiple properties…)
· Can attributes be placed on specific parameters to a method? Why is this useful?
· Yes I have seen that being using in case of .net remoting but didn’t use/need much sooo.
C# Component Developers
· Juxtapose the use of override with new. What is shadowing?
· Overriding
means giving implementation of virtual/abstract/overrideable method in
derived class and if we use new it means it can’t be access through by
any other class ref/object. Shadowing is somehow opposite to overriding
as it lets redefine method implementation with signature as well.
· Explain the use of virtual, sealed, override, and abstract.
· Through
Virtual keyword, we enforce programmer of derive class to override this
function. Sealed make sure that class won’t be able to inherit (you may
say Such mother who can’t birth a baby
) and through abstract class, we are able to define methods as abstract
to make them must overrideable by child classes and don’t let anyone to
instantiate it.
· Explain
the importance and use of each component of this string: Foo.Bar,
Version=2.0.205.0, Culture=neutral, PublicKeyToken=593777ae2d274679d
· Foo.Bar
Assembly name, Version defines its version in following pattern (Major,
Miner, Build) to track version number of that assembly, Culture
specifies culture for locale settings and publickeytoken makes it
unique so could be kept and accessed in shared environment.
· Explain the differences between public, protected, private and internal.
· Public
is shareable so anyone can access no matter out of the
class/assembly/assembly. Through Protected you can only access within
class or from child classes and through internal you can access within
the assembly only.
· What benefit do you get from using a Primary Interop Assembly (PIA)?
· —————————–?????????????????
· By what mechanism does NUnit know what methods to test?
· Using attributes
· What is the difference between: catch(Exception e){throw e;} and catch(Exception e){throw;}
· Throw also return stack trace which throw e doesn’t
· What is the difference between typeof(foo) and myFoo.GetType()?
· First 1 takes type name and return result at compile time whereas 2nd 1 takes object and return type at runtime using reflection ofcourse.
· Explain
what’s happening in the first constructor: public class c{ public
c(string a) : this() {;}; public c() {;} } How is this construct
useful?
· First one calls the base contructor.
· What is this? Can this be used within a static method?
· this keyword points to current object and as static methods can’t be invoked through object sooo
ASP.NET (UI) Developers
· Describe how a browser-based Form POST becomes a Server-Side event like Button1_OnClick.
· I
am not certain but I think when we need to submit some information or
manipulate data at server side we use POST method which transmit client
side information to server side in Request object and send the
information to server and server perform task according to information
given by client so in this case Button1_OnClick is transferred to server and it’s handler called the relevant method.
· What is a PostBack?
· Postback is way to send client side information to server after loading it.
· What is ViewState? How is it encoded? Is it encrypted? Who uses ViewState?
· ViewState stores information so it could be accessible after postback and information could be persisted after
any number of postbacks but only within the scope of page. It encoded
into Base64 format. It can be encrypted. Controls uses viewstate to
store control state and data to be preserved after postback.
· What is the <machinekey> element and what two ASP.NET technologies is it used for?
· machinekey
defines unique key which could be use by session and cache so if site
is cluster based or single sign on based then it’s very useful.
· What three Session State providers are available in ASP.NET 1.1? What are the pros and cons of each?
· In-proc, out-proc, sqlserver
· What is Web Gardening? How would using it affect a design?
· If
server has multiple processors and requests traffic is dividing
accordingly that is called web gardening. If server is using external
resources (like sql server, web services, logging) then it could be
very useful.
· Given
one ASP.NET application, how many application objects does it have on a
single proc box? A dual? A dual with Web Gardening enabled? How would
this affect a design?
· HTTPApplication
object with single key based would be only 1 per worker process so in
case of single processor box ONLY 1, in case of dual processor box
without webgardening there would be only 1 single worker process so
again single object but in case of web gardening two worker process
means 2 objects. So need to have machine key otherwise …
· Are
threads reused in ASP.NET between reqeusts? Does every HttpRequest get
its own thread? Should you use Thread Local storage with ASP.NET?
· ASP.NET
is MTA based so multiple threads are possible but I remember once I
tried to call methods through callback based async delegates which
makes it run on separate thread so when I tried that I lost httpcontext
L in that thread. So each thread gets its own thread and usage is depends upon need.
· Is the [ThreadStatic] attribute useful in ASP.NET? Are there side effects? Good or bad?
· I
never used it but I think I got my just above mentioned problem’s
solution that we can share httpContext through this attribute in
multiple threads
· Give an example of how using an HttpHandler could simplify an existing design that serves Check Images from an .aspx page.
· We
can simply make httphandler for such specific requirements as .aspx are
nto specialized for images based web page which we could make and make
things efficient and manipulate response according to our need. If page
is based upon images only and needs to show loads of images thumbnail
and such features we can make specific httpHandler for such pages to
customize response and have more command on request.
· What
kinds of events can an HttpModule subscribe to? What influence can they
have on an implementation? What can be done without recompiling the
ASP.NET Application?
· HTTPModule
subscribe to Request life cycle kinds of events like
beginRequest,EndRequest,Session,… They are useful to manipulate Request
and generate Response according to state and lifecycle. They are
separate DLL which are referred by asp.net application and if we change
HTTPModule and recompile it we don’t need to recompile our whole
application. So they are plugged like plugins
· Describe ways to present an arbitrary endpoint (URL) and route requests to that endpoint to ASP.NET.
· I
am sure either I interpreted this question in right way but here is the
answer according to my understanding about this question. URL could be
define in couple of ways relative path and absolute path and request
could be route in multiple ways using Redirect, Transfer, URL Rewrite…
· Explain how cookies work. Give an example of Cookie abuse.
· Cookie
stored at client side and readable by any user if it’s not encrypted,
if you stored some important information about client data at server
any other site could read cookies and get that information.
· Explain the importance of HttpRequest.ValidateInput()?
· It
checks integrity of data in Request object (Form, Querystring,
Cookies), you can prevented by XSS types of attacks and validate
request data to see so there is no malicious input
· What kind of data is passed via HTTP Headers?
· HTTP Header contains information about browser and some of page like browser name, version, page size, mime type, cookies
· Juxtapose the HTTP verbs GET and POST. What is HEAD? J
· Get
is used when we don’t need to do manipulation at server side and have
nothing really secret information to send in querystring as it send
information through querystring which is limited so input can’t be very
long like article
but it’s pretty fast as compare to POST as post sends information in
hidden fields and preferred in case of manipulation at server side.
Using Head we just send page header information not the actual
contents/body.
· Name and describe at least a half dozen HTTP Status Codes and what they express to the requesting client.
· Very famous I just remember like 404 error page (page not found) 200 for OK, 500 Server not found
· How does if-not-modified-since work? How can it be programmatically implemented with ASP.NET?
Explain <@OutputCache%> and the usage of VaryByParam, VaryByHeader.
· No
idea about the if-not-modified thingy but can tell about OutputCache
which is directive used for caching contents and tells server that
Header information could be change by VaryByHeader Param and Parameter
could be change in query string using VaryByParam so it get different
versions for different header (like browsers) and parameters
respectively.
· How does VaryByCustom work?
· Can output different pages from cache on the basis of change of state of any control or value or object within that page
· How
would one implement ASP.NET HTML output caching, caching outgoing
versions of pages generated via all values of q= except where q=5 (as
in http://localhost/page.aspx?q=5)?
· <@OutputCache VaryByParam=”q” %>
Please dont’ forget to correct me if I am wrong and please give references as well with your answers.
Thanks