Вы находитесь на странице: 1из 24

What is the main difference between an ASP.

NET Web application and a traditional


Windows application.
An ASP.NET Web application runs under common language runtime using managed code where as
Unmanaged Windows application runs under Windows using unmanaged code. 

What are the two main parts of the .NET Framework?


The two main parts of the .NET Framework are

1. The common language runtime (CLR).


2. The .NET Framework class library.

When can’t you use ASP.NET to create a Web application?


When you are developing for non–Microsoft Windows Web servers, such as Linux/Apache. 

List the four major differences between Web and Windows applications.
 Web forms cannot use the standard Windows controls. Instead, they use server controls, HTML
controls, user controls, or custom controls created specially for Web forms.
 Web applications are displayed in a browser. Windows applications display their own windows
and have more control over how those windows are displayed.
 Web forms are instantiated on the server, sent to the browser, and destroyed immediately.
Windows forms are instantiated, exist for as long as needed, and are destroyed.
 Web applications run on a server and are displayed remotely on clients. Windows applications
run on the same machine they are displayed on.

Describe the life cycle of a Web application: When are Web forms instantiated and how long do
they exist?
A Web application starts with the first request for a resource within the application’s boundaries. Web
forms are instantiated when they are requested. They are processed by the server and are abandoned
immediately after the server sends its response to the client. A Web application ends after all client
sessions end. 

How do you preserve persistent data, such as simple variables, in a Web application?
You can preserve data in state variables, such as ApplicationState, SessionState, or ViewState. 

How does the .NET Framework organize its classes?


The .NET Framework uses namespaces to organize its classes. 

In Visual Basic .NET, what is the difference between a class module and a code module?
Class modules are instantiated at run time to create objects that provide separate storage for variables
and properties in each instance. Code modules do not have instances, so any module-level variables
they use are shared among calls to the module’s procedures. 

In Visual C#, how do you declare a method to make it available without having to first instantiate
an object from the class?
To create a method that can be called without instantiating an object, declare that method as static. 

How do you call a member of a base class from within a derived class?
To refer to a member of a base class in Visual Basic .NET, use the MyBase keyword. To refer to a
member of a base class in Visual C#, use the base keyword. 
Where would you save the following data items so that they persist between requests to a Web
form?

 A control created at run time


 An object that provides services to all users
 User preferences

 Save controls created at run time in the Page object’s ViewState.


 Save objects that provide services to all users in the Application state.
 Save user preferences in SessionState.

What is the main difference between the Button server control and the Button HTML control?
When clicked, the Button server control triggers an ASP.NET Click event procedure on the server. The
Button HTML control triggers the event procedure indicated in the button’s onclick attribute, which runs
on the client. 

How do you get several RadioButton controls to interoperate on a Web form so that only one of
the RadioButton controls can have a value of True/true at any given time?
Set the GroupName property of each RadioButton to the same name. 

Why does ASP.NET perform validation on both the client and the server?
Client-side validation helps avoid round-trips to the server. Validating on the client ensures that the data
is valid before it is submitted, in most cases. However, because validation might be turned off (or
maliciously hacked) on the client, data must be revalidated on the server side. This provides full
assurance that the data is valid while avoiding as many round-trips as possible. 

What types of validation would you use to verify that a user entered a valid customer number?
You would use a RequiredFieldValidator and a RegularExpressionValidator. If you have access to a list
of expected customer numbers, you could replace the RegularExpressionValidator with a
CustomValidator that checked the list. 

What is wrong with the following line of code?


Server.Transfer("Default.htm");
You can’t use the Transfer method with HTML pages. It works only with .aspx pages. 

Why can’t you open a new browser window from within server code?
Server code executes on the server, whereas the new window is created on the client. You need to use
client-side code to do things that affect the client, such as upload files, display new windows, or navigate
back in history. 

What steps would you follow and what objects would you use to quickly find the number of
records in a database table?
There are two ways to accomplish this task:

 Use a database connection and a command object to execute a SQL command that re-turns the
number of rows in the table.
 Use a database connection and data adapter object to create a data set for the table, and then
get the number rows in the data set.

How do typed data sets differ from untyped data sets, and what are the advantages of typed data
sets?
Typed data sets use explicit names and data types for their members, whereas untyped data sets use
collections to refer to their members. The following examples show a typed reference vs. an untyped
reference to a data item:
// Typed reference to the Contacts table's HomePhone column.
DataSet1.Contacts.HomePhoneColumn.Caption = "@Home";
// Untyped reference to the Contacts table's HomePhone column.
DataSet1.Tables["Contacts"].Columns["HomePhone"].Caption = "@Home";
Typed data sets do error checking at design time. This error checking helps catch typos and type
mismatch errors, which would be detected only at run time with untyped data sets. 

How do you call a stored procedure?


Create a command object, set the object’s CommandText property to the name of the stored procedure,
and set the CommandType property to StoredProcedure. To execute the stored procedure, use the
command object’s ExecuteNonQuery, ExcecuteScalar, ExecuteReader, or ExecutelXmlReader method.
For example, the following code calls the Ten Most Expensive Products stored procedure on the
Northwind Traders database:
// Create a connection for NorthWind Trader's database.
SqlConnection connNWind = new SqlConnection("integrated security=SSPI;" + 
"data source=(local);initial catalog=Northwind");
// Create a command object to execute.
SqlCommand cmdTopTen = new SqlCommand(connNWind);
cmdTopTen.CommandText = "Ten Most Expensive Products";
// Set the command properties.
cmdTopTen.CommandType = CommandType.StoredProcedure;
// Create a data reader object to get the results.
SqlDataReader drdTopTen;
// Open the connection.
connNWind.Open();
// Excecute the stored procedure.
drdTopTen = cmdTopTen.ExecuteReader();

