tag:blogger.com,1999:blog-79887925899542616882024-03-08T12:36:28.249+03:00CodeBuildSoftware Development & Architecture BlogCBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.comBlogger47125tag:blogger.com,1999:blog-7988792589954261688.post-72383942671353830472015-01-25T16:12:00.000+02:002015-01-25T21:23:03.609+02:00Algorithms Explained : Minesweeper Game<br />
<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com.tr/2015/01/algorithms-explained-minesweeper-game.html';
</script>
<script type="text/javascript">
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">This blog post explains most critical algorithms for well-known windows oriented game, minesweeper:</span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfdJfPqkOYw40xWjJF5ZSEwBv_Njt_EhtZjc0D6y8aFwVMIYqeKisuGwGufGHUl-R6THb4SrKYG2oDZhF1JFbcOrhdvrEqP2pu7NV6TTdIwLf03Tb9ro09bBiyU951_YmVadJZVvqLx0fb/s1600/ms.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfdJfPqkOYw40xWjJF5ZSEwBv_Njt_EhtZjc0D6y8aFwVMIYqeKisuGwGufGHUl-R6THb4SrKYG2oDZhF1JFbcOrhdvrEqP2pu7NV6TTdIwLf03Tb9ro09bBiyU951_YmVadJZVvqLx0fb/s1600/ms.png" height="278" width="400" /></a></div>
<br />
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<b><span style="font-family: Trebuchet MS, sans-serif;">Game Rules:</span></b></div>
<br />
<ol>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">The board is a two dimensional space, which </span><span style="font-family: 'Trebuchet MS', sans-serif;">has a predetermined number of mines.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">Cells has two states, opened and closed.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If you left-click on a closed cell:</span></li>
<ol>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">Cell is empty and opened. </span></li>
<ol>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If neighbour cell(s) have mine(s), this opened cell shows neighbour mine count.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If neighbour cells have no mine, all neighbour cells are opened automatically.</span></li>
</ol>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">Cell has a mine, game ends with FAIL.</span></li>
</ol>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If you right-click on a closed cell, you put a flag which shows that "I know that cell has a mine".</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If you multiclick (both right and left click) on a cell which is opened and has at least one mine on its neighbours:</span></li>
<ol>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If neighbour cells' total flag count equals to this multi-clicked cell's count and predicted mine locations are true, all closed and unflagged neighbour cells are opened automatically.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If neighbour cells' total flag count equals to this multi-clicked cell's count and at least one predicted mine location is wrong, game ends with FAIL.</span></li>
</ol>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If all cells (without mines) are opened using left clicks and/or multi-clicks, game ends with SUCCESS.</span></li>
</ol>
<div style="text-align: left;">
<b><span style="font-family: Trebuchet MS, sans-serif;">Data Structures:</span></b></div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">We may think each cell as a UI structure (e.g. button), which has following attributes:</span></div>
<div>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">colCoord = 0 to colCount</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">rowCoord = 0 to rowCount</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">isOpened = true / false (default false)</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">hasFlag = true / false (default false)</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">hasMine = true / false (default false)</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">neighbourMineCount 0 to 8 (default 0, count of total of mines on neighbour cells)</span></li>
</ul>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">So, we have a two dimensional "Button[][] cells" data structure to handle game actions.</span></div>
</div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<b><span style="font-family: Trebuchet MS, sans-serif;">Algorithms:</span></b></div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<i><u><span style="font-family: Trebuchet MS, sans-serif;">Before Start:</span></u></i></div>
<div>
<ol>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">Assign mines to cells randomly (set hasMine=true) .</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">Calculate neighbourMineCount values for each cell, which have hasMine=false. (this step may be done for each clicked cell while game continues but it may be inefficient)</span></li>
</ol>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><i>Note1</i>: Neighbour cells should be accessed with {(colCoord-1, rowCoord-1),(colCoord-1, rowCoord),(colCoord-1, rowCoord+1),(colCoord, rowCoord-1),(colCoord, rowCoord+1),(colCoord+1, rowCoord-1),(colCoord+1, rowCoord),(colCoord+1, rowCoord+1)} coordinates. And don't forget that, neighbour cell counts may be 3 (for corner cells), 5 (for edge cells) or 8 (for middle cells).</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<i style="font-family: 'Trebuchet MS', sans-serif;">Note2:</i><span style="font-family: 'Trebuchet MS', sans-serif;"> It's recommended to handle mouse clicks with "mouse release" actions instead of "mouse pressed/click" actions, otherwise left or right click may be understood as multi-clicks or vice versa.</span></div>
</div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<i><u><span style="font-family: Trebuchet MS, sans-serif;">Right Click on a Cell:</span></u></i></div>
<div>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell isOpened=true, do nothing.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell isOpened=false, set cell hasFlag=true and show a flag on the cell. </span></li>
</ul>
</div>
<div style="text-align: left;">
<i><u><span style="font-family: Trebuchet MS, sans-serif;">Left Click on a Cell:</span></u></i></div>
<div>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell isOpened=true, do nothing.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell isOpened=false:</span></li>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell hasMine=true, game over.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell hasMine=false:</span></li>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell has neighbourMineCount > 0, set isOpened=true, show neighbourMineCount on the cell. If all cells which hasMine=false are opened, end game with SUCCESS.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell has neighbourMineCount == 0, set isOpened=true, call <i><u>Left Click on a Cell</u></i> for all neighbour cells, which hasFlag=false and isOpened=false.</span></li>
</ul>
</ul>
</ul>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><i>Note</i>: Last step may be implemented with recursive call or using a stack data structure.</span></div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<i><u><span style="font-family: Trebuchet MS, sans-serif;">Multi Click (both Left and Righ Click) on a Cell:</span></u></i></div>
</div>
<div>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell isOpened=false, do nothing.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell isOpened=true:</span></li>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell neighbourMineCount == 0, no nothing.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell neighbourMineCount > 0:</span></li>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell neighbourMineCount != "neighbour hasFlag=true cell count", do nothing.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If cell neighbourMineCount == "neighbour hasFlag=true cell count":</span></li>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If all neighbour hasFlag=true cells are not hasMine=true, game over.</span></li>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;">If all neighbour hasFlag=true cells are hasMine=true (every flag is put on correct cell), call <i><u>Left Click on a Cell</u></i> for all neighbour cells, which hasFlag=false and isOpened=false.</span></li>
</ul>
</ul>
</ul>
</ul>
</div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><i>Note</i>: Last step may be implemented with recursive call or using a stack data structure.</span></div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<br /></div>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com1tag:blogger.com,1999:blog-7988792589954261688.post-25833972633284794772014-02-26T00:15:00.000+02:002014-02-26T00:19:10.476+02:00Software Version Controlling Best Practices<br />
<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com.tr/2014/02/software-version-controlling-best.html';
</script>
<script type="text/javascript">
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<b><span style="font-family: Trebuchet MS, sans-serif;">Always use version controlling</span></b><br />
<span style="font-family: Trebuchet MS, sans-serif;">Use version controlling/source control even if one developer exists. This issue brings change tracking and versioning of the application continuously. For multi developers, it brings more benefits like co-working on same files and fast codebase updates.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><b><br /></b>
<b>Do not commit halfdone work</b></span><br />
<span style="font-family: Trebuchet MS, sans-serif;">Each commit should consist of a complete task (issue, bugfix, etc.). Partial commits may cause unfunctionality, crash of application or even compilation errors.</span><br />
<b style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></b>
<b style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">Full Update -> Build -> Run -> Full Commit rule</span></b><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">For having no trouble, a stable version controlling process should be applied. According to this process, you should full update the code, then build and run your application. If application runs correctly, you should commit all of your updated files. While committing, inspect all of your changed files and changes. If all team members apply this process, application will always continue to run and no one will prevent others work.</span> </div>
<br />
<div style="text-align: justify;">
<b><span style="font-family: Trebuchet MS, sans-serif;">Commit atomicity/granularity</span></b></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Do not use version controlling system to backup each single file separately and do not commit hundreds of files after days or weeks of development. Commits should be atomic, and as a best practice, should include files which are related with only one task. Late commits also brings more conflicts.</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b><span style="font-family: Trebuchet MS, sans-serif;">Use descriptive commit messages</span></b></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Commit messages are important for tracking changes. Descriptive commit messages help developers to control old versions of code within a functional context, instead of date and time only.</span></div>
<br />
<div style="text-align: justify;">
<b style="font-family: 'Trebuchet MS', sans-serif;">Don't commit generated files</b></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Use "ignore" funcionalities of your version controlling tool to ignore commiting and updating of generated files (e.g. target folders, user settings, IDE generated files, generated classes after each build etc.) By doing this, you will not waste your time for managing those unstable/unimportant files.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<b><span style="font-family: Trebuchet MS, sans-serif;">Continuous integration</span></b></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Use continuous integration along with version controlling. By doing that, perform automated builds and deploys to a specific location. Also, configure the tool to create a separate version number (with a predefined versioning algorithm, e.g. <major_changes>.<minor_changes>.<bug_fixes>) for each build. This will be useful to trace tests and deployments.</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
</div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Use qualified version controlling tools and plugins (especially for merge)</b></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Version controlling tool quality is also important. It must at least show changed files clearly, give ability to merge conflicted files easily and view old versions of files. Besides, it will be better to have a branching function to manage versions and and issue tracking system synchronization to manage issue-related code file matchings.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<b style="font-family: 'Trebuchet MS', sans-serif;">Use branches for testing and different lines of code</b></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">You should use different code branches for development, testing and also production. If a version of code is being tested, development should not continue on that branch. Development can continue on another branch and when a new version will be tested after fixing some bugs and adding new properties, a new test branch should be provided with a new version. When a stable test branch is reached, it may be released as a production branch.</span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<span style="font-family: Trebuchet MS, sans-serif;">You can also take a look at the below link for version controlling basics:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><a href="http://betterexplained.com/articles/a-visual-guide-to-version-control/">http://betterexplained.com/articles/a-visual-guide-to-version-control/</a></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com3tag:blogger.com,1999:blog-7988792589954261688.post-82523279475052173182013-04-22T14:14:00.000+03:002013-04-22T14:15:24.245+03:00A Theorical Look into Object/Resource Pool Pattern<br />
<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2013/04/a-theorical-look-into-objectresource.html';
</script>
<script type="text/javascript">
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Definition:</b></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Sometimes our software projects need costly object creations (database connections, socket connections, large graphical objects etc.). This cost may be about time and/or memory. Those objects may also be needed to be created frequently. At that moment, Object/Resource Pool pattern comes to help.</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Object Pool pattern:</b></span></div>
<div style="text-align: justify;">
</div>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Reuses unused costly objects without re-creating those objects (e.g. books in a library).</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">May create objects eagerly before they are needed, to manage application performance.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">May limit created number of objects to manage application performance and user access.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Working principle:</b></span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6n26PwR4UKWff04ofLketHTzI-CIvzJfE1aMLCs83APC0Wa806lK_37GfKDRRC8B4ZF5nIjafg879lRkyr-Db5fLnZ7UJ7o072m4zrxxEzDDDQKL-blsSTu5QL93eL2KAMxc-MmSwem6h/s1600/objectpool.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6n26PwR4UKWff04ofLketHTzI-CIvzJfE1aMLCs83APC0Wa806lK_37GfKDRRC8B4ZF5nIjafg879lRkyr-Db5fLnZ7UJ7o072m4zrxxEzDDDQKL-blsSTu5QL93eL2KAMxc-MmSwem6h/s1600/objectpool.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Object Pool Class Diagram</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
</div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Client requests an object (Reusable) from object pool. Object pool has a list of predefined reusables and gives an available one from pool. For the client's point of view, given reusable is a new object but it is probably (object creation strategies will be told later) a pre-created object with a new object's field values. For the optimum performance, client should notify object pool when reusable is no longer needed. Just in case client doesn't notify, object pool may define a timeout for each created reusable. Object pool must also have a synchronization mechanism for reusable serving, especially on multithreaded or multiuser applications.</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>When to use/Trade offs:</b></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">If objects are not costly, object pool pattern should not be used because this pattern needs clients to inform object pool (brings extra code complexity) and object creation management code (synchronization of pool, object creation limitation strategy etc.). This extra management code also brings a little performance loss. If performance gain of reusable object usage is bigger than extra management code performance loss, and application must frequently create those reusable objects, object pool pattern is recommended to be used.</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Implementation Strategies:</b></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b> Object pool limit:</b></span></div>
<div style="text-align: justify;">
</div>
<ul>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">If memory is limited and/or maximum number of clients are needed to be restricted, an object number limit value may be defined for object pool (limited pool).</span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">If there is no restriction, limit value is not needed (unlimited pool).</span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">If all object pool list is in use, new objects may be created (expanding pool) or client may be enforced to waiting (fixed pool).</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><b> Eager/lazy creation:</b></span></div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">If application startup is performed infrequently and startup time is not very important, object pool list objects may be created at the startup (eager ceration).</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">If no restrictions exist, no objects are needed to be created eagerly (lazy creation).</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Some number of objects may be created eagerly, others may be created lazily according to the application parameters (mixed creation).</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><b> Empty object pool strategy:</b></span></div>
<div>
<ul>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">If object pool is expanding, create a new object and return it.</span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">If object pool is not expanding, return null or enforce client to wait until an object is ready to be given.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"> <b>Synchronization strategy:</b></span></div>
<div>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Object pool should have a synchronization mechanism for object serving. Otherwise, especially on multiuser systems, pooling system may fail.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><b> Unused object strategy:</b></span></div>
</div>
<div>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Usage of the pool objects may be lower than expected in some cases. Object pool may have a pool object removing strategy (i.e. descreasing object limit) for increasing performance.</span></li>
</ul>
</div>
<div>
<b><span style="font-family: Trebuchet MS, sans-serif;"> Returning object strategy:</span></b></div>
</div>
<div>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Clients should return pool objects back to the pool after their job is completed. But pool code can't control this and poor client code may return pool objects. For this situation, object pool may have a timer mechanism for given but unused pool objects.</span></li>
</ul>
</div>
<div>
<div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
</div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">According to the project requirements, some of those strategies or mixed versions should be selected and implemented for object pool. But "reusing available objects" principle is the key and can not be changed for any implementation strategy.</span></div>
</div>
<br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Example Implementations will exist on the next post.</span></div>
<div style="text-align: justify;">
<br /></div>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com1tag:blogger.com,1999:blog-7988792589954261688.post-934007273239386872013-02-20T10:02:00.000+02:002013-02-27T20:14:06.134+02:00Layers of a Standard Enterprise Application<br />
<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2013/02/layers-of-standard-enterprise.html';
</script>
<script type="text/javascript">
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">In a standard enterprise application which has a database and graphical UI (web or desktop), there are some typical layers which constitute the application. In this article we will mention those layers and give some instructions about them. </span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">The general diagram is as below:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYXrz9qUqaujYgG2BKTN1uHsauMSv5z9HZdGCyzpcFfTXqPn7nmMN8uRsH5b4Ky9sRmnUJ7XxIy5oE9mhBYtRBgnihF4ssAsWkCRVqS36gXFtInyiXFiEEeT1ffcZHQ_v9qFcnzO7lvi9I/s1600/layers.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYXrz9qUqaujYgG2BKTN1uHsauMSv5z9HZdGCyzpcFfTXqPn7nmMN8uRsH5b4Ky9sRmnUJ7XxIy5oE9mhBYtRBgnihF4ssAsWkCRVqS36gXFtInyiXFiEEeT1ffcZHQ_v9qFcnzO7lvi9I/s1600/layers.png" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">There are some important properties about that diagram: </span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">There are vertical and horizontal layers. Vertical layers may be thought as general application service libraries which can paralelly work on all horizontal layers and independent from each other. However, a horizontal layer's subject of interest is only its neighbour (top and bottom) horizontal layers, and they work sequentially from top-to-bottom and bottom-to-top. Lastly, user can only interact with topmost horizontal layer. </span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>Horizontal layers:</b></span></div>
<div style="text-align: justify;">
<br />
<ul>
<li><b style="font-family: 'Trebuchet MS', sans-serif;">Presentation</b><span style="font-family: 'Trebuchet MS', sans-serif;">: </span><span style="font-family: 'Trebuchet MS', sans-serif;">Every enterprise application has a UI, in fact graphical UI. This UI can be web or desktop based, which doesn't matter. The rule is simple. UI takes user action and sends it to the controller. And at the end it shows result taken from controller </span><span style="font-family: 'Trebuchet MS', sans-serif;">to the user</span><span style="font-family: 'Trebuchet MS', sans-serif;">. UI can be implemented according to MVC, MVP, MVVM or another approach.</span></li>
<li><b style="font-family: 'Trebuchet MS', sans-serif;">Control</b><span style="font-family: 'Trebuchet MS', sans-serif;">: </span><span style="font-family: 'Trebuchet MS', sans-serif;">Handles business logic of the application. Takes info from user and sends it to DB layer (DAO or ORM framework) and vice versa. Abstraction type of controller may vary (a separate control and business layers for example) according to the application parameters or development patterns (MVC, MVP, MVVM, ...) but the main idea remains the same.</span></li>
<li><b style="font-family: 'Trebuchet MS', sans-serif;">Data Access</b><span style="font-family: 'Trebuchet MS', sans-serif;">: </span><span style="font-family: 'Trebuchet MS', sans-serif;">Database handling layer of the application. It may contain entity definitions, ORM framework or DB connection codes having SQL sentences, according to the abstraction decision. Its role is getting data from controller, performing data operation on database and sending results again to controller (if result exists). Database independence is a very important plus for this layer, which brings flexibility.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
</div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>Vertical layers:</b></span></div>
<div style="text-align: justify;">
<br />
<ul>
<li><b style="font-family: 'Trebuchet MS', sans-serif;">Security</b><span style="font-family: 'Trebuchet MS', sans-serif;">: </span><span style="font-family: 'Trebuchet MS', sans-serif;">Security is a general concept, which includes user authorization, user authentication, user role management, network or SQL injection attack prevention, data recovery etc but we grouped that items generally as "Security". Those issues must be handled for each horizontal layer if you want to have a fully secure software.</span></li>
<li><b style="font-family: 'Trebuchet MS', sans-serif;">Logging: </b><span style="font-family: 'Trebuchet MS', sans-serif;">Logging is very important for maintenance and reporting in enterprise applications. An easily configurable, parameterized, readable, flexible and correctly implemented logging layer for all horizontal layers is very useful for both developers and users. </span></li>
<li><b style="font-family: 'Trebuchet MS', sans-serif;">i18n</b><span style="font-family: 'Trebuchet MS', sans-serif;">: </span><span style="font-family: 'Trebuchet MS', sans-serif;">i18n (internationalization) brings multiple language support and user interface text changing capability without rebuilding code. It may also have localization property which can handle number, currency and date formatting. So i18n provides flexibility on applications and should not be ignored.</span></li>
<li><b style="font-family: 'Trebuchet MS', sans-serif;">Exception Handling: </b><span style="font-family: 'Trebuchet MS', sans-serif;">Exception handling may also be included in "Security" or "Logging" layers. We should not use only general exception classes or absorb all exceptions if we want to develop a quality software. We sometimes need our special exception classes with their specific behaviours for better security, logging and application performance.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
</div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">If you design an architecture which has that layer structure considering software quality factors (which are told </span><a href="http://codebuild.blogspot.com/2013/02/10-most-important-software-quality.html" style="font-family: 'Trebuchet MS', sans-serif;">here</a><span style="font-family: 'Trebuchet MS', sans-serif;">), you will probably have a successful enterprise software application.</span></div>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com2tag:blogger.com,1999:blog-7988792589954261688.post-77045822476373831762013-02-06T09:44:00.005+02:002013-02-06T10:05:15.616+02:0010 Groups of Software Quality Factors That Should Always Be Remembered<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2013/02/10-most-important-software-quality.html';
</script>
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<br />
<b style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">Flexibility and Extensibility</b><span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">: </span><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Flexibility is the ability of software to add/modify/remove functionality without damaging current system. Extensibility is the ability of software to add functionality without damaging system, so it may be thought as a subset of flexibility. Those functionality changes may occur acoording to changing requirements, or an obligation if development process is one of the iterative methods. Change is inevitable in software development and so, this is one of the most important properties of quality software.</span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><b>Maintainability and Readability:</b></span><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Maintainability is a little similar with flexibility but it focuses on modifications about error corrections and minor function modifications, not major functional extensibilities. It can be supported with useful interface definitions, documentations and also self-documenting code and/or code documentation. The more correct and useful documentation exists, the more maintainability can be performed.</span></div>
<br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Performance and Efficiency:</b></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Performance is mostly about response time of the software. This response time should be in acceptable intervals (e.g. max. a few seconds), and should not increase if transaction count increases. And also, resources are expensive. Efficiency must be supported with resource utilization. As an exaggerated example, ability of performing a simple function only by using a 32 processor machine or 1 TB disk space is not acceptable. Optimal source/performance ratio must be aimed. </span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><b>Scalability:</b></span><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">A scalable system responds user actions in an acceptable amount of time, even if load increases. Of course more hardware may be added for handling increasing user transaction, but the architecture should not change while doing this. This is called vertical scalability. Ability of running on multiple, increasing count of machines is multiple processing. If the software can perform that type of processing, this is called horizontal scalability. A preffered scalable system should suit both of these methods.</span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><b>Availability, Robustness, Fault Tolerance and Reliability:</b></span><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">A robust software should not lose its availabilty even in most failure states. Even if some components are broken down, it may continue running. Besides, even if whole application crashes, it may recover itself using backup hardware and data with fault tolerance approaches. There should always be B and even C, D .. plans. </span><span style="font-family: 'Trebuchet MS', sans-serif;">Reliability also stands for the integrity and consistency of the software even under high load conditions. So it is relevant with availability and scalability. An unreliable system is also unscalable.</span></div>
<br />
<span style="font-family: Trebuchet MS, sans-serif;"><b>Usability and Accessability:</b></span><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">User interfaces are the only visible parts of software according to the viewpoint of user. So, simplicity, taking less time to complete a job, fast learnability etc. are very important in this case. The most well known principle for this property is KISS (Keep It Simple Stupid). Simple is always the best. A usable software should also support different accessibility types of control for people with disabilities.</span><br />
<b style="font-family: 'Trebuchet MS', sans-serif;"><br /></b>
<b style="font-family: 'Trebuchet MS', sans-serif;">Platform Compatibility and Portability:</b></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">A quality software should run on as much various platforms as it can. So, more people can make use of it. In different contexts we may mention different platforms, this may be OS platforms, browser types etc. And p</span><span style="font-family: 'Trebuchet MS', sans-serif;">ortability is about adapting software that can run on different platforms, for being more platform compatible. In this sense, portability is also related with flexibility.</span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><b>Testability and Managability:</b></span><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Quality software requires quality testing. Source code should be tested with the most coverage and with the most efficient testing methods. This can be performed by using </span><span style="font-family: 'Trebuchet MS', sans-serif;">encapsulation, interfaces, patterns, low coupling etc. techniques correctly. Besides testability, a qualified software should be manageable after deployment. It may be monitored for e.g. performance or data usage status, or may enable developer to configure system easily. Creating a successful logging system is another very important issue about managability.</span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><b>Security:</b></span><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Security is a very important issue on software development, especially for web or mobile based ones which may have millions of users with the ability of remote accessing to system. You should construct a security policy and apply it correctly by leaving no entry points. This may include authorization and authentication techniques, network attack protections, data encryption and so on. all possible types of security leaks should be considered, otherwise one day only one attack may crash your whole applicaion and whole company.</span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><b>Functionality and Correctness:</b></span><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Functionality (or correctness) is the conformity of the software with actual requirements and specifications. In fact this is the precendition attribute of an application, and maybe not a quality factor but we wanted to point that as the last </span><span style="font-family: 'Trebuchet MS', sans-serif;">quality factor, for taking attention: Quality factors are not meaningful when we are talking about unfunctional software. First, perform desired functionality and produce correct software, then apply quality factors on it. If you can perform both paralelly, it is the best.</span></div>
<div style="text-align: justify;">
<br /></div>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com2tag:blogger.com,1999:blog-7988792589954261688.post-89422632512441406162013-01-14T08:33:00.000+02:002013-01-14T14:58:32.996+02:00A Serverless, Zero-Configuration Database Solution : SQLite<style type="text/css">
.java .de1, .java .de2 {font: normal normal 1em/1em monospace; margin:0; padding:0; background:none;color: #000020;}
.java {font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;}
.java a:link {color: #000060;}
.java a:hover {background-color: #f0f000;}
.java .imp {font-weight: bold; color: red;}
.java li, .java .li1 {font-weight: normal;font: normal normal 100% 'Courier New', Courier, monospace; color: #003030;}
.java .ln {width:1px;text-align:right;margin:0;padding:0 2px;}
.java .li2 {font-weight: bold;font-weight: bold; color: #006060;}
.java .kw1 {color: #000000; font-weight: bold;}
.java .kw2 {color: #000066; font-weight: bold;}
.java .kw3 {color: #003399;}
.java .kw4 {color: #000066; font-weight: bold;}
.java .co1 {color: #666666; font-style: italic;}
.java .co2 {color: #006699;}
.java .co3 {color: #008000; font-style: italic; font-weight: bold;}
.java .coMULTI {color: #666666; font-style: italic;}
.java .es0 {color: #000099; font-weight: bold;}
.java .br0 {color: #009900;}
.java .sy0 {color: #339933;}
.java .st0 {color: #0000ff;}
.java .nu0 {color: #cc66cc;}
.java .me1 {color: #006633;}
.java .me2 {color: #006633;}
.java span.xtra { display:block; }
</style>
<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2013/01/a-serverless-zero-configuration.html';
</script>
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Most software need saving data. Sometimes that data is predicted to be small and hundreds or thousands of transactions on it will not be needed at the same time. But you will need some SQL-like operations on that data, because some modifications can be difficult and time consuming with regular file operations. At that time, SQLite becomes a very practical solution to this situation.</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">It started as a C/C++ library (on <a href="http://www.sqlite.org/">http://www.sqlite.org/</a>) but it also has Xerial jdbc project for Java (on <a href="http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC">http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC</a> and <a href="https://bitbucket.org/xerial/sqlite-jdbc">https://bitbucket.org/xerial/sqlite-jdbc</a> lastly). We will tell some details of Java JDBC project here. Some critical properties are:</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
</div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">You need only <u>one</u> jar file and adding it to the classpath.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Download latest jar (from here: <a href="https://bitbucket.org/xerial/sqlite-jdbc/downloads">https://bitbucket.org/xerial/sqlite-jdbc/downloads</a>) and add to the classpath.</span><span style="font-family: 'Trebuchet MS', sans-serif;"> </span></div>
<div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">Needs <u>one</u> line of code to start using.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Class.forName("org.sqlite.JDBC"); line is enough for activating driver.</span></div>
</div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">It creates <u>one</u> database file per schema at the place which you will determine.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Connection con = DriverManager.getConnection("jdbc:sqlite:mydb.db"); line creates "mydb.db" file as database file on the root of your project and creates a connection for DB operations.</span></div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">Supports a general formed JDBC SQL syntax with a useful JDBC API.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Some code examples are shown below (connection opening/closing statements are not included each time for simplifying statements):</span></div>
<br />
<div class="java">
<ol>
<li class="li1"><div class="de1">
<span class="co1">// opening connection</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://www.google.com/search?hl=en&q=allinurl%3Aconnection+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Connection</span></a> con <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&q=allinurl%3Adrivermanager+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">DriverManager</span></a>.<span class="me1">getConnection</span><span class="br0">(</span><span class="st0">"jdbc:sqlite:person.db"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://www.google.com/search?hl=en&q=allinurl%3Astatement+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Statement</span></a> stat <span class="sy0">=</span> con.<span class="me1">createStatement</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<br />
<li class="li1"><div class="de1">
<span class="co1">// closing connection</span></div>
</li>
<li class="li2"><div class="de2">
con.<span class="me1">close</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co1">// creating table</span></div>
</li>
<li class="li1"><div class="de1">
stat.<span class="me1">executeUpdate</span><span class="br0">(</span><span class="st0">"create table person(id INT, name varchar(30));"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="co1">// dropping table</span></div>
</li>
<li class="li1"><div class="de1">
stat.<span class="me1">executeUpdate</span><span class="br0">(</span><span class="st0">"drop table if exists person"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co1">// inserting data</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://www.google.com/search?hl=en&q=allinurl%3Apreparedstatement+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">PreparedStatement</span></a> prep <span class="sy0">=</span> con.<span class="me1">prepareStatement</span><span class="br0">(</span><span class="st0">"insert into person values(?,?);"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li2"><div class="de2">
prep.<span class="me1">setInt</span><span class="br0">(</span><span class="nu0">1</span>, <span class="st0">1</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
prep.<span class="me1">setString</span><span class="br0">(</span><span class="nu0">2</span>, <span class="st0">"andy brown"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
prep.<span class="me1">execute</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co1">// selecting data</span></div>
</li>
<li class="li2"><div class="de2">
<a href="http://www.google.com/search?hl=en&q=allinurl%3Aresultset+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">ResultSet</span></a> res <span class="sy0">=</span> stat.<span class="me1">executeQuery</span><span class="br0">(</span><span class="st0">"select * from person"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">while</span> <span class="br0">(</span>res.<span class="me1">next</span><span class="br0">(</span><span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://www.google.com/search?hl=en&q=allinurl%3Asystem+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">(</span>res.<span class="me1">getString</span><span class="br0">(</span><span class="st0">"id"</span><span class="br0">)</span> <span class="sy0">+</span> <span class="st0">" "</span> <span class="sy0">+</span> res.<span class="me1">getString</span><span class="br0">(</span><span class="st0">"name"</span><span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="co1">// updating data</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://www.google.com/search?hl=en&q=allinurl%3Apreparedstatement+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">PreparedStatement</span></a> prep <span class="sy0">=</span> con.<span class="me1">prepareStatement</span><span class="br0">(</span><span class="st0">"update person set name = ? where id = ?;"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
prep.<span class="me1">setString</span><span class="br0">(</span><span class="nu0">1</span>, <span class="st0">"andy black"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
prep.<span class="me1">setInt</span><span class="br0">(</span><span class="nu0">2</span>, <span class="nu0">1</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
prep.<span class="me1">execute</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<br />
<span style="font-family: Trebuchet MS, sans-serif;">For more detailed examples about SQL syntax, please take a look at:
</span><br />
<pre class="brush: java;" style="background-color: white; text-align: left;"><span style="color: #444444;"><span style="font-family: Trebuchet MS, sans-serif; line-height: 18px;"><a href="http://docs.oracle.com/javase/tutorial/jdbc/index.html">http://docs.oracle.com/javase/tutorial/jdbc/index.html</a></span></span></pre>
<pre class="brush: java;" style="background-color: white; text-align: left;"></pre>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com1tag:blogger.com,1999:blog-7988792589954261688.post-39048099091188590122012-12-13T08:55:00.000+02:002012-12-13T10:14:42.715+02:0010 Software Process Management Best Practices<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/12/10-software-process-management-best.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Regardless of software process management type (waterfall, scrum, iterative etc.), there are some main rules which should be considered about software process management. In this post we will mention most important of these practices theorically:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAq8Qb37DKvYwvHpxxKYekChmzZGbRDE53V6V6CqR_hJ8yX9mp7KS9yiQ0MCdK9qUvqZ3ixxvPWxTRJ5fBYVjBns_NO-qubpancdabViWe-xTzm2XQRVeFAP8wZJb3NaJjtjW9sXVhQYL5/s1600/software_process.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAq8Qb37DKvYwvHpxxKYekChmzZGbRDE53V6V6CqR_hJ8yX9mp7KS9yiQ0MCdK9qUvqZ3ixxvPWxTRJ5fBYVjBns_NO-qubpancdabViWe-xTzm2XQRVeFAP8wZJb3NaJjtjW9sXVhQYL5/s1600/software_process.jpg" /></a></div>
<br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>1. </b></span><b style="font-family: 'Trebuchet MS', sans-serif;">Define roles and tasks of team members:</b></div>
<div style="text-align: justify;">
<div>
<span style="font-family: Trebuchet MS, sans-serif;">For productivity, roles of team members should be defined clearly. These roles may be project manager, team lead, develeoper, tester etc. Furthermore, authorizations and responsibilities of these roles should be defined very clearly. Task-assignment based development should also be applied for avoiding redundant effords and chaos. </span><br />
<b style="font-family: 'Trebuchet MS', sans-serif;"><br /></b>
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>2. </b></span><b style="font-family: 'Trebuchet MS', sans-serif;">Define meeting types:</b></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Meetings are very important if we are talking about software process management and should be defined in detail (meeting participants, context, average duration etc.). Team members should also obey meeting rules. This will bring more productive meeting and development process, and will avoid losing time unnecessarily.</span><br />
<b style="font-family: 'Trebuchet MS', sans-serif;"><br /></b>
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>3. </b></span><b style="font-family: 'Trebuchet MS', sans-serif;">Define documentation strategy:</b></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Every single software process has a documentation strategy, even agile or extreme methods (backlogs, lessons learned info, bug items etc.). These documentation types should be defined clearly (document physical properties, standard sections, document update period, version numbering etc.) for consistency, understandability and more effective software production. </span><br />
<b style="font-family: 'Trebuchet MS', sans-serif;"><br /></b>
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>4. </b></span><b style="font-family: 'Trebuchet MS', sans-serif;">Define software quality metrics and measure them:</b><br />
<div>
<span style="font-family: Trebuchet MS, sans-serif;">There are so many metric types (line of code, cyclomatic complexity etc.) in software world. According to the properties of your software type, some of these should be chosen to measure quality and growth of code. These info may be discussed periodically and production quality will be increased after assessments.</span></div>
<div>
<b style="font-family: 'Trebuchet MS', sans-serif;"><br /></b></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>5. </b></span><b style="font-family: 'Trebuchet MS', sans-serif;">Perform issue/requirement tracking:</b></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;">Requirement management or issue tracking is one of the key points in software development. They determine the scope of software, also supports a traceability base for functional tests. Those issues/requirements are preferred to be saved and managed with useful tools which have more features than text editing.</span></div>
<div>
<b style="font-family: 'Trebuchet MS', sans-serif;"><br /></b></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>6. </b></span><b style="font-family: 'Trebuchet MS', sans-serif;">Perform version controlling:</b></div>
</div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Version controlling is also crutial in production. This should include code and other documents. It will support co-working on code, returning to older versions of code and will ease versioning and dependency management. Versioning strategy (version numbering,versioning periods etc.) should also be determined clearly to obtain consistency.</span></div>
<div>
<b style="font-family: 'Trebuchet MS', sans-serif;"><br /></b></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>7. </b></span><b style="font-family: 'Trebuchet MS', sans-serif;">Perform testing:</b></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Testing is one of the main phases of software development. Unit testing must be performed for every type of software, except a few exceptions like some user interface code. Other testing types (system, user, integration etc.) should be defined clearly and applied consistently as defined. This will increase quality of production and decrease bugs.</span></div>
<div>
<b style="font-family: 'Trebuchet MS', sans-serif;"><br /></b></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>8. </b></span><b style="font-family: 'Trebuchet MS', sans-serif;">Perform dependency management:</b></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">As software projects grow, more external libraries (jar, dll, ...) or projects (external projects or internal company projects) are included. If those items are added to projects imprecisely, later updates or version changes will bring chaos and so much time consumption. Dependency management strategies and tools should be used for efficient productivity.</span></div>
<div>
<b style="font-family: 'Trebuchet MS', sans-serif;"><br /></b></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>9. </b></span><b style="font-family: 'Trebuchet MS', sans-serif;">Perform code reviews frequently: </b></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Code review brings high quality code. First of all it enforces developer to produce better code, because it will be controlled by others. Besides, a junior developer will learn better coding quickly by corrections of senior developers. So, code review is a partial type of pair programming and it enhances productivity.</span></div>
<div>
<b style="font-family: 'Trebuchet MS', sans-serif;"><br /></b></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>10. </b></span><b style="font-family: 'Trebuchet MS', sans-serif;">Save "lessons learned" info for your projects:</b></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Even if there are experienced staff in projects, there may be unforeseen events which may obstruct or retard development process. This can be a complex item configuration, error, production experience etc. Those happenings are highly preferred to be written in "lessons learned" documents and shared in public locations. This will avoid recurrence of time loss and provide more productive software.</span></div>
</div>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com10tag:blogger.com,1999:blog-7988792589954261688.post-34398382837416146712012-11-30T15:44:00.000+02:002012-12-01T08:17:32.506+02:00Software Unit Testing and Best Practices<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/11/software-unit-testing-and-best-practices.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">Software Unit Testing is about testing of individual units of source code. Those units are generally methods and they are grouped by class names (called as Test Case). </span><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifluXn99BNKw3A2M3ePuU0GO0IOp5oP6GivgX-9Kvte8hgmWAW5g507jk9GAPWBxHTeSHwP97EGoDsIIfPbK-_AuBxzH192kX0M6cecDqlPl8L1VWQm7984-1rufaPgIolAiUlFG52s0qi/s1600/13UnitTests_thumb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifluXn99BNKw3A2M3ePuU0GO0IOp5oP6GivgX-9Kvte8hgmWAW5g507jk9GAPWBxHTeSHwP97EGoDsIIfPbK-_AuBxzH192kX0M6cecDqlPl8L1VWQm7984-1rufaPgIolAiUlFG52s0qi/s1600/13UnitTests_thumb.png" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">For example, if you have an XYZUtility class which having methodA, methodB, methodC methods, you will potentially have an XYZUtilityTestCase class having methodATest, methodBTest and methodCTest tests.</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Unit tests must cover as much code as they can while running, but it is not the primary purpose. Code coverage is prefferred to be high as a result but the main purpose of the unit tests are:</span></div>
<div style="text-align: justify;">
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">Testing output of a function with specific inputs. Those inputs must include boundary (min/max) values and potential exceptional values (divide by 0 etc.). And the inputs are also preffered to be chosen for covering all condition cases of the method.</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Documenting the software. One of the self-documenting code development techniques is unit testing. It shows usage of the code section.</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Increasing modularity, flexibility and extensibility of the code along with concerning the developer with the interface before implementation, in <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test Driven Development (TDD)</a> approach.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">There are also 5 important properties for unit tests that must be obeyed according to <a href="http://www.amazon.com/Pragmatic-Unit-Testing-Java-JUnit/dp/0974514012/ref=sr_1_2?ie=UTF8&s=books&qid=1224012947&sr=8-2">Andy Hunt's Pragmatic Unit Testing</a> book.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;"><b>Automatic</b></span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Unit test results (pass/fail) must be controlled automatically with tools. And generally more than one tests are need to be run together. A test should not have a manual step which stops execution of all tests.</span></div>
<ul>
<li style="font-family: 'Trebuchet MS', sans-serif;"><b>Repeatable</b></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">A unit test must be repeatable. In other words, if it passes on a certain version of code, it must always pass with that code or </span><span style="font-family: 'Trebuchet MS', sans-serif;">if it fails on a certain version of code, it must always fail with that code. Database changes or other external services or files etc. should not change the result of the unit test.</span></div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;"><b>Independent</b></span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Unit test results must be independent of other unit tests. If a unit test result changes after changing the running order or other environment change (database data etc.), it can not be called as a unit test.</span></div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;"><b>Thorough</b></span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">A unit test must control every condition as it can (all possibilities, exceptions, boundaries ...). Its code coverage must be as much as it can and controlled conditions are preferred to be logical and functional.</span></div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;"><b>Professional</b></span></li>
</ul>
</div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Unit test code must obey coding standards of the project which it belongs to, because it also is a professional code. Furthermore, it was stated before that unit test is another way of self-documenting code. Clean and understandable unit test code will bring better documentation.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">As a last word, f</span><span style="font-family: 'Trebuchet MS', sans-serif;">or providing repeatable and independent unit tests, using </span><a href="http://en.wikipedia.org/wiki/Mock_object" style="font-family: 'Trebuchet MS', sans-serif;">mock objects</a><span style="font-family: 'Trebuchet MS', sans-serif;"> is a good practice. </span><span style="font-family: 'Trebuchet MS', sans-serif;">Mock objects replaces the external sources (database, services, etc.) and returns predefined results. </span><span style="font-family: 'Trebuchet MS', sans-serif;">A good object oriented design having required amount of interfaces will simplfy the creation of mock objects. You can also use some API's like <a href="http://www.easymock.org/">EasyMock</a> or <a href="http://code.google.com/p/mockito/">Mockito</a>. </span></div>
</div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com3tag:blogger.com,1999:blog-7988792589954261688.post-37398194177248127022012-11-02T10:41:00.001+02:002012-11-02T11:47:28.729+02:0010 Software Documentation Best Practices<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/11/10-software-documentation-best-practices.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<br />
<ol>
<li style="text-align: justify;"><span style="background-color: white; line-height: 18px;"><span style="font-family: Trebuchet MS, sans-serif;">Perform documentation as required (e.g. %10 of total production time). No documentation is never a good solution as much as excessive documentation. It may include code documentation, requirement specifications, design documents, test documents, user manuals etc. Those documents are needed to be managed and shared also, by using version controlling tools and/or web based platforms.</span></span></li>
<li style="text-align: justify;"><span style="background-color: white; line-height: 18px;"><span style="font-family: Trebuchet MS, sans-serif;">Code documentation is important. Best way of doing this is producing self-documenting code. Variable, method, class, package etc. names must be meaningful and codeflow must be pure. For very complex code sections, short comment lines may be included. Javadoc-like standard entries are not required but may be added for auto document generation from code.</span></span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">For the future developers, short and useful design documents may be prepared including key design features and UML diagrams. Practical user help documents may be useful also. These documents must not include unnecessary bulk info.</span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">Requirements/issues/backlog item/function points tracking is important. For that operation, a tracking tool is more effective (it will have quick search, edit capabilities and a few more features) than writing them into a plain text file.</span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">Test tracking is also important. Test scenarios and results may be tracked using tools (or with text files, which is not preferred) and associated with related requirements. By doing this, functional status of software may be monitored easily.</span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">Documentation is a live process. If you produce some documents, it is a good practice to update or produce new version of those documents until the end of development process. If a document is not up-to-date, it is practically worthless.</span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">For text file documents, versioning is important. For each new version of a document, a new version number (which is given with a stable versioning strategy) must be given. Also a version tracking table having change info may be included for better tracking.</span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">Having a consistent document template is important for companies. Header, footer, headings, font sizes must be consistent in document and among other documents for better readability. It is also a good practice that having a cover page, table of content, table of pictures and a glossary for documents.</span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">Document formatting, language usage and typing are other physical issues about documents and attention must be paid. Typing errors, unconsistent table sizes, indentations etc. will distract the reader.</span></li>
<li style="text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">Saving "lessons-learned" info on a shared place is another good practice. Those items are some useful experiences (information or code/configuration sections etc.) about development process which may not be included in standard process documents. Lessons-learned info may give acceleration to the current developers or future developers about some challenging and repeating operations.</span></li>
</ol>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com0tag:blogger.com,1999:blog-7988792589954261688.post-26562984370773506642012-10-18T15:16:00.000+03:002012-10-18T15:39:40.132+03:00Best Must-Read Books for Software Engineers<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/10/best-must-read-books-for-software.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Here are the CodeBuild selection of must-read software engineering books. Books are grouped according to their content with some description.</span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;"><b>Reference Books</b></span></li>
</ul>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">These Robert C. Martin and Gang of Four books are very fundamental OOP resources for every software engineer.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;"><a href="http://www.amazon.com/Software-Development-Principles-Patterns-Practices/dp/0135974445/ref=cm_lmf_tit_17"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbkCQPzWahC5l_sW3c7ewRt__a2JQZX_9G7nMEpHMoULsDcUENL5rZZIHL1gkWw34tUBQv3uceDFeZRjogf-y2R-2wtLyHEbhFt9jniFHg73TwcBC_XiB5Pfcv1gPIzVX-ra245mpHU-mi/s200/agileSoftwareDev.jpg" width="152" /></a> </span><a href="http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhqWFE5Y2J9WITr1e_l2V4bQs0sgjCKP4wR03e-0O6m7IMVor8501qmTmyBFUujtSffROL9EKObFDUp14dJ1sFI5DWcS663pYNSy_zFtHLJoXuvM-OwJK2GqTuIzfSI4FaRSONFoqPLpH0/s200/designPatterns.jpg" width="153" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;"><b>Coding Perfection</b></span></li>
</ul>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">These Steve McConnell, Robert C. Martin and Joshua Bloch books are very helpful with increasing your coding skills.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;"><a href="http://www.amazon.com/exec/obidos/ASIN/1556154844/ref=nosim/joelonsoftware/"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrnXglL7HTB4oGpeZsYZTkNsP4FYbbVEcMpcTkwZi70wzouBhB4ir5twfBpFVqWZ0oAv84IF1ss1gPwyWKYXRrHBOYCsaxiOh2hwrPDkzCztC3lHL4B4xp1vbmYVR0ai3jEITIXYfordsF/s200/codeComplete.jpg" width="153" /></a> </span><a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=la_B000APG87E_1_1?ie=UTF8&qid=1350477667&sr=1-1"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnvrr6FD0TeWnAEjBjuglABblfDj28N8Xh_ZkW6ebQn5mhN4fMoe2AGA_DrNcjHCwElxXqGJ7q0JXK0xHjoUMJ9DSaRyIZIdkJT7KkLkfkfm5KRA0SC9_9GBVksBnPl26qJ-RBra1ezZYJ/s200/cleanCode.jpg" width="149" /></a> <a href="http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZhkAWD3MSDQP4RWx1404EJ565hop_Bo94A2vbleMIChk8vHlx0YAAAqY8MsQ5uPbxNEeaSU8XwQ0qof4plIZL9BvreULnN1mZ6hHny1iOFI4GVkSw6ASbZNDG6He_idQfnN35kRR0ijlC/s200/effectiveJava.jpg" width="159" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<ul>
<li style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;"><b>Refactoring and Patterns</b></span></li>
</ul>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Refactoring and patterns are very important issues of OOP, which brings quality and maintainability. These Martin Fowler and Joshua Kerievsky books are maybe the best references about this issue.</span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;"></span><a href="http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672/"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIer5PGVxFPpTeIBHg0tfDDeUaD9o1GovnB8yTubWiQbS-VfLKIf7rPjfnd-h5VRDLj73C-8csS4py3dFzCILCrWLwexrS9UVCpSVp_CIujTgznJVhby-Tj8FN1LkiirTKPTrEFcU1FLbn/s200/refactoring.jpg" width="156" /></a> <a href="http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420/ref=sr_1_1?ie=UTF8&qid=1350477708&sr=8-1&keywords=Patterns+of+Enterprise+Application+Architecture"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOTJ9XmR_Qdko9R5wW26Rq2Kj1rljncvP0ffNGrfi_zub47XJfc5kwcN_jPuJujMDCHjlGe6IvQUyqKCw5I2_88RTCJBkZcwIjA8jGzZLgTMPcWa-cghIvmjC3yThXtvjkpdUwY2PnWjxo/s200/patternsOfEAA.jpg" width="159" /></a> <a href="http://www.amazon.com/Refactoring-Patterns-Joshua-Kerievsky/dp/0321213351/ref=sr_1_1?ie=UTF8&qid=1350477785&sr=8-1&keywords=Refactoring+to+Patterns"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBXnD9vU0TC_hyphenhyphen37zBqcXoV3huALxpMtHfgZx96pFUNvUkQ6rhZDN_0w7KgWDTcQc10MyaKOZYOF-qNl4NREMumrgX3BEGN8S50YnpdlVAZq2reZyPO5YtdXT6R3NpRUAD5mPQt0M57KpA/s200/refactoringToPatterns.jpg" width="145" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<ul>
<li><b><span style="font-family: Trebuchet MS, sans-serif;">Pragmatic Programming</span></b></li>
</ul>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Andrew Hunt's and David Thomas's "pragmatic" approach to programming brings very important viewpoints to software engineering.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><b><br /></b></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtxrzb2eHGiVWCdONE_eb44PArpvBVfAZ9umceU3Tm27ZBkB5EfQc95CndQbvFVg1-v_uCm4MVzv2J-OlfgRtCp8gnNY4jYUEJqWRnty-Hle_KEH0-DUbBrNCw1geRk1Q8QkuPpf0EKi5D/s200/pragmaticProgrammer.jpg" width="160" /></a> <a href="http://www.amazon.com/Pragmatic-Unit-Testing-Junit-Programmers/dp/0974514012"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgc_dLWgdEo5yPav0EHVs2b0jsX_dLdT1G5US54KAPBnjQzL5LCUPyzqzx5S1UDi6JWfs7K1u8ei6qi64s398jw-j-S7NPmgeRskOuUpd2BJ_FE7AsDdviXxmWWfUtjhYrbvtAyP0ez0UNE/s200/pragmaticUnitTesting.jpg" width="148" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<ul>
<li style="text-align: left;"><b><span style="font-family: Trebuchet MS, sans-serif;">Project Management</span></b></li>
</ul>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">There are many project management books in the market but Frederick P. Brooks Jr. and Tom DeMarco presents very impressive important viewpoints to project management.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;"><a href="http://www.amazon.com/The-Mythical-Man-Month-Engineering-Anniversary/dp/0201835959"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC3XlH8uKPX3nE6qAiAlD8dwHcE154w2VB-01aTYXcqzgmyR_lPaVNCXF7QC_E_lmzDZVKdrnXUoaaDodt7dpwho3hqbADEDBE57sSPeiRwNMM4x9hMlLY3WRp6OoWNuMZvnrZ9-bv-p89/s200/myticalManMonth.jpg" width="135" /></a> <a href="http://www.amazon.com/exec/obidos/ASIN/0932633439/ref=nosim/joelonsoftware/"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMw894uhT_LGJ9arjhgJvIXvZ2xzQIV3GNR4F4p1uSKHbl0vOtTf5JtnwVCdpKu-gWZSwr8Usgbxdq4imqn3xUq8byxsMKUzYSaif8bYPYUUkp6oKIfp8eKBXhAz9nOz4IY496rPf2vYp2/s200/peopleware.jpg" width="135" /></a></span></div>
<br />CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com7tag:blogger.com,1999:blog-7988792589954261688.post-60763957425410824922012-10-15T20:09:00.000+03:002012-10-16T08:15:43.940+03:00Start Android Development in 5 Minutes<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/10/start-android-development-in-5-minutes.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Android OS is the most popular mobile OS nowadays (leading market with %46.9 above iOS's %18.8). Besides, globally over %20 of computers are mobile devices. So, over %10 of people in the world uses Android OS and softwares related with it. </span><span style="font-family: 'Trebuchet MS', sans-serif;">For this reason, Android application development is a very important issue for developers and software engineers. </span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">This post will describe a fast (5 minutes, excluding tool download periods) and simple startup of an android project on Eclipse IDE, for developers who deal with the matter.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEZkpNUO3LVnZjb0Rzvs-3A2tvYdOlAcm8iMi2hebWtSENJ1hOfykzrs1xZ89BR8jrMhgP7yHmDU9BXWCq12oWFQzJmR_ACRRLpp86IErtlKvhSr0pS1StUe57j65gR3GM-XoPbwrNNIgg/s1600/and.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEZkpNUO3LVnZjb0Rzvs-3A2tvYdOlAcm8iMi2hebWtSENJ1hOfykzrs1xZ89BR8jrMhgP7yHmDU9BXWCq12oWFQzJmR_ACRRLpp86IErtlKvhSr0pS1StUe57j65gR3GM-XoPbwrNNIgg/s1600/and.jpg" /></a></div>
<div style="text-align: justify;">
<b><span style="font-family: Trebuchet MS, sans-serif;">1. JDK and </span><span style="font-family: 'Trebuchet MS', sans-serif;">Eclipse IDE</span><span style="font-family: 'Trebuchet MS', sans-serif;">:</span></b></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Download and install appropriate JDK for your computer and OS (JDK 6 or 7 are preferred)</span></div>
<div style="text-align: justify;">
<a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html"><span style="font-family: Trebuchet MS, sans-serif;">http://www.oracle.com/technetwork/java/javase/downloads/index.html</span></a></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Download latest Eclipse distribution, unzip it to your computer.</span></div>
<div style="text-align: justify;">
<a href="http://www.eclipse.org/downloads/"><span style="font-family: Trebuchet MS, sans-serif;">http://www.eclipse.org/downloads/</span></a></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>2. Android SDK:</b></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Download and install android SDK:</span></div>
<div style="text-align: justify;">
<a href="http://developer.android.com/sdk/index.html"><span style="font-family: Trebuchet MS, sans-serif;">http://developer.android.com/sdk/index.html</span></a></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Run Android SDK and install some API (e.g. 8, 14, 16, ...). Android distributions have various APIs and your application API must be compatible with your device. This step may also be performed using Eclipse ADT plug-in Android toolbar buttons. For each API, "SDK Platform" is required. "SDK Tools" and "SDK Platform Tools" under "Tools" menu and "Android Support Library" under "Extras" menu should be installed for general usage.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ObshuofBo-HCjFQ3b1ckxqs87Ehs0FKE3u4CtKpf-A5lR37xTUsNlGLKtJLjhJ1tyFMeRLwbCbUe167uzO885SGEaj-JvQvSiAnPodAlbWpZqIgWCfSs_VdzCSkO4ZNryeY3ZS3u70sq/s1600/sdk-mng.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ObshuofBo-HCjFQ3b1ckxqs87Ehs0FKE3u4CtKpf-A5lR37xTUsNlGLKtJLjhJ1tyFMeRLwbCbUe167uzO885SGEaj-JvQvSiAnPodAlbWpZqIgWCfSs_VdzCSkO4ZNryeY3ZS3u70sq/s1600/sdk-mng.PNG" /></a></div>
<br /></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Don't forget to set your Android SDK directory on Eclipse Window --> Preferences:</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEJvm1SM18kei6QXHaZuZePwdNpFlFsCfOq9SmSTxY8NRdxA3SrLEFDtwUBPVdjE6y8PKhj6dsR03uZiI6FnuLGoq1DnBxgNtcgGvNAQ-babxytIMfOZlYc6lRQW-4wdBIu7gFOp6UT_FK/s1600/sdk-setup.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEJvm1SM18kei6QXHaZuZePwdNpFlFsCfOq9SmSTxY8NRdxA3SrLEFDtwUBPVdjE6y8PKhj6dsR03uZiI6FnuLGoq1DnBxgNtcgGvNAQ-babxytIMfOZlYc6lRQW-4wdBIu7gFOp6UT_FK/s1600/sdk-setup.PNG" /></a></div>
</div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>3. Eclipse ADT Plugin:</b></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Start Eclipse. Click Help --> Install New Software, paste adress below and click OK:</span></div>
<div style="text-align: justify;">
<a href="https://dl-ssl.google.com/android/eclipse/"><span style="font-family: Trebuchet MS, sans-serif;">https://dl-ssl.google.com/android/eclipse/</span></a></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg5pfDJQFSM0m27BWPln4-zwJOpQiny1lrbJVax_CN9WGJCgHto9hEwPt2-prq6pfcVHwQz5VIlIdLdi-DUkXHsSAWMXRlV05FQpni_fypDdzmLo6hrMwEnrmkrNKwnH745Rs5yRedDHhO/s1600/new-software.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg5pfDJQFSM0m27BWPln4-zwJOpQiny1lrbJVax_CN9WGJCgHto9hEwPt2-prq6pfcVHwQz5VIlIdLdi-DUkXHsSAWMXRlV05FQpni_fypDdzmLo6hrMwEnrmkrNKwnH745Rs5yRedDHhO/s1600/new-software.PNG" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Select "Android Development Tools" from "Developer Tools", click "Next" various times and finish installation.</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">You will see Android SDK (which performs installing different APIs as told in step 2) and Android emulator buttons on the top panel. You can also start Android projects from now on.</span><br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyFlTy1maBtBwZwEXv0XAyw2CN9Bxsajl9utAwPVb5Uu5TQ_HmQKk5bBABZqxfLwQF7V2wlqyy0X-RN9tcShNGrfahsLdGngogV4RwlCzrAtHRLzp1vAaCAKTVGt5tmijZQfElzyi8159Y/s1600/and-toolbar.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyFlTy1maBtBwZwEXv0XAyw2CN9Bxsajl9utAwPVb5Uu5TQ_HmQKk5bBABZqxfLwQF7V2wlqyy0X-RN9tcShNGrfahsLdGngogV4RwlCzrAtHRLzp1vAaCAKTVGt5tmijZQfElzyi8159Y/s1600/and-toolbar.PNG" /></a></div>
</div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>4. Android Emulator:</b></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Android SDK includes a useful emulator for testing. After installing ADT plug-in, you can start emulator by "Android Virtual Device Manageer" button from toolbar. After that you may add one or more android devices with different API and system configurations.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1qdhl4mHJGauJRqQ8zmwRWEsHvsZ-NhELgLJmMzCDR3Q0miIR2u8FhsMifnWEKNtIyMAcCCOHQlWkRNXL5KmLjvo3-mmet0UYjQEXbQAXdlp-B_hCZZrnR1iD9ZgALpgYu25ALu3zYJ3Y/s1600/avd-mng.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1qdhl4mHJGauJRqQ8zmwRWEsHvsZ-NhELgLJmMzCDR3Q0miIR2u8FhsMifnWEKNtIyMAcCCOHQlWkRNXL5KmLjvo3-mmet0UYjQEXbQAXdlp-B_hCZZrnR1iD9ZgALpgYu25ALu3zYJ3Y/s1600/avd-mng.PNG" /></a></div>
<br /></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">You can have detailed info about emulator usage and command line parameters here:</span></div>
<div style="text-align: justify;">
<a href="http://developer.android.com/tools/help/emulator.html"><span style="font-family: Trebuchet MS, sans-serif;">http://developer.android.com/tools/help/emulator.html</span></a></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>5. Creating Project:</b></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Select File --> New --> Project --> Android Application Project. You can also start an Android Sample Project for exercising. </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxIQ0uKpOgnUYHi0yc6LnzsMbdsm5O4t8tR59qO5gz9GcYrs9lE2DMW7NM8UdDRf8SLxewhFDxtUgmmeBt62angfwS-wrfIGafViIM9qK0nhHX1y3CD-RYmTprF2wTECZvNteb6BJV52Bx/s1600/new-project.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxIQ0uKpOgnUYHi0yc6LnzsMbdsm5O4t8tR59qO5gz9GcYrs9lE2DMW7NM8UdDRf8SLxewhFDxtUgmmeBt62angfwS-wrfIGafViIM9qK0nhHX1y3CD-RYmTprF2wTECZvNteb6BJV52Bx/s1600/new-project.PNG" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">You must select "Build SDK" and "Minimum Required SDK" while creating project. </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihkkzMFhI53hfCxAAEzYOwp2xDmh92o2dL0zhhIt51L4ncEcbBrWhtd7wgWbPoK4OpSPEuWh1BJPppgi8Y17NBGx4YPlLn1NqMDDnNc1wq3alRYUT0PfRan8pVpLqgqr1WeIlPoC3a3D-H/s1600/new-project2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihkkzMFhI53hfCxAAEzYOwp2xDmh92o2dL0zhhIt51L4ncEcbBrWhtd7wgWbPoK4OpSPEuWh1BJPppgi8Y17NBGx4YPlLn1NqMDDnNc1wq3alRYUT0PfRan8pVpLqgqr1WeIlPoC3a3D-H/s1600/new-project2.PNG" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">After that right click your project and select "Run". Your project will run on selected emulator.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">After this short and simple start, you may want to look at these:</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<a href="http://developer.android.com/training/basics/firstapp/index.html"><span style="font-family: Trebuchet MS, sans-serif;">http://developer.android.com/training/basics/firstapp/index.html</span></a></div>
<div style="text-align: justify;">
<a href="http://www.vogella.com/articles/Android/article.html"><span style="font-family: Trebuchet MS, sans-serif;">http://www.vogella.com/articles/Android/article.html</span></a></div>
<div style="text-align: justify;">
<a href="http://www.coreservlets.com/android-tutorial/"><span style="font-family: Trebuchet MS, sans-serif;">http://www.coreservlets.com/android-tutorial/</span></a></div>
<div style="text-align: justify;">
<a href="http://java.dzone.com/articles/10-attractive-android"><span style="font-family: Trebuchet MS, sans-serif;">http://java.dzone.com/articles/10-attractive-android</span></a></div>
<div style="text-align: justify;">
<a href="http://www.javacodegeeks.com/2010/10/android-full-application-tutorial.html"><span style="font-family: Trebuchet MS, sans-serif;">http://www.javacodegeeks.com/2010/10/android-full-application-tutorial.html</span></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com1tag:blogger.com,1999:blog-7988792589954261688.post-12136862321588571632012-09-27T15:28:00.001+03:002012-09-27T15:32:50.472+03:005 Common Automized Software Quality Metrics (with Pros & Cons)<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/09/5-common-automized-software-quality.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<b style="font-family: 'Trebuchet MS', sans-serif;">1. Source Lines of Code (SLOC)</b><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Counting lines of code is probably the most simple method. It mostly indicates the scale of the software and gives an input for project growth and planning. For example, if we get SLOC count once a month, we may sketch a graph of project growth. Of course this is not reliable due to refactoring and design phases but may give a viewpoint.</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">SLOC may be counted as Source Logical Line of Code (SLLOC) for better info. Logical code lines does not include empty lines, one char brackets and comment lines. You can easily calculate SLLOC using tools like <a href="http://www.jajakarta.org/turbine/en/turbine/maven/reference/metrics.html">Metrics</a>. </span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Line of code should not be used for evaluating developer performance. This may cause duplicate, unmaintainable and unprofessional code.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><b><br /></b></span>
<span style="font-family: Trebuchet MS, sans-serif;"><b>2. Bugs per code_section/module/time_period</b></span><br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Bug tracking is essential for better testing and faster maintainability. If bugs are tracked, bugs per code section, module or specific time period (day, week, month etc.) may be calculated easily by reporting tools (e.g. <a href="http://www.mantisbt.org/">Mantis</a>). If this value is obtained, bug causes may be noticed and intervened early.</span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Bug count may be used as one of the inputs of evaluating developer performance, but attention must be paid. If it is most important evaluation method, software developers and testers may become enemies. In a productive company, all employees must be coherent with each other.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">For better evaluation, bugs may be classified as low, medium, high etc. for weighting, because their importance and resolving costs are not the same.<span style="-webkit-text-size-adjust: none; background-color: #fcfcfc; font-size: 14px; text-align: start;"> </span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="-webkit-text-size-adjust: none; background-color: #fcfcfc; font-size: 14px; text-align: start;"><br /></span></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>3. Code Coverage</b></span><br />
<span style="font-family: Trebuchet MS, sans-serif;">Code coverage states the degree to which the source code of a program has been tested. </span><span style="font-family: 'Trebuchet MS', sans-serif;">Automaticity of code coverage calculation is a plus. There are so many tools which perform that operation (e.g. <a href="http://www.ibm.com/developerworks/java/library/j-cobertura/">Cobertura</a>). </span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<span style="font-family: 'Trebuchet MS', sans-serif;">Code coverage does not represent the whole quality of unit tests, but may give some info about test coverage. It may be used as a software metric together with a few other test metrics. Also unit test codes, integration test scenarios and results should be reviewed frequently.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
</div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>4. Design/Development Constraints</b></span><br />
<span style="font-family: Trebuchet MS, sans-serif;">There are so many design constraints and principles for software development. Some of them are:</span><br />
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">Class/method length,</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Number of methods/attributes in a class,</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Method/constructor parameter counts,</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Magical number, string usage in code files,</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Comment lines percentage etc.</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">These are important for code maintainability and readability. Development teams may choose a few (or all) of those metrics and follow them with automized tools (like <a href="http://maven.apache.org/plugins/maven-pmd-plugin/">maven pmd plugin</a>). This will raise the quality of produced software.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<b style="font-family: 'Trebuchet MS', sans-serif;">5. Cyclomatic Complexity</b></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">We separated cyclomatic complexity from other design/development constraints because its concept is a bit different. Cyclomatic complexity is about the detailed implementation and code execution. It also may be calculated automatically with tools like <a href="http://maven.apache.org/plugins/maven-pmd-plugin/">pmd</a>.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">It is calculated as "<span style="background-color: white; line-height: 19.200000762939453px; text-align: start;">the count of the number of linearly independent </span><span style="background-color: white; line-height: 19.200000762939453px; text-align: start;">paths</span><span style="background-color: white; line-height: 19.200000762939453px; text-align: start;"> through a </span><span style="background-color: white; line-height: 19.200000762939453px; text-align: start;">source code section". For example, if there are a path diagram of a source code section as below:</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="background-color: white; line-height: 19.200000762939453px; text-align: start;"><br /></span></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgCapDc_OJNxj7g94mvZBNSd2Xed7F2WximgYJgD1eiiodth5oBLAkaYzQtDaRIL_mG5HJSoEKcDDql4yBlg2OlHp32rEnbZYxBQODK8yL1Zyap48e0JgerOWVj7a8-pf7RmLQJCDKbh9p/s1600/cc.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgCapDc_OJNxj7g94mvZBNSd2Xed7F2WximgYJgD1eiiodth5oBLAkaYzQtDaRIL_mG5HJSoEKcDDql4yBlg2OlHp32rEnbZYxBQODK8yL1Zyap48e0JgerOWVj7a8-pf7RmLQJCDKbh9p/s1600/cc.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Cyclomatic Complexity = E(edges) - N(nodes) + 2P (exit nodes)</span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">So, Cyc.Cmp. = 8 - 7 + 2*1 = 3</span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">You can also see that there are 3 different paths from leftmost node to rightmost node. This value can be calculated especially for methods, using the whole method source as the execution path. Some upper limit numbers (6, 8 or 10 etc.) may be defined according to the project type.</span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Only one metric does not detect the quality of your whole project or solve everything. If you use more metrics, you will have more viewpoints about the quality of your project. </span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="background-color: white; line-height: 19.200000762939453px; text-align: start;"><br /></span></span></div>
<div>
<br /></div>
</div>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com1tag:blogger.com,1999:blog-7988792589954261688.post-2182651486899520302012-06-25T19:22:00.000+03:002012-06-25T19:24:30.391+03:0020 Subjects Every Software Engineer Should Know<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/06/20-subjects-every-software-engineer.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Here are the most important subjects for software engineering, with brief explanations:</span></div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
</div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>1.Object oriented analysis & design</b>: For better maintainability, reusability and faster development, the most well accepted approach, shortly <a href="http://en.wikipedia.org/wiki/Object-oriented_analysis_and_design">OOAD</a> and its <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">SOLID</a> principals are very important for software engineering.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<b style="font-family: 'Trebuchet MS', sans-serif;">2.Software quality factors</b><span style="font-family: 'Trebuchet MS', sans-serif;">: Software engineering depends on some very important <a href="http://en.wikipedia.org/wiki/Software_quality">quality factors</a>. Understanding and applying them is crucial.</span></div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>3.Data structures & algorithms</b>: Basic <a href="http://en.wikipedia.org/wiki/List_of_data_structures">data structures</a> like array, list, stack, tree, map, set etc. and useful <a href="http://en.wikipedia.org/wiki/List_of_algorithms">algorithms</a> are vital for software development. T<span style="background-color: white;">heir logical structure should be known.</span></span></div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>4</b>. <b style="background-color: white;">Big-O notation: </b><span style="background-color: white;"><a href="http://en.wikipedia.org/wiki/Big_O_notation">Big-O notation</a> indicates the performance of an algorithm/code section. Understanding it is very important for comparing performances.</span><b style="background-color: white;"> </b></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>5.UML notation</b>: <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language">UML</a> is the universal and complete language for software design & analysis. If there is lack of UML in a development process, it feels there is no engineering.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>6.Software processes and metrics</b>: Software enginnering is not a random process. It requires a high level of systematic and some numbers to monitor those techniques. So, <a href="http://en.wikipedia.org/wiki/Software_development_process">processes </a>and <a href="http://en.wikipedia.org/wiki/Software_metric">metrics</a> are essential.</span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>7.Design patterns</b>: <a href="http://en.wikipedia.org/wiki/Software_design_pattern">Design patterns</a> are standard and most effective solutions for specific problems. If you don't want to reinvent the wheel, you should learn them.</span></div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>8.Operating systems basics</b>: Learning <a href="http://en.wikipedia.org/wiki/Operating_system">OS</a> basics is very important because all applications runs on it. By learning it, we can have better vision, viewpoints and performance for our applications.</span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>9.Computer organization basics</b>: All applications including OS requires a hardware for physical interaction. So, learning <a href="http://en.wikipedia.org/wiki/Microarchitecture">computer organization</a> basics is vital again for better <span style="background-color: white;">vision, viewpoints and performance.</span></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>10.Network basics</b>: <a href="http://en.wikipedia.org/wiki/Computer_network">Network</a> is related with computer organization, OS and the whole information transfer process. In any case we will face it while software development. So, it is important to learn network basics.</span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>11.Requirement analysis</b>: <a href="http://en.wikipedia.org/wiki/Requirements_analysis">Requirement analysis</a> is the starting point and one of the most important parts of software engineering. Performing it correctly and practically needs experience but it is very essential.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>12.Software testing</b>: <a href="http://en.wikipedia.org/wiki/Software_testing">Testing</a> is another important part of software engineering. <a href="http://en.wikipedia.org/wiki/Unit_testing">Unit testing</a>, its <a href="http://richard.jp.leguen.ca/tutoring/soen343-f2010/tutorials/properties-of-good-unit-tests">best practices</a> and techniques like black box, white box, mocking, <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a>, integration testing etc. are subjects which must be known.</span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>13.Dependency management</b>: Library (JAR, DLL etc.) management, and widely known tools (Maven, Ant, Ivy etc.) are essential for large projects. Otherwise, antipatterns like <a href="http://en.wikipedia.org/wiki/Java_Classloader#JAR_hell">Jar Hell</a> are inevitable.</span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>14.Continuous integration</b>: <a href="http://en.wikipedia.org/wiki/Continuous_integration">Continuous integration</a> brings easiness and automaticity for testing large modules, components and also performs auto-versioning. Its aim and tools (like <a href="http://hudson-ci.org/">Hudson</a> etc.) should be known.</span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>15.ORM (Object relational mapping)</b>: <a href="http://en.wikipedia.org/wiki/Object-relational_mapping">ORM</a> and its widely known implementation Hibernate framework is an important technique for mapping objects into database tables. It reduces code length and maintenance time.</span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>16.DI (Dependency Injection)</b>: <a href="http://en.wikipedia.org/wiki/Dependency_injection">DI or IoC</a> (Inversion of Control) and its widely known implementation Spring framework makes life easy for object creation and lifetime management on big enterprise applications.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>17.Version controlling systems</b>: <a href="http://en.wikipedia.org/wiki/Revision_control">VCS</a> tools <span style="background-color: white;">(SVN, TFS, CVS etc.) </span><span style="background-color: white;">are very important by saving so much time for collaborative works and versioning. Their logical viewpoint and standard cammands should be known. </span></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>18.Internationalization (i18n)</b>: <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">i18n</a> by extracting strings into external files is the best way of supporting multiple languages in our applications. Its practices on different IDEs and technologies must be known.</span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
</div>
<div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>19.Architectural patterns</b>: Understanding <a href="http://www.codeproject.com/Articles/42830/Model-View-Controller-Model-View-Presenter-and-Mod">architectural design patterns</a> (like MVC, MVP, MVVM etc.) is essential for producing a maintainable, clean, extendable and testable source code.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>20.Writing clean code</b>: Working code is not enough, it must be readable and maintainable also. So, <a href="http://en.wikipedia.org/wiki/Prettyprint">code formatting</a> and <a href="http://net.tutsplus.com/tutorials/html-css-techniques/top-15-best-practices-for-writing-super-readable-code/">readable code</a> development techniques are needed to be known and applied.</span>
</div>
</div>
</div>
</div>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com11tag:blogger.com,1999:blog-7988792589954261688.post-52008981475419334212012-06-13T14:38:00.000+03:002012-10-10T14:06:50.238+03:005 Common Antipatterns in Software Project Management<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/06/5-common-antipatterns-in-software.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<br />
<div style="text-align: justify;">
<b><span style="font-family: 'Trebuchet MS', sans-serif;">Overplanning/analysis/meetings:</span></b></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Some companies or project teams falls into error of spending time for the project planning & analysis & meetings much more than needed. Planning detail is not needed to be "complete" in each phase. This may be a serious bottleneck for projects. Like planning, analysis is also not needed to be complete at the beginning, except waterfall projects. As we know, waterfall is not such an efficient software process/methodology, until there is not a contract obligation about that. Planning and analysis should be "as required" and have flexibility points. Also, meeting duration and intervals are very important about this concept. Only required meetings with required staff and with shortest possible duration should be performed. Otherwise a huge time loss and unnecessary brain fatigue on staff will be inevitable.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<b><span style="font-family: 'Trebuchet MS', sans-serif;">Project mismanagement:</span></b></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Most employees like working in a relaxed environment and company. But on the other hand, if their work is not monitored and controlled, they are also not satisfied. Monitoring and controlling is required for non-managers because they need to be directed (they are not employer and they don't have to make every important decision), leaded (code reviews, trainings etc. are important for self development, also scheduling is important for efficiency) and appreciated (high performance and skills needs good feedbacks, at least a few good words). And they also want to know that they are doing an important job and they are part of that organization. So, an ethical staff will also require to be managed and controlled "as required".</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<b><span style="font-family: 'Trebuchet MS', sans-serif;">Wrong choices of staff motivation techniques:</span></b></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Job satisfaction (passion for the job concept, learning and self-development), human interactions (between employers and employee) and income (convenient with job type and sector averages) are very important for staff motivation. Job details, development plans, income and midterm income possibilities must be explained before starting job and if everything is OK, they must not be changed after starting job. Beyond the technical and economical issues, communication is the most important concept in teamworks. IT staff is not a kind of people that can be motivated using hard wording, hierarchical and forbidding working style. They should feel confidence and comfort. After that, performance will be OK. If these things cause inactivity on staff, those staff is not right choice and an action must be taken as soon as possible.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<b><span style="font-family: 'Trebuchet MS', sans-serif;">Wrong selection of metrics and evaluation methods:</span></b></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Metrics are important tools for monitoring software development process and they can provide some different viewpoints. For example, widely used "line of code" (especially logical line of code LLOC) metric may be used for "monitoring the growth of project by code size". If you attempt to evaluate developer efficieny using LOC, this will be a huge mistake because short and efficient code, design patterns etc. will be punished. Also copy paste programming, unreadable code etc. will be rewarded. E.g. cyclometic complexity, scheduling compliance, bug count are better methods. But best of all is determining right metrics according to the project type and team member properties.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<b><span style="font-family: 'Trebuchet MS', sans-serif;">Documentation strategy mistakes</span></b></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Documentation is very important for software projects. Planning, analysis, design, development and testing phases need "required" level of documentation. Even for some fastest agile processes like SCRUM, documentation is needed. Main purpose of documentation is making life easier for developers and users. For example use case definitions are important on development phase, complex problem solutions are important on maintainance phase or on employee shifts, diagrams are important for understanding concepts fast and clearly. However documentation should not consume a very important percentage of whole project schedule. Generally it may be %5-10.</span></div>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com3tag:blogger.com,1999:blog-7988792589954261688.post-52606821070774970412012-04-19T16:38:00.000+03:002012-04-20T09:48:17.376+03:00A Generic Text Comparison Tool Implementation with LCS Approach<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/04/generic-text-comparison-tool.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<style type="text/css">
<!--
/**
* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
* (http://qbnz.com/highlighter/ and http://geshi.org/)
*/
.java5 .de1, .java5 .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;color: #000020;}
.java5 {font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;}
.java5 a:link {color: #000060;}
.java5 a:hover {background-color: #f0f000;}
.java5 .imp {font-weight: bold; color: red;}
.java5 li, .java5 .li1 {font-weight: normal; vertical-align:top;font: normal normal 80% 'Courier New', Courier, monospace; color: #003030;}
.java5 .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.java5 .kw1 {color: #000000; font-weight: bold;}
.java5 .kw2 {color: #000000; font-weight: bold;}
.java5 .kw3 {color: #006600; font-weight: bold;}
.java5 .kw4 {color: #006600; font-weight: bold;}
.java5 .kw5 {color: #003399; font-weight: bold;}
.java5 .kw6 {color: #003399; font-weight: bold;}
.java5 .kw7 {color: #003399; font-weight: bold;}
.java5 .kw8 {color: #003399; font-weight: bold;}
.java5 .kw9 {color: #003399; font-weight: bold;}
.java5 .kw10 {color: #003399; font-weight: bold;}
.java5 .kw11 {color: #003399; font-weight: bold;}
.java5 .kw12 {color: #003399; font-weight: bold;}
.java5 .kw13 {color: #003399; font-weight: bold;}
.java5 .kw14 {color: #003399; font-weight: bold;}
.java5 .kw15 {color: #003399; font-weight: bold;}
.java5 .kw16 {color: #003399; font-weight: bold;}
.java5 .kw17 {color: #003399; font-weight: bold;}
.java5 .kw18 {color: #003399; font-weight: bold;}
.java5 .kw19 {color: #003399; font-weight: bold;}
.java5 .kw20 {color: #003399; font-weight: bold;}
.java5 .kw21 {color: #003399; font-weight: bold;}
.java5 .kw22 {color: #003399; font-weight: bold;}
.java5 .kw23 {color: #003399; font-weight: bold;}
.java5 .kw24 {color: #003399; font-weight: bold;}
.java5 .kw25 {color: #003399; font-weight: bold;}
.java5 .kw26 {color: #003399; font-weight: bold;}
.java5 .kw27 {color: #003399; font-weight: bold;}
.java5 .kw28 {color: #003399; font-weight: bold;}
.java5 .kw29 {color: #003399; font-weight: bold;}
.java5 .kw30 {color: #003399; font-weight: bold;}
.java5 .kw31 {color: #003399; font-weight: bold;}
.java5 .kw32 {color: #003399; font-weight: bold;}
.java5 .kw33 {color: #003399; font-weight: bold;}
.java5 .kw34 {color: #003399; font-weight: bold;}
.java5 .kw35 {color: #003399; font-weight: bold;}
.java5 .kw36 {color: #003399; font-weight: bold;}
.java5 .kw37 {color: #003399; font-weight: bold;}
.java5 .kw38 {color: #003399; font-weight: bold;}
.java5 .kw39 {color: #003399; font-weight: bold;}
.java5 .kw40 {color: #003399; font-weight: bold;}
.java5 .kw41 {color: #003399; font-weight: bold;}
.java5 .kw42 {color: #003399; font-weight: bold;}
.java5 .kw43 {color: #003399; font-weight: bold;}
.java5 .kw44 {color: #003399; font-weight: bold;}
.java5 .kw45 {color: #003399; font-weight: bold;}
.java5 .kw46 {color: #003399; font-weight: bold;}
.java5 .kw47 {color: #003399; font-weight: bold;}
.java5 .kw48 {color: #003399; font-weight: bold;}
.java5 .kw49 {color: #003399; font-weight: bold;}
.java5 .kw50 {color: #003399; font-weight: bold;}
.java5 .kw51 {color: #003399; font-weight: bold;}
.java5 .kw52 {color: #003399; font-weight: bold;}
.java5 .kw53 {color: #003399; font-weight: bold;}
.java5 .kw54 {color: #003399; font-weight: bold;}
.java5 .kw55 {color: #003399; font-weight: bold;}
.java5 .kw56 {color: #003399; font-weight: bold;}
.java5 .kw57 {color: #003399; font-weight: bold;}
.java5 .kw58 {color: #003399; font-weight: bold;}
.java5 .kw59 {color: #003399; font-weight: bold;}
.java5 .kw60 {color: #003399; font-weight: bold;}
.java5 .kw61 {color: #003399; font-weight: bold;}
.java5 .kw62 {color: #003399; font-weight: bold;}
.java5 .kw63 {color: #003399; font-weight: bold;}
.java5 .kw64 {color: #003399; font-weight: bold;}
.java5 .kw65 {color: #003399; font-weight: bold;}
.java5 .kw66 {color: #003399; font-weight: bold;}
.java5 .kw67 {color: #003399; font-weight: bold;}
.java5 .kw68 {color: #003399; font-weight: bold;}
.java5 .kw69 {color: #003399; font-weight: bold;}
.java5 .kw70 {color: #003399; font-weight: bold;}
.java5 .kw71 {color: #003399; font-weight: bold;}
.java5 .kw72 {color: #003399; font-weight: bold;}
.java5 .kw73 {color: #003399; font-weight: bold;}
.java5 .kw74 {color: #003399; font-weight: bold;}
.java5 .kw75 {color: #003399; font-weight: bold;}
.java5 .kw76 {color: #003399; font-weight: bold;}
.java5 .kw77 {color: #003399; font-weight: bold;}
.java5 .kw78 {color: #003399; font-weight: bold;}
.java5 .kw79 {color: #003399; font-weight: bold;}
.java5 .kw80 {color: #003399; font-weight: bold;}
.java5 .kw81 {color: #003399; font-weight: bold;}
.java5 .kw82 {color: #003399; font-weight: bold;}
.java5 .kw83 {color: #003399; font-weight: bold;}
.java5 .kw84 {color: #003399; font-weight: bold;}
.java5 .kw85 {color: #003399; font-weight: bold;}
.java5 .kw86 {color: #003399; font-weight: bold;}
.java5 .kw87 {color: #003399; font-weight: bold;}
.java5 .kw88 {color: #003399; font-weight: bold;}
.java5 .kw89 {color: #003399; font-weight: bold;}
.java5 .kw90 {color: #003399; font-weight: bold;}
.java5 .kw91 {color: #003399; font-weight: bold;}
.java5 .kw92 {color: #003399; font-weight: bold;}
.java5 .kw93 {color: #003399; font-weight: bold;}
.java5 .kw94 {color: #003399; font-weight: bold;}
.java5 .kw95 {color: #003399; font-weight: bold;}
.java5 .kw96 {color: #003399; font-weight: bold;}
.java5 .kw97 {color: #003399; font-weight: bold;}
.java5 .kw98 {color: #003399; font-weight: bold;}
.java5 .kw99 {color: #003399; font-weight: bold;}
.java5 .kw100 {color: #003399; font-weight: bold;}
.java5 .kw101 {color: #003399; font-weight: bold;}
.java5 .kw102 {color: #003399; font-weight: bold;}
.java5 .kw103 {color: #003399; font-weight: bold;}
.java5 .kw104 {color: #003399; font-weight: bold;}
.java5 .kw105 {color: #003399; font-weight: bold;}
.java5 .kw106 {color: #003399; font-weight: bold;}
.java5 .kw107 {color: #003399; font-weight: bold;}
.java5 .kw108 {color: #003399; font-weight: bold;}
.java5 .kw109 {color: #003399; font-weight: bold;}
.java5 .kw110 {color: #003399; font-weight: bold;}
.java5 .kw111 {color: #003399; font-weight: bold;}
.java5 .kw112 {color: #003399; font-weight: bold;}
.java5 .kw113 {color: #003399; font-weight: bold;}
.java5 .kw114 {color: #003399; font-weight: bold;}
.java5 .kw115 {color: #003399; font-weight: bold;}
.java5 .kw116 {color: #003399; font-weight: bold;}
.java5 .kw117 {color: #003399; font-weight: bold;}
.java5 .kw118 {color: #003399; font-weight: bold;}
.java5 .kw119 {color: #003399; font-weight: bold;}
.java5 .kw120 {color: #003399; font-weight: bold;}
.java5 .kw121 {color: #003399; font-weight: bold;}
.java5 .kw122 {color: #003399; font-weight: bold;}
.java5 .kw123 {color: #003399; font-weight: bold;}
.java5 .kw124 {color: #003399; font-weight: bold;}
.java5 .kw125 {color: #003399; font-weight: bold;}
.java5 .kw126 {color: #003399; font-weight: bold;}
.java5 .kw127 {color: #003399; font-weight: bold;}
.java5 .kw128 {color: #003399; font-weight: bold;}
.java5 .kw129 {color: #003399; font-weight: bold;}
.java5 .kw130 {color: #003399; font-weight: bold;}
.java5 .kw131 {color: #003399; font-weight: bold;}
.java5 .kw132 {color: #003399; font-weight: bold;}
.java5 .kw133 {color: #003399; font-weight: bold;}
.java5 .kw134 {color: #003399; font-weight: bold;}
.java5 .kw135 {color: #003399; font-weight: bold;}
.java5 .kw136 {color: #003399; font-weight: bold;}
.java5 .kw137 {color: #003399; font-weight: bold;}
.java5 .kw138 {color: #003399; font-weight: bold;}
.java5 .kw139 {color: #003399; font-weight: bold;}
.java5 .kw140 {color: #003399; font-weight: bold;}
.java5 .kw141 {color: #003399; font-weight: bold;}
.java5 .kw142 {color: #003399; font-weight: bold;}
.java5 .kw143 {color: #003399; font-weight: bold;}
.java5 .kw144 {color: #003399; font-weight: bold;}
.java5 .kw145 {color: #003399; font-weight: bold;}
.java5 .kw146 {color: #003399; font-weight: bold;}
.java5 .kw147 {color: #003399; font-weight: bold;}
.java5 .kw148 {color: #003399; font-weight: bold;}
.java5 .kw149 {color: #003399; font-weight: bold;}
.java5 .kw150 {color: #003399; font-weight: bold;}
.java5 .kw151 {color: #003399; font-weight: bold;}
.java5 .kw152 {color: #003399; font-weight: bold;}
.java5 .kw153 {color: #003399; font-weight: bold;}
.java5 .kw154 {color: #003399; font-weight: bold;}
.java5 .kw155 {color: #003399; font-weight: bold;}
.java5 .kw156 {color: #003399; font-weight: bold;}
.java5 .kw157 {color: #003399; font-weight: bold;}
.java5 .kw158 {color: #003399; font-weight: bold;}
.java5 .kw159 {color: #003399; font-weight: bold;}
.java5 .kw160 {color: #003399; font-weight: bold;}
.java5 .kw161 {color: #003399; font-weight: bold;}
.java5 .kw162 {color: #003399; font-weight: bold;}
.java5 .kw163 {color: #003399; font-weight: bold;}
.java5 .kw164 {color: #003399; font-weight: bold;}
.java5 .kw165 {color: #003399; font-weight: bold;}
.java5 .kw166 {color: #003399; font-weight: bold;}
.java5 .co1 {color: #666666; font-style: italic;}
.java5 .co2 {color: #006699;}
.java5 .co3 {color: #008000; font-style: italic; font-weight: bold;}
.java5 .coMULTI {color: #666666; font-style: italic;}
.java5 .es0 {color: #000099; font-weight: bold;}
.java5 .br0 {color: #009900;}
.java5 .sy0 {color: #339933;}
.java5 .st0 {color: #0000ff;}
.java5 .nu0 {color: #cc66cc;}
.java5 .me1 {color: #006633;}
.java5 .me2 {color: #006633;}
.java5 span.xtra { display:block; }
--!>
</style><span style="font-family: 'Trebuchet MS', sans-serif;">
Detecting and showing differences of two texts (especially having hundreds or thousands of lines) is a common problem. Using pure java.lang.String class methods may be a solution, but the most important issue for that kind of operations, "performance" will not be satisfactory. We want an efficient solution which may have a view as below: </span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicLYVRCQZgaQ5qRIEfjt1LHdrYBRs5EF8mbWPbkOHj6yet4T4gKZcwPw0sBubOm5jnMidsGIqXTySNt_AJseOJD-hJZrOn-yQyyltmjRTnGr5LCNgGeVZpayCu8AqoIUrqxF32O-8xHviJ/s1600/textdiffExample.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicLYVRCQZgaQ5qRIEfjt1LHdrYBRs5EF8mbWPbkOHj6yet4T4gKZcwPw0sBubOm5jnMidsGIqXTySNt_AJseOJD-hJZrOn-yQyyltmjRTnGr5LCNgGeVZpayCu8AqoIUrqxF32O-8xHviJ/s1600/textdiffExample.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Text Difference Tool Example</span></td></tr>
</tbody></table>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">The problem contains two parts: </span></div>
<div style="text-align: justify;">
</div>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Detecting differences of two texts: For detecting differences, <a href="http://en.wikipedia.org/wiki/Longest_common_subsequence_problem">an efficient dynamic algorithm of LCS (Longest Common Subsequence)</a> used in this solution. This solution has O(text1WordCount * text2WordCount) complexity and coded as "longestCommonSubsequence" method below.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Visualizing the differences: For visualizing, an HTML tag based approach is used, which marks new words of text2 with green color and old words of text1 with red color. This solution h</span><span style="font-family: 'Trebuchet MS', sans-serif;">as O(changedWordsCount * (text1WordCount+text2WordCount)) complexity and coded as "ma</span><span style="font-family: 'Trebuchet MS', sans-serif;">rkTextDifferences" method below.</span></li>
</ul>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Note1: For simplicity, "normalizeText" method is used for removing \n, \t and multiple space characters. </span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Note2: This class was created as a Vaadin component. But "longestCommonSubsequence" is pure generic and "markTextDifferences" method is generic on HTML based visual components, so they can also be used with different frameworks.</span></div>
<br />
<div style="text-align: justify;">
<br /></div>
<div class="java5">
<ol>
<li class="li1"><div class="de1">
<span class="kw2">import</span> <span class="co2">java.util.ArrayList</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">import</span> <span class="co2">com.vaadin.ui.CustomComponent</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">import</span> <span class="co2">com.vaadin.ui.Label</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">import</span> <span class="co2">com.vaadin.ui.Layout</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">import</span> <span class="co2">com.vaadin.ui.VerticalLayout</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co3">/**</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * Text comparison component which marks differences of two texts with colors.</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * </span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @author cb</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> */</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">public</span> <span class="kw2">class</span> TextCompareComponent <span class="kw2">extends</span> CustomComponent <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">private</span> Layout mainLayout = <span class="kw2">new</span> VerticalLayout<span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">private</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html"><span class="kw46">ArrayList</span></a><span class="sy0"><</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a><span class="sy0">></span> longestCommonSubsequenceList<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">private</span> <span class="kw2">static</span> <span class="kw2">final</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> INSERT_COLOR = <span class="st0">"#99FFCC"</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">private</span> <span class="kw2">static</span> <span class="kw2">final</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> DELETE_COLOR = <span class="st0">"#CB6D6D"</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">public</span> TextCompareComponent<span class="br0">(</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> text1, <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> text2<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
text1 = normalizeText<span class="br0">(</span>text1<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
text2 = normalizeText<span class="br0">(</span>text2<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">this</span>.<span class="me1">longestCommonSubsequenceList</span> = longestCommonSubsequence<span class="br0">(</span>text1, text2<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> result = markTextDifferences<span class="br0">(</span>text1, text2, </div>
</li>
<li class="li1"><div class="de1">
longestCommonSubsequenceList, INSERT_COLOR, DELETE_COLOR<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Label.html"><span class="kw6">Label</span></a> label = <span class="kw2">new</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Label.html"><span class="kw6">Label</span></a><span class="br0">(</span>result, <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Label.html"><span class="kw6">Label</span></a>.<span class="me1">CONTENT_XHTML</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
mainLayout.<span class="me1">addComponent</span><span class="br0">(</span>label<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
setCompositionRoot<span class="br0">(</span>mainLayout<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co3">/**</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * Finds a list of longest common subsequences (lcs) of given two texts.</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * </span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @param text1</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @param text2</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @return - longest common subsequence list</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> */</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">private</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html"><span class="kw46">ArrayList</span></a><span class="sy0"><</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a><span class="sy0">></span> longestCommonSubsequence<span class="br0">(</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> text1, <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> text2<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a><span class="br0">[</span><span class="br0">]</span> text1Words = text1.<span class="me1">split</span><span class="br0">(</span><span class="st0">" "</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a><span class="br0">[</span><span class="br0">]</span> text2Words = text2.<span class="me1">split</span><span class="br0">(</span><span class="st0">" "</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw3">int</span> text1WordCount = text1Words.<span class="me1">length</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw3">int</span> text2WordCount = text2Words.<span class="me1">length</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw3">int</span><span class="br0">[</span><span class="br0">]</span><span class="br0">[</span><span class="br0">]</span> solutionMatrix = <span class="kw2">new</span> <span class="kw3">int</span><span class="br0">[</span>text1WordCount + <span class="nu0">1</span><span class="br0">]</span><span class="br0">[</span>text2WordCount + <span class="nu0">1</span><span class="br0">]</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">for</span> <span class="br0">(</span><span class="kw3">int</span> i = text1WordCount - <span class="nu0">1</span><span class="sy0">;</span> i <span class="sy0">></span>= <span class="nu0">0</span><span class="sy0">;</span> i--<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">for</span> <span class="br0">(</span><span class="kw3">int</span> j = text2WordCount - <span class="nu0">1</span><span class="sy0">;</span> j <span class="sy0">></span>= <span class="nu0">0</span><span class="sy0">;</span> j--<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">if</span> <span class="br0">(</span>text1Words<span class="br0">[</span>i<span class="br0">]</span>.<span class="me1">equals</span><span class="br0">(</span>text2Words<span class="br0">[</span>j<span class="br0">]</span><span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
solutionMatrix<span class="br0">[</span>i<span class="br0">]</span><span class="br0">[</span>j<span class="br0">]</span> = solutionMatrix<span class="br0">[</span>i + <span class="nu0">1</span><span class="br0">]</span><span class="br0">[</span>j + <span class="nu0">1</span><span class="br0">]</span> + <span class="nu0">1</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">else</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
solutionMatrix<span class="br0">[</span>i<span class="br0">]</span><span class="br0">[</span>j<span class="br0">]</span> = <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html"><span class="kw21">Math</span></a>.<span class="me1">max</span><span class="br0">(</span>solutionMatrix<span class="br0">[</span>i + <span class="nu0">1</span><span class="br0">]</span><span class="br0">[</span>j<span class="br0">]</span>,</div>
</li>
<li class="li1"><div class="de1">
solutionMatrix<span class="br0">[</span>i<span class="br0">]</span><span class="br0">[</span>j + <span class="nu0">1</span><span class="br0">]</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw3">int</span> i = <span class="nu0">0</span>, j = <span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html"><span class="kw46">ArrayList</span></a><span class="sy0"><</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a><span class="sy0">></span> lcsResultList = <span class="kw2">new</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html"><span class="kw46">ArrayList</span></a><span class="sy0"><</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a><span class="sy0">></span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">while</span> <span class="br0">(</span>i <span class="sy0"><</span> text1WordCount <span class="sy0">&&</span> j <span class="sy0"><</span> text2WordCount<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">if</span> <span class="br0">(</span>text1Words<span class="br0">[</span>i<span class="br0">]</span>.<span class="me1">equals</span><span class="br0">(</span>text2Words<span class="br0">[</span>j<span class="br0">]</span><span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
lcsResultList.<span class="me1">add</span><span class="br0">(</span>text2Words<span class="br0">[</span>j<span class="br0">]</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
i++<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
j++<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span> </div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">(</span>solutionMatrix<span class="br0">[</span>i + <span class="nu0">1</span><span class="br0">]</span><span class="br0">[</span>j<span class="br0">]</span> <span class="sy0">></span>= solutionMatrix<span class="br0">[</span>i<span class="br0">]</span><span class="br0">[</span>j + <span class="nu0">1</span><span class="br0">]</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
i++<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">else</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
j++<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">return</span> lcsResultList<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co3">/**</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * Normalizes given string by deleting \n, \t and extra spaces.</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * </span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @param text - initial string</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @return - normalized string</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> */</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">private</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> normalizeText<span class="br0">(</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> text<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
text = text.<span class="me1">trim</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
text = text.<span class="me1">replace</span><span class="br0">(</span><span class="st0">"<span class="es0">\n</span>"</span>, <span class="st0">" "</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
text = text.<span class="me1">replace</span><span class="br0">(</span><span class="st0">"<span class="es0">\t</span>"</span>, <span class="st0">" "</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">while</span> <span class="br0">(</span>text.<span class="me1">contains</span><span class="br0">(</span><span class="st0">" "</span><span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
text = text.<span class="me1">replace</span><span class="br0">(</span><span class="st0">" "</span>, <span class="st0">" "</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">return</span> text<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co3">/**</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * Returns colored inserted/deleted text representation of given two texts.</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * Uses longestCommonSubsequenceList to determine colored sections.</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * </span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @param text1</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @param text2</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @param lcsList</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @param insertColor</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @param deleteColor</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @return - colored result text</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> */</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">private</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> markTextDifferences<span class="br0">(</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> text1, <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> text2, </div>
</li>
<li class="li1"><div class="de1">
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html"><span class="kw46">ArrayList</span></a><span class="sy0"><</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a><span class="sy0">></span> lcsList, <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> insertColor, <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> deleteColor<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html"><span class="kw21">StringBuffer</span></a> stringBuffer = <span class="kw2">new</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html"><span class="kw21">StringBuffer</span></a><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">if</span> <span class="br0">(</span>text1 <span class="sy0">!</span>= <span class="kw4">null</span> <span class="sy0">&&</span> lcsList <span class="sy0">!</span>= <span class="kw4">null</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a><span class="br0">[</span><span class="br0">]</span> text1Words = text1.<span class="me1">split</span><span class="br0">(</span><span class="st0">" "</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a><span class="br0">[</span><span class="br0">]</span> text2Words = text2.<span class="me1">split</span><span class="br0">(</span><span class="st0">" "</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw3">int</span> i = <span class="nu0">0</span>, j = <span class="nu0">0</span>, word1LastIndex = <span class="nu0">0</span>, word2LastIndex = <span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">for</span> <span class="br0">(</span><span class="kw3">int</span> k = <span class="nu0">0</span><span class="sy0">;</span> k <span class="sy0"><</span> lcsList.<span class="me1">size</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span> k++<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">for</span> <span class="br0">(</span>i = word1LastIndex, j = word2LastIndex<span class="sy0">;</span> </div>
</li>
<li class="li1"><div class="de1">
i <span class="sy0"><</span> text1Words.<span class="me1">length</span> <span class="sy0">&&</span> j <span class="sy0"><</span> text2Words.<span class="me1">length</span><span class="sy0">;</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">if</span> <span class="br0">(</span>text1Words<span class="br0">[</span>i<span class="br0">]</span>.<span class="me1">equals</span><span class="br0">(</span>lcsList.<span class="me1">get</span><span class="br0">(</span>k<span class="br0">)</span><span class="br0">)</span> <span class="sy0">&&</span> </div>
</li>
<li class="li1"><div class="de1">
text2Words<span class="br0">[</span>j<span class="br0">]</span>.<span class="me1">equals</span><span class="br0">(</span>lcsList.<span class="me1">get</span><span class="br0">(</span>k<span class="br0">)</span><span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
stringBuffer.<span class="me1">append</span><span class="br0">(</span><span class="st0">"<SPAN>"</span> + lcsList.<span class="me1">get</span><span class="br0">(</span>k<span class="br0">)</span> + <span class="st0">" </SPAN>"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
word1LastIndex = i + <span class="nu0">1</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
word2LastIndex = j + <span class="nu0">1</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
i = text1Words.<span class="me1">length</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
j = text2Words.<span class="me1">length</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">(</span><span class="sy0">!</span>text1Words<span class="br0">[</span>i<span class="br0">]</span>.<span class="me1">equals</span><span class="br0">(</span>lcsList.<span class="me1">get</span><span class="br0">(</span>k<span class="br0">)</span><span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">for</span> <span class="br0">(</span><span class="sy0">;</span> i <span class="sy0"><</span> text1Words.<span class="me1">length</span> <span class="sy0">&&</span> </div>
</li>
<li class="li1"><div class="de1">
<span class="sy0">!</span>text1Words<span class="br0">[</span>i<span class="br0">]</span>.<span class="me1">equals</span><span class="br0">(</span>lcsList.<span class="me1">get</span><span class="br0">(</span>k<span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span> i++<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
stringBuffer.<span class="me1">append</span><span class="br0">(</span><span class="st0">"<SPAN style='BACKGROUND-COLOR:"</span> + </div>
</li>
<li class="li1"><div class="de1">
deleteColor + <span class="st0">"'>"</span> + text1Words<span class="br0">[</span>i<span class="br0">]</span> + <span class="st0">" </SPAN>"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">(</span><span class="sy0">!</span>text2Words<span class="br0">[</span>j<span class="br0">]</span>.<span class="me1">equals</span><span class="br0">(</span>lcsList.<span class="me1">get</span><span class="br0">(</span>k<span class="br0">)</span><span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">for</span> <span class="br0">(</span><span class="sy0">;</span> j <span class="sy0"><</span> text2Words.<span class="me1">length</span> <span class="sy0">&&</span> </div>
</li>
<li class="li1"><div class="de1">
<span class="sy0">!</span>text2Words<span class="br0">[</span>j<span class="br0">]</span>.<span class="me1">equals</span><span class="br0">(</span>lcsList.<span class="me1">get</span><span class="br0">(</span>k<span class="br0">)</span><span class="br0">)</span>, j++<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
stringBuffer.<span class="me1">append</span><span class="br0">(</span><span class="st0">"<SPAN style='BACKGROUND-COLOR:"</span> + </div>
</li>
<li class="li1"><div class="de1">
insertColor + <span class="st0">"'>"</span> + text2Words<span class="br0">[</span>j<span class="br0">]</span> + <span class="st0">" </SPAN>"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">for</span> <span class="br0">(</span><span class="sy0">;</span> word1LastIndex <span class="sy0"><</span> text1Words.<span class="me1">length</span><span class="sy0">;</span> word1LastIndex++<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
stringBuffer.<span class="me1">append</span><span class="br0">(</span><span class="st0">"<SPAN style='BACKGROUND-COLOR:"</span> + </div>
</li>
<li class="li1"><div class="de1">
deleteColor + <span class="st0">"'>"</span> + text1Words<span class="br0">[</span>word1LastIndex<span class="br0">]</span> + <span class="st0">" </SPAN>"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">for</span> <span class="br0">(</span><span class="sy0">;</span> word2LastIndex <span class="sy0"><</span> text2Words.<span class="me1">length</span><span class="sy0">;</span> word2LastIndex++<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
stringBuffer.<span class="me1">append</span><span class="br0">(</span><span class="st0">"<SPAN style='BACKGROUND-COLOR:"</span> + </div>
</li>
<li class="li1"><div class="de1">
insertColor + <span class="st0">"'>"</span> + text2Words<span class="br0">[</span>word2LastIndex<span class="br0">]</span> + <span class="st0">" </SPAN>"</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw2">return</span> stringBuffer.<span class="me1">toString</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
</ol>
</div>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com2tag:blogger.com,1999:blog-7988792589954261688.post-58916387086929103352012-04-04T11:19:00.001+03:002012-04-04T11:26:41.789+03:00A Regular Expression HashMap Implementation in Java<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/04/regular-expression-hashmap.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<style type="text/css">
<!--
/**
* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
* (http://qbnz.com/highlighter/ and http://geshi.org/)
*/
.java .de1, .java .de2 {font: normal normal 1em/1.0em monospace; margin:0; padding:0; background:none; vertical-align:top;color: #000020;}
.java {font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;}
.java a:link {color: #000060;}
.java a:hover {background-color: #f0f000;}
.java .imp {font-weight: bold; color: red;}
.java li, .java .li1 {font-weight: normal; vertical-align:top;font: normal normal 100% 'Courier New', Courier, monospace; color: #003030;}
.java .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.java .li2 {font-weight: bold; vertical-align:top;font-weight: bold; color: #006060;}
.java .kw1 {color: #000000; font-weight: bold;}
.java .kw2 {color: #000066; font-weight: bold;}
.java .kw3 {color: #003399;}
.java .kw4 {color: #000066; font-weight: bold;}
.java .co1 {color: #666666; font-style: italic;}
.java .co2 {color: #006699;}
.java .co3 {color: #008000; font-style: italic; font-weight: bold;}
.java .coMULTI {color: #666666; font-style: italic;}
.java .es0 {color: #000099; font-weight: bold;}
.java .br0 {color: #009900;}
.java .sy0 {color: #339933;}
.java .st0 {color: #0000ff;}
.java .nu0 {color: #cc66cc;}
.java .me1 {color: #006633;}
.java .me2 {color: #006633;}
.java span.xtra { display:block; }
--!>
</style><span style="font-family: 'Trebuchet MS', sans-serif;"></span>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"></span></div>
<span style="font-family: 'Trebuchet MS', sans-serif;">
</span>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Below is an implementation of a Regular Expression HashMap. It works with key-value pairs which the key is a regular expression. It compiles the key (regular expression) while adding (i.e. putting), so there is no compile time while getting. Once getting an element, you don't give regular expression; you give any possible value of a regular expression. </span></div><br />
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">As a result, this behaviour provides to map numerous values of a regular expression into the same value. The class does not depend to any external libraries, uses only default java.util. So, it will be used simply when a behaviour like that is required. </span></div>
<span style="font-family: 'Trebuchet MS', sans-serif;">
</span><br />
<div class="java">
<ol>
<li class="li1"><div class="de1">
<span class="kw1">import</span> <span class="co2">java.util.ArrayList</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">import</span> <span class="co2">java.util.HashMap</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">import</span> <span class="co2">java.util.regex.Pattern</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="co3">/**</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * This class is an extended version of Java HashMap </span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * and includes pattern-value lists which are used to </span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * evaluate regular expression values. If given item </span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * is a regular expression, it is saved in regexp lists.</span></div>
</li>
<li class="li2"><div class="de2">
<span class="co3"> * If requested item matches with a regular expression, </span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * its value is get from regexp lists.</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * </span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @author cb</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> *</span></div>
</li>
<li class="li2"><div class="de2">
<span class="co3"> * @param <K> : Key of the map item.</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * @param <V> : Value of the map item.</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> */</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw1">class</span> RegExHashMap<span class="sy0"><</span>K, V<span class="sy0">></span> <span class="kw1">extends</span> HashMap<span class="sy0"><</span>K, V<span class="sy0">></span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="co1">// list of regular expression patterns</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">private</span> ArrayList<span class="sy0"><</span>Pattern<span class="sy0">></span> regExPatterns <span class="sy0">=</span> <span class="kw1">new</span> ArrayList<span class="sy0"><</span>Pattern<span class="sy0">></span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span> </div>
</li>
<li class="li1"><div class="de1">
<span class="co1">// list of regular expression values which match patterns</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">private</span> ArrayList<span class="sy0"><</span>V<span class="sy0">></span> regExValues <span class="sy0">=</span> <span class="kw1">new</span> ArrayList<span class="sy0"><</span>V<span class="sy0">></span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span> </div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="co3">/**</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * Compile regular expression and add it to the regexp list as key.</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> */</span></div>
</li>
<li class="li1"><div class="de1">
@Override</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> V put<span class="br0">(</span>K key, V value<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li2"><div class="de2">
</div>
</li>
<li class="li1"><div class="de1">
regExPatterns.<span class="me1">add</span><span class="br0">(</span>Pattern.<span class="me1">compile</span><span class="br0">(</span>key.<span class="me1">toString</span><span class="br0">(</span><span class="br0">)</span><span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
regExValues.<span class="me1">add</span><span class="br0">(</span>value<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">return</span> value<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li2"><div class="de2">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co3">/**</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * If requested value matches with a regular expression, </span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> * returns it from regexp lists.</span></div>
</li>
<li class="li1"><div class="de1">
<span class="co3"> */</span></div>
</li>
<li class="li2"><div class="de2">
@Override</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> V get<span class="br0">(</span><a href="http://www.google.com/search?hl=en&q=allinurl%3Aobject+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Object</span></a> key<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
CharSequence cs <span class="sy0">=</span> <span class="kw1">new</span> <a href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a><span class="br0">(</span>key.<span class="me1">toString</span><span class="br0">(</span><span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="kw1">for</span> <span class="br0">(</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0"><</span> regExPatterns.<span class="me1">size</span><span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">if</span> <span class="br0">(</span>regExPatterns.<span class="me1">get</span><span class="br0">(</span>i<span class="br0">)</span>.<span class="me1">matcher</span><span class="br0">(</span>cs<span class="br0">)</span>.<span class="me1">matches</span><span class="br0">(</span><span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">return</span> regExValues.<span class="me1">get</span><span class="br0">(</span>i<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li2"><div class="de2">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">return</span> <span class="kw1">super</span>.<span class="me1">get</span><span class="br0">(</span>key<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
</ol>
</div>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com9tag:blogger.com,1999:blog-7988792589954261688.post-86837572557969218762012-03-21T13:57:00.000+02:002012-03-21T13:58:19.580+02:0010 Best Practices of Code Commenting & Formatting<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/03/10-best-practices-of-code-commenting.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Code commenting and formatting are all about code understandability. Code understandability is very relevant to code maintainability. So, small details about programming may help maintainability. In this context, some practices about commenting and formatting will be told here:
</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>Commenting</b></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b><br /></b></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Comments may be thought as part of the code, so they are really important. E.g. a commentless code library will be useless in a short time with high probability. Even though there are some approaches which suggests self-documenting code over code documentation, we suggest (self-documenting code + code documentation).</span></div>
<ol>
<li><span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">Use comments "as required". </span></li>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Unnecessary over-commenting in each line will reduce readability:</span></li>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Courier New', Courier, monospace;">int count = 0;</span><span style="font-family: 'Trebuchet MS', sans-serif;"> // assigning zero as initial value to the count (?!?)</span></li>
</ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Lack of commenting will increase maintenance time. Also, variable/method names should be understandable and self commenting</span></li>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Courier New', Courier, monospace;">int s = sqrt(v1) + v2 / v3 + fread(s). getChar(0) </span> <span style="font-family: 'Trebuchet MS', sans-serif;">//</span><span style="font-family: 'Trebuchet MS', sans-serif;">(?!?)</span></li>
<li style="text-align: justify;"><span style="font-family: 'Courier New', Courier, monospace;">List<int> getVal(int val, int len, String op) </span><span style="font-family: 'Trebuchet MS', sans-serif;">//</span><span style="font-family: 'Trebuchet MS', sans-serif;">(?!?)</span></li>
</ul>
</ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Don't write uncorrect comments. Uncorrect explanations are worse than no-comment.</span><span style="font-family: 'Trebuchet MS', sans-serif;"> </span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Write comments for variables which are important and non-selfdocumenting.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Writing comments (e.g. JavaDoc declaration) for all public methods is a good practice. Of course, these comments should be "really necessary" and "as required".</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Document "gotcha"s and "todo"s instantly when detected. These items may be remembered for that day but may not for tomorrow when not documented, so a buggy code will be inevitable.</span></li>
</ol>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>Formatting</b></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b><br /></b></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Formatting rules can be detected automatically by most tools (e.g. <a href="http://maven.apache.org/plugins/maven-checkstyle-plugin/">maven checkstyle</a>) and applied automatically by most IDEs (e.g. Eclipse <a href="http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/preferences/java/codestyle/ref-preferences-formatter.htm">Code Formatter</a> ctrl+shift+f). But there may be little differences between company formatting rules, so these tools should be configured before applying formatting.</span></div>
<ol>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Use brackets consistently. You may choose opening a bracket at the end of the current line or at the beginnning of the new line. Choose one of them and use consistently in the whole application.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Use blank lines consistently and as required. Blank lines may be used for separating code lines or line groups semantically for readability. E.g. 3 blank lines at the end of a method, no-blanks on whole code or one or two blank lines between each line of code reduces readability and not good for eye pleasure.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Pay attention for indentation. Correct indentation for grouping statements is as important as using brackets and blank lines.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Character count of a line should be limited for readability. This limit is generally 80 for most developers, but may change a little due to some other development parameters. </span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Using space chars in code should also be consistent in whole application. Generally, situations below are suitable for using spaces:</span></li>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">Between operators and operands:</span><span style="text-align: justify;"><span style="font-family: 'Courier New', Courier, monospace;"> </span></span></li>
<ul>
<li><span style="text-align: justify;"><span style="font-family: 'Courier New', Courier, monospace;">a += b , c = 0; (a == b)</span></span></li>
</ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">Between statement keywords and brackets: </span></li>
<ul>
<li><span style="text-align: justify;"><span style="font-family: 'Courier New', Courier, monospace;">if (value) {, public class A { </span></span></li>
</ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">After ';' char in loops: </span></li>
<ul>
<li><span style="text-align: justify;"><span style="font-family: 'Courier New', Courier, monospace;">for (int i = 0; i < length; i++) </span></span></li>
</ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">Between type casters and operands: </span></li>
<ul>
<li><span style="text-align: justify;"><span style="font-family: 'Courier New', Courier, monospace;">(int) value , (String) value</span></span></li>
</ul>
</ul>
</ol>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com7tag:blogger.com,1999:blog-7988792589954261688.post-19104322246360726572012-03-07T14:01:00.001+02:002012-03-07T14:11:31.452+02:002 Implementations of "Chain of Responsibility" Pattern with Java<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/03/2-implementations-of-chain-of.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<style type="text/css">
<!--
/**
* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
* (http://qbnz.com/highlighter/ and http://geshi.org/)
*/
.java .de1, .java .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;color: #000020;}
.java {font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;}
.java a:link {color: #000060;}
.java a:hover {background-color: #f0f000;}
.java .imp {font-weight: bold; color: red;}
.java li, .java .li1 {font-weight: normal; vertical-align:top;font: normal normal 100% 'Courier New', Courier, monospace; color: #003030;}
.java .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.java .li2 {font-weight: bold; vertical-align:top;font-weight: bold; color: #006060;}
.java .kw1 {color: #000000; font-weight: bold;}
.java .kw2 {color: #000066; font-weight: bold;}
.java .kw3 {color: #003399;}
.java .kw4 {color: #000066; font-weight: bold;}
.java .co1 {color: #666666; font-style: italic;}
.java .co2 {color: #006699;}
.java .co3 {color: #008000; font-style: italic; font-weight: bold;}
.java .coMULTI {color: #666666; font-style: italic;}
.java .es0 {color: #000099; font-weight: bold;}
.java .br0 {color: #009900;}
.java .sy0 {color: #339933;}
.java .st0 {color: #0000ff;}
.java .nu0 {color: #cc66cc;}
.java .me1 {color: #006633;}
.java .me2 {color: #006633;}
.java span.xtra { display:block; }
--!>
</style>
<br />
<br />
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Chain of Responsibility design pattern is needed when a few processors should exist for performing an operation and a particular order should be defined for those processors. Also the changeability of the order of processors on runtime are important.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">UML represantation of the pattern is as below:</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFtR8KQTYl6mGl136kgWxfc6ZxOWAX5JSlynO7NDmvmMLGVclApp2raCYNWbFLgldcga6RzWQjwdGOdjPVYlJ0dEexfL9sxnb-BhWhbfBppuMcJZR9PseeSl3iEpbPXiNhDcPE9uWIJZak/s1600/CoR_UML.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFtR8KQTYl6mGl136kgWxfc6ZxOWAX5JSlynO7NDmvmMLGVclApp2raCYNWbFLgldcga6RzWQjwdGOdjPVYlJ0dEexfL9sxnb-BhWhbfBppuMcJZR9PseeSl3iEpbPXiNhDcPE9uWIJZak/s1600/CoR_UML.jpg" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Handler defines the general structure of processor objects. "HandleRequest" here is the abstract processor method. Handler also has a reference of its own type, which represents the next handler. For this a public "setNextHandler" method should be defined and exactly the handler is an abstract class. </span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">ConcreteHandler define different representations of processors. At last, Client is responsible with creating required handlers (processors) and define a chain order between them.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">Generally two diffent implementation may exist for this pattern. Difference is related with the "location of the chain routing business logic". Chain routing business logic may be either in Handler abstract class or ConcreteHandler classes, or both of them. Sample of first two approaches will be given below:</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><b>1. "Handler" has chain routing business logic:</b></span></div>
<br />
<div class="java">
<ol>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw1">abstract</span> <span class="kw1">class</span> Processor <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">protected</span> Processor next<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">protected</span> <span class="kw4">int</span> threshold<span class="sy0">;</span></div>
</li>
<li class="li2"><div class="de2">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw4">void</span> setNextProcessor<span class="br0">(</span>Processor p<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
next <span class="sy0">=</span> p<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="kw1">public</span> <span class="kw4">void</span> process<span class="br0">(</span><a href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> data, <span class="kw4">int</span> value<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">if</span> <span class="br0">(</span>value <span class="sy0"><=</span> threshold<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
process<span class="br0">(</span>data<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">if</span> <span class="br0">(</span>next <span class="sy0">!=</span> <span class="kw2">null</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li2"><div class="de2">
next.<span class="me1">message</span><span class="br0">(</span>data, threshold<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">abstract</span> <span class="kw1">protected</span> <span class="kw4">void</span> processData<span class="br0">(</span><a href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> data<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li2"><div class="de2">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw1">class</span> ProcessorA <span class="kw1">extends</span> Processor <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> ProcessorA <span class="br0">(</span><span class="kw4">int</span> threshold<span class="br0">)</span> <span class="br0">{</span> </div>
</li>
<li class="li2"><div class="de2">
<span class="kw1">this</span>.<span class="me1">threshold</span> <span class="sy0">=</span> threshold<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">protected</span> <span class="kw4">void</span> processData<span class="br0">(</span><a href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> data<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://www.google.com/search?hl=en&q=allinurl%3Asystem+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">(</span><span class="st0">"Processing with A: "</span> <span class="sy0">+</span> data<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li2"><div class="de2">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw1">class</span> ProcessorB <span class="kw1">extends</span> Processor <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="kw1">public</span> ProcessorB <span class="br0">(</span><span class="kw4">int</span> threshold<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">this</span>.<span class="me1">threshold</span> <span class="sy0">=</span> threshold<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">protected</span> <span class="kw4">void</span> writeMessage<span class="br0">(</span><a href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> data<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li2"><div class="de2">
<a href="http://www.google.com/search?hl=en&q=allinurl%3Asystem+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">err</span>.<span class="me1">println</span><span class="br0">(</span><span class="st0">"Processing with B: "</span> <span class="sy0">+</span> data<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw1">class</span> Client <span class="br0">{</span></div>
</li>
<li class="li2"><div class="de2">
<span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">void</span> main<span class="br0">(</span><a href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a><span class="br0">[</span><span class="br0">]</span> args<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
Processor p, p1, p2<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
p1 <span class="sy0">=</span> p <span class="sy0">=</span> <span class="kw1">new</span> ProcessorA<span class="br0">(</span><span class="nu0">2</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
p2 <span class="sy0">=</span> <span class="kw1">new</span> ProcessorB<span class="br0">(</span><span class="nu0">1</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
p1.<span class="me1">setNextProcessor</span><span class="br0">(</span>p2<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li2"><div class="de2">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co1">// Handled by ProcessorA</span></div>
</li>
<li class="li1"><div class="de1">
p.<span class="me1">process</span><span class="br0">(</span><span class="st0">"data1"</span>, <span class="nu0">2</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co1">// Handled by ProcessorA and ProcessorB</span></div>
</li>
<li class="li2"><div class="de2">
p.<span class="me1">process</span><span class="br0">(</span><span class="st0">"data2"</span>, <span class="nu0">1</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
</ol>
</div>
<br />
<b><span style="font-family: 'Trebuchet MS', sans-serif;">2. "ConcreteHandler"s have chain routing business logic:</span></b>
<br />
<br />
<div class="java">
<ol>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw1">abstract</span> <span class="kw1">class</span> Processor <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">protected</span> Processor next<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">protected</span> <span class="kw4">int</span> threshold<span class="sy0">;</span></div>
</li>
<li class="li2"><div class="de2">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw4">void</span> setNextProcessor<span class="br0">(</span>Processor p<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
next <span class="sy0">=</span> p<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="kw1">abstract</span> <span class="kw1">protected</span> <span class="kw4">void</span> processData<span class="br0">(</span><a href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> data<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw1">class</span> ProcessorA <span class="kw1">extends</span> Processor <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="kw1">public</span> ProcessorA <span class="br0">(</span><span class="kw4">int</span> threshold<span class="br0">)</span> <span class="br0">{</span> </div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">this</span>.<span class="me1">threshold</span> <span class="sy0">=</span> threshold<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">protected</span> <span class="kw4">void</span> processData<span class="br0">(</span><a href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> data, <span class="kw4">int</span> value<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li2"><div class="de2">
<a href="http://www.google.com/search?hl=en&q=allinurl%3Asystem+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">(</span><span class="st0">"Processing with A: "</span> <span class="sy0">+</span> data<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">if</span> <span class="br0">(</span>value <span class="sy0">>=</span> threshold <span class="sy0">&&</span> next <span class="sy0">!=</span> <span class="kw2">null</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
next.<span class="me1">processData</span><span class="br0">(</span>data, value<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li2"><div class="de2">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw1">class</span> ProcessorB <span class="kw1">extends</span> Processor <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> ProcessorB <span class="br0">(</span><span class="kw4">int</span> threshold<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li2"><div class="de2">
<span class="kw1">this</span>.<span class="me1">threshold</span> <span class="sy0">=</span> threshold<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">protected</span> <span class="kw4">void</span> processData<span class="br0">(</span><a href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> data, <span class="kw4">int</span> value<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<a href="http://www.google.com/search?hl=en&q=allinurl%3Asystem+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">(</span><span class="st0">"Processing with B: "</span> <span class="sy0">+</span> data<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li2"><div class="de2">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">if</span> <span class="br0">(</span>value <span class="sy0">>=</span> threshold <span class="sy0">&&</span> next <span class="sy0">!=</span> <span class="kw2">null</span><span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
next.<span class="me1">processData</span><span class="br0">(</span>data, value<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
<li class="li2"><div class="de2">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw1">class</span> Client <span class="br0">{</span></div>
</li>
<li class="li1"><div class="de1">
<span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">void</span> main<span class="br0">(</span><a href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a><span class="br0">[</span><span class="br0">]</span> args<span class="br0">)</span> <span class="br0">{</span></div>
</li>
<li class="li2"><div class="de2">
Processor p, p1, p2<span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
p1 <span class="sy0">=</span> p <span class="sy0">=</span> <span class="kw1">new</span> ProcessorA<span class="br0">(</span><span class="nu0">2</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
p2 <span class="sy0">=</span> <span class="kw1">new</span> ProcessorB<span class="br0">(</span><span class="nu0">1</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
p1.<span class="me1">setNextProcessor</span><span class="br0">(</span>p2<span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li2"><div class="de2">
<span class="co1">// Handled by ProcessorA</span></div>
</li>
<li class="li1"><div class="de1">
p.<span class="me1">processData</span><span class="br0">(</span><span class="st0">"data1"</span>, <span class="nu0">1</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li1"><div class="de1">
</div>
</li>
<li class="li1"><div class="de1">
<span class="co1">// Handled by ProcessorA and ProcessorB</span></div>
</li>
<li class="li1"><div class="de1">
p.<span class="me1">processData</span><span class="br0">(</span><span class="st0">"data2"</span>, <span class="nu0">2</span><span class="br0">)</span><span class="sy0">;</span></div>
</li>
<li class="li2"><div class="de2">
<span class="br0">}</span></div>
</li>
<li class="li1"><div class="de1">
<span class="br0">}</span></div>
</li>
</ol>
</div>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com0tag:blogger.com,1999:blog-7988792589954261688.post-8265061901301578282012-02-24T22:25:00.000+02:002012-02-24T23:05:19.800+02:00Customized Internationalization (i18n) in Java - Step by Step<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/02/customized-internationalization-i18n-in.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">Internationalization (i18n)</a> is very important in our software projects. It brings mainly these benefits:</span></div>
<br />
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Externalizing UI strings into external files other than code files and so easy-to-manage UI content.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Supporting multiple languages.</span></li>
</ul>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">In this post, a brief practical example of i18n will be given for Eclipse and Java projects, including customizing i18n mechanism to have more maintainable and encapsulated approach.</span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">First, we must have some classes which includes string values shown on user interface:</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVBobDTScZRkT5ro886zMATAF-smaFBnNwu5RwXvLV1msk2bVxZSjg3JeqD0UShyTAgjUj8d5WffOYWtFOU-IT37zQliDVsdes_rbNH0iZ-dxs6R35y1u56mnBGU6zIG96QK3TxjO81hRB/s1600/i18n0.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVBobDTScZRkT5ro886zMATAF-smaFBnNwu5RwXvLV1msk2bVxZSjg3JeqD0UShyTAgjUj8d5WffOYWtFOU-IT37zQliDVsdes_rbNH0iZ-dxs6R35y1u56mnBGU6zIG96QK3TxjO81hRB/s1600/i18n0.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">An example UI class</span></td></tr>
</tbody></table>
<div>
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span><br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span></div>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Then we must have an instance of an i18n utility class. This is generally one of the two in Java:</span></li>
</ul>
<ol><ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">java.util.ResourceBundle (doesn't need spring dependency)</span></li>
</ul>
</ol>
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAGHa44V3TNWPZt837uFqUIr_ODa6JOe5ML-R2mf9dIUbnoLzFkgHSm9vfbPBUFfqkQyQQCqXA0LPKjvZDsnJLGYKYY1MqFhYWVjAkDoFiNk8zsAg0OjmsCu3Cb1zJT6NaGnyxEPQRB0Lu/s1600/i18n0-1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAGHa44V3TNWPZt837uFqUIr_ODa6JOe5ML-R2mf9dIUbnoLzFkgHSm9vfbPBUFfqkQyQQCqXA0LPKjvZDsnJLGYKYY1MqFhYWVjAkDoFiNk8zsAg0OjmsCu3Cb1zJT6NaGnyxEPQRB0Lu/s1600/i18n0-1.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">ResourceBundle initialization</span></td></tr>
</tbody></table>
<div style="text-align: justify;">
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span><br />
<ol><ul>
<li style="text-align: left;"><span style="font-family: 'Trebuchet MS', sans-serif;">org.springframework.context.support.ResourceBundleMessageSource (</span><span style="font-family: 'Trebuchet MS', sans-serif;">has multiple word externalization capability (which will be told later)).</span></li>
</ul>
</ol>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg6orZo9yGkWMYTwSPmAfl5ksNN3pqZI_mOUgqPQIcbZdQM_uD3QoEhGnCydEE-KMSmKmv6swE-4jGnlT1PcsRsu_yrP_WTxwT0Zp93_B01H8ye581mwqMAFEpsyvz_jgR_0EQyxJ7E_-Z/s1600/i18n0-2.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg6orZo9yGkWMYTwSPmAfl5ksNN3pqZI_mOUgqPQIcbZdQM_uD3QoEhGnCydEE-KMSmKmv6swE-4jGnlT1PcsRsu_yrP_WTxwT0Zp93_B01H8ye581mwqMAFEpsyvz_jgR_0EQyxJ7E_-Z/s1600/i18n0-2.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">ResourceBundleMessageSource initialization</span></td></tr>
</tbody></table>
<div style="text-align: left;">
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span></div>
<div style="font-family: 'Trebuchet MS', sans-serif;">
<br /></div>
<div style="font-family: 'Trebuchet MS', sans-serif;">
We'll use ResourceBundleMessageSource instance in this tutorial because of its extended capabilities.<br />
<br />
<br /></div>
<div>
<ul style="font-family: 'Trebuchet MS', sans-serif;">
<li>Then right click on the class and choose Source --> Externalize Strings. A window as below will be shown. Enter keys for strings into the right column. Keys will be started with class name as default. Keys must be unique on the system, so a predefined pattern should be applied (e.g. <class_name>.<type_id>.<description>)</li>
</ul>
<div class="separator" style="clear: both; font-family: 'Trebuchet MS', sans-serif; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="font-family: 'Trebuchet MS', sans-serif;">
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWnD-_qce4R_3UUkIs4xgUlUAU5ubnoWd3op945HTFfIvXHXeNBfie524fssmVGpg4uXxC3HiJobKgXnmQkWMK_HWfRtblVUuHEkHLQOnhIGs80ERDURirIOq2Nivw2Rfcw1yrBdh2lLWG/s1600/i18n1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWnD-_qce4R_3UUkIs4xgUlUAU5ubnoWd3op945HTFfIvXHXeNBfie524fssmVGpg4uXxC3HiJobKgXnmQkWMK_HWfRtblVUuHEkHLQOnhIGs80ERDURirIOq2Nivw2Rfcw1yrBdh2lLWG/s1600/i18n1.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Eclipse string externalization window
</td></tr>
</tbody></table>
<br />
<br /></div>
<ul style="font-family: 'Trebuchet MS', sans-serif;">
<li>Click Next--> Finish and your strings will be changed as follows. And also Messages class and externalizer properties file will be created automatically (auto-comments on the right are markers for eclipse which means
"externalized"):</li>
</ul>
<div class="separator" style="clear: both; font-family: 'Trebuchet MS', sans-serif; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="font-family: 'Trebuchet MS', sans-serif;">
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAPsv5MDalMjBHcnIUDNQFJXTuKIDC-3Us_1s9jmiN-ZqygC8LXlwdVGShh4S-nNGb5mAMTqSMowOmB8fGy-6itUxJwawsVaEn04T2IjVe6LIA2giFlDkBSNlFdNudtZdbbaKCnaErwJJo/s1600/i18n2.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAPsv5MDalMjBHcnIUDNQFJXTuKIDC-3Us_1s9jmiN-ZqygC8LXlwdVGShh4S-nNGb5mAMTqSMowOmB8fGy-6itUxJwawsVaEn04T2IjVe6LIA2giFlDkBSNlFdNudtZdbbaKCnaErwJJo/s1600/i18n2.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Class with externalized strings
</td></tr>
</tbody></table>
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYiD883yFkWP2uYmwnB6M_1rdIP9WuqIW_DVaMrdPSo2ZZ7_Ph0Mr_20cp133s4uL8MWiLKJslHthJdN7QksvCNNfHO4-RVBTl_J0-nq1i9c5V0Wl5YIB1EXPWrucDQvCvw7rj5_DA1rl7/s1600/i18n3.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYiD883yFkWP2uYmwnB6M_1rdIP9WuqIW_DVaMrdPSo2ZZ7_Ph0Mr_20cp133s4uL8MWiLKJslHthJdN7QksvCNNfHO4-RVBTl_J0-nq1i9c5V0Wl5YIB1EXPWrucDQvCvw7rj5_DA1rl7/s1600/i18n3.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Auto-created i18n utility and property classes
</td></tr>
</tbody></table>
<br /></div>
<div class="separator" style="clear: both; font-family: 'Trebuchet MS', sans-serif; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="font-family: 'Trebuchet MS', sans-serif;">
<br />
<br /></div>
<ul style="font-family: 'Trebuchet MS', sans-serif;">
<li>Now externalization is complete. But we want i18n, and we must support multiple languages. For this, define another properties file with location post-tag (e.g. "EN", "FR", "TR", ...), copy keys and fill values with new language and set locale of resource bundle in a proper place/action of your application (e.g. on settings window or login page):</li>
</ul>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkV9_lX7-Z3nyP0L9FtCs8vcSpQyuTJs1gKfW2uKe2wAU00U5XEKZWtg5NI_x6qmRhNg24loEoublXsKWiyVphCGCJj_fB_hTq-5Oq5HumhEgo2OZ93rg6NDRfhcbDeVU__yxljKKsLDze/s1600/i18n4.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkV9_lX7-Z3nyP0L9FtCs8vcSpQyuTJs1gKfW2uKe2wAU00U5XEKZWtg5NI_x6qmRhNg24loEoublXsKWiyVphCGCJj_fB_hTq-5Oq5HumhEgo2OZ93rg6NDRfhcbDeVU__yxljKKsLDze/s1600/i18n4.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Multiple property files for each language</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; font-family: 'Trebuchet MS', sans-serif; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; font-family: 'Trebuchet MS', sans-serif; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie-rwXeUq9qtu_tZSCTe8JNhMB_U4y9CsrWzSYqHt6yMeNfKbZrGL9JwjCZbYEFDk8rMSwhQKSpdXwbUc9xYSejiRs95GjkjYK58iIkke3obzK_e2lU6zGRMOaOvPamkLE_X4oPpAZ_jFc/s1600/i18n5.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie-rwXeUq9qtu_tZSCTe8JNhMB_U4y9CsrWzSYqHt6yMeNfKbZrGL9JwjCZbYEFDk8rMSwhQKSpdXwbUc9xYSejiRs95GjkjYK58iIkke3obzK_e2lU6zGRMOaOvPamkLE_X4oPpAZ_jFc/s1600/i18n5.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Messages_tr_TR.properties file content</span>
</td></tr>
</tbody></table>
<div class="separator" style="clear: both; font-family: 'Trebuchet MS', sans-serif; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; font-family: 'Trebuchet MS', sans-serif; text-align: center;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipdn65GXZsNoc-hhRlkwxzM1zjF6Hl_Ev2SJdEZIwBkax7OGdgsfwxkfNoVGVc4yTspSgi8tuRFsVvQLuLS5DFj7ltLg_TAqQhg7_WBk5vIf7ANRjScHu9VLfWA-QPoMR-q00WjlSDHa_Z/s1600/i18n8.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipdn65GXZsNoc-hhRlkwxzM1zjF6Hl_Ev2SJdEZIwBkax7OGdgsfwxkfNoVGVc4yTspSgi8tuRFsVvQLuLS5DFj7ltLg_TAqQhg7_WBk5vIf7ANRjScHu9VLfWA-QPoMR-q00WjlSDHa_Z/s1600/i18n8.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Setting new locale to the resource bundle</span></td></tr>
</tbody></table>
<div>
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span><br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<ul style="font-family: 'Trebuchet MS', sans-serif;">
<li>As the last step, we want to encapsulate i18n utility class and also want to use a more capable i18n utility (e.g.
<span style="font-family: 'Courier New', Courier, monospace; text-align: left;">ResourceBundleMessageSource</span>). For this, define a class as below:</li>
</ul>
<div class="separator" style="clear: both; font-family: 'Trebuchet MS', sans-serif; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaewEV77PCXHvGBpxMy83Jozy4ykFPGHiYg49flB2eNCiP53go5ftQB9tSrmm51AOTWA3twfAAgYwxx9nC4bueN7AcasxSvpOpTkW5zaYx7AVaAQZex2wQeXuTGmRvIOmyAtTOeKJOJz7L/s1600/i18n6.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaewEV77PCXHvGBpxMy83Jozy4ykFPGHiYg49flB2eNCiP53go5ftQB9tSrmm51AOTWA3twfAAgYwxx9nC4bueN7AcasxSvpOpTkW5zaYx7AVaAQZex2wQeXuTGmRvIOmyAtTOeKJOJz7L/s1600/i18n6.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Customized and encapsulated message source (i18n utility) class</span></td></tr>
</tbody></table>
<div style="font-family: 'Trebuchet MS', sans-serif;">
<br />
<br /></div>
<ul style="font-family: 'Trebuchet MS', sans-serif;">
<li>Finally, change "Messages.getString" statements into your new instance:</li>
</ul>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPopviI6UziG-yXWGP19BgHhC-mG3WCuhwfg5hj9zF0akg5Fu6gzzSs_PGIryJWrS_oYfT_uTVH7kutb3j3keWKvlTTf2s_iCjnhDpUw09Q8OB94PbT8sylwKDVJldADxDLt6HZjIYw7K4/s1600/i18n7.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPopviI6UziG-yXWGP19BgHhC-mG3WCuhwfg5hj9zF0akg5Fu6gzzSs_PGIryJWrS_oYfT_uTVH7kutb3j3keWKvlTTf2s_iCjnhDpUw09Q8OB94PbT8sylwKDVJldADxDLt6HZjIYw7K4/s1600/i18n7.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Class with externalized strings (with customized i18n utility class)</span></td></tr>
</tbody></table>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; font-family: 'Trebuchet MS', sans-serif; text-align: center;">
</div>
<div>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">You can also externalize parameterized strings using your class. Its usage will be as follows:</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnRhfXaFiME6CMz23L7IIbrzXQbRhtQ2zaq6HY1j7lvwV_SObdwSCwcaMs17i_AH_SB_5PwbaAN8I7fblkQHd4b1NYrQsTr8ZnfjcLj-qPSikAgUDDkJu3BxL3wCGAFRhr-eIaHvVLCGBF/s1600/i18n9.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnRhfXaFiME6CMz23L7IIbrzXQbRhtQ2zaq6HY1j7lvwV_SObdwSCwcaMs17i_AH_SB_5PwbaAN8I7fblkQHd4b1NYrQsTr8ZnfjcLj-qPSikAgUDDkJu3BxL3wCGAFRhr-eIaHvVLCGBF/s1600/i18n9.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Getting a parameterized string from i18n utility</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLT-eunYjVRTysRR_egmKrWjwpRDcnHDFE7zDiQjzST8LXCjlPiRz4N5OGKBbRdd-AWVTy4zlKmDoSa8PXXc0v6geRVjTfUnI5mLbwqkeA-4fGx9ubZk0fT_IQ6EfCjkdIPntdo0ntHBAF/s1600/i18n10.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLT-eunYjVRTysRR_egmKrWjwpRDcnHDFE7zDiQjzST8LXCjlPiRz4N5OGKBbRdd-AWVTy4zlKmDoSa8PXXc0v6geRVjTfUnI5mLbwqkeA-4fGx9ubZk0fT_IQ6EfCjkdIPntdo0ntHBAF/s1600/i18n10.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Defining a parameterized string in property file</span></td></tr>
</tbody></table>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
</div>
</div>
<div style="font-family: 'Trebuchet MS', sans-serif;">
<br /></div>
</div>
</div>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com0tag:blogger.com,1999:blog-7988792589954261688.post-18004134226312647562012-02-20T17:05:00.001+02:002013-05-06T08:37:48.487+03:0015 Best Practices of Variable & Method Naming<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/02/15-best-practices-of-variable-method.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div>
<br /></div>
<ol>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Use short enough and long enough variable names in each scope of code. Generally length may be 1 char for loop counters, 1 word for condition/loop variables, 1-2 words for methods, 2-3 words for classes, 3-4 words for globals.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Use specific names for variables, for example "value", "equals", "data", ... are not valid names for any case.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Use meaningful names for variables. Variable name must define the exact explanation of its content.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Don't start variables with o_, obj_, m_ etc. A variable does not need tags stating that it is a variable.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Obey company naming standards and write variable names consistently in application: e.g. txtUserName, lblUserName, cmbSchoolType, ... Otherwise readability will reduce and find/replace tools will be unusable.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Obey programming language standards and don't use lowercase/uppercase characters inconsistently: e.g. userName, UserName, USER_NAME, m_userName, username, ...</span></li>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">For example for Java, </span></li>
</ul>
<ol><ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">use Camel Case (aka Upper Camel Case) for classes: VelocityResponseWriter</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">use Lower Case for packages: com.company.project.ui</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">use Mixed Case (aka Lower Camel Case) for variables: studentName</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">use Upper Case for constants : MAX_PARAMETER_COUNT = 100</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">use Camel Case for enum class names and Upper Case for enum values.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">don't use '_' anywhere except constants and enum values (which are constants).</span></li>
</ul>
</ol>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Don't reuse same variable name in the same class in different contexts: e.g. in method, constructor, class. So you can provide more simplicity for understandability and maintainability.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Don't use same variable for different purposes in a method, conditional etc. Create a new and different named variable instead. This is also important for maintainability and readability.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Don't use non-ASCII chars in variable names. Those may run on your platform but may not on others.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Don't use too long variable names (e.g. 50 chars). Long names will bring ugly and hard-to-read code, also may not run on some compilers because of character limit.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Decide and use one natural language for naming, e.g. using mixed English and German names will be inconsistent and unreadable.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Use meaningful names for methods. The name must specify the exact action of the method and for most cases must start with a verb. (e.g. createPasswordHash)</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Obey company naming standards and write method names consistently in application: e.g. getTxtUserName(), getLblUserName(), isStudentApproved(), ... Otherwise readability will reduce and find/replace tools will be unusable.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Obey programming language standards and don't use lowercase/uppercase characters inconsistently: e.g. getUserName, GetUserName, getusername, ...</span></li>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">For example for Java, </span></li>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">use
Mixed Case for method names: getStudentSchoolType </span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">use
Mixed Case for method parameters: setSchoolName(String schoolName)</span></li>
</ul>
</ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Use meaningful names for method parameters, so it can documentate itself in case of no documentation.</span></li>
</ol>
CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com18tag:blogger.com,1999:blog-7988792589954261688.post-63896194554320759052012-01-31T11:06:00.000+02:002012-02-15T09:43:37.222+02:0015 Best Practices for Exception Handling<script type="text/javascript">
var dzone_url = 'http://codebuild.blogspot.com/2012/01/15-best-practices-about-exception.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<br />
<ol>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Don't manage business logic with exceptions. Use conditional statements instead. If a control can be done with if-else statement clearly, don't use exceptions because it reduces readability and performance
(e.g. null control, divide by zero control). .</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Exception names must be clear and meaningful, stating the causes of exception.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Throw exceptions for error conditions while implementing a method. E.g. if you return -1, -2, -3 etc. values instead of FileNotFoundException, that method can not be understand.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Catch specific exceptions instead of the top Exception class. This will bring additional performance, readability and more specific exception handling.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Null control with conditionals is not an alternative to catching NullPointerException. If a method may return null, control it with if-else statement. If a return may throw NullPointerException, catch it.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Try not to re-throw the exception because of the price. Bu if re-throwing had been a must, re-throw the same exception instead of creating a new exception. This will bring additional performance. You may add additional info in each layer to that exception.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Define your own exception hierarchy by extending current Exception class (e.g. UserException, SystemException and their sub types) and use them. By doing this you can specialize your exceptions and define a reusable module/layer of exceptions.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Use types of exceptions clearly. Fatal: System crash states. Error: Lack of requirement. Warn: Not an error but error probability. Info: Info for user. Debug: Info for developer. </span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Don't absorb exceptions with no logging and operation. Ignoring exceptions will save that moment but will create a chaos for maintainability later.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Don't log the same exception more than once. This will provide clearness of the exception location.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Always clean up resources (opened files etc.) and perform this in "finally" blocks.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Exception handling inside a loop is not recommended for most cases. Surround the loop with exception block instead.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Granularity is very important. One try block must exist for one basic operation. So don't put hundreds of lines in a try-catch statement.</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Produce enough documentation for your exception definitions (at least JavaDoc).</span></li>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Giving a number/code for each different exception message is a good practice for documentation and faster communication.</span></li>
</ol>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com38tag:blogger.com,1999:blog-7988792589954261688.post-28171521858089667472012-01-10T17:47:00.000+02:002012-02-24T22:35:36.936+02:00Java Dynamic Web Project to Maven 3 Project - Migration Steps<script type="text/javascript">
var dzone_url = 'http://codebalance.blogspot.com/2012/01/java-dynamic-web-project-to-maven-3.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">If you start a java project in eclipse as "maven project" at the beginning, all you need is downloading maven distribution or maven plug-in and add dependencies to the pom.xml file when required. But some issues exist while migrating from java dynamic web project to maven project. In this post, required configuration steps will be told. Maven introduction, installation, "repository" concept and maven commands are out of scope for this post.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span><br />
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Source codes for a maven project must be located in src/main/java folder. Also test and resources must be located in src/test/java and src/main/resources folders respectively. For this conversion, you can create required folders manually and copy old source codes in it, but more preferred and stable way is defining source paths in Project Properties --> Java Build Path section:</span></li>
</ul>
</div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjcDGSo6H1c2UZg-IH6pibR4H9rTg8IGeAuTwsq2WFlPlxfqIE_zVzlI89ISsBWYh5y755Zp4Ex2ABpyHqNzeLhctjnZQ5HiTzYgz_zCG9f9wp50IwnyZ5FxwMwesrUh11jOVQAAG9YNap/s1600/maven_1.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjcDGSo6H1c2UZg-IH6pibR4H9rTg8IGeAuTwsq2WFlPlxfqIE_zVzlI89ISsBWYh5y755Zp4Ex2ABpyHqNzeLhctjnZQ5HiTzYgz_zCG9f9wp50IwnyZ5FxwMwesrUh11jOVQAAG9YNap/s1600/maven_1.PNG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Source folder configuration</span></td></tr>
</tbody></table>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;"><project_name>/WEB_INF folder is not used in maven projects. There is "webapp" folder instead. You can move WEB_INF files into webapp folder as the given structure and delete old WEB_INF folder. You don't even need lib folder because maven will create required jars:</project_name></span></li>
</ul>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcnVLYZRPCcGuesBLUBWOieCF_uQX-Op3TTOcL4fgjWXsn-EOU2D_sK5FSwvk0_YIkyarFvgU2YJctSowB1wUfmeYgN4XnmVthgTV1EfNFaLP0ohn5K8W64hk77F7BhAl1_AH2EpTYd2eR/s1600/maven_2.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcnVLYZRPCcGuesBLUBWOieCF_uQX-Op3TTOcL4fgjWXsn-EOU2D_sK5FSwvk0_YIkyarFvgU2YJctSowB1wUfmeYgN4XnmVthgTV1EfNFaLP0ohn5K8W64hk77F7BhAl1_AH2EpTYd2eR/s1600/maven_2.PNG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">webapp folder</span></td></tr>
</tbody></table>
<span style="font-family: 'Trebuchet MS', sans-serif;"></span><br />
<ul><span style="font-family: 'Trebuchet MS', sans-serif;">
<li style="text-align: justify;">target/classes folder must be the output (deploy) path instead of build/classes. Again in Project Properties --> Java Build Path section:</li>
</span></ul>
<span style="font-family: 'Trebuchet MS', sans-serif;"></span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIylymOwoYQOxoXcRu4bR0i3FR7p6A_q9RrwNwFxCY5xV_9ZblkcekaJPrstUi1_0uRSvBwxjkw_1imOzPRvFTpu3Oblgbk9bkQ647V1sgRyHARaV9jwpInLuco5aYPRrMy0WiD5Tge5xz/s1600/maven_3.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIylymOwoYQOxoXcRu4bR0i3FR7p6A_q9RrwNwFxCY5xV_9ZblkcekaJPrstUi1_0uRSvBwxjkw_1imOzPRvFTpu3Oblgbk9bkQ647V1sgRyHARaV9jwpInLuco5aYPRrMy0WiD5Tge5xz/s1600/maven_3.PNG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Output folder</span></td></tr>
</tbody></table>
<span style="font-family: 'Trebuchet MS', sans-serif;"></span><br />
<ul><span style="font-family: 'Trebuchet MS', sans-serif;">
<li style="text-align: justify;">org.eclipse.wst.common.component file needs some changes. Open it using ctrl+shift+R and edit deploy path and output path as below:</li>
</span></ul>
<span style="font-family: 'Trebuchet MS', sans-serif;"></span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihXzsC-QW_pkOPlDRBLOTXGWyLhAVVOS_EdacYQGOA1f2k_RLa2Pn2zd_cbOeZEctWPF2ATD_S2JBvE4fwFSnyehj6y4P1dU2MtnBq2dkYVZM2_vdL1nT8Tz_Cn3kXjcYFTKrS7GdS6HDz/s1600/maven_4.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihXzsC-QW_pkOPlDRBLOTXGWyLhAVVOS_EdacYQGOA1f2k_RLa2Pn2zd_cbOeZEctWPF2ATD_S2JBvE4fwFSnyehj6y4P1dU2MtnBq2dkYVZM2_vdL1nT8Tz_Cn3kXjcYFTKrS7GdS6HDz/s1600/maven_4.PNG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small; text-align: justify;">org.eclipse.wst.common.component file</span></td></tr>
</tbody></table>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<ul>
<li style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;">Create pom.xml file on project root folder and configure required sections with your project details. Then add required dependencies one-by-one between <dependency> tags (This will be the most time consuming issue if there are tens or hundreds of JARs). If maven global repository has required jar, it will be downloaded automatically, otherwise you must find required jar and run "mvn install" command to install that jar to maven repository:</dependency></span></li>
</ul>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgClxzJAy1oPHy3_oTOJS41H1QN93v96HHxFaePxA4tv4Wi3I5RFey8EWqPRbZJMX6LVQu1LDwBL6GSdWEWm6TFB_OWwLLV66LJFUPqb_0-mebW_1ERe8_PDq3x1rfWdaR3OmCLzQAu_AXL/s1600/maven_5.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgClxzJAy1oPHy3_oTOJS41H1QN93v96HHxFaePxA4tv4Wi3I5RFey8EWqPRbZJMX6LVQu1LDwBL6GSdWEWm6TFB_OWwLLV66LJFUPqb_0-mebW_1ERe8_PDq3x1rfWdaR3OmCLzQAu_AXL/s1600/maven_5.PNG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">pom.xml file</span></td></tr>
</tbody></table>
<span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;"></span><br />
<ul><span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">
<li>Run mvn-install or mvn-package commands for the project. Created JARS, web.xml, other resources and class files will be located under /target folder automatically. Also a WAR file for the project will be created. You can copy WAR file to server (e.g. apache tomcat) and run the application, or you can run the application using the server defined in eclipse. </li>
</span></ul>
<span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">
</span><span style="font-family: 'Trebuchet MS', sans-serif;"></span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzpW_XpG3drFgyOz0vaSthZi5PR_tDp73ZZoZm2VppdKevif7Pzdyg9YPLJyEOyweZxtSNZ_Sqvi0e6S9Tcsa-obCZNlKpsgjV7HTv3Ko0cKhgJqz1IWTjZ2XyLgDq5953_GogNLn9esEu/s1600/maven_7.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzpW_XpG3drFgyOz0vaSthZi5PR_tDp73ZZoZm2VppdKevif7Pzdyg9YPLJyEOyweZxtSNZ_Sqvi0e6S9Tcsa-obCZNlKpsgjV7HTv3Ko0cKhgJqz1IWTjZ2XyLgDq5953_GogNLn9esEu/s1600/maven_7.PNG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">target directory</td></tr>
</tbody></table>
<span style="font-family: 'Trebuchet MS', sans-serif;">
</span><br />
<div style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">
<ul>
<li>Depending on the running style of mvn-install command (by plug-in, command etc.) , created JARs under the /target folder may not be copied to src/main/webapp/WEB-INF folder. If you will run the application using the server of the ide, you may be needed to copy created libs into src/main/webapp/WEB-INF/lib folder and add those libs to project using Project Properties --> Java Build Path --> Libraries --> Add JARs section for once.</li>
</ul>
</div>
<ol></ol>
</div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKz0ZgeKQ5OOpKLzKnFg8wExYiCdheMQ5S89aY_OYuHmoyjMdeLvV92XacZMgSuZarNC48Z8uI265IE2pyljiOhj6pUznEA0FD34XmcK8DxLexsMX_mgKXV_193XGrjM3U-6chmzD9pVov/s1600/maven_6.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKz0ZgeKQ5OOpKLzKnFg8wExYiCdheMQ5S89aY_OYuHmoyjMdeLvV92XacZMgSuZarNC48Z8uI265IE2pyljiOhj6pUznEA0FD34XmcK8DxLexsMX_mgKXV_193XGrjM3U-6chmzD9pVov/s1600/maven_6.PNG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif;">Adding required jars under webapp/WEB-INF/lib</span></td></tr>
</tbody></table>
<br /></div>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com0tag:blogger.com,1999:blog-7988792589954261688.post-87617470190268809962011-12-29T17:26:00.000+02:002012-01-12T14:24:10.440+02:00A Look Into Java Annotations & A Real World Spring Example<script type="text/javascript">var dzone_url = 'http://codebalance.blogspot.com/2011/12/look-into-java-annotations-real-world.html';</script><br /><script type="text/javascript">var dzone_style = '2';</script><br /><script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> <br /><br /><div class="MsoNormal" style="text-align: justify;"><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">An "annotation" is a type of programminglanguage definition and used as a “marker”. They can be thought as commentlines which programming language engine can understand. They don’t directlyaffect program execution but affect indirecly if wanted. </span><o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><b><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">Definition</span><o:p></o:p></span></b></div><div class="MsoNormal" style="text-align: justify;"><b><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><br /></span></b></div><div class="MsoNormal" style="text-align: justify;"><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">An annotation is defined with <b>@interface</b> keyword and is similar withan interface. It has attributes which are defined like interface methods.Attributes can have default values. Let’s define an annotation named “Page”,which defines UI pages of an application:</span><o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><br /></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">public @interface</span></b> Page {<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">int </span></b>id();<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">String </span></b>url();<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">String </span></b>icon()<b><span style="color: #0b5394;">default </span></b>"[none]"; <o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">String </span></b>name();<b><span style="color: #0b5394;">default </span></b>"[none]"; <o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;">}</span><span style="font-family: 'Courier New';"><o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="text-align: justify;"><b><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">Usage<o:p></o:p></span></span></b></div><div class="MsoNormal" style="text-align: justify;"><b><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></span></b></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;"><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;">Annotations are widely used to informcompiler or compile-time/runtime/deployment-time processing.</span><span style="font-size: 10pt; line-height: 115%;"><o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">Usage ofan annotation is simpler:</span><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">@Page</span></b>(id=1, url=”studentView”, icon=“icons/student.png”,name=”Students”)<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">public class</span></b> StudentWindow <b><span style="color: #0b5394;">extends </span></b>Window { … }</span><span style="font-family: 'Courier New';"><o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">Annotationscan also be defined for methods and attributes:</span><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">@AnAnnotation</span></b><o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">public String</span> </b>getElementName() {…}<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">@AnAnnotation</span></b>(type=”manager”, score=3)<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">public int</span></b> income;</span><span style="font-family: 'Courier New';"><o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: 'Trebuchet MS', sans-serif;"><b><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;">Examples</span></b></span></div><div class="MsoNormal" style="text-align: justify;"><span style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; text-indent: -18pt;"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; text-indent: -18pt;"><b>1)</b><span style="font: 7.0pt "Times New Roman";"><b> </b> </span></span><span style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; text-indent: -18pt;">Reflection/code generation:</span></div><br /><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">Methods havinga specific annotation can be processed at runtime:</span><o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">public @interface</span> </b>MyAnnotation { ... }</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">public class</span> </b>TestClass {</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">@MyAnnotation</span></b></span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">public static</span> </b>method1() { ... }</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> </span></span><b style="background-color: white; font-family: 'Courier New', Courier, monospace; font-size: 13px;"><span style="color: #0b5394;">@MyAnnotation</span></b></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">public static</span> </b>method2() { ... }</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> </span></span><b style="background-color: white; font-family: 'Courier New', Courier, monospace; font-size: 13px;"><span style="color: #0b5394;">@MyAnnotation</span></b></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">public static</span> </b>method3() { ... }</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;">}</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><br /></span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">public static void</span></b> main(<b><span style="color: #0b5394;">String</span></b>[] args) {</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">for </span></b>(Method method : Class.forName("TestClass").getMethods()) {</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">if </span></b>(method.isAnnotationPresent(MyAnnotation.<b><span style="color: #0b5394;">class</span></b>)) {</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> // do what you want</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> }</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> }</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;">}</span></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="background-color: white; font-size: 10pt; text-indent: -18pt;"><br /></span></div><div class="MsoListParagraphCxSpMiddle" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="background-color: white; font-size: 10pt; text-indent: -18pt;"><b>2</b><span style="font-family: 'Trebuchet MS', sans-serif;"><b>)</b><span style="font: 7.0pt "Times New Roman";"> </span></span></span><span style="background-color: white; font-size: 10pt; text-indent: -18pt;"><span style="font-family: 'Trebuchet MS', sans-serif;">Spring bean configuration (this section requires Spring bean configurationknowledge):</span></span></div><br /><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">Let’s useour “Page” annotation again:</span><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">package </span></b><span style="background-color: transparent;">com.cmp.annotation;</span></span></div><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"></span><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">public @interface</span></b> Page {<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">int </span></b>id();<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">String </span></b>url();<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">String </span></b>icon() <b><span style="color: #0b5394;">default </span></b>"[none]";<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"> <b><span style="color: #0b5394;">String </span></b>name(); <b><span style="color: #0b5394;">default </span></b>"[none]";<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;">}</span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><br /></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">Say thatwe have a few classes having @Page annotation in a package:</span><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">@Page</span></b>(id=1, url=”studentView”, icon=“icons/student.png”, name=”Students”)<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><b><span style="color: #0b5394;">public class</span></b> StudentWindow <b><span style="color: #0b5394;">extends </span></b>Window { … }</span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><span style="font-family: 'Courier New', Courier, monospace;"><br /></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">If wedefine a bean configuration as below in a Spring application-context.xml file, Springwill create class instances “which has @Page annotation” placed in “givenpackage”.</span><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="background-color: white; font-family: 'Courier New', Courier, monospace;"><span style="color: teal; font-size: 10pt;"><</span><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #3f7f7f; font-size: 10pt;">context:component-scan</span><span style="font-size: 10pt;"> <span style="color: #7f007f;">base-package</span>=<i><span style="color: #2a00ff;">"com.cmp.ui"</span></i> <span style="color: #7f007f;">annotation-config</span>=<i><span style="color: #2a00ff;">"true"</span></i><span style="color: teal;">></span> <o:p></o:p></span></span></div><div class="MsoNormal" style="margin-bottom: 0.0001pt;"><span style="background-color: white; font-family: 'Courier New', Courier, monospace;"><span style="color: teal; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-size: 10pt;">context:include-filter</span><span style="font-size: 10pt;"> <span style="color: #7f007f;">type</span>=<i><span style="color: #2a00ff;">"annotation"</span> </i><span style="color: #7f007f;">expression</span>=<i><span style="color: #2a00ff;">"com.cmp.annotation.Page"</span></i><span style="color: teal;">/></span><o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; margin-bottom: 0.0001pt;"><span style="background-color: white; font-family: 'Courier New', Courier, monospace;"><span style="color: teal; font-size: 10pt;"><!--</span--><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; color: #3f7f7f; font-size: 10pt;">context:component-scan</span><span style="color: teal; font-size: 10pt;">></span></span></span><span style="background-color: white; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10.0pt; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">So, we havebeen enforced Spring to instantiate only a selection of classes at runtime.<o:p></o:p></span></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-size: 10pt;"><o:p><span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></o:p></span></div><div class="MsoNormal"><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;">For more detailed info about annotations, please refer to:<o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><span style="font-family: 'Trebuchet MS', sans-serif;"><a href="http://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html</span></a><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-size: 10.0pt; line-height: 115%; mso-ansi-language: TR;"><a href="http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html"><span style="color: windowtext; text-decoration: none; text-underline: none;"><span style="font-family: 'Trebuchet MS', sans-serif;">http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html</span></span></a><o:p></o:p></span></div>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com0tag:blogger.com,1999:blog-7988792589954261688.post-8907925442174950072011-12-29T12:00:00.000+02:002012-01-12T17:26:24.480+02:00A Selection of Successful Software Engineering Posts (2011)<script type="text/javascript">
var dzone_url = 'http://codebalance.blogspot.com/2011/12/selection-of-successful-software.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="font-family: 'Trebuchet MS', sans-serif;">
<div style="text-align: justify;">
<span style="font-size: small;">This </span><span style="font-size: small;">selection contains 25 blog posts selected by </span><span style="font-size: small;">C</span><span style="font-size: small;">odeBuild which were placed on DZone in 2011.</span></div>
<div style="text-align: justify;">
<br /></div>
</div>
<div style="font-family: 'Trebuchet MS', sans-serif;">
<b>Java</b><br />
<a href="http://www.dzone.com/links/r/producer_and_consumer_pattern_in_java.html">Producer and Consumer Pattern in Java</a><br />
<a href="http://www.dzone.com/links/r/quick_tips_for_improving_java_apps_performance.html">Quick Tip for Improving Java Apps Performance</a><br />
<a href="http://www.dzone.com/links/r/junit_tutorial_2.html">JUnit Tutorial 2</a><br />
<a href="http://www.dzone.com/links/r/clientside_improvements_in_java_6_and_java_7.html">Clientside Improvements in Java 6 & 7</a><br />
<a href="http://www.dzone.com/links/r/java_productivity_report_2011_india_vs_rest_of_wo.html">Java Productivity Report 2011 (India vs Rest of the World)</a><br />
<a href="http://www.dzone.com/links/r/be_a_better_java_programmer_a_reading_list.html">Be a Better Java Programmer - A Reading List</a><br />
<a href="http://www.dzone.com/links/r/method_size_limits_in_java.html">Method Size Limits in Java</a><br />
<a href="http://www.dzone.com/links/r/why_i_choose_java_2.html">Why I Choose Java?</a><br />
<a href="http://www.dzone.com/links/r/best_practices_list_in_java.html">Best Practices List in Java</a><br />
<a href="http://www.dzone.com/links/r/lessons_in_software_reliability_java_code_geeks.html">Lessons in Software Reliability</a><br />
<a href="http://www.dzone.com/links/r/music_components_in_java_effects.html">Music Components in Java Effects</a><br />
<a href="http://www.dzone.com/links/r/presentation_world_wide_wait_a_performance_compar.html">WWW: World Wide Wait - A Performance Comparison</a><br />
<br />
<b>Software Engineering & Practices</b><br />
<a href="http://www.dzone.com/links/r/the_principles_of_good_programming.html">The Principles of Good Programming</a><br />
<a href="http://www.dzone.com/links/r/a_detailed_study_on_understanding_code.html">A Detailed Study on Understanding Code</a><br />
<a href="http://www.dzone.com/links/r/making_better_software_forget_new_features_just_d.html">Making Better Software - Forget New Features</a><br />
<a href="http://www.dzone.com/links/r/making_code_easy_to_understand_what_developers_wa.html">Making Code Easy to Understand What Developers Want</a><br />
<a href="http://www.dzone.com/links/r/things_to_remember_when_doing_code_review.html">Things to Remember When Doing Code Review</a><br />
<a href="http://www.dzone.com/links/r/the_seven_phases_of_introducing_continuous_integr.html">The Seven Phases of Introducing Continuous Integration</a><br />
<br />
<b>General</b><br />
<a href="http://www.dzone.com/links/r/the_most_important_man_in_tech_died_last_weekit_w.html">The Most Important Man in Tech Dies Last Week…It wasn't Steve Jobs.</a><br />
<a href="http://www.dzone.com/links/r/the_top_10_attributes_of_a_great_programmer_2.html">The Top 10 Attributes of a Great Programmer</a><br />
<a href="http://www.dzone.com/links/r/build_facebook_bot_in_2_easy_hours.html">Build Facebook Bot in 2 Easy Hours</a><br />
<a href="http://www.dzone.com/links/r/30_free_programming_ebooks.html">30 Free Programming E-Books</a><br />
<a href="http://www.dzone.com/links/r/signs_that_youre_a_bad_programmer.html">Signs That You're a Bad Programmer</a><br />
<a href="http://www.dzone.com/links/r/a_complete_list_of_all_major_algorithms_300_in_an.html">A Complete List of All Major Algorithms (300)</a><br />
<a href="http://www.dzone.com/links/r/100_android_articlestutorials.html">10 Android Articles/Tutorials</a><br />
<br />
<br />
<div>
<span style="font-size: small;">You can also review Part 1 (2010) here:</span><br />
<a href="http://codebuild.blogspot.com/2011/01/selection-of-successful-software.html">http://codebuild.blogspot.com/2011/01/selection-of-successful-software.html</a></div>
<div>
<br class="Apple-interchange-newline" /></div>
<br />
<br />
<br /></div>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com2tag:blogger.com,1999:blog-7988792589954261688.post-58372450944202906122011-12-28T17:26:00.000+02:002012-03-06T09:51:40.952+02:00Improve Software Quality with Tools and Processes<script type="text/javascript">
var dzone_url = 'http://codebalance.blogspot.com/2011/12/improve-software-quality-with-tools-and.html';
</script><br />
<script type="text/javascript">
var dzone_style = '2';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js">
</script> <br />
<br />
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">As most of the software developers know, software engineering is not just "coding". It's a complex process which requires engineering vision, analytical thinking, designing and software process management supported with tools. This article contains some important approaches, techniques and tools to improve software production quality.</span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">Software quality depends on time and cost of course.</span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"> But you can be sure that spent money and time will return as so much more. Quality standards will also be used for upcoming projects and increase company growth speed on midterm.</span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-family: 'Times New Roman';"></span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-family: 'Times New Roman';"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixCFGu__-Ep6lod0pO7ZgPqY_nwjPSVssND6ksUjURv1OgI9mdwX9P8BH636xxSDkqlJM4VaOu1KdL4XZvkUDoKHLcoh9oiTBglT04m_8sChFXZeX-yIlB-Zhbg0yn7SXB2Ek2mtI8d1aT/s1600/projecttriangle.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixCFGu__-Ep6lod0pO7ZgPqY_nwjPSVssND6ksUjURv1OgI9mdwX9P8BH636xxSDkqlJM4VaOu1KdL4XZvkUDoKHLcoh9oiTBglT04m_8sChFXZeX-yIlB-Zhbg0yn7SXB2Ek2mtI8d1aT/s1600/projecttriangle.png" /></a></span></span></div>
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-family: 'Times New Roman';"></span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-family: 'Times New Roman';"><br /></span></span></div>
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-family: 'Times New Roman';"></span></span><br />
<ul>
<li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><b>Choose a suitable process model and apply it correctly</b></span></li>
</ul>
<div>
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">As you know there are software process models like <a href="http://en.wikipedia.org/wiki/Agile_software_development">agile</a>, <a href="http://en.wikipedia.org/wiki/Scrum_(development)">scrum</a>, <a href="http://en.wikipedia.org/wiki/Iterative_and_incremental_development">iterative and incremental</a> etc. Choose one of these according to the project type. You don't have to perform all rules strictly, you can modify most of them. The point is "using a process" here, for a systematic and ordered development.</span></div>
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-family: 'Times New Roman';"></span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-family: 'Times New Roman';"><br /></span></span></div>
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-family: 'Times New Roman';"></span></span></div>
<ul>
<li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><b>Control the version of each required source</b></span></li>
</ul>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">Using a version controlling system is a must. Even if only one developer exist, it must be used. Historical data, versioning, merging, ... is very important for increasing productivity. Otherwise developers will wait each other, can not detect performers and lines of previous changes, can not perform versioning systematically etc. <a href="http://subversion.tigris.org/">SVN</a>, <a href="http://cvs.nongnu.org/">CVS</a> and <a href="http://www.microsoft.com/visualstudio/en-us/products/2010-editions/team-foundation-server/overview">TFS </a>are used for this purpose.</span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<ul>
<li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><b>Track issues with easy-to-use tools</b></span></li>
</ul>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">Parallel with using a process model, issue tracking tool usage is essential. <a href="https://jira.atlassian.com/secure/Dashboard.jspa">JIRA</a>-like tools are useful and easy-to-use. By tracking issues, you can track productivity and software growth and get production reports easily. Besides, those tools can be used to monitor developer work-hour productivity.</span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<ul>
<li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><b>Perform and manage documentation</b></span></li>
</ul>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">Perform documentation as required (e.g. %10 of total production time). No documentation is never a good solution as much as excessive documentation. It may include code documentation, requirement specifications, design documents, test documents, user manuals etc. Those documents are needed to be managed and shared also, by using version controlling tools or web based platforms (like <a href="http://confluence.atlassian.com/dashboard.action">Confluence</a>). </span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<ul>
<li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><b>Use dependency management tools</b></span></li>
</ul>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">Managing dependency libraries (library projects, jars, DLLs etc.) are a big problem especially for big projects. Configuring libraries to run the application after each release or after each project check-out is a hell. Use a dependency managing tool like <a href="http://maven.apache.org/">Maven</a> or at least auto build/copy script tools like <a href="http://ant.apache.org/">Ant</a>.</span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<ul>
<li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><b>Use continuous integration</b></span></li>
</ul>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">Building, deploying and versioning software is a big problem. Its time consuming and reduces productivity. Because of these, use a continuous integration tool (<a href="http://hudson-ci.org/">Hudson</a> for example) and integrate it with dependency management or build tools (like <a href="http://maven.apache.org/">Maven</a>, <a href="http://ant.apache.org/">Ant</a>, ..). The tool may be configured to perform a build on each commit, on clicking a button manually or on predefined periodic times...</span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<ul>
<li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><b>Perform testing and integration testing constantly</b></span></li>
</ul>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">Testing is very important for software quality. Test documentation which may consist test scenarios, results and relations with issues is required. Also, testing (UI testing, integration testing, ...) must be performed constantly and periodically. Even if changing a single line of code may crush the whole system or crash a hidden functionality. for example, <a href="http://www.junit.org/">JUnit</a> is very popular for Java applications.</span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<ul>
<li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><b>Perform unit testing and automatize it</b></span></li>
</ul>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">Unit testing is as important as the other testing methods. Unit tests provide pre-detection of most of the problems. By performing qualitative unit testing, time consumption for other testing methods also descreases. Automatizing these tests using continuous integration tools or at least command line tools (<a href="http://hudson-ci.org/">Hudson</a> with <a href="http://maven.apache.org/">Maven</a> for example) are important to keep software consistency and reliability.</span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<ul>
<li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><b>Collect metrics from production and use results</b></span></li>
</ul>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">Coding metrics (e.g. line of code, abstraction ratio, cyclomatic complexity, ...) gives us some good viewpoints about software. For example, by using line of code maybe we can't (or we mustn't) determine the productivity of a developer; but we can determine the growth speed of software monthly. Complexity-like metrics tells us design errors before deployment. These metrics can be collected by tools or plug-ins (e.g. <a href="http://code.google.com/javadevtools/download-codepro.html">CodePro</a> Eclipse plug-in). </span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<ul>
<li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><b>Follow best practices of coding and control with tools</b></span></li>
</ul>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">There is no "golden rule" suitable with all software projects, but there are best practices for p</span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">roject management, architecture, designing, coding, testing for most</span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"> situations. Performing those rules will increase the quality. For example, you can define rules for code production (about indentation, commenting, magic numbering, paranthesis etc.) and monitor convenience automatically and periodically with external tools or plug-ins like <a href="http://maven.apache.org/plugins/maven-surefire-report-plugin/">Maven Surefire Report</a> plug-in.</span></div>
<div style="text-align: justify;">
<br class="Apple-interchange-newline" /></div>CBhttp://www.blogger.com/profile/13504212299235753253noreply@blogger.com3