<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>electrofriends.com &#187; Computer Science</title>
	<atom:link href="http://electrofriends.com/category/articles/computer-science/feed/" rel="self" type="application/rss+xml" />
	<link>http://electrofriends.com</link>
	<description>...bringing innovative minds together</description>
	<lastBuildDate>Mon, 30 Jan 2012 02:21:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.6</generator>
		<item>
		<title>Dependency Injection in C# .NET</title>
		<link>http://electrofriends.com/articles/dependency-injection/</link>
		<comments>http://electrofriends.com/articles/dependency-injection/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 01:56:01 +0000</pubDate>
		<dc:creator>Ranjan</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=2578</guid>
		<description><![CDATA[Dependency injection basically allows us to create loosely coupled, reusable, and testable objects in your software designs by removing dependencies. We will take a look into the Object dependencies before digging in more. Consider a scenario of fetching an employee details and show display in UI. Let us say create a Business logic layer class [...]]]></description>
			<content:encoded><![CDATA[<p>Dependency injection basically allows us to create loosely coupled, reusable, and testable objects in your software designs by removing dependencies.</p>
<p>We will take a look into the Object dependencies before digging in more.<br />
Consider a scenario of fetching an employee details and show display in UI. Let us say create a Business logic layer class named EmployeeBAL and a data access layer class named EmployeeDAO</p>
<p>public class EmployeeDao<br />
{<br />
//Some code<br />
}</p>
<p>public class EmployeeBAL<br />
{<br />
var employeeDAO = new EmployeeDao();<br />
//Some code<br />
}</p>
<p>From the above code you will notice one thing that we are creating EmployeeDAO instance inside the Business logic layer class. So here comes the dependency</p>
<h2><strong>What is wrong if we have a dependency?</strong></h2>
<p>Think about whether your code is unit testable. We cannot fully unit test the EmployeeBAL as it has a dependency on Employee DAO. So we can say as long as the composition of the DAO exists within the BAL we cannot unit test the EmployeeBAL.</p>
<p>You will also notice one more thing here; with this type of implementation you will see a high coupling of BAL and DAL.</p>
<h2><strong>How to make it loose coupling?</strong></h2>
<p>The basic idea behind Dependency Injection is that you should isolate the implementation of an object from the construction of objects on which it depends.</p>
<p>Coming to the example, we should be isolating the implementation of EmployeeBAL object and the construction of the dependent EmployeeDAO object.</p>
<p>We will see how we can make loosely coupled objects in detail</p>
<h2><strong> Constructor based dependency injection</strong></h2>
<p>We will have to modify the EmployeeBAL to accept an EmployeeDAO instance within its constructor.</p>
<p>public class EmployeeDao<br />
{<br />
//Some code<br />
}</p>
<p>public class EmployeeBAL<br />
{<br />
EmployeeDao employeeDAO;</p>
<p>public EmployeeBAL(EmployeeDAO employeeDao){<br />
this.employeeDAO  = employeeDao;<br />
}<br />
//Some code<br />
}</p>
<h2><strong> Property based dependency injection</strong></h2>
<p>With property based injection we will have a public getter and setter Property of type EmployeeDao so that the dependency can be externally set.</p>
<p>public class EmployeeBAL<br />
{<br />
Public EmployeeDao EmployeeDataAccess{ get; set; }<br />
}</p>
<p>var employeeBAL = new EmployeeBAL();<br />
EmployeeBAL.EmployeeDataAccess = new EmployeeDao();</p>
<p>Wait!!!</p>
<p>The above ones are just some techniques of injecting the dependency. We are still yet to discuss one more interesting thing Unit Testing.</p>
<p>Are you agreeing that we have removed the DAO creation from the Business Logic EmployeeBAL? Yes it is good but it still depends on the actual instance of EmployeeDao.</p>
<p>Consider the below mentioned implementation of the same sample senarios</p>
<p>interface IDataAccess<br />
{<br />
//Some code<br />
}</p>
<p>class EmployeeDao : IDataAccess<br />
{<br />
//Some code<br />
}</p>
<p>public class EmployeeBAL<br />
{<br />
private IDataAccess dataAccess;<br />
public BusinessFacade(IDataAccess dao)<br />
{<br />
dataAccess = dao;<br />
}<br />
}</p>
<p>You can notice we are doing a constructor dependency injection but most important thing here<br />
is we are using Interface type than creating a strongly typed object.</p>
<p>The advantage that we are getting here is we can have an in memory data access object of<br />
IDataAccess interface type and we can  easily inject the dependency to the EmployeeBAL.<br />
By this way we no need to have the actual database dependency.</p>
<p>Are you happy that we can unit test the BAL without the data access dependency?</p>
<h2><strong>Advantages of Dependency Injection</strong></h2>
<p><strong></strong><br />
The primary advantages of dependency injection are:<br />
Loose coupling<br />
Centralized configuration<br />
Easily testable</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/dependency-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delegate and Events in C# .NET</title>
		<link>http://electrofriends.com/articles/delegate-events-net/</link>
		<comments>http://electrofriends.com/articles/delegate-events-net/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 16:54:06 +0000</pubDate>
		<dc:creator>Ranjan</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Delegates]]></category>
		<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=2560</guid>
		<description><![CDATA[Delegates A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Delegates</strong></p>
<p>A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.</p>
<p>The signature of a single cast delegate is shown below:</p>
<p><strong>delegate result-type identifier ([parameters]);</strong></p>
<p>where:</p>
<ul>
<li>result-type: The result type, which matches      the return type of the function.</li>
<li>identifier: The delegate name.</li>
<li>parameters: The Parameters that the function      takes.</li>
</ul>
<p>Delegates allow a clearer separation of specification and implementation. A delegate specifies the signature of a method, and authors can write methods that are compatible with the delegate specification.</p>
<p><strong>Multicast delegates</strong><strong></strong></p>
<p>With multicast delegate, it is just like a normal delegate but it can point to multiple functions so on invocation of such delegate it will invoke all the methods and functions associated with the same one after another sequentially.</p>
<p><strong>Events: </strong></p>
<p>Events are wrapper around the delegate. It sits on top of the delegate and provides only the necessary encapsulation so that the destination objects can subscribe to the Event and not have full control on the delegate object.</p>
<p>Events are declared using delegates. The delegate object encapsulates a method so that it can be called anonymously. An event is a way for a class to allow clients to give it delegates to methods that should be called when the event occurs. When the event occurs, the delegate(s) given to it by its clients are invoked.<br />
We will consider an example implementation of Logger application, which can be used to log messages in Console, File or Database etc.</p>
<p><div id="attachment_2585" class="wp-caption alignleft" style="width: 275px"><a href="http://electrofriends.com/wp-content/uploads/2012/01/ClassDiagram-e1326646129665.png"><img src="http://electrofriends.com/wp-content/uploads/2012/01/ClassDiagram-e1326646265275.png" alt="ClassDiagram of Logger Application" width="265" height="300" class="size-medium wp-image-2585" /></a><p class="wp-caption-text">Logger Application ClassDiagram</p></div><br />
We will declare a delegate named LogWriteDelegate which accepts one parameter named message.</p>
<p><code>public delegate void LogWriteDelegate(string message);</code></p>
<p>Next we will declare an Event of type LogWriteDelegate</p>
<p><code>public event LogWriteDelegate LogWriteEvent;</code></p>
<p>In our sample Logger the FileLogger and ConsoleLogger will subscribe or register to the above mentioned event so that when the Write method of logger is called the respective logic within the Write method of FileLogger and ConsolLogger will also gets invoked.</p>
<p><code>using (var logger = new Logger("testing", EntryType.Debug))<br />
{<br />
    logger.LogWriteEvent += new Logger.LogWriteDelegate(consoleLogger.Write);<br />
    logger.LogWriteEvent += new Logger.LogWriteDelegate(fileLogger.Write);<br />
    logger.Write();<br />
}</code></p>
<p>You can notice here a multicast delegate; the LogWriteEvent is being registered with Console and File log write methods.</p>
<p>While firing an Event within the Logger object, it is always a good practice to check whether the event is registered or not.</p>
<p><code>public void Write()<br />
{<br />
if (LogWriteEvent != null)<br />
LogWriteEvent(ToString());<br />
}</code></p>
<p>Here the LogWriteEvent holds the address of the methods console.Write and fileLogger.Write. When firing an event it will sequentially call the respective methods which are pre-registered to this Event.</p>
<p>Note: The Logger application is designed in such a way that in future you can have multiple implementations of Loggers. Right now we have Console and File Logger; if you are interested in implementing a Database logger we can create a new Class named DatabaseLogger which will implement ILogger interface. Provide necessary Write method logic so that it will log messages to database.</p>
<p>Ones you have done with the DatabaseLogger implementation, you just have to create an instance and register the event as we have done for Console and File Loggers.</p>
<p><a href="http://electrofriends.com/wp-content/uploads/2012/01/LoggerLibrary.zip">Download Sample Logger Application</a></p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/delegate-events-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile Information Device Profile (MIDP 2.0) in J2ME</title>
		<link>http://electrofriends.com/articles/mobile-information-device-profile-midp-20-j2me/</link>
		<comments>http://electrofriends.com/articles/mobile-information-device-profile-midp-20-j2me/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 11:25:42 +0000</pubDate>
		<dc:creator>Ranjan</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=2573</guid>
		<description><![CDATA[MIDP in general is one of the J2ME profile, a profile consists of Java classes. MIDP provides high-level API’s using which J2ME developer can easily develop applications, which is easy to use, highly graphical, with optimized for small computing devices such as Mobile phone. Also provides low-level user interface API’s giving the developers a control [...]]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong></p>
<p>MIDP in general is one of the J2ME profile, a profile consists of Java classes. MIDP provides high-level API’s using which J2ME developer can easily develop applications, which is easy to use, highly graphical, with optimized for small computing devices such as Mobile phone. Also provides low-level user interface API’s giving the developers a control over the graphics and input. Thus reduces the development effort.</p>
<p>MIDP is targeted at a class of devices known as <em>mobile information devices</em> (MIDs). These are devices that have the following minimal characteristics:</p>
<p>1)      Enough memory to run MIDP applications</p>
<p>2)      A bit addressable display at least 96 pixels wide by 56 pixels high, either monochrome or color.</p>
<p>3)      A keypad, keyboard, or touch screen.</p>
<p>4)      Two-way wireless networking capability</p>
<p>Before we start up with MIDP 2.0 we will look over MIDP 1.0, which basically provides local storage, a user interface, networking capabilities and ability to operate in disconnected mode, ability to write applications in Java. But it was lacking end-to-end security and some other new features which is existing in MIDP 2.0</p>
<p>With MIDP 2.0, end-to-end security is now supported. MIDP 2.0 introduces the security concepts of <em>application signing</em> and <em>privileged domains</em>. With application signing applications can be trusted or not based on the ability to corroborate, via the use of a X.509 digital certificate, the application&#8217;s origin and integrity. These new features protect the device against unauthorized applications accessing data and functions. Also standard security protocols such as HTTPS, TLS/SSL and WTLS allows for secure transmission by encrypting the data. It is important to understand that MIDP in general is targeted at cell phones and low-end PDAs</p>
<p>The new MIDP 2.0 also includes support for an enhanced user interface API that allow developers create more functional and attractive business or consumer applications with less effort. It also includes new gaming and media APIs that can be used for business-applications.</p>
<p>MIDP 2.0 has expanded network connectivity support beyond HTTP, with support for UDP datagrams, TCP sockets, and serial port communication. Also a powerful feature called the push registry that activates dormant applications when new information is available. For example, with push support, server software can activate an application on the device to notify employees when a new calendar event has been scheduled or new sales lead generated, even if the application is not currently running.</p>
<p>The new Over-The-Air (OTA) application provisioning standardizes support for client-initiated download of applications over the wireless network. It allows users to find and install <em>authorized</em> applications wirelessly. It also allows application providers to track the installation and removal of applications for billing (or other) purposes.</p>
<p>MIDP also supports Short messaging service (SMS) and Cell Broadcast Service (CBS)</p>
<p><strong>What does it MIDP provide?</strong></p>
<p>The MIDP adds the following packages on top of the CLDC:</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="111">javax.microediton.lcdui</td>
<td width="513">Provides classes for user interface.</td>
</tr>
<tr>
<td width="111">javax.microedition.midlet</td>
<td width="513">Defines MIDP applications and the interactions between the application and the environment in which the application runs.</td>
</tr>
<tr>
<td width="111">javax.microedition.rms</td>
<td width="513">Provides persistent storage (Record Management System).</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/mobile-information-device-profile-midp-20-j2me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best Practices for Small computing devices</title>
		<link>http://electrofriends.com/articles/practices-small-computing-devices/</link>
		<comments>http://electrofriends.com/articles/practices-small-computing-devices/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 11:21:30 +0000</pubDate>
		<dc:creator>Ranjan</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=2568</guid>
		<description><![CDATA[Keep your application Simple and Small. Limit the use of memory Avoid using object types. Always use minimum data type for storing data. Clean up the resources held by our program manually because even though garbage collector takes care of that we don’t know when it cleans up. Allocate an object immediately before the object [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>Keep your application Simple and Small.</li>
</ul>
<ul>
<li>Limit the use of memory</li>
</ul>
<ol>
<li>
<p style="text-align: left">Avoid using object types.</p>
</li>
<li>Always use minimum data type for storing data.</li>
<li>Clean up the resources held by our program manually because even though garbage collector takes care of that we don’t know when it cleans up.</li>
<li>Allocate an object immediately before the object is used in the application rather than at the beginning of your application.</li>
<li>Set all references to objects to null once the application no longer needs the object. This decreases the memory application of the object to the minimum memory necessary to store the object references.</li>
<li>Reuse the objects instead of creating a new object; this reduces both the memory allocation and the need for processing power.</li>
<li>Reduce the exception thrown by our application because it reduces the memory.</li>
</ol>
<p style="text-align: left">
<ul>
<li>Offload computation to server.</li>
<li>If application uses multiple screens make sure that each displays only relevant information.</li>
<li>Application must accomplishes a task within 2 minutes otherwise the user is likely to turn off the mobile small computing devices.</li>
<li>Limit the user input to few keystrokes.</li>
<li>Avoid memory-consuming task such as communication, animation and sound.</li>
<li>Reduce the data communication to minimum because users pay for transmission by byte usually in the range of 50,000 to 300,000 bytes per month.</li>
<li>Pre load as many files as possible into a mobile small computing device in order to reduce data transmission.</li>
<li>Always use a thread whenever an operation takes longer than a 10<sup>th</sup> of a second to run because a thread requires fewer overheads than non-thread innovation methods.</li>
</ul>
<ol></ol>
<ol></ol>
<ol></ol>
<ol></ol>
<ol></ol>
<ol></ol>
<ol></ol>
<ol></ol>
<ol></ol>
<ol></ol>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/practices-small-computing-devices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java APIs for Bluetooth Wireless Technology (JABWT)</title>
		<link>http://electrofriends.com/articles/java-apis-bluetooth-wireless-technology-jabwt/</link>
		<comments>http://electrofriends.com/articles/java-apis-bluetooth-wireless-technology-jabwt/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 11:18:12 +0000</pubDate>
		<dc:creator>Ranjan</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=2565</guid>
		<description><![CDATA[The JABWT specification defines an optional J2ME package for Bluetooth wireless technology. What is it? The JABWT operates on top of the CLDC and is intended to extend the capabilities of profiles like the MIDP. JABWT use the Generic Connection Framework (GCF) defined in the CLDC specification for Bluetooth communication. What does it provide? JABWT [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>The JABWT specification defines an optional J2ME package for Bluetooth wireless technology.</p>
<p><strong>What is it?</strong></p>
<p>The JABWT operates on top of the CLDC and is intended to extend the capabilities of profiles like the MIDP. JABWT use the Generic Connection Framework (GCF) defined in the CLDC specification for Bluetooth communication.</p>
<p><strong>What does it provide?</strong></p>
<p>JABWT consists of two packages.</p>
<table border="0" cellspacing="0" cellpadding="1" width="613">
<tbody>
<tr>
<td width="198">javax.bluetooth</td>
<td width="411">The core Bluetooth API.</td>
</tr>
<tr>
<td width="198">javax.obex</td>
<td width="411">The Object Exchange (OBEX) API.</td>
</tr>
</tbody>
</table>
<p>These packages are separate optional packages so the CLDC implementation may include either of the packages or both of them.</p>
<p>The javax.bluetooth package provides an API for discovering devices and the services they provide. In addition it provides functionality for setting up services of your own and customization of local service records. Setting up L2CAP and RFCOMM connections is available through an extension to the Generic Connection Framework (GCF) from the CLDC.</p>
<p>The javax.obex provides an API for the OBject EXchange (OBEX) protocol. This package is not implemented on the Nokia 6600 smartphone. It is not tied to the Bluetooth API alone but is intended to be of more general use</p>
<p><span style="text-decoration: underline"><strong>Security</strong></span></p>
<p>The JABWT does not define any security models itself. It depends on the security models available through the Bluetooth stack. However, it does define how the JABWT should interact with the lower layers in the Bluetooth stack responsible for security features. The device must have a Bluetooth Control Center (BCC) to which JABWT applications can direct their security requests.</p>
<p><span style="text-decoration: underline"><strong>BCC</strong></span></p>
<p>The JABWT depends on a BCC implemented on the device. The BCC is the central authority for local Bluetooth device settings. It controls base security settings and provides lists of devices both known and trusted by the local device. The BCC is responsible for pairing devices and providing authorization for connection request. All of these functions must be included in the BCC.</p>
<p>The BCC may have other capabilities like setting the Bluetooth friendly-name of the device, setting timeouts for the baseband layer, determining how connectable and discoverable modes are set, resetting the local device or enumerating services on the local device. This BCC functionality is implementation dependent and may vary between OEMs an their devices. Some implementations may provide a GUI to the BCC while others provide hard-coded defaults in the BCC. For example, a headset will provide only defaults in the BCC since it does not have an input device or screen. When sending request to the BCC one should always check if the request was fulfilled by the BCC. One is not guaranteed that the BCC can fulfill the request at the given time.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/java-apis-bluetooth-wireless-technology-jabwt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Midlet in J2ME</title>
		<link>http://electrofriends.com/articles/midlet-j2me/</link>
		<comments>http://electrofriends.com/articles/midlet-j2me/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 11:16:51 +0000</pubDate>
		<dc:creator>Ranjan</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=2563</guid>
		<description><![CDATA[A MIDlet is a Java program for embedded devices, more specifically the Java ME virtual machine. Generally, these are games and applications that run on a cell phone A MIDlet requires a device that implements Java ME, MIDP to run. Like other Java programs, MIDlets have a &#8220;compile once, run anywhere&#8221; potential. MIDlet distributions also consist [...]]]></description>
			<content:encoded><![CDATA[<div>
<p lang="en">A <strong>MIDlet</strong> is a Java program for embedded devices, more specifically the Java ME virtual machine. Generally, these are games and applications that run on a cell phone</p>
<p lang="en">A MIDlet requires a device that implements Java ME, MIDP to run. Like other Java programs, MIDlets have a &#8220;compile once, run anywhere&#8221; potential. MIDlet distributions also consist of a .jad file describing the contents of the JAR file.</p>
<p lang="en">A MIDlet has to fulfill the following requirements in order to run on a mobile phone:</p>
<ul>
<li>
<p lang="en">The main class needs to be a subclass of javax.microedition.midlet.MIDlet</p>
</li>
<li>
<p lang="en">The MIDlet needs to be packed inside a .jar file (e.g. by using the jar-tool)</p>
</li>
<li>
<p lang="en">The .jar file needs to be pre-verified by using a preverifier.</p>
</li>
<li>
<p lang="en">In some cases, the .jar file needs to be signed by the mobile phone&#8217;s carrier.</p>
</li>
</ul>
<h3>MIDP Applications (MIDlets) and MIDlet Lifecycle</h3>
<p>The applications written for mobile information devices such as cellular phones and pagers are called MIDlets. Like applets, MIDlets are controlled by the software that runs them. In the case of an applet, the underlying software is a browser or the applet viewer tool and in the case of a MIDlet, the underlying software is the cell phone or two-way pager device implementation that supports the CLDC and MIDP. A MIDlet is a well-behaved MIDP application, which lives within the resource constraints, which runs and terminates when requested.</p>
<p>All the devices, which support MIDP, are supposed to have a device-specific Application Management Software that takes care of installing, managing and removing MIDlets interactively.</p>
<h4><span style="text-decoration: underline">MIDlet lifecycle</span></h4>
<p>MIDlets move through a well-defined lifecycle consisting of five phases. It is the task of the Application Management Software to move MIDlets through these phases:</p>
<ul>
<li>Retrieval &#8211; The AMS retrieves the MIDlet from some source and reads the MIDlet into the device&#8217;s memory. The medium through which the MIDlet is downloaded depends on the device. It could be through a serial cable, an IRDA port, or a wireless network.</li>
<li>Installation &#8211; Once the MIDlet is downloaded, the AMS installs the MIDlet on the device. During the installation process, the MIDP implementation verifies that the MIDlet does not violate the device&#8217;s security policies.</li>
<li>Launching &#8211; A MIDlet is launched when a user selects it using the interface provided in the device. At this point, the MIDlet enters the KVM and the lifecycle methods of the MIDlet are invoked.</li>
<li>Version Management &#8211; The AMS keeps track of all the MIDlets that are installed on the device including their version numbers. This information is used to upgrade a MIDlet to its new version.</li>
<li>Removal &#8211; The AMS removes a MIDlet and cleans up the related resources from the memory.</li>
</ul>
<p>A MIDlet can be in one of the three states after the Application Management Software launches it:</p>
<ul>
<li>Paused A MIDlet enters the Paused state once it is created and initialized by the AMS. It can also enter this state when it is Active.</li>
<li>Active this state means the MIDlet is running normally. A MIDlet goes to the Active state from the paused state if there are no runtime exceptions during its initialization.</li>
<li>Destroyed this state means the MIDlet has released all its resources and is terminated. A MIDlet can reach this state either from the paused state due to a runtime exception during its initialization or from the active state when the user has chosen to close the application.</li>
</ul>
<h1>MIDlet suites:</h1>
<p>MIDlets are usually available through MIDlet suites. A MIDlet suite consists of two files, a .jar and a .jad file. The Java ARchive (JAR) file contains your compiled classes in a compressed and preverified fashion. All MIDlets must be preverified. This means that a checksum is computed, enabling the resource-constrained MID to easily check the integrity of the jar-file (using only a few hundred bytes of memory). Several MIDlets may be included in a MIDlet suite. Hence, the JAR file will contain all these MIDlet classes.</p>
<p>The Java Application Descriptor (JAD) file is a plain text file containing information about your MIDlet suite. All MIDlets must be named in this file, the size of the JAR file must be included (and be correct!) and the URL to the JAR file must be present. In addition, the MIDlet suite version number is included here. This is essential information for a MID. If the suite is already installed, it will know if a newer version is available. The size of the JAR file is important information, the MID can determine if there is enough memory available to install the MIDlet suite.</p>
<p>Every MIDLet contains 3 abstract methods that are called by the application manager to manage the life cycle of MIDLet. These abstract methods are startApp(), pauseApp(), destroyApp ( boolean unconditional)</p>
<p>public class Mymidlet extends MIDLet{</p>
<p>public void startApp(){</p>
<p>}</p>
<p>public void pauseApp(){</p>
<p>}</p>
<p>public void destroyApp( boolean unconditional ){</p>
<p>}</p>
<p>}</p>
<h4>What does a JAD file contain? Why it’s required?</h4>
<p>The JAD file is used by the application manager to know whether the MIDLet suite can be implemented on the device.</p>
<p>There are five required system attributes for a JAD file.</p>
<ol>
<li>MIDLet Name.</li>
<li>MIDLet Version.</li>
<li>MIDLet – vendor.</li>
<li>MIDLet-n.</li>
<li>MIDLet-Jar-URL.</li>
</ol>
<p>An Example of JAD File:</p>
<p>MIDLet-Name: Best MIDLet</p>
<p>MIDLet-Version: 2.0</p>
<p>MIDLet-Vendor: Mycompany</p>
<p>MIDLet-Jar-URL: <span style="color: #0000ff"><span style="text-decoration: underline"><a href="http://www.mycompany.com/bestmidlet.jar">http://www.mycompany.com/bestmidlet.jar</a></span></span></p>
<p>MIDLet-1: Best MIDLet, /images/BestMIDLet.png , Best.BestMIDLet</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/midlet-j2me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Record management in J2ME MIDP</title>
		<link>http://electrofriends.com/articles/record-management-midp/</link>
		<comments>http://electrofriends.com/articles/record-management-midp/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 11:15:05 +0000</pubDate>
		<dc:creator>Ranjan</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=2556</guid>
		<description><![CDATA[MIDP doesn’t use filesystem to save application data; in turn it uses a non-volatile memory using a system called Record Management System The MIDP Record Management System (RMS) provides a means to store application data that persists across invocations of a MIDlet. You can visualize the RMS record store as a very simple database, where each [...]]]></description>
			<content:encoded><![CDATA[<p>MIDP doesn’t use filesystem to save application data; in turn it uses a non-volatile memory using a system called <strong>Record Management System</strong></p>
<p>The MIDP Record Management System (RMS) provides a means to store application data that persists across invocations of a MIDlet. You can visualize the RMS record store as a very simple database, where each row consists of two columns: one containing a unique row identifier, the other a series of bytes representing the data in the record.</p>
<table border="1" cellspacing="3" cellpadding="3" width="208">
<tbody>
<tr>
<td width="63"><strong>Record ID</strong></td>
<td width="123"><strong>Data</strong></td>
</tr>
<tr>
<td width="63">1</td>
<td width="123">Array of bytes</td>
</tr>
<tr>
<td width="63">2</td>
<td width="123">Array of bytes</td>
</tr>
<tr>
<td width="63">3</td>
<td width="123">Array of bytes</td>
</tr>
<tr>
<td width="63">&#8230;</td>
<td width="123">&#8230;</td>
</tr>
</tbody>
</table>
<p>The unique row identifier is an integer value. The first entry will have the ID of 1, the next of 2, and so on. Row identifiers are not re-used if a row is deleted. That is, if we have three rows in a table with the IDs 1, 2, and 3, deleting ID 2 will remove this identifier permanently from the record store. If we were to add another row to this table, it would have an identifier of 4.</p>
<p>Record stores are identified by name. A name may consist of up to 32 characters, and all characters are case sensitive. No two record stores within a MIDlet suite (that is, a collection of one or more MIDlets packaged together) may contain the same name.</p>
<p>Each record store has a version number as well as a date/time stamp. Both values are updated whenever a record is added, replaced, or deleted.</p>
<p>Record management system provides a file system like environment that is used to store and maintain persistence in a small computing device. RMS is a combination of file system and Database management system that enables you to store data in columns and rows similar to the organization of data in a table of database.</p>
<p>The operations which can be performed in RMS are you can insert records, read records, search for a particular records and sort records stored in RMS.</p>
<p><span style="text-decoration: underline"><strong>Creating/Opening a Record Store:</strong></span></p>
<p><strong>openRecordStore()</strong> is called to create and open an existing record store. Accepts 2 parameters first parameter is a string-containing name of the record store, second parameter is a Boolean value (true) causes the record store to open if the record store already exists or else it will create.</p>
<p><strong>RecordStore rs = RecordStore.openRecordStore (&#8220;MyAppointments&#8221;, true);</strong></p>
<p>Here “MyAppointments”is the Record store name</p>
<p><strong><span style="text-decoration: underline">Inserting records:</span></strong></p>
<p>The MIDlet invokes the <strong>addRecord()</strong> method of javax.microedition.rms.RecordStore class to insert a new record into the record store. This is a blocking atomic operation and returns the recordId for the new record. The record is written to persistent storage before the method returns.</p>
<p>public int addRecord(byte[] data, int offset, int numBytes) inserts a record represented by an array of bytes data with offset as its starting index and numBytes as its length.</p>
<p>String appt = &#8220;new record&#8221;;</p>
<p>byte bytes[] = appt.getBytes();</p>
<p>rs.addRecord(bytes,0,bytes.length);</p>
<p><strong><span style="text-decoration: underline">Updating Records in a Record Store:</span></strong></p>
<p>Updating a particular record involves getting a handle for that record and setting new information.</p>
<p>public int getRecord(int recordId, byte[] buffer, int offset) returns the data stored in the given record in the byte array represented by buffer. public byte[] getRecord(int recorded) returns a copy of the data represented by recordId. public void setRecord(int recordId, byte[] newData, int offset, int numBytes) sets new information, a stream of bytes (newData) with offset as its starting index and numBytes as its length, at the record location represented by recordId.</p>
<p>String newappt = &#8220;update record&#8221;;</p>
<p>Byte data = newappt.getBytes();</p>
<p>Rs.setRecord(1, data, 0, data.length());</p>
<p><span style="text-decoration: underline"><strong>Closing a record store:</strong></span></p>
<p>Internal resources are utilized to make an open record store available to MIDlets with in a MIDlet suite. You can reuse the resources utilized by the record store by closing the record store, which you don’t need <strong>closeRecordStore() </strong>method is used to close the record store.</p>
<p><strong>Rs.closeRecordStore();</strong></p>
<p><span style="text-decoration: underline"><strong>Deleting a Record Store:</strong></span></p>
<p>A record store can be deleted by using <strong>deleteRecordStore(String)</strong>. It requires one parameter which is a string containing the name of the record store.</p>
<p><strong>RecordStore. deleteRecordStore(“</strong><strong>MyAppointments”);</strong></p>
<p><strong><span style="text-decoration: underline">Writing Mixed Datatypes Into A RecordStore:</span></strong></p>
<p>Private RecordStore recordstore=null;</p>
<p>Try</p>
<p>{</p>
<p>byte [] outputRecord;</p>
<p>String outputString=”First Record”;</p>
<p>int outputInteger= 15;</p>
<p>Boolean outputBooelan=true;</p>
<p>ByteOutputStream outputStream=new ByteOutputStream ();</p>
<p>DataOutputStream outputDataStream=new DataOutputStream(outputStream);</p>
<p>outputDataStream.writeUTF (outputString);</p>
<p>outputDataStream.writeUTF(outputInteger);</p>
<p>outputDataStream.writeUTF(outputBooelan);</p>
<p>outputDataStream.flush();</p>
<p>outputRecord= outputDataStream.toByteArray ();</p>
<p>recordStore.addRecord (outputRecord,0,outputRecord.length);</p>
<p>outputStream.close();</p>
<p>OutputDataStream.close ();</p>
<p>}</p>
<p>catch (Exception error)</p>
<p>{</p>
<p>// handle proper exceptions…</p>
<p>}</p>
<p><strong><span style="text-decoration: underline">Reading Mixed Datatypes From A RecordStore:</span></strong></p>
<p>Try</p>
<p>{</p>
<p>String inputString=null;</p>
<p>int inputInteger= 0;</p>
<p>boolean inputBooelan=false;</p>
<p>byte [] byteInputData= new byte[100];</p>
<p>ByteArrayInputStream inputStream=new ByteArrayInputStream(byteInputData);</p>
<p>DataInputStream inputDataStream=new DataInputStream (inputStream);</p>
<p>for ( int i=0;recordstore.getnumRecords(); i++)</p>
<p>{</p>
<p>recordstore.getRecord (i, byteInputData, 0);</p>
<p>inputString=inputDataStream.readUTF();</p>
<p>inputBooelan= inputDataStream.readBoolean();</p>
<p>inputInteger = inputDataStream.readInt();</p>
<p>inputStream.reset();</p>
<p>}</p>
<p>inputStream.close();</p>
<p>inputDataStream.close();</p>
<p>}</p>
<p>catch (Exception error)</p>
<p>{</p>
<p>// handle proper exceptions…</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/record-management-midp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>J2ME Core Concepts</title>
		<link>http://electrofriends.com/articles/j2me-core-concepts/</link>
		<comments>http://electrofriends.com/articles/j2me-core-concepts/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 11:13:23 +0000</pubDate>
		<dc:creator>Ranjan</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=2547</guid>
		<description><![CDATA[J2ME Core Concepts: Configurations, Profile and Optional packages are 3 major concepts. Configurations: A configuration is a complete Java runtime environment, consisting of three things: A Java virtual machine (VM) to execute Java byte code. Native code to interface to the underlying system. A set of core Java runtime classes. To use a configuration, a device [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline"><strong>J2ME Core Concepts:</strong></span></p>
<p>Configurations, Profile and Optional packages are 3 major concepts.</p>
<p><span style="text-decoration: underline"><strong>Configurations:</strong></span></p>
<p>A <em>configuration</em> is a complete Java runtime environment, consisting of three things:</p>
<ol>
<li>A Java virtual machine (VM) to execute Java byte code.</li>
<li>Native code to interface to the underlying system.</li>
<li>A set of core Java runtime classes.</li>
</ol>
<p>To use a configuration, a device must meet certain minimum requirements as defined in the configuration&#8217;s formal specification. Although a configuration does provide a complete Java environment, the set of core classes is normally quite small and must be enhanced with additional classes supplied by J2ME profiles or by configuration implementor. In particular, configurations do not define any user interface classes.</p>
<p>J2ME defines two configurations, the <em>Connected Limited Device Configuration</em> (CLDC) and the <em>Connected Device Configuration</em> (CDC). The CLDC is for very constrained (limited) devices &#8212; devices with small amounts of memory and/or slow processors. The VM used by the CLDC omits important features like finalization, while the set of core runtime classes is a tiny fraction of the J2SE core classes, just the basics from the java.lang, java.io and java.util packages, with a few additional classes from the new javax.microedition.io package. The CDC, on the other hand, includes a full Java VM and a much larger set of core classes, so it requires more memory than the CLDC and a faster processor. The CDC is in fact a superset of the CLDC. We&#8217;ll discuss the configurations in detail in the next two articles in this series.</p>
<p><span style="text-decoration: underline"><strong>Profiles:</strong></span></p>
<p>A <em>profile</em> adds domain-specific classes to a configuration to fill in missing functionality and to support specific uses of a device. For example, most profiles define user interface classes for building interactive applications.</p>
<p>To use a profile, the device must meet all the minimum requirements of the underlying configuration as well as any additional requirements mandated by the profile&#8217;s formal specification.</p>
<p>There are several profiles in various stages of development. The first profile to be released was the <em>Mobile Information Device Profile</em> (MIDP), a CLDC-based profile for running applications on cellphones and interactive pagers with small screens, wireless HTTP connectivity, and limited memory. Another CLDC-based profile under development is the <em>Personal Digital Assistant Profile</em> (PDAP), which extends MIDP with additional classes and features for more powerful handheld devices. In terms of CDC-based profiles, the <em>Foundation Profile</em> (FP) extends the CDC with additional J2SE classes, the <em>Personal Basis Profile</em> (PBP) extends the FP with lightweight (AWT-derived) user interface classes and a new application model, and the <em>Personal Profile</em> extends the PBP with applet support and heavyweight UI classes.</p>
<p><span style="text-decoration: underline"><strong>Optional Packages:</strong></span></p>
<p>An <em>optional package</em> is a set of APIs in support of additional, common behaviors that don&#8217;t really belong in one specific configuration or profile. Bluetooth support, for example, is defined as an optional package. Making it part of a profile wouldn&#8217;t work, because none of the behaviors of a profile can be optional &#8212; if a device supports a profile, it must support the entire profile &#8212; and that would limit the profile to Bluetooth-enabled devices.</p>
<p>Optional packages have their own minimum requirements, of course, just like configurations and profiles. Optional packages also have specific dependencies on a particular configuration and/or one or more profiles &#8212; they do not define a complete runtime environment, just sets of related APIs.</p>
<p>There are many optional packages in development, including the <em>RMI Optional Package</em>, which adds RMI support to CDC/FP-based profiles, the <em>Java APIs for Bluetooth</em>, which adds Bluetooth support to CLDC-based profiles, and the <em>JDBC Optional Package for CDC/Foundation Profile</em>, which defines a subset of JDBC (database access APIs) for use with CDC/FP-based profiles. Again, we&#8217;ll be covering these later on in the series as the need arises.</p>
<p><span style="text-decoration: underline"><strong>The CLDC Specification:</strong></span></p>
<p>The CLDC is defined by a specification that has passed through the Java Community Process (JCP)</p>
<p>The CLDC specification defines three things:</p>
<ol>
<li>The capabilities of the Java virtual machine (VM), which is <em>not</em> a full-featured Java VM.</li>
<li>A <em>very small</em> subset of the J2SE 1.3 classes.</li>
<li>A new set of APIs (application programming interfaces) for input/output called the Generic Connection Framework.</li>
</ol>
<p>It&#8217;s also important to understand what the CLDC does <em>not</em> define. The CLDC does not define any APIs related to user interfaces. The CLDC does not define how applications are loaded onto a device or how they are activated or deactivated. These and other things are defined by the J2ME profiles that use the CLDC as their base. So while it&#8217;s true that the CLDC does define a complete Java runtime environment, the additional APIs defined by a profile or supplied by the vendor are really necessary to build useful applications.</p>
<p><span style="text-decoration: underline"><strong>The Virtual Machine:</strong></span></p>
<p>The Java VM used in the CLDC is restricted in certain important ways when compared to a full-featured J2SE VM. These restrictions allow the VM to fit the memory and power constraints of the small devices that the CLDC target: the CLDC VM and classes can fit in 128K of memory. The primary restrictions on the VM are:</p>
<ol>
<li>No floating point types.</li>
<li>No object finalization or weak references.</li>
<li>No JNI or reflection (hence no object serialization).</li>
<li>No thread groups or daemon threads (note that threads <em>are</em> supported, just not thread groups).</li>
<li>No application-defined class loaders.</li>
</ol>
<p>Note that CLDC 1.1 relaxes some of these restrictions, in particular reenabling support for floating point types and weak references.</p>
<p>In addition to the above restrictions, the CLDC also requires class verification to be done differently. Class files are processed by an off-device class verifier, a process called <em>preverification</em>. At runtime, the VM uses information inserted into the class files by the preverifier to perform the final verification steps. Files that have not been processed by the preverifier are not loaded since they cannot be verified.</p>
<p><span style="text-decoration: underline"><strong>The J2SE Subset:</strong></span></p>
<p>The subset of J2SE 1.3 included in the CLDC consists of classes from these three packages:</p>
<ol>
<li>java.lang</li>
<li>java.io</li>
<li>java.util</li>
</ol>
<p>Only selected classes from each package are included: for example, the java.util.Vector and java.util.Hashtable classes are included, but none of the collection classes are. The largest package is the java.lang package, which defines the classes that are fundamental to any java application, classes like java.lang.Object or java.lang.Integer. The java.io subset only includes abstract and memory-based classes and interfaces like java.io.DataInput or java.io.ByteArrayInputStream. The java.util subset only includes a few utility classes.</p>
<p>Some of the classes are subsets of their J2SE equivalents. Configurations are allowed to remove unnecessary methods or fields, but they cannot add new public or protected methods or fields.</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/j2me-core-concepts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Association , Aggregation and Composition</title>
		<link>http://electrofriends.com/articles/computer-science/association-aggregation-composition/</link>
		<comments>http://electrofriends.com/articles/computer-science/association-aggregation-composition/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 10:44:22 +0000</pubDate>
		<dc:creator>Ranjan</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Aggregation]]></category>
		<category><![CDATA[Association]]></category>
		<category><![CDATA[Composition]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=2545</guid>
		<description><![CDATA[Association “Association represents the static relationship shared among the objects of two classes. “So any relationship between object of two classes is called association. An association says there is some kind of dependency between the objects. It can either be a weak or Strong dependency. Consider an example of Teacher and Student classes. Multiple students [...]]]></description>
			<content:encoded><![CDATA[<h2>Association</h2>
<p>“Association represents the static relationship shared among the objects of two classes. “So any relationship between object of two classes is called association.</p>
<p>An association says there is some kind of dependency between the objects. It can either be a weak or Strong dependency.</p>
<p>Consider an example of Teacher and Student classes. Multiple students can associate with single teacher and single student can associate with multiple teachers. This is a kind of a weak relationship because there is no ownership between the student and teacher and the life cycle are maintained by themselves.</p>
<h2>Composition</h2>
<p><em>Composition</em> is <strong>specialized</strong> form of <strong>aggregation</strong> and we can call this as a “<strong>life and death</strong>” relationship. It is a strong type of <strong>aggregation</strong>. Child object does not have their life-cycle and if parent object deletes all child objects will also be deleted.</p>
<p>Consider an example of a set of classes Engine and Car. The object Engine is said to be composed with in the Car object as the Engine cannot leave without the Car object and the relationship is said to be whole because the Engine is a part of the Car object. Here the life cycle of Engine is managed by the Car object. If the Car gets destructed the associated composite object like Engine will also get destroyed.</p>
<p>Thus a composition relationship specifies that the lifetime of the part classifier is dependent on the lifetime of the whole classifier.</p>
<p>public class Engine<br />
{<br />
. . .<br />
}</p>
<p>public class Car</p>
<p>{</p>
<p>Engine e = new Engine();</p>
<p>&#8230;&#8230;.</p>
<p>}</p>
<p>Yet another example for Composite relationship is, consider a set of classed Person, Leg and Hand. The objects Leg and Hand are composed within the Person object. The life cycle of Leg and Hand objects are maintained by Person object. Also you can see the Leg and Hand object cannot leave independently without the Person object. And note there is a strong relationship of Leg and Hand object with the Person.</p>
<h2><a href="http://electrofriends.com/wp-content/uploads/2012/01/Composition1.png"><img class="alignleft size-medium wp-image-2551" src="http://electrofriends.com/wp-content/uploads/2012/01/Composition1-300x246.png" alt="" width="300" height="246" /></a></h2>
<h2>Aggregation</h2>
<p>The difference between aggregation and composition is the object which can exists independently uses aggregation and an object that has no meaning outside of the relationship uses composition</p>
<p>Let’s take an example of Department and teacher. A single teacher cannot belong to multiple departments, but if we delete the department, the teacher object will not destroy. We can think about “has-a” relationship.</p>
<p>Let us take another example of Company and Employee classes. The employee is said to be aggregated with the Company. The Employee is working for a company and has a relationship with the company.  The employee object can still survive even if say the Company object does not exists.</p>
<h2>Conclusion</h2>
<p>I will conclude here by taking a real world example which has aggregation and compositions.</p>
<p>Consider a scenario of a University which owns various departments (e.g., physics, chemistry) and each department has a number of professors. If the university closes, the departments will no longer exist, but the professors in those departments will continue to exist. Therefore, a University can be seen as a composition of departments, whereas departments have an aggregation of professors. In addition, a Professor could work in more than one department, but a department could not be part of more than one university.</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/computer-science/association-aggregation-composition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Automapper</title>
		<link>http://electrofriends.com/articles/introduction-automapper/</link>
		<comments>http://electrofriends.com/articles/introduction-automapper/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 05:25:10 +0000</pubDate>
		<dc:creator>Ranjan</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=2504</guid>
		<description><![CDATA[Introduction AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type. When to use Automapper? Here is one Sample scenario. Assume we have a domain model say a Customer entity and we are planning to show a list of Customers in [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type.</p>
<p><strong>When to use Automapper?</strong></p>
<p>Here is one Sample scenario. Assume we have a domain model say a <code>Customer</code> entity and we are planning to show a list of <code>Customers</code> in a UI, for that, we need a much lighter object say <code>CustomerViewModel</code>, which has a list of <code>Customer</code> objects that can be used to bind the controls in UI layer.</p>
<p>Would you like to have something that will do mapping from <code>Customer</code> to the <code>CustomerViewModel</code> automatically?</p>
<p>Of course, you do, especially if you have another situation like mapping of heavy data objects into DTO objects which are considered to be sent though the wire.</p>
<p><strong>How do I use AutoMapper?</strong></p>
<p>First, you need both a source and destination type to work with. The destination type&#8217;s design can be influenced by the layer in which it lives, but AutoMapper works best as long as the names of the members match up to the source type&#8217;s members. If you have a source member called &#8220;FirstName&#8221;, this will automatically be mapped to a destination member with the name &#8220;FirstName&#8221;.</p>
<p>Once you have your types, and a reference to AutoMapper, you can create a map for the two types.</p>
<p><code>Mapper.CreateMap&lt;Order, OrderDto&gt;();</code></p>
<p>The type on the left is the source type, and the type on the right is the destination type. To perform a mapping, use the Map method.</p>
<p><code>OrderDto dto = Mapper.Map&lt;Order, OrderDto&gt;(order);<br />
</code><br />
AutoMapper also has non-generic versions of these methods, for those cases where you might not know the type at compile time.</p>
<p><strong>Where do I configure AutoMapper?</strong></p>
<p>If you&#8217;re using the static Mapper method, configuration only needs to happen once per AppDomain. That means the best place to put the configuration code is in application startup, such as the Global.asax file for ASP.NET applications. Typically, the configuration bootstrapper class is in its own class, and this bootstrapper class is called from the startup method.</p>
<p><strong>Samples and DLL’s: </strong></p>
<p><a href="http://www.codeproject.com/KB/library/AutoMapper.aspx">http://www.codeproject.com/KB/library/AutoMapper.aspx</a></p>
<p><a href="http://automapper.codeplex.com/">http://automapper.codeplex.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/introduction-automapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