Explain the difference between handling transactions at the data set level and at the database
level.
Data sets provide implicit transactions, because changes to the data set aren’t made permanent in the
database until you call the Update method. To handle transactions in a data set, process the Update
method and check for errors. If errors occur during an update, none of the changes from the data set is
made in the database. You can try to correct the error and resubmit the update, or you can roll back the
changes to the data set using the RejectChanges method. 

Databases provide explicit transactions through the Transaction object. You create a Transaction object
from a database connection and then assign that Transaction object to the commands you want to
include in the transaction through the command object’s Transaction property. As you perform the
commands on the database, you check for errors. If errors occur, you can either try to correct them and
resubmit the command, or you can restore the state of the database using the Transaction object’s
RollBack method. If no errors occur, you can make the changes permanent by calling the transaction
object’s Commit method. 

Explain why exception handling is important to a completed application.


When an unhandled exception occurs in an application, the application stops—the user can’t proceed,
and any work he or she did immediately prior to the exception is lost. Exception handling provides a way
to intercept and correct unusual occurrences that would otherwise cause these problems. 

List two different exception-handling approaches in ASP.NET Web applications.


Exceptions can be handled in exception-handling blocks using the Try, Catch, and Finally keywords in
Visual Basic .NET or the try, catch, and finally keywords in Visual C#. They can also be handled using
Error event procedures at the Global, Application, or Page levels using the Server object’s GetLastError
and ClearError methods. 

Describe the purpose of error pages and why they are needed.
Because Web applications run over the Internet, some exceptions occur outside the scope of the
application. This means that your application can’t respond directly to these exceptions. These types of
exceptions are identified by HTTP response codes, which IIS can respond to by displaying custom error
pages listed in your application’s Web.config file. 

Explain why tracing helps with exception handling.


Tracing allows you to record unusual events while your application is running, without users being aware
of it. If an unanticipated exception occurs, your application can write a message to the trace log, which
helps you diagnose problems during testing and after deployment. 

Write the HTML for a hyperlink that will send mail when the user clicks the link.
<a href="mailto:you@pragim.com?SUBJECT=Sending from a client&BODY=Some message text.">
Send mail </a>

Write the code that creates a cookie containing the user name Rob Young and the current date to
the user’s computer. Set the cookie to remain on the user’s computer for 30 days.
HttpCookie cookUserInfo = new HttpCookie("UserInfo");
CookUserInfo["Name"] = "Rob Young";
CookUserInfo["Time"] = DateTime.Now.ToString();
cookUserInfo.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(cookUserInfo);

What attribute do you use to hide a public .NET class from COM?
Use the ComVisible attribute to select which public .NET classes and members are visible to COM. This
attribute applies hierarchically for the assembly, class, and member levels.

Why can’t you open a new browser window using server-side code? How would you display a
page in a new window with a client-side script?
Server-side code can execute tasks only on the server. To perform a task on the client’s computer, such
as opening a new browser window, the code needs to run on the client. 

You can open a new window using the DOM window object. For example, the following HTML Button
control opens a Help page in a new window: 
< button id="butHelp" onclick="window.open('help.aspx', 'help', 'height=200,width=300')" > Help </
button>

How do you declare an unmanaged procedure within .NET?


Use the DllImport attribute or a Visual Basic .NET Declare statement to declare an unmanaged
procedure for use with a .NET assembly. The DllImport attribute is found in the
System.Runtime.InteropServices namespace. 

Which ASP.NET authentication mode is best suited to identifying and authorizing users who
belong to a corporate network?
Windows authentication is best suited to authenticating users of a corporate network because it uses the
accounts and permissions that already exist for network users. 

What is the difference between Windows and Forms authentication user lists in Web.config?
User lists for Windows authentication are included in the <authorization> element of Web.config. User
lists for Forms authentications are included in the <credentials> element of Web.config or as part of an
external users database or file. 

How do you require authentication using the Web.config file?


Include the following <authorization> element to require authentication:
<authorization>
  <deny users="?" />
</authorization>

How do you run a Web application using the permission set of an authenticated user?
Use the identity element in Web.config to execute code using the authenticated user’s account. For
example:
<!-- Impersonate the authenticated user -->
<identity impersonate="true" />

How does the Secure Sockets Layer (SSL) provide security in a Web application?
SSL protects data exchanged between a client and a Web application by encrypting the data before it is
sent across the Internet. 

How do you begin and end secure communication via SSL?


To begin secure communication, specify https in an address. For example:
<a href="https://www.pragim.com/home.aspx">Secure page.</a>
To end secure communication, specify http. For example:
<a href="http://www.pragim.com/home.aspx">Not secure.</a>

What permissions do Web applications run under by default?


By default, Web applications run as the ASPNET user, which has limited permissions equivalent to the
Users group. 

Why is the Machine.config file important to deployed Web applications?


The Machine.config file controls many aspects of how Web applications run, including how processes are
recycled, what types of request queue limits are imposed, and what interval is used when checking if
users are still connected. 

How do you configure a setup project to install an application over the Web?
To configure a setup project to install an application over the Web, select the Web Bootstrapper option
from the setup project’s properties. This setting allows the Windows Installerto be downloaded and
installed over the Web. 

How do you distribute shared components as part of an installation program?


Shared components should be included as a merge module within the setup project. Merge modules
manage the installation of shared components so that they’re not unnecessarily overwritten and so that
they can be safely removed when no longer used. Unlike regular setup projects, merge modules can’t be
installed by themselves—they can be installed only as part of an application installation. 

How does deploying to a Web farm or a Web garden affect Session state in a Web application?
Web applications that are deployed to a Web farm or a Web garden need to identify a Session state
provider in their Web.config file. This is because a single client’s requests can be directed to different
processes over the course of his or her session. The Session state provider allows each different process
to access the client’s Session state. 

How do unit, integration, and regression testing relate to each other?


Unit testing is the foundation that ensures that each piece of code works correctly. Integration testing
extends this concept by verifying that pieces work together without errors. Regression tests are made up
of the existing unit and integration tests, which are run on a regular schedule to assure that new code did
not break previously working code. 

Why is load testing likely to be more important for a Web application than for a stand-alone
Windows application?
Because Web applications can be public on the Internet, they can have hundreds, thousands, or even
millions of users. Load tests let you simulate the expected demand to locate resource conflicts,
performance bottlenecks, and other problems that aren’t apparent in single-user tests. 

What is the difference between the Debug and Trace classes?


Under the default environment settings, code using the Debug class is stripped out of release builds,
while code using the Trace class is left in. The classes are otherwise equivalent. 

What are the two special steps you need to take to ensure that a COM component can use a
component from a .NET assembly?
To use a .NET component from a COM tool, such as VBScript, you must:
 Register the .NET assembly in the system registry using RegAsm.exe.
 Make sure that the COM component can find the .NET assembly, either by placing the .NET
assembly in the global assembly cache, by placing the two components in the same folder, or by
following the other assembly-probing rules.

When do you generally create a web user control?


You generally create a web user control when you want to create a group of controls that can be reused
throughout a project to perform some logical unit of work. 

When do you generally create a custom control ?


You generally create a custom control when you want to combine one or more existing controls into a
compiled assembly that can be easily reused in many different projects. 

How is deriving important to creating custom Web controls?


Both composite and rendered custom controls are derived from the WebControl base class. That class
provides the methods that you override to create the appearance of the custom control. 

What is the most important method to override when you’re creating a composite custom
control?
You override the CreateChildControls method to add existing controls to a composite custom control. 

How is raising a post-back event in a composite control different from raising a post-back event
in a rendered control?
In a composite control, you can use one of the contained controls to raise a post-back event. In a
rendered control, you must implement the IPostBackEventHandler interface and write a client-side script
to raise a post-back event. 

Write a directive to cache responses for a Web form for 30 seconds, storing different cache
responses based on the value of the lstNames control.
<%@ OutputCache Duration=”30” VaryByParam=”lstNames” %>
A Web form uses fragment caching to store a frequently used user control. At run time, an Object
not found error occurs whenever the page is refreshed. What is a likely cause of the error?
The most likely cause is that the user control is referenced in code after it has been cached. Once
cached, a user control’s properties and methods are no longer available. 

How can you detect when application data is about to be removed from the cache?
Use the onRemoveCallback delegate. 

What is the advantage of using CSS rather than in-line styles for formatting a Web application?
Using CSS allows you to maintain formatting separately from the content of your Web forms, so changes
are easier to make and consistency is easier to maintain. 

Why would you create a style for a class rather than for an HTML element?
You create style classes when you want to apply the same formatting to different types of elements within
an application. For example, you might want to create an emphasis style class that applies the same
formatting to any text, control, heading, or image that you want to draw the user’s attention to. 

How do CSS and XSL relate to each other when it comes to formatting a Web application?
CSS and XSL are complementary techniques for formatting. CSS determines the font, color, size,
background, and other appearance aspects of HTML elements on a Web page. XSL is used to transform
XML files into HTML output. In this way, XSL controls the position and appearance of items based on
their content. Used together, XSL performs the high-level tasks of composition and layout while CSS
performs the low-level tasks of applying fonts, colors, and other appearance features 

What are the differences between HTML and XML?


1. HTML uses predefined element names, such as <p> and <br>. In XML, you create your own
element names to identify hierarchical nodes of data.
2. XML syntax is much stricter than HTML: elements must always have end-tags, element names
are case sensitive, attribute values must always be enclosed in quotation marks, and nested
elements must be terminated within their parent elements.
3. XML identifies data conceptually based on the data’s content, rather than based on the type of
formatting to apply.

Which HTML attribute does the server control’s ToolTip property map to in the HTML rendered by
ASP.NET?
The ToolTip property is rendered as the title attribute at run time. 

What is the difference between the CurrentCulture property and the Current UICulture property?
The CurrentCulture property affects how the .NET Framework handles dates, currencies, sorting, and
formatting issues. The CurrentUICulture property determines which satelliteassembly is used when
loading resources. 

How do you detect the user’s culture?


Use the Request object’s UserLanguages array. The value at element 0 corresponds to one of the culture
codes used by the CultureInfo class. For example: SLang = Request.UserLanguages(0)
SLang = Request.UserLanguages(0)

What is a neutral culture?


Neutral cultures represent general languages without region-specific differences, such as currency. For
example, the “es” culture code represents Spanish.
What are the two broad classifications of types in .NET?
2 broad classifications of types in .NET

 Value Types which include simple types (e.g., char, int, and float), enum types, and struct types
 Reference Types which class types, interface types, delegate types, and array types

What are the 2 different types of strings we have in .NET?


The following are the 2 different types of strings we have in .NET

 Strings of type System.String. These strings are immutable which can affect the


performance incase if we are doing intense string manipulations in our application.
 Strings of type System.Text.StringBuilder . These strings are mutable. If the application
invloves intense string manipulations it is good practice to use
System.Text.StringBuilder class over System.String
Vb.net

What is a Windows Service and how does its lifecycle differ from a “standard” EXE?

Windows service is a application that runs in the background. It is equivalent to a NT service.


The executable created is not a Windows application, and hence you can’t just click and run it . it needs
to be installed as a service, VB.Net has a facility where we can add an installer to our program and then
use a utility to install the service. Where as this is not the case with standard exe

How can a win service developed in .NET be installed or used in Win98?

Windows service cannot be installed on Win9x machines even though the .NET framework runs on
machine.

Web Services Interview Question »

| 0 Comments |

Can you give an example of when it would be appropriate to use a web service as opposed to non-
serviced .NET component
Web service is one of main component in Service Oriented Architecture. You could use web services
when your clients and servers are running on different networks and also different platforms. This
provides a loosely coupled system. And also if the client is behind the firewall it would be easy to use
web service since it runs on port 80 (by default) instead of having some thing else in Service Oriented
Architecture applications.

What is the standard you use to wrap up a call to a Web service


“SOAP”

What is the transport protocol you use to call a Web service SOAP
HTTP with SOAP

What does WSDL stand for? 


“WSDL stands for Web Services Dsescription Langauge. There is WSDL.exe that creates a .wsdl Files
which defines how an XML Web service behaves and instructs clients as to how to interact with the
service. eg: wsdl http://LocalHost/WebServiceName.asmx”
Where on the Internet would you look for Web Services?
www.uddi.org

What does WSDL stand for? 


Web Services Description Language

True or False: To test a Web service you must create a windows application or Web application to
consume this service?
False.

What are the various ways of accessing a web service?


1. Asynchronous Call
Application can make a call to the Web service and then continue to-do whatever it wants to do. When
the service is ready it will notify the application. Application can use BEGIN and END method to make
asynchronous call to the webmethod.We can use either a Wait Handle or a Delegate object when
making asynchronous call.
The Wait Handle class share resources between several objects. It provides several methods which will
wait for the resources to become available
The easiest and most powerful way to implement an asynchronous call is using a delegate object. A
delegate object wraps up a callback function. The idea is to pass a method in the invocation of the web
method. When the web method has finished it will call this callback function to process the result

2. Synchronous Call
Application has to wait until execution has completed.

What are VSDISCO files?


VSDISCO files are DISCO files that support dynamic discovery of Web services. If you place the following
VSDISCO file in a directory on your Web server, for example, it returns references to all ASMX and DISCO
files in the host directory and any subdirectories not noted in elements:

<dynamicdiscovery
xmlns="urn:schemas-dynamicdiscovery:disco.2000-03-17">

</dynamicdiscovery

How does dynamic discovery work?


ASP.NET maps the file name extension VSDISCO to an HTTP handler that scans the host directory and
subdirectories for ASMX and DISCO files and returns a dynamically generated DISCO document. A client
who requests a VSDISCO file gets back what appears to be a static DISCO document.
Note that VSDISCO files are disabled in the release version of ASP.NET. You can reenable them by
uncommenting the line in the section of Machine.config that maps *.vsdisco to
System.Web.Services.Discovery.DiscoveryRequestHandler and granting the ASPNET user account
permission to read the IIS metabase. However, Microsoft is actively discouraging the use of VSDISCO
files because they could represent a threat to Web server security.

Is it possible to prevent a browser from caching an ASPX page?


Just call SetNoStore on the HttpCachePolicy object exposed through the Response object’s Cache
property, as demonstrated here:

<%@ Page Language="C#" %>

<%
Response.Cache.SetNoStore ();
Response.Write (DateTime.Now.ToLongTimeString ());
%>

SetNoStore works by returning a Cache-Control: private, no-store header in the HTTP response. In this
example, it prevents caching of a Web page that shows the current time.

What base class do all Web Forms inherit from? 


System.Windows.Forms.Form

What is the difference between Debug.Write and Trace.Write? When should each be used? 
The Debug.Write call won’t be compiled when the DEBUGsymbol is not defined (when doing a release
build). Trace.Write calls will be compiled. Debug.Write is for information you want only in debug builds,
Trace.Write is for when you want it in release build as well.

Difference between Anchor and Dock Properties?


Dock Property->Gets or sets which edge of the parent container a control is docked to. A control can be
docked to one edge of its parent container or can be docked to all edges and fill the parent container.
For example, if you set this property to DockStyle.Left, the left edge of the
control will be docked to the left edge of its parent control. Additionally, the docked edge of the control
is resized to match that of its container
control.
Anchor Property->Gets or sets which edges of the control are anchored to the edges of its container. A
control can be anchored to one or more edges of its parent container. Anchoring a control to its parent
ensures that the anchored edges remain in the same position relative to the edges of the parent
container when the parent container is resized.

When would you use ErrorProvider control?


ErrorProvider control is used in Windows Forms application. It is like Validation Control for ASP.NET
pages. ErrorProvider control is used to provide validations in Windows forms and display user friendly
messages to the user if the validation fails.
E.g
If we went to validate the textBox1 should be empty, then we can validate as below
1). You need to place the errorprovide control on the form
private void textBox1_Validating (object sender, System.ComponentModel.CancelEventArgs e)
{
ValidateName();
}
Private bool ValidateName()
{
bool bStatus = true;
if (textBox1.Text == “”)
{
errorProvider1.SetError (textBox1,”Please enter your Name”);
bStatus = false;
}
else
errorProvider1.SetError (textBox1,”");
return bStatus;
}
it check the textBox1 is empty . If it is empty, then a message Please enter your name is displayed.

Can you write a class without specifying namespace? Which namespace does it belong to by default?
Yes, you can, and then the class belongs to global namespace which has no name. For commercial
products, naturally, you wouldn’t want global namespace.

You are designing a GUI application with windows and several widgets on it. The user then resizes the
app window and sees a lot of grey space, while the widgets stay in place. What’s the problem?
One should use anchoring for correct resizing. Otherwise the default property of a widget on a form is
top-left, so it stays at the same location when resized.

How can you save the desired properties of Windows Forms application? 
.config files in .NET are supported through the API to allow storing and retrieving information. They are
nothing more than simple XML files, sort of like what .ini files were before for Win32 apps.

So how do you retrieve the customized properties of a .NET application from XML .config file? 
Initialize an instance of AppSettingsReader class. Call the GetValue method of AppSettingsReader class,
passing in the name of the property and the type expected. Assign the result to the appropriate variable.

Can you automate this process? 


In Visual Studio yes, use Dynamic Properties for automatic .config creation, storage and retrieval.

My progress bar freezes up and dialog window shows blank, when an intensive background process
takes over.
Yes, you should’ve multi-threaded your GUI, with taskbar and main form being one thread, and the
background process being the other.

What’s the safest way to deploy a Windows Forms app?


Web deployment: the user always downloads the latest version of the code, the program runs within
security sandbox, properly written app will not require additional security privileges.

Why is it not a good idea to insert code into InitializeComponent method when working with Visual
Studio?
The designers will likely through it away, most of the code inside InitializeComponent is auto-generated.

What’s the difference between WindowsDefaultLocation and WindowsDefaultBounds?


WindowsDefaultLocation tells the form to start up at a location selected by OS, but with internally
specified size. WindowsDefaultBounds delegates both size and starting position choices to the OS.

What’s the difference between Move and LocationChanged? Resize and SizeChanged? 
Both methods do the same, Move and Resize are the names adopted from VB to ease migration to C#.

How would you create a non-rectangular window, let’s say an ellipse? 


Create a rectangular form, set the TransparencyKey property to the same value as BackColor, which will
effectively make the background of the form transparent. Then set the FormBorderStyle to
FormBorderStyle.None, which will remove the contour and contents of the form.

How do you create a separator in the Menu Designer? 


A hyphen ‘-’ would do it. Also, an ampersand ‘&\’ would underline the next letter.

How’s anchoring different from docking? 


Anchoring treats the component as having the absolute size and adjusts its location relative to the
parent form. Docking treats the component location as absolute and disregards the component size. So
if a status bar must always be at the bottom no matter what, use docking. If a button should be on the
top right, but change its position with the form being resized, use anchoring.

How do you trigger the Paint event in System.Drawing?


Invalidate the current form; the OS will take care of repainting. The Update method forces the repaint.

With these events, why wouldn’t Microsoft combine Invalidate and Paint, so that you wouldn’t have
to tell it to repaint, and then to force it to repaint?
Painting is the slowest thing the OS does, so usually telling it to repaint, but not forcing it allows for the
process to take place in the background.

How can you assign an RGB color to a System.Drawing.Color object?


Call the static method FromArgb of this class and pass it the RGB values.

What class does Icon derive from? 


Isn’t it just a Bitmap with a wrapper name around it? No, Icon lives in System.Drawing namespace. It’s
not a Bitmap by default, and is treated separately by .NET. However, you can use ToBitmap method to
get a valid Bitmap object from a valid Icon object.

Before in my VB app I would just load the icons from DLL. How can I load the icons provided by .NET
dynamically? 
By using System.Drawing.SystemIcons class, for example System.Drawing.SystemIcons.Warning
produces an Icon with a warning sign in it.

When displaying fonts, what’s the difference between pixels, points and ems? 
A pixel is the lowest-resolution dot the computer monitor supports. Its size depends on user’s settings
and monitor size. A point is always 1/72 of an inch. An em is the number of pixels that it takes to display
the letter M.

Best Interview Questions For Embedded Programmers »

| 0 Comments |

1. What are static variables?

Variables that have only one copy per class are known as static variables. They are not attached to a
particular instance of a class but rather belong to a class as a whole. They are declared by using the
static keyword as a modifier. For example:

static type varIdentifier;

where, the name of the variable is varIdentifier and its data type is specified by type.

Static variables that are not explicitly initialized in the code are automatically initialized with a default
value. The default value depends on the data type of the variables. The table given below shows the
default values:

<!– /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:”";


margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:”Times
New Roman”; mso-fareast-font-family:”Times New Roman”;} @page Section1 {size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;}
div.Section1 {page:Section1;} –>

Data Type Initial Value

boolean false

byte 0

short 0

int 0
long 0L

char ‘u0000′

float 0.0F

double 0.0D

Object reference null

2. What are volatile variables?

A volatile variable is modified asynchronously by concurrently running threads in a Java application.It is


not allowed to have a local copy of a variable that is different from the value currently held in “main”
memory. Effectively, a variable declared volatile must have it’s data synchronized across all threads, so
that whenever you access or update the variable in any thread, all other threads immediately see the
same value. Of course, it is likely that volatile variables have a higher access and update overhead than
“plain” variables, since the reason threads can have their own copy of data is for better efficiency.

3. What do you mean by const keyword?


4. What is interrupt latency?

Interrupt latency is the time between the generation of an interrupt by a device and the servicing of the
device which generated the interrupt. For many operating systems, devices are serviced as soon as the
device’s interrupt handler is executed. Interrupt latency may be affected by interrupt controllers,
interrupt masking, and the operating system’s (OS) interrupt handling methods.

5. How you can optimize it?


6. What is size of character, integer, integer pointer, character pointer?
7. What is NULL pointer and what is its use?

A null pointer has a reserved value, often but not necessarily the value zero, indicating that it refers to
no object. Null pointers are used routinely, particularly in C and C++ where the compile-time constant
NULL is used, to represent conditions such as the lack of a successor to the last element of a linked list,
while maintaining a consistent structure for the list nodes.

8. What is void pointer and what is its use?

A special pointer type called the “void pointer” points to an object of unspecified type and cannot be
dereferenced. The address can be directly manipulated by casting a pointer to and from an integral type
of sufficient size.

9. What is ISR?
Integrated Services Routers (ISRs) are Cisco router product series that integrates many functions into a
single device. An example of such devices is a device that acts as both router and switch, and provides
other functions as well.

10. What is return type of ISR?

Void

11. Can we use any function inside ISR?


12. Can we use printf inside ISR?

No we cannot use printf() in ISR because ISRs’ are a part of kernel and kernel is not linked with libaray
provided by C,so when we use printf() in ISR it should generate a linkage error.

13. Can we put breakpoint inside ISR?


14. How to decide whether given processor is using little endian format or big endian format?
15. What is Top half & bottom half of a kernel?
16. Difference between RISC and CISC processor.
RISC is designed with the philosophy that simplicity means fast, disregard the esoteric and combinatory
cases.

CISC is designed in mind that if a procedure being designed into the CPU it would be faster compare to if
it was written as software code.

17. What is RTOS?

A real-time operating system (RTOS) is an operating system that guarantees a certain capability within a
specified time constraint. For example, an operating system might be designed to ensure that a certain
object was available for a robot on an assembly line. In what is usually called a “hard” real-time
operating system, if the calculation could not be performed for making the object available at the
designated time, the operating system would terminate with a failure. In a “soft” real-time operating
system, the assembly line would continue to function but the production output might be lower as
objects failed to appear at their designated time, causing the robot to be temporarily unproductive.
Some real-time operating systems are created for a special application and others are more general
purpose. Some existing general purpose operating systems claim to be a real-time operating systems. To
some extent, almost any general purpose operating system such as Microsoft’s Windows 2000 or IBM’s
OS/390 can be evaluated for its real-time operating system qualities. That is, even if an operating system
doesn’t qualify, it may have characteristics that enable it to be considered as a solution to a particular
real-time application problem.

In general, real-time operating systems are said to require:

* multitasking
* Process threads that can be prioritized
* A sufficient number of interrupt levels
Real-time operating systems are often required in small embedded operating systems that are packaged
as part of micro devices. Some kernels can be considered to meet the requirements of a real-time
operating system. However, since other components, such as device drivers, are also usually needed for
a particular solution, a real-time operating system is usually larger than just the kernel.

18. What is the difference between hard real-time and soft real-time OS?

A hard real time system guarantees that critical tasks complete on time this goal requires that all delays
in the system be bounded from the retrieval of the stored data to the time that it takes the o.s to finish
any request made of it.
A soft real time system where a critical real time task gets priority over other tasks and retains that
priority until it completes.As in hard real time system kernel delays need to be bounded.

19. What type of scheduling is there in RTOS?


In typical designs, a task has three states: 1) running, 2) ready, 3) blocked. Most tasks are blocked, most
of the time. Only one task per CPU is running. In simpler systems, the ready list is usually short, two or
three tasks at most.
The real key is designing the scheduler. Usually the data structure of the ready list in the scheduler is
designed to minimize the worst-case length of time spent in the scheduler’s critical section, during
which preemption is inhibited, and, in some cases, all interrupts are disabled. But, the choice of data
structure depends also on the maximum number of tasks that can be on the ready list.

20. What is priority inversion?

Priority inversion is a situation where in lower priority tasks will run blocking higher priority tasks waiting
for resource (mutex). For ex: consider 3 tasks. A, B and C, A being highest priority task and C is lowest.
Look at sequence of context swaps

A goes for I/O . unlocks mutex.


C was ready to run. So C starts running. locks mutex
B is ready to run. Swaps out C and takes mutex.
A is ready to run. but A is blocked as mutex is locked by B. but B will never relinqishes the mutex as its
higher priority than C.

The solution to priority inversion is Priority inheritance.

21. What is priority inheritance?

Priority inheritance is a method for eliminating priority inversion problems. Using this programming
method, a process scheduling algorithm will increase the priority of a process to the maximum priority
of any process waiting for any resource on which the process has a resource lock.
The basic idea of the priority inheritance protocol is that when a job blocks one or more high priority
jobs, it ignores its original priority assignment and executes its critical section at the highest priority level
of all the jobs it blocks. After executing its critical section, the job returns to its original priority level.
22. How many types of IPC mechanism you know?

Local
Local IPC is for communication among process on a single machine. Local IPC is useful for data sharing,
signaling, and synchronization.
Mutexes, semaphores, and events can be named, or unnamed (identified by handle) and can be
protected by NT permissions.

Atoms
Atoms are globally available strings or integer values identified by a handle. Atoms were typically used
for DDE. The global atom table is also limited to 37 strings total. I do not recommend the use of atoms as
they seem to be outdated. Instead, other more up to date IPC mechanisms should be used.

Shared Memory
Shared memory is a block o f memory which multiple processes can access. Under Win16 all memory
was accessible by any process so pointers could be just passed between processes. Win32 has memory
protection mechanisms, and a processes memory is virtually mapped to that process. Win32 however
can map a block of memory into multiple processes virtual memory spaces. Even though the shared
block of memory may appear to be at different locations to each process, each will point to the same
physical location in memory. In addition, this mechanism allows you to control which processes have
access to shared memory blocks. Win32 can also map a disk file into virtual memory. Because of this,
when shared memory is used, it is called a memory mapped file.
Win32 also does this to the code segment of executables. When multiple instances of an executable are
loaded, only one copy of the code is loaded into physical memory, while it is mapped into multiple
virtual spaces.

Mutexes
A mutex (Mutual Exclusion) is an object which can be owned, but only owned by a single thread at a
time. Any other thread trying to gain ownership, will be blocked and queued in order of requests.
Mutexes are used to control exclusive access to any global object, or non reentrant code. Mutexes can
be used to control access to shared memory, hardware, or other single access items.

Semaphores
A semaphore is like a mutex, except that a specified number of threads can own a specific semaphore at
one time. When the semaphore is created, this number is specified. Semaphores are typically used to
limit access to resources. An example of this might be to prevent “thrashing” of a resource by setting the
maximum number of threads which can concurrently access the object.

Critical Sections
Critical sections are similar to mutexes, however mutexes differ from critical sections in that they can be
accessed across processes and threads, while a critical section, can only be access across threads from
within the same process. Critical sections are also lighter weight, cannot be named, or have security
attributes assigned to them.
Events
An event is an object which threads can wait for to be triggered. Any free thread may then trigger the
event, which will then release the other waiting threads. An event can be used to hold threads from
accessing something that has not been initialized or ready yet. They can also be used to signal that input
is available, or a device is ready to accept more data.

Messages
Messages can be used to send a one way queued instructions/status to a single thread. You can send
messages to an existing windows message queue, and filter them as they come in, or create your own
queue within a secondary thread. Messages are good for non time critical communications, or to
serialize handling. Messages can contain only a limited amount of data however. Each message can
contain only one 16 bit integer, and one 32 bit integer. When communicating between threads, pointers
may be passed in the 32 bit parameter. However when communicating between processes pointers may
not be passed, even when the pointer identifies shared memory as each process may see the shared
memory at a different location in it s virtual space. Object handles (Mutexes, semaphores, events)
cannot be passed in the message data, however such handles can be duplicated, and the duplicated
handles may be passed via the message data. (See DuplicateHandle)

DDE
DDE (Dynamic Data Exchange) was the common way to externally control applications in the 16 bit
world. DDE is still used occasionally, however it has been strategically replaced by COM. You should use
Com instead of DDE, unless the application you need to communicate with only understands DDE. DDE
also tends to be slow, and the built in DDE in Delphi/C++ Builder is “less than perfect”.

Clipboard
The clipboard can also be used for IPC, however in most situations it is not advisable as it is a global
resource.

OLE/Com
OLE (Object Linking & Embedding) has evolved into COM (Component Object Model). COM allows you
to do many things. With COM you can create language independent objects, expose interfaces from
applications to allow external control, and much more. COM allows you to expose interfaces. An
interface is a defined set of methods and properties which allow you to proxy calls to any code or object
that you wish. An interface is like a contract. Any time that the interface is implemented, all of it s
members must be implemented.

Network
Network IPC is for communication between processes on different machines.

Network Protocols
Network protocols allow you the most flexibility, however they bind you to a single protocol, and
require a lot of extra programming. Most times you do not need this flexibility and it is better to use a
higher level protocol. Network protocols are also lighter weight.
Some common protocols used for network communication are IPX/SPX (Novell), NetBEUI (Microsoft),
and TCP/IP (Internet).
NetBios is also a protocol, but it is a slightly higher protocol than the others. It abstracts some of the
features of the other network protocols while still providing you with most of their advantages. NetBios
s main feature is that is does not bin you to a particular protocol which your network configuration
and/or hardware may dictate. NetBios commonly runs on top of NetBEUI or TCP/IP.
If you do decide you need to work at the network protocol level, TCP/IP is probably your best bet. It is
very flexible, in widespread use (The internet runs on it), works with any operating system, has tons of
existing services, and has become the de facto standard.

Mailslots
Mailslots are like messages except that they can be sent across a network. Mailslots also differ from
messages in that they are not arbitrarily limited in the amount of data they can contain, and mailslots
can be broadcast to a group of receivers. Mailslots however are sent as datagrams, and therefore are
not guaranteed to arrive at their destination. Mailslots are similar to TCP/IP s UDP mechanism, but at a
slightly higher level. If delivery must be guaranteed, another method should be used.

Pipes
A pipe is a communication channel with two endpoints. Pipes are similar to TCP connections. Pipes
however can be optionally named, and contain security attributes. Pipes can also be one or two way.
Pipes are used both for network communication, and locally. For example, the console is a pipe. If you
want to open a DOS session / command window, you can swap a pipe for it s standard in and standard
out, thus giving your application full control of the window.

RPC
RPC (Remote Procedure Calls) allow you to make function/procedure calls in which the code actually
executes on another system. RPCs are typically used with older systems, mainframes, or for
implementing distributed object systems.

Distributed Objects
Distributed objects are used for communication among objects. These objects can be local or remote.
This easily allows you to distribute your programs with complete abstraction of location. The two most
common distributed object standards are DCom and Corba.
Without distributed object systems, developers need to implement their own protocols and also decide
upon and program for a network transport. In many cases they also tie their protocol to a specific
language, and even a platform. Distributed object systems abstract the user from all this and provide a
high level interface which is platform independent, language independent, and network protocol
independent.

DCom
DCom is just a distributed version of COM (Component Object Model). DCom is controlled by Microsoft
and therefore is tied heavily to Win32 and other Microsoft technologies. The specification is available for
other platforms, but is rarely used. For all intents and purposes, DCom is for WinTel only. DCom is also
heavily tied to NT security. If you have lots of users that do not have NT accounts, this may pose a major
headache for you. NT security can be bypassed by using the Midas socket server (I ve been told you do
not need a Midas license to merely use this single component).

Corba
Corba (Common Object Request Broker Architecture) is a platform independent distributed object
protocol. Corba is also implemented by many vendors including Inprise/Visigenic. This allows you to
choose your implementation. The Corba standard is controlled by the OMG (Object Management
Group).

23. What is semaphore?

In simple terms a Semaphore is a unit or resource which is used for synchronization between two
processes , it is kind of flag (in abstract terms) which every process will check before processing ahead to
avoid the deadlock situation

24. What is spin lock?

A spin lock is a lock where the thread simply waits in a loop (”spins”) repeatedly checking until the lock
becomes available. As the thread remains active but isn’t performing a useful task, the use of such a lock
is a kind of busy waiting. Once acquired, spin locks will usually be held until they are explicitly released,
although in some implementations they may be automatically released if the thread blocks, or “goes to
sleep”.

25. What is difference between binary semaphore and mutex?

The differences are:


1) Mutex can be used only for mutual exclusion, while binary can be used of mutual exclusion as well as
synchronisation.
2) Mutex can be given only by the task that took it.
3) Mutex cannot be given from an ISR.
4) Mutual-exclusion semaphores can be taken recursively. This means that the semaphore can be taken
more than once by the task that holds it before finally being released.
5) Mutex provides a options for making the task that took it as DELETE_SAFE. This means, that the task
cannot be deleted when it holds mutex.

26. What is virtual memory?

Virtual memory is a common part of most operating systems on desktop computers. It has become so
common because it provides a big benefit for users at a very low cost.

Most computers today have something like 64 or 128 megabytes of RAM (random-access memory)
available for use by the CPU (central processing unit). Often, that amount of RAM is not enough to run
all of the programs that most users expect to run at once. For example, if you load the Windows
operating system, an e-mail program, a Web browser and word processor into RAM simultaneously, 64
megabytes is not enough to hold it all. If there were no such thing as virtual memory, your computer
would have to say, “Sorry, you cannot load any more applications. Please close an application to load a
new one.” With virtual memory, the computer can look for areas of RAM that have not been used
recently and copy them onto the hard disk. This frees up space in RAM to load the new application.
Because it does this automatically, you don’t even know it is happening, and it makes your computer
feel like is has unlimited RAM space even though it has only 32 megabytes installed. Because hard-disk
space is so much cheaper than RAM chips, virtual memory also provides a nice economic benefit.

The area of the hard disk that stores the RAM image is called a page file. It holds pages of RAM on the
hard disk, and the operating system moves data back and forth between the page file and RAM. (On a
Windows machine, page files have a .SWP extension.)

Of course, the read/write speed of a hard drive is much slower than RAM, and the technology of a hard
drive is not geared toward accessing small pieces of data at a time. If your system has to rely too heavily
on virtual memory, you will notice a significant performance drop. The key is to have enough RAM to
handle everything you tend to work on simultaneously. Then, the only time you “feel” the slowness of
virtual memory is in the slight pause that occurs when you change tasks. When you have enough RAM
for your needs, virtual memory works beautifully. When you don’t, the operating system has to
constantly swap information back and forth between RAM and the hard disk. This is called thrashing,
and it can make your computer feel incredibly slow.

27. What is kernel paging?


28. Can structures be passed to the functions by value?

Yes structures can be passed to functions by value. Though it has two disadvatanges :

1) The chages by the calling function are not reflected


2) Its slower than the pass by refrence funcion call.

29. Why cannot arrays be passed by values to functions?

When a array is passed to a function, the array is internally changed to a ‘pointer’. And pointers are
always passed by reference.

30. Advantages and disadvantages of using macro and inline functions?

A macro is a constant that provides straight textual substitution where used, while an inline function is a
procedure that is actually called each time. Macros do have a few advantages over inline functions, but
the disadvantages are numerous. For example, type checking and argument validation is not performed
in a macro, while they are in functions for the most part.

It is a matter that everyone should decide for themselves, but Bjarne Stroustrup, who created C++,
advocates the use of inline functions over macros.
Inline functions are an imperative feature of C++ and are frequently used with classes. These are no
different from the normal functions except for the fact that they are never actually called. These
functions are, as their name suggests, expanded in line at each point of invocation. All that needs to be
done to enable or cause a function to expand at the point of invocation is to add the inline keyword
before the function definition.

31. What happens when recursion functions are declared inline?

An inline function replaces the call to the function by the body of the function, thus reducing the
overhead of saving the context in stack. This is good for functions which are small in size and called
occasionally. A recursive function calls an instance of it and thus can be a deeply nested. In this case if
we define the recursive function as inline, it would replace every call to itself with the body of function
and thus eating up a lot of code space.

32. #define cat(x,y) x##y concatenates x to y. But cat(cat(1,2),3) does not expand but gives
preprocessor warning. Why?

Macro expanding becomes illegal if done recursively

Or

in this case the cat(x,y) is the macro which is defined by using the preprocessor directive , this will be
substituted only at the place where it is called in this example it happens like this

cat(1,2)##3 which will once again become 1##2##3


here if we use ## in between we can join or concatenate only two variables that why it gives a
preprocessor warning

33. Can you have constant volatile variable? Yes, you can have a volatile pointer?

You can have a constant pointer to a volatile variable but not a constant volatile variable.

Or

YES. We can have a const volatile variable.


a volatile variable is a variable which can be changed by the extrenal events (like an interrput timers will
increment the voltile varible. If you dont want you volatile varibale to be changed then declare them as
“const volatile”.

Or

It is possible to have “const volatile” declaration. This indicates that the variable defined like this is not
possible to change within that context. It can be changed by an external event. const declaraion just says
that it will be readonly within the context, that area can be modified by an interrupt routine or another
process.

34. ++*ip increments what? it increments what ip points to

I will explain this with an example:


int a = 10;
int *p = &a;
// suppose &a = 4010 (address of a)
Because both ++ and * are unary operators, the are calculated from right to left –> ++ (*p)
++*p will inrement 4010 by 4 (int size) -> ++*p will have the value 4014.

35. Operations involving unsigned and signed — unsigned will be converted to signed

Macro expanding becomes illegal if done recursively

36. Malloc (sizeof(0)) will return — valid pointer

yes. sizeof(0) –> int size and it is 4

37.main() {fork();fork();fork();printf(”hello world”); } — will print 8 times.

It will print 8 times. Because, each fork will print twice.


if u flush, (using “fflush”), then it will be printed only once. thats is you need to flush the iostreams.

38. Array of pts to functions — void (*fptr[10])()

39. Which way of writing infinite loops is more efficient than others?

There are 3ways.

40. Who to know whether system uses big endian or little endian format and how to convert among
them?
41. What are forward reference w.r.t. pointers in c?
42. How is generic list manipulation function written which accepts elements of any kind?
43. What is the difference between embedded systems and the system in which RTOS is running?
44. How can you define a structure with bit field members?

struct abc {
unsigned int a:1;
unisgned int b:2;
};

Вам также может понравиться