<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Meherchilakalapudi,  writes for u....</title>
	<atom:link href="http://meherchilakalapudi.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://meherchilakalapudi.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Tue, 31 Jan 2012 02:21:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='meherchilakalapudi.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Meherchilakalapudi,  writes for u....</title>
		<link>http://meherchilakalapudi.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://meherchilakalapudi.wordpress.com/osd.xml" title="Meherchilakalapudi,  writes for u...." />
	<atom:link rel='hub' href='http://meherchilakalapudi.wordpress.com/?pushpress=hub'/>
		<item>
		<title>DBMS &#8211; COMMANDS(Notes)</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/12/31/dbms-commandsnotes/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/12/31/dbms-commandsnotes/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 10:38:56 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[DBMS - COMMANDS(Notes)]]></category>
		<category><![CDATA[database management system]]></category>
		<category><![CDATA[query language sql]]></category>
		<category><![CDATA[relational database management]]></category>
		<category><![CDATA[relational database management system]]></category>
		<category><![CDATA[structured query language]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1438</guid>
		<description><![CDATA[Introduction to SQL  &#8230;meher SQL is a standard language for accessing and manipulating databases. What is SQL? SQL stands for Structured Query Language SQL lets you access and manipulate databases SQL is an ANSI (American National Standards Institute) standard What Can SQL do? SQL can execute queries against a database SQL can retrieve data from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1438&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1 align="center">Introduction to SQL</h1>
<h1 style="text-align:right;" align="center"><span style="color:#0000ff;"> &#8230;meher</span></h1>
<p>SQL is a standard language for accessing and manipulating databases.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>What is SQL?</h2>
<ul>
<li>SQL stands for Structured Query Language</li>
<li>SQL lets you access and manipulate databases</li>
<li>SQL is an ANSI (American National Standards Institute) standard</li>
</ul>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>What Can SQL do?</h2>
<ul>
<li>SQL can execute queries against a database</li>
<li>SQL can retrieve data from a database</li>
<li>SQL can insert records in a database</li>
<li>SQL can update records in a database</li>
<li>SQL can delete records from a database</li>
<li>SQL can create new databases</li>
<li>SQL can create new tables in a database</li>
<li>SQL can create stored procedures in a database</li>
<li>SQL can create views in a database</li>
<li>SQL can set permissions on tables, procedures, and views</li>
</ul>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL is a Standard &#8211; BUT&#8230;.</h2>
<p>Although SQL is an ANSI (American National Standards Institute) standard, there are many different versions of the SQL language.</p>
<p>However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.</p>
<p><strong>Note:</strong> Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Using SQL in Your Web Site</h2>
<p>To build a web site that shows some data from a database, you will need the following:</p>
<ul>
<li>An RDBMS database program (i.e. MS Access, SQL Server, MySQL)</li>
<li>A server-side scripting language, like PHP or ASP</li>
<li>SQL</li>
<li>HTML / CSS</li>
</ul>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>RDBMS</h2>
<p>RDBMS stands for Relational Database Management System.</p>
<p>RDBMS is the basis for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.</p>
<p>The data in RDBMS is stored in database objects called tables.</p>
<p>A table is a collections of related data entries and it consists of columns and rows.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h1 align="center"> </h1>
<h1 align="center">SQL Syntax</h1>
<h1 align="center"> </h1>
<h2>Database Tables</h2>
<p>A database most often contains one or more tables. Each table is identified by a name (e.g. &#8220;Customers&#8221; or &#8220;Orders&#8221;). Tables contain records (rows) with data.</p>
<p>Below is an example of a table called &#8220;Persons&#8221;:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The table above contains three records (one for each person) and five columns (P_Id, LastName, FirstName, Address, and City).</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Statements</h2>
<p>Most of the actions you need to perform on a database are done with SQL statements.</p>
<p>The following SQL statement will select all the records in the &#8220;Persons&#8221; table:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons</td>
</tr>
</tbody>
</table>
<p>In this tutorial we will teach you all about the different SQL statements.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Keep in Mind That&#8230;</h2>
<ul>
<li>SQL is not case sensitive</li>
</ul>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Semicolon after SQL Statements?</h2>
<p>Some database systems require a semicolon at the end of each SQL statement.</p>
<p>Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.</p>
<p>We are using MS Access and SQL Server 2000 and we do not have to put a semicolon after each SQL statement, but some database programs force you to use it.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL DML and DDL</h2>
<p>SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data Definition Language (DDL).</p>
<p>The query and update commands form the DML part of SQL:</p>
<ul>
<li><strong>SELECT</strong> &#8211; extracts data from a database</li>
<li><strong>UPDATE</strong> &#8211; updates data in a database</li>
<li><strong>DELETE</strong> &#8211; deletes data from a database</li>
<li><strong>INSERT INTO</strong> &#8211; inserts new data into a database</li>
</ul>
<p>The DDL part of SQL permits database tables to be created or deleted. It also define indexes (keys), specify links between tables, and impose constraints between tables. The most important DDL statements in SQL are:</p>
<ul>
<li><strong>CREATE DATABASE</strong> &#8211; creates a new database</li>
<li><strong>ALTER DATABASE</strong> &#8211; modifies a database</li>
<li><strong>CREATE TABLE</strong> &#8211; creates a new table</li>
<li><strong>ALTER TABLE</strong> &#8211; modifies a table</li>
<li><strong>DROP TABLE</strong> &#8211; deletes a table</li>
<li><strong>CREATE INDEX</strong> &#8211; creates an index (search key)</li>
<li><strong>DROP INDEX</strong> &#8211; deletes an index</li>
</ul>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center">SQL SELECT Statement</h1>
<h1 align="center"> </h1>
<p>This chapter will explain the SELECT and the SELECT * statements.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The SQL SELECT Statement</h2>
<p>The SELECT statement is used to select data from a database.</p>
<p>The result is stored in a result table, called the result-set.</p>
<h3>SQL SELECT Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name</td>
</tr>
</tbody>
</table>
<p>and</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM table_name</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> SQL is not case sensitive. SELECT is the same as select.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>An SQL SELECT Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the content of the columns named &#8220;LastName&#8221; and &#8220;FirstName&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LastName,FirstName FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
</tr>
<tr>
<td>Svendson</td>
<td>Tove</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SELECT * Example</h2>
<p>Now we want to select all the columns from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement: </p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons</td>
</tr>
</tbody>
</table>
<p><strong>Tip:</strong> The asterisk (*) is a quick way of selecting all columns!</p>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Navigation in a Result-set</h2>
<p>Most database software systems allow navigation in the result-set with programming functions, like: Move-To-First-Record, Get-Record-Content, Move-To-Next-Record, etc.</p>
<p>Programming functions like these are not a part of this tutorial. To learn about accessing data with function calls, please visit our <a href="http://www.w3schools.com/ado/default.asp">ADO tutorial</a> or our <a href="http://www.w3schools.com/php/default.asp">PHP tutorial</a>.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h1 align="center">SQL SELECT DISTINCT Statement</h1>
<h1> </h1>
<p>This chapter will explain the SELECT DISTINCT statement.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The SQL SELECT DISTINCT Statement</h2>
<p>In a table, some of the columns may contain duplicate values. This is not a problem, however, sometimes you will want to list only the different (distinct) values in a table.</p>
<p>The DISTINCT keyword can be used to return only distinct (different) values.</p>
<h3>SQL SELECT DISTINCT Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT DISTINCT column_name(s)<br />
FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SELECT DISTINCT Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select only the distinct values from the column named &#8220;City&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT DISTINCT City FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>City</strong></td>
</tr>
<tr>
<td>Sandnes</td>
</tr>
<tr>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1 align="center"> </h1>
<h1 align="center">SQL WHERE Clause</h1>
<h1> </h1>
<p>The WHERE clause is used to filter records.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The WHERE Clause </h2>
<p>The WHERE clause is used to extract only those records that fulfill a specified criterion.</p>
<h3>SQL WHERE Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name operator value</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>WHERE Clause Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select only the persons living in the city &#8220;Sandnes&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERECity=&#8217;Sandnes&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Quotes Around Text Fields</h2>
<p>SQL uses single quotes around text values (most database systems will also accept double quotes).</p>
<p>Although, numeric values should not be enclosed in quotes.</p>
<p>For text values:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>This is correct:</p>
<p>SELECT * FROM Persons WHERE FirstName=&#8217;Tove&#8217;</p>
<p>This is wrong:</p>
<p>SELECT * FROM Persons WHERE FirstName=Tove</td>
</tr>
</tbody>
</table>
<p>For numeric values:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>This is correct:</p>
<p>SELECT * FROM Persons WHERE Year=1965</p>
<p>This is wrong:</p>
<p>SELECT * FROM Persons WHERE Year=&#8217;1965&#8242;</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Operators Allowed in the WHERE Clause</h2>
<p>With the WHERE clause, the following operators can be used:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top">
<p align="center"><strong>Operator</strong></p>
</td>
<td>
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top">=</td>
<td>Equal</td>
</tr>
<tr>
<td valign="top">&lt;&gt; </td>
<td>Not equal</td>
</tr>
<tr>
<td valign="top">&gt; </td>
<td>Greater than</td>
</tr>
<tr>
<td valign="top">&lt; </td>
<td>Less than</td>
</tr>
<tr>
<td valign="top">&gt;=</td>
<td>Greater than or equal</td>
</tr>
<tr>
<td valign="top">&lt;=</td>
<td>Less than or equal</td>
</tr>
<tr>
<td valign="top">BETWEEN</td>
<td>Between an inclusive range</td>
</tr>
<tr>
<td valign="top">LIKE</td>
<td>Search for a pattern</td>
</tr>
<tr>
<td valign="top">IN</td>
<td>If you know the exact value you want to return for at least one of the columns</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> In some versions of SQL the &lt;&gt; operator may be written as !=</p>
<h1 align="center">SQL AND &amp; OR Operators</h1>
<p>The AND &amp; OR operators are used to filter records based on more than one condition.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The AND &amp; OR Operators</h2>
<p>The AND operator displays a record if both the first condition and the second condition is true.</p>
<p>The OR operator displays a record if either the first condition or the second condition is true.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>AND Operator Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select only the persons with the first name equal to &#8220;Tove&#8221; AND the last name equal to &#8220;Svendson&#8221;:</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE FirstName=&#8217;Tove&#8217;<br />
AND LastName=&#8217;Svendson&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>OR Operator Example</h2>
<p>Now we want to select only the persons with the first name equal to &#8220;Tove&#8221; OR the first name equal to &#8220;Ola&#8221;:</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE FirstName=&#8217;Tove&#8217;<br />
OR FirstName=&#8217;Ola&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Combining AND &amp; OR</h2>
<p>You can also combine AND and OR (use parenthesis to form complex expressions).</p>
<p>Now we want to select only the persons with the last name equal to &#8220;Svendson&#8221; AND the first name equal to &#8220;Tove&#8221; OR to &#8220;Ola&#8221;:</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons WHERE<br />
LastName=&#8217;Svendson&#8217;<br />
AND (FirstName=&#8217;Tove&#8217; OR FirstName=&#8217;Ola&#8217;)</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1 align="center">SQL ORDER BY Keyword</h1>
<p>The ORDER BY keyword is used to sort the result-set.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The ORDER BY Keyword</h2>
<p>The ORDER BY keyword is used to sort the result-set by a specified column.</p>
<p>The ORDER BY keyword sort the records in ascending order by default.</p>
<p>If you want to sort the records in a descending order, you can use the DESC keyword.</p>
<h3>SQL ORDER BY Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
ORDER BY column_name(s) ASC|DESC</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>ORDER BY Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Tom</td>
<td>Vingvn 23</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select all the persons from the table above, however, we want to sort the persons by their last name.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
ORDER BY LastName</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Tom</td>
<td>Vingvn 23</td>
<td>Stavanger</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>ORDER BY DESC Example</h2>
<p>Now we want to select all the persons from the table above, however, we want to sort the persons descending by their last name.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
ORDER BY LastName DESC</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Tom</td>
<td>Vingvn 23</td>
<td>Stavanger</td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<h1 align="center"> </h1>
<h1 align="center">SQL INSERT INTO Statement</h1>
<p>The INSERT INTO statement is used to insert new records in a table.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The INSERT INTO Statement</h2>
<p>The INSERT INTO statement is used to insert a new row in a table.</p>
<h3>SQL INSERT INTO Syntax</h3>
<p>It is possible to write the INSERT INTO statement in two forms.</p>
<p>The first form doesn&#8217;t specify the column names where the data will be inserted, only their values:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>INSERT INTO table_name<br />
VALUES (value1, value2, value3,&#8230;)</td>
</tr>
</tbody>
</table>
<p>The second form specifies both the column names and the values to be inserted:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>INSERT INTO table_name (column1, column2, column3,&#8230;)<br />
VALUES (value1, value2, value3,&#8230;)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL INSERT INTO Example</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to insert a new row in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>INSERT INTO Persons<br />
VALUES (4,&#8217;Nilsen&#8217;, &#8216;Johan&#8217;, &#8216;Bakken 2&#8242;, &#8216;Stavanger&#8217;)</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table will now look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken 2</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Insert Data Only in Specified Columns</h2>
<p>It is also possible to only add data in specific columns.</p>
<p>The following SQL statement will add a new row, but only add data in the &#8220;P_Id&#8221;, &#8220;LastName&#8221; and the &#8220;FirstName&#8221; columns:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>INSERT INTO Persons (P_Id, LastName, FirstName)<br />
VALUES (5, &#8216;Tjessem&#8217;, &#8216;Jakob&#8217;)</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table will now look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken 2</td>
<td>Stavanger</td>
</tr>
<tr>
<td>5</td>
<td>Tjessem</td>
<td>Jakob</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1 align="center">SQL UPDATE Statement</h1>
<h1> </h1>
<p>The UPDATE statement is used to update records in a table.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The UPDATE Statement</h2>
<p>The UPDATE statement is used to update existing records in a table.</p>
<h3>SQL UPDATE Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>UPDATE table_name<br />
SET column1=value, column2=value2,&#8230;<br />
WHERE some_column=some_value</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL UPDATE Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken 2</td>
<td>Stavanger</td>
</tr>
<tr>
<td>5</td>
<td>Tjessem</td>
<td>Jakob</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>Now we want to update the person &#8220;Tjessem, Jakob&#8221; in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>UPDATE Persons<br />
SET Address=&#8217;Nissestien 67&#8242;, City=&#8217;Sandnes&#8217;<br />
WHERE LastName=&#8217;Tjessem&#8217; AND FirstName=&#8217;Jakob&#8217;</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table will now look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken 2</td>
<td>Stavanger</td>
</tr>
<tr>
<td>5</td>
<td>Tjessem</td>
<td>Jakob</td>
<td>Nissestien 67</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL UPDATE Warning</h2>
<p>Be careful when updating records. If we had omitted the WHERE clause in the example above, like this:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>UPDATE Persons<br />
SET Address=&#8217;Nissestien 67&#8242;, City=&#8217;Sandnes&#8217;</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table would have looked like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Nissestien 67</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Nissestien 67</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Nissestien 67</td>
<td>Sandnes</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Nissestien 67</td>
<td>Sandnes</td>
</tr>
<tr>
<td>5</td>
<td>Tjessem</td>
<td>Jakob</td>
<td>Nissestien 67</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<h1 align="center"> </h1>
<h1 align="center">SQL DELETE Statement</h1>
<p>The DELETE statement is used to delete records in a table.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The DELETE Statement</h2>
<p>The DELETE statement is used to delete rows in a table.</p>
<h3>SQL DELETE Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>DELETE FROM table_name<br />
WHERE some_column=some_value</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL DELETE Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken 2</td>
<td>Stavanger</td>
</tr>
<tr>
<td>5</td>
<td>Tjessem</td>
<td>Jakob</td>
<td>Nissestien 67</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>Now we want to delete the person &#8220;Tjessem, Jakob&#8221; in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>DELETE FROM Persons<br />
WHERE LastName=&#8217;Tjessem&#8217; AND FirstName=&#8217;Jakob&#8217;</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table will now look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken 2</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Delete All Rows</h2>
<p>It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>DELETE FROM table_name</p>
<p>or</p>
<p>DELETE * FROM table_name</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> Be very careful when deleting records. You cannot undo this statement!</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h1> </h1>
<h1 align="center"> </h1>
<p align="center"> </p>
<p align="center">SQL TOP Clause</p>
<p>&nbsp;</p>
<h2>The TOP Clause</h2>
<p>The TOP clause is used to specify the number of records to return.</p>
<p>The TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance.</p>
<p><strong>Note:</strong> Not all database systems support the TOP clause.</p>
<h3>SQL Server Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT TOP number|percent column_name(s)<br />
FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL SELECT TOP Equivalent in MySQL and Oracle</h2>
<h3>MySQL Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
LIMIT number</td>
</tr>
</tbody>
</table>
<h3>Example</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT *<br />
FROM Persons<br />
LIMIT 5</td>
</tr>
</tbody>
</table>
<h3>Oracle Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
WHERE ROWNUM &lt;= number</td>
</tr>
</tbody>
</table>
<h3>Example</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT *<br />
FROM Persons<br />
WHERE ROWNUM &lt;=5</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL TOP Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Tom</td>
<td>Vingvn 23</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select only the two first records in the table above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT TOP 2 * FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL TOP PERCENT Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Tom</td>
<td>Vingvn 23</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select only 50% of the records in the table above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT TOP 50 PERCENT * FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center">SQL LIKE Operator</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p>The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The LIKE Operator</h2>
<p>The LIKE operator is used to search for a specified pattern in a column.</p>
<h3>SQL LIKE Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name LIKE pattern</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>LIKE Operator Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the persons living in a city that starts with &#8220;s&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERECity LIKE &#8216;s%&#8217;</td>
</tr>
</tbody>
</table>
<p>The &#8220;%&#8221; sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern.</p>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Next, we want to select the persons living in a city that ends with an &#8220;s&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERECity LIKE &#8216;%s&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>Next, we want to select the persons living in a city that contains the pattern &#8220;tav&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERECity LIKE &#8216;%tav%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>It is also possible to select the persons living in a city that NOT contains the pattern &#8220;tav&#8221; from the &#8220;Persons&#8221; table, by using the NOT keyword.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERECity NOT LIKE &#8216;%tav%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center">SQL Wildcards</p>
<p>SQL wildcards can be used when searching for data in a database.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Wildcards </h2>
<p>SQL wildcards can substitute for one or more characters when searching for data in a database.</p>
<p>SQL wildcards must be used with the SQL LIKE operator.</p>
<p>With SQL, the following wildcards can be used:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="15%"><strong>Wildcard</strong></td>
<td valign="top" width="85%"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">%</td>
<td valign="top">A substitute for zero or more characters</td>
</tr>
<tr>
<td valign="top">_</td>
<td valign="top">A substitute for exactly one character</td>
</tr>
<tr>
<td valign="top">[charlist]</td>
<td valign="top">Any single character in charlist</td>
</tr>
<tr>
<td valign="top">[^charlist]</p>
<p>or</p>
<p>[!charlist]</td>
<td valign="top">Any single character not in charlist</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Wildcard Examples</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Using the % Wildcard</h2>
<p>Now we want to select the persons living in a city that starts with &#8220;sa&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERECity LIKE &#8216;sa%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>Next, we want to select the persons living in a city that contains the pattern &#8220;nes&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERECity LIKE &#8216;%nes%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Using the _ Wildcard</h2>
<p>Now we want to select the persons with a first name that starts with any character, followed by &#8220;la&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE FirstName LIKE &#8216;_la&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>Next, we want to select the persons with a last name that starts with &#8220;S&#8221;, followed by any character, followed by &#8220;end&#8221;, followed by any character, followed by &#8220;on&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName LIKE &#8216;S_end_on&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Using the [charlist] Wildcard</h2>
<p>Now we want to select the persons with a last name that starts with &#8220;b&#8221; or &#8220;s&#8221; or &#8220;p&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName LIKE &#8216;[bsp]%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Next, we want to select the persons with a last name that do not start with &#8220;b&#8221; or &#8220;s&#8221; or &#8220;p&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName LIKE &#8216;[!bsp]%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center">SQL IN Operator</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The IN Operator</h2>
<p>The IN operator allows you to specify multiple values in a WHERE clause.</p>
<h3>SQL IN Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name IN (value1,value2,&#8230;)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>IN Operator Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the persons with a last name equal to &#8220;Hansen&#8221; or &#8220;Pettersen&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName IN (&#8216;Hansen&#8217;,'Pettersen&#8217;)</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center">SQL BETWEEN Operator</p>
<p>The BETWEEN operator is used in a WHERE clause to select a range of data between two values.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The BETWEEN Operator</h2>
<p>The BETWEEN operator selects a range of data between two values. The values can be numbers, text, or dates.</p>
<h3>SQL BETWEEN Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name<br />
BETWEEN value1 AND value2</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>BETWEEN Operator Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the persons with a last name alphabetically between &#8220;Hansen&#8221; and &#8220;Pettersen&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName<br />
BETWEEN &#8216;Hansen&#8217; AND &#8216;Pettersen&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> The BETWEEN operator is treated differently in different databases.</p>
<p>In some databases, persons with the LastName of &#8220;Hansen&#8221; or &#8220;Pettersen&#8221; will not be listed, because the BETWEEN operator only selects fields that are between and excluding the test values).</p>
<p>In other databases, persons with the LastName of &#8220;Hansen&#8221; or &#8220;Pettersen&#8221; will be listed, because the BETWEEN operator selects fields that are between and including the test values).</p>
<p>And in other databases, persons with the LastName of &#8220;Hansen&#8221; will be listed, but &#8220;Pettersen&#8221; will not be listed (like the example above), because the BETWEEN operator selects fields between the test values, including the first test value and excluding the last test value.</p>
<p>Therefore: Check how your database treats the BETWEEN operator.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Example 2</h2>
<p>To display the persons outside the range in the previous example, use NOT BETWEEN:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName<br />
NOT BETWEEN &#8216;Hansen&#8217; AND &#8216;Pettersen&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p align="center"> </p>
<p align="center"> </p>
<p align="center">SQL Alias</p>
<p>With SQL, an alias name can be given to a table or to a column.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Alias</h2>
<p>You can give a table or a column another name by using an alias. This can be a good thing to do if you have very long or complex table names or column names.</p>
<p>An alias name could be anything, but usually it is short.</p>
<h3>SQL Alias Syntax for Tables</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
AS alias_name</td>
</tr>
</tbody>
</table>
<h3>SQL Alias Syntax for Columns</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name AS alias_name<br />
FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Alias Example</h2>
<p>Assume we have a table called &#8220;Persons&#8221; and another table called &#8220;Product_Orders&#8221;. We will give the table aliases of &#8220;p&#8221; an &#8220;po&#8221; respectively.</p>
<p>Now we want to list all the orders that &#8220;Ola Hansen&#8221; is responsible for.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT po.OrderID, p.LastName, p.FirstName<br />
FROM Persons AS p,<br />
Product_Orders AS po<br />
WHERE p.LastName=&#8217;Hansen&#8217;<br />
WHERE p.FirstName=&#8217;Ola&#8217;</td>
</tr>
</tbody>
</table>
<p>The same SELECT statement without aliases:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Product_Orders.OrderID, Persons.LastName, Persons.FirstName<br />
FROM Persons,<br />
Product_Orders<br />
WHERE Persons.LastName=&#8217;Hansen&#8217;<br />
WHERE Persons.FirstName=&#8217;Ola&#8217;</td>
</tr>
</tbody>
</table>
<p>As you&#8217;ll see from the two SELECT statements above; aliases can make queries easier to both write and to read.</p>
<h1 align="center">SQL Joins</h1>
<p>SQL joins are used to query data from two or more tables, based on a relationship between certain columns in these tables.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL JOIN</h2>
<p>The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.</p>
<p>Tables in a database are often related to each other with keys.</p>
<p>A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.</p>
<p>Look at the &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Note that the &#8220;P_Id&#8221; column is the primary key in the &#8220;Persons&#8221; table. This means that <strong>no</strong> two rows can have the same P_Id. The P_Id distinguishes two persons even if they have the same name.</p>
<p>Next, we have the &#8220;Orders&#8221; table:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>34764</td>
<td>15</td>
</tr>
</tbody>
</table>
<p>Note that the &#8220;O_Id&#8221; column is the primary key in the &#8220;Orders&#8221; table and that the &#8220;P_Id&#8221; column refers to the persons in the &#8220;Persons&#8221; table without using their names.</p>
<p>Notice that the relationship between the two tables above is the &#8220;P_Id&#8221; column.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Different SQL JOINs</h2>
<p>Before we continue with examples, we will list the types of JOIN you can use, and the differences between them.</p>
<ul>
<li><strong>JOIN</strong>: Return rows when there is at least one match in both tables</li>
<li><strong>LEFT JOIN</strong>: Return all rows from the left table, even if there are no matches in the right table</li>
<li><strong>RIGHT JOIN</strong>: Return all rows from the right table, even if there are no matches in the left table</li>
<li><strong>FULL JOIN</strong>: Return rows when there is a match in one of the tables</li>
</ul>
<p align="center"> </p>
<p align="center">SQL INNER JOIN Keyword</p>
<h2>SQL INNER JOIN Keyword</h2>
<p>The INNER JOIN keyword return rows when there is at least one match in both tables.</p>
<h3>SQL INNER JOIN Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name1<br />
INNER JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
</tbody>
</table>
<p><strong>PS:</strong> INNER JOIN is the same as JOIN.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL INNER JOIN Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>34764</td>
<td>15</td>
</tr>
</tbody>
</table>
<p>Now we want to list all the persons with any orders.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo<br />
FROM Persons<br />
INNER JOIN Orders<br />
ON Persons.P_Id=Orders.P_Id<br />
ORDER BY Persons.LastName</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>OrderNo</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>22456</td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>24562</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>77895</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>44678</td>
</tr>
</tbody>
</table>
<p>The INNER JOIN keyword return rows when there is at least one match in both tables. If there are rows in &#8220;Persons&#8221; that do not have matches in &#8220;Orders&#8221;, those rows will NOT be listed.</p>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center">SQL LEFT JOIN Keyword</h1>
<h2>SQL LEFT JOIN Keyword</h2>
<p>The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2).</p>
<h3>SQL LEFT JOIN Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name1<br />
LEFT JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
</tbody>
</table>
<p><strong>PS:</strong> In some databases LEFT JOIN is called LEFT OUTER JOIN.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL LEFT JOIN Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>34764</td>
<td>15</td>
</tr>
</tbody>
</table>
<p>Now we want to list all the persons and their orders &#8211; if any, from the tables above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo<br />
FROM Persons<br />
LEFT JOIN Orders<br />
ON Persons.P_Id=Orders.P_Id<br />
ORDER BY Persons.LastName</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>OrderNo</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>22456</td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>24562</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>77895</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>44678</td>
</tr>
<tr>
<td>Svendson</td>
<td>Tove</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>The LEFT JOIN keyword returns all the rows from the left table (Persons), even if there are no matches in the right table (Orders).</p>
<p align="center"> </p>
<p align="center">SQL RIGHT JOIN Keyword</p>
<p>&nbsp;</p>
<h2>SQL RIGHT JOIN Keyword</h2>
<p>The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no matches in the left table (table_name1).</p>
<h3>SQL RIGHT JOIN Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name1<br />
RIGHT JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
</tbody>
</table>
<p><strong>PS:</strong> In some databases RIGHT JOIN is called RIGHT OUTER JOIN.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL RIGHT JOIN Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>34764</td>
<td>15</td>
</tr>
</tbody>
</table>
<p>Now we want to list all the orders with containing persons &#8211; if any, from the tables above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo<br />
FROM Persons<br />
RIGHT JOIN Orders<br />
ON Persons.P_Id=Orders.P_Id<br />
ORDER BY Persons.LastName</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>OrderNo</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>22456</td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>24562</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>77895</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>44678</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>34764</td>
</tr>
</tbody>
</table>
<p>The RIGHT JOIN keyword returns all the rows from the right table (Orders), even if there are no matches in the left table (Persons).</p>
<h1 align="center"> </h1>
<h1 align="center">SQL FULL JOIN Keyword</h1>
<h2>SQL FULL JOIN Keyword</h2>
<p>The FULL JOIN keyword return rows when there is a match in one of the tables.</p>
<h3>SQL FULL JOIN Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name1<br />
FULL JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL FULL JOIN Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>34764</td>
<td>15</td>
</tr>
</tbody>
</table>
<p>Now we want to list all the persons and their orders, and all the orders with their persons.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo<br />
FROM Persons<br />
FULL JOIN Orders<br />
ON Persons.P_Id=Orders.P_Id<br />
ORDER BY Persons.LastName</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>OrderNo</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>22456</td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>24562</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>77895</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>44678</td>
</tr>
<tr>
<td>Svendson</td>
<td>Tove</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>34764</td>
</tr>
</tbody>
</table>
<p>The FULL JOIN keyword returns all the rows from the left table (Persons), and all the rows from the right table (Orders). If there are rows in &#8220;Persons&#8221; that do not have matches in &#8220;Orders&#8221;, or if there are rows in &#8220;Orders&#8221; that do not have matches in &#8220;Persons&#8221;, those rows will be listed as well.</p>
<h1 align="center">SQL UNION Operator</h1>
<p>The SQL UNION operator combines two or more SELECT statements.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The SQL UNION Operator</h2>
<p>The UNION operator is used to combine the result-set of two or more SELECT statements.</p>
<p>Notice that each SELECT statement within theUNIONmust have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.</p>
<h3>SQL UNION Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s) FROM table_name1<br />
UNION<br />
SELECT column_name(s) FROM table_name2</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> The UNION operator selects only distinct values by default. To allow duplicate values, use UNION ALL.</p>
<h3>SQLUNIONALL Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s) FROM table_name1<br />
UNION ALL<br />
SELECT column_name(s) FROM table_name2</td>
</tr>
</tbody>
</table>
<p><strong>PS:</strong> The column names in the result-set of a UNION are always equal to the column names in the first SELECT statement in theUNION.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL UNION Example</h2>
<p>Look at the following tables:</p>
<p><strong>&#8220;Employees_Norway&#8221;</strong>:</p>
<table width="60%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="25%"><strong>E_ID</strong></td>
<td width="35%"><strong>E_Name</strong></td>
</tr>
<tr>
<td>01</td>
<td>Hansen, Ola</td>
</tr>
<tr>
<td>02</td>
<td>Svendson, Tove</td>
</tr>
<tr>
<td>03</td>
<td>Svendson, Stephen</td>
</tr>
<tr>
<td>04</td>
<td>Pettersen, Kari</td>
</tr>
</tbody>
</table>
<p><strong>&#8220;Employees_USA&#8221;</strong>:</p>
<table width="60%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="25%"><strong>E_ID</strong></td>
<td width="35%"><strong>E_Name</strong></td>
</tr>
<tr>
<td>01</td>
<td>Turner, Sally</td>
</tr>
<tr>
<td>02</td>
<td>Kent, Clark</td>
</tr>
<tr>
<td>03</td>
<td>Svendson, Stephen</td>
</tr>
<tr>
<td>04</td>
<td>Scott, Stephen</td>
</tr>
</tbody>
</table>
<p>Now we want to list <strong>all the different</strong> employees inNorway andUSA.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT E_Name FROM Employees_Norway<br />
UNION<br />
SELECT E_Name FROM Employees_USA</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="60%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="35%"><strong>E_Name</strong></td>
</tr>
<tr>
<td>Hansen, Ola</td>
</tr>
<tr>
<td>Svendson, Tove</td>
</tr>
<tr>
<td>Svendson, Stephen</td>
</tr>
<tr>
<td>Pettersen, Kari</td>
</tr>
<tr>
<td>Turner, Sally</td>
</tr>
<tr>
<td>Kent, Clark</td>
</tr>
<tr>
<td>Scott, Stephen</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> This command cannot be used to list all employees inNorway andUSA. In the example above we have two employees with equal names, and only one of them will be listed. The UNION command selects only distinct values.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQLUNIONALL Example</h2>
<p>Now we want to list <strong>all</strong> employees inNorway andUSA:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT E_Name FROM Employees_Norway<br />
UNION ALL<br />
SELECT E_Name FROM Employees_USA</td>
</tr>
</tbody>
</table>
<p><strong>Result</strong></p>
<table width="60%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="35%"><strong>E_Name</strong></td>
</tr>
<tr>
<td>Hansen, Ola</td>
</tr>
<tr>
<td>Svendson, Tove</td>
</tr>
<tr>
<td>Svendson, Stephen</td>
</tr>
<tr>
<td>Pettersen, Kari</td>
</tr>
<tr>
<td>Turner, Sally</td>
</tr>
<tr>
<td>Kent, Clark</td>
</tr>
<tr>
<td>Svendson, Stephen</td>
</tr>
<tr>
<td>Scott, Stephen</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center">SQL SELECT INTO Statement</p>
<p>&nbsp;</p>
<p>The SQL SELECT INTO statement can be used to create backup copies of tables.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The SQL SELECT INTO Statement</h2>
<p>The SELECT INTO statement selects data from one table and inserts it into a different table.</p>
<p>The SELECT INTO statement is most often used to create backup copies of tables.</p>
<h3>SQL SELECT INTO Syntax</h3>
<p>We can select all columns into the new table:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT *<br />
INTO new_table_name [IN externaldatabase]<br />
FROM old_tablename</td>
</tr>
</tbody>
</table>
<p>Or we can select only the columns we want into the new table:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
INTO new_table_name [IN externaldatabase]<br />
FROM old_tablename</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL SELECT INTO Example</h2>
<p><strong>Make a Backup Copy</strong> &#8211; Now we want to make an exact copy of the data in our &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT *<br />
INTO Persons_Backup<br />
FROM Persons</td>
</tr>
</tbody>
</table>
<p>We can also use the IN clause to copy the table into another database:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT *<br />
INTO Persons_Backup IN &#8216;Backup.mdb&#8217;<br />
FROM Persons</td>
</tr>
</tbody>
</table>
<p>We can also copy only a few fields into the new table:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LastName,FirstName<br />
INTO Persons_Backup<br />
FROM Persons</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL SELECT INTO &#8211; With a WHERE Clause</h2>
<p>We can also add a WHERE clause.</p>
<p>The following SQL statement creates a &#8220;Persons_Backup&#8221; table with only the persons who lives in the city &#8220;Sandnes&#8221;:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LastName,Firstname<br />
INTO Persons_Backup<br />
FROM Persons<br />
WHERECity=&#8217;Sandnes&#8217;</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL SELECT INTO &#8211; Joined Tables</h2>
<p>Selecting data from more than one table is also possible.</p>
<p>The following example creates a &#8220;Persons_Order_Backup&#8221; table contains data from the two tables &#8220;Persons&#8221; and &#8220;Orders&#8221;:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Persons.LastName,Orders.OrderNo<br />
INTO Persons_Order_Backup<br />
FROM Persons<br />
INNER JOIN Orders<br />
ON Persons.P_Id=Orders.P_Id</td>
</tr>
</tbody>
</table>
<h1 align="center"> </h1>
<h1 align="center">SQL CREATE DATABASE Statement</h1>
<h2>The CREATE DATABASE Statement</h2>
<p>The CREATE DATABASE statement is used to create a database.</p>
<h3>SQL CREATE DATABASE Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE DATABASE database_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>CREATE DATABASE Example</h2>
<p>Now we want to create a database called &#8220;my_db&#8221;.</p>
<p>We use the following CREATE DATABASE statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE DATABASE my_db</td>
</tr>
</tbody>
</table>
<p>Database tables can be added with the CREATE TABLE statement.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center">SQL CREATE TABLE Statement</p>
<p>&nbsp;</p>
<h2>The CREATE TABLE Statement</h2>
<p>The CREATE TABLE statement is used to create a table in a database.</p>
<h3>SQL CREATE TABLE Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE table_name<br />
(<br />
column_name1 data_type,<br />
column_name2 data_type,<br />
column_name3 data_type,<br />
&#8230;.<br />
)</td>
</tr>
</tbody>
</table>
<p>The data type specifies what type of data the column can hold. For a complete reference of all the data types available in MS Access, MySQL, and SQL Server, go to our complete <a href="http://www.w3schools.com/SQl/sql_datatypes.asp">Data Types reference</a>.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>CREATE TABLE Example</h2>
<p>Now we want to create a table called &#8220;Persons&#8221; that contains five columns: P_Id, LastName, FirstName, Address, and City.</p>
<p>We use the following CREATE TABLE statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int,<br />
LastName varchar(255),<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>The P_Id column is of type int and will hold a number. The LastName, FirstName, Address, and City columns are of type varchar with a maximum length of 255 characters.</p>
<p>The empty &#8220;Persons&#8221; table will now look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>The empty table can be filled with data with the INSERT INTO statement.</p>
<h1 align="center">SQL Constraints</h1>
<h2>SQL Constraints</h2>
<p>Constraints are used to limit the type of data that can go into a table.</p>
<p>Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement).</p>
<p>We will focus on the following constraints:</p>
<ul>
<li>NOT NULL</li>
<li>UNIQUE</li>
<li>PRIMARY KEY</li>
<li>FOREIGN KEY</li>
<li>CHECK</li>
<li>DEFAULT</li>
</ul>
<p>The next chapters will describe each constraint in details.</p>
<p align="center">SQL NOT NULL Constraint</p>
<p>&nbsp;</p>
<h2>SQL NOT NULL Constraint</h2>
<p>The NOT NULL constraint enforces a column to NOT accept NULL values.</p>
<p>The NOT NULL constraint enforces a field to always contain a value. This means that you cannot insert a new record, or update a record without adding a value to this field.</p>
<p>The following SQL enforces the &#8220;P_Id&#8221; column and the &#8220;LastName&#8221; column to not accept NULL values:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p align="center"> </p>
<p align="center"> </p>
<p align="center">SQL UNIQUE Constraint</p>
<p>&nbsp;</p>
<h2>SQL UNIQUE Constraint</h2>
<p>The UNIQUE constraint uniquely identifies each record in a database table.</p>
<p>The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns.</p>
<p>A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it.</p>
<p>Note that you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL UNIQUE Constraint on CREATE TABLE</h2>
<p>The following SQL creates a UNIQUE constraint on the &#8220;P_Id&#8221; column when the &#8220;Persons&#8221; table is created:</p>
<p><strong>MySQL:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
UNIQUE (P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL UNIQUE,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a UNIQUE constraint, and for defining a UNIQUE constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName)<br />
)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL UNIQUE Constraint on ALTER TABLE</h2>
<p>To create a UNIQUE constraint on the &#8220;P_Id&#8221; column when the table is already created, use the following SQL:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD UNIQUE (P_Id)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a UNIQUE constraint, and for defining a UNIQUE constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>To DROP a UNIQUE Constraint</h2>
<p>To drop a UNIQUE constraint, use the following SQL:</p>
<p><strong>MySQL:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP INDEX uc_PersonID</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP CONSTRAINT uc_PersonID</td>
</tr>
</tbody>
</table>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center">SQL PRIMARY KEY Constraint</p>
<p>&nbsp;</p>
<h2>SQL PRIMARY KEY Constraint</h2>
<p>The PRIMARY KEY constraint uniquely identifies each record in a database table.</p>
<p>Primary keys must contain unique values.</p>
<p>A primary key column cannot contain NULL values.</p>
<p>Each table should have a primary key, and each table can have only one primary key.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL PRIMARY KEY Constraint on CREATE TABLE</h2>
<p>The following SQL creates a PRIMARY KEY on the &#8220;P_Id&#8221; column when the &#8220;Persons&#8221; table is created:</p>
<p><strong>MySQL:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
PRIMARY KEY (P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL PRIMARY KEY,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)<br />
)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL PRIMARY KEY Constraint on ALTER TABLE</h2>
<p>To create a PRIMARY KEY constraint on the &#8220;P_Id&#8221; column when the table is already created, use the following SQL:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD PRIMARY KEY (P_Id)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> If you use the ALTER TABLE statement to add a primary key, the primary key column(s) must already have been declared to not contain NULL values (when the table was first created).</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>To DROP a PRIMARY KEY Constraint</h2>
<p>To drop a PRIMARY KEY constraint, use the following SQL:</p>
<p><strong>MySQL:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP PRIMARY KEY</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP CONSTRAINT pk_PersonID</td>
</tr>
</tbody>
</table>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center">SQL FOREIGN KEY Constraint</p>
<p>&nbsp;</p>
<h2>SQL FOREIGN KEY Constraint</h2>
<p>A FOREIGN KEY in one table points to a PRIMARY KEY in another table.</p>
<p>Let&#8217;s illustrate the foreign key with an example. Look at the following two tables:</p>
<p>The &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>2</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
</tbody>
</table>
<p>Note that the &#8220;P_Id&#8221; column in the &#8220;Orders&#8221; table points to the &#8220;P_Id&#8221; column in the &#8220;Persons&#8221; table.</p>
<p>The &#8220;P_Id&#8221; column in the &#8220;Persons&#8221; table is the PRIMARY KEY in the &#8220;Persons&#8221; table.</p>
<p>The &#8220;P_Id&#8221; column in the &#8220;Orders&#8221; table is a FOREIGN KEY in the &#8220;Orders&#8221; table.</p>
<p>The FOREIGN KEY constraint is used to prevent actions that would destroy link between tables.</p>
<p>The FOREIGN KEY constraint also prevents that invalid data is inserted into the foreign key column, because it has to be one of the values contained in the table it points to.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL FOREIGN KEY Constraint on CREATE TABLE</h2>
<p>The following SQL creates a FOREIGN KEY on the &#8220;P_Id&#8221; column when the &#8220;Orders&#8221; table is created:</p>
<p><strong>MySQL:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Orders<br />
(<br />
O_Id int NOT NULL,<br />
OrderNo int NOT NULL,<br />
P_Id int,<br />
PRIMARY KEY (O_Id),<br />
FOREIGN KEY (P_Id) REFERENCES Persons(P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Orders<br />
(<br />
O_Id int NOT NULL PRIMARY KEY,<br />
OrderNo int NOT NULL,<br />
P_Id int FOREIGN KEY REFERENCES Persons(P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a FOREIGN KEY constraint, and for defining a FOREIGN KEY constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Orders<br />
(<br />
O_Id int NOT NULL,<br />
OrderNo int NOT NULL,<br />
P_Id int,<br />
PRIMARY KEY (O_Id),<br />
CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id)<br />
REFERENCES Persons(P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL FOREIGN KEY Constraint on ALTER TABLE</h2>
<p>To create a FOREIGN KEY constraint on the &#8220;P_Id&#8221; column when the &#8220;Orders&#8221; table is already created, use the following SQL:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Orders<br />
ADD FOREIGN KEY (P_Id)<br />
REFERENCES Persons(P_Id)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a FOREIGN KEY constraint, and for defining a FOREIGN KEY constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Orders<br />
ADD CONSTRAINT fk_PerOrders<br />
FOREIGN KEY (P_Id)<br />
REFERENCES Persons(P_Id)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>To DROP a FOREIGN KEY Constraint</h2>
<p>To drop a FOREIGN KEY constraint, use the following SQL:</p>
<p><strong>MySQL:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Orders<br />
DROP FOREIGN KEY fk_PerOrders</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Orders<br />
DROP CONSTRAINT fk_PerOrders</td>
</tr>
</tbody>
</table>
<p align="center"> </p>
<p align="center"> </p>
<p align="center">SQL CHECK Constraint</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>SQL CHECK Constraint</h2>
<p>The CHECK constraint is used to limit the value range that can be placed in a column.</p>
<p>If you define a CHECK constraint on a single column it allows only certain values for this column.</p>
<p>If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL CHECK Constraint on CREATE TABLE</h2>
<p>The following SQL creates a CHECK constraint on the &#8220;P_Id&#8221; column when the &#8220;Persons&#8221; table is created. The CHECK constraint specifies that the column &#8220;P_Id&#8221; must only include integers greater than 0.</p>
<p><strong>My SQL:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
CHECK (P_Id&gt;0)<br />
)</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL CHECK (P_Id&gt;0),<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a CHECK constraint, and for defining a CHECK constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
CONSTRAINT chk_Person CHECK (P_Id&gt;0 AND City=&#8217;Sandnes&#8217;)<br />
)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL CHECK Constraint on ALTER TABLE</h2>
<p>To create a CHECK constraint on the &#8220;P_Id&#8221; column when the table is already created, use the following SQL:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD CHECK (P_Id&gt;0)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a CHECK constraint, and for defining a CHECK constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD CONSTRAINT chk_Person CHECK (P_Id&gt;0 AND City=&#8217;Sandnes&#8217;)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>To DROP a CHECK Constraint</h2>
<p>To drop a CHECK constraint, use the following SQL:</p>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP CONSTRAINT chk_Person</td>
</tr>
</tbody>
</table>
<h1 align="center"> </h1>
<h1 align="center">SQL DEFAULT Constraint</h1>
<h2>SQL DEFAULT Constraint</h2>
<p>The DEFAULT constraint is used to insert a default value into a column.</p>
<p>The default value will be added to all new records, if no other value is specified.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL DEFAULT Constraint on CREATE TABLE</h2>
<p>The following SQL creates a DEFAULT constraint on the &#8220;City&#8221; column when the &#8220;Persons&#8221; table is created:</p>
<p><strong>My SQL / SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255) DEFAULT &#8216;Sandnes&#8217;<br />
)</td>
</tr>
</tbody>
</table>
<p>The DEFAULT constraint can also be used to insert system values, by using functions like GETDATE():</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Orders<br />
(<br />
O_Id int NOT NULL,<br />
OrderNo int NOT NULL,<br />
P_Id int,<br />
OrderDate date DEFAULT GETDATE()<br />
)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL DEFAULT Constraint on ALTER TABLE</h2>
<p>To create a DEFAULT constraint on the &#8220;City&#8221; column when the table is already created, use the following SQL:</p>
<p><strong>MySQL:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTERTABLEPersons<br />
ALTERCity SET DEFAULT &#8216;SANDNES&#8217;</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTERTABLEPersons<br />
ALTERCOLUMNCity SET DEFAULT &#8216;SANDNES&#8217;</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>To DROP a DEFAULT Constraint</h2>
<p>To drop a DEFAULT constraint, use the following SQL:</p>
<p><strong>MySQL:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTERTABLEPersons<br />
ALTERCity DROP DEFAULT</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTERTABLEPersons<br />
ALTERCOLUMNCity DROP DEFAULT</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center">SQL CREATE INDEX Statement</p>
<p>The CREATE INDEX statement is used to create indexes in tables.</p>
<p>Indexes allow the database application to find data fast; without reading the whole table.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Indexes</h2>
<p>An index can be created in a table to find data more quickly and efficiently.</p>
<p>The users cannot see the indexes, they are just used to speed up searches/queries.</p>
<p><strong>Note:</strong> Updating a table with indexes takes more time than updating a table without (because the indexes also need an update). So you should only create indexes on columns (and tables) that will be frequently searched against.</p>
<h3>SQL CREATE INDEX Syntax</h3>
<p>Creates an index on a table. Duplicate values are allowed:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE INDEX index_name<br />
ON table_name (column_name)</td>
</tr>
</tbody>
</table>
<h3>SQL CREATE UNIQUE INDEX Syntax</h3>
<p>Creates a unique index on a table. Duplicate values are not allowed:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE UNIQUE INDEX index_name<br />
ON table_name (column_name)</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> The syntax for creating indexes varies amongst different databases. Therefore: Check the syntax for creating indexes in your database.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>CREATE INDEX Example</h2>
<p>The SQL statement below creates an index named &#8220;PIndex&#8221; on the &#8220;LastName&#8221; column in the &#8220;Persons&#8221; table:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE INDEX PIndex<br />
ON Persons (LastName)</td>
</tr>
</tbody>
</table>
<p>If you want to create an index on a combination of columns, you can list the column names within the parentheses, separated by commas:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE INDEX PIndex<br />
ON Persons (LastName, FirstName)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h1 align="center">SQL DROP INDEX, DROP TABLE, and DROP DATABASE</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p>Indexes, tables, and databases can easily be deleted/removed with the DROP statement.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The DROP INDEX Statement</h2>
<p>The DROP INDEX statement is used to delete an index in a table.</p>
<h3>DROP INDEX Syntax for MS Access:</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>DROP INDEX index_name ON table_name</td>
</tr>
</tbody>
</table>
<h3>DROP INDEX Syntax for MS SQL Server:</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>DROP INDEX table_name.index_name</td>
</tr>
</tbody>
</table>
<h3>DROP INDEX Syntax for DB2/Oracle:</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>DROP INDEX index_name</td>
</tr>
</tbody>
</table>
<h3>DROP INDEX Syntax for MySQL:</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE table_name DROP INDEX index_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The DROP TABLE Statement</h2>
<p>The DROP TABLE statement is used to delete a table.</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>DROP TABLE table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The DROP DATABASE Statement</h2>
<p>The DROP DATABASE statement is used to delete a database.</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>DROP DATABASE database_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The TRUNCATE TABLE Statement</h2>
<p>What if we only want to delete the data inside the table, and not the table itself?</p>
<p>Then, use the TRUNCATE TABLE statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>TRUNCATE TABLE table_name</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1 align="center">SQL ALTER TABLE Statement</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The ALTER TABLE Statement</h2>
<p>The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.</p>
<h3>SQL ALTER TABLE Syntax</h3>
<p>To add a column in a table, use the following syntax:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE table_name<br />
ADD column_name datatype</td>
</tr>
</tbody>
</table>
<p>To delete a column in a table, use the following syntax (notice that some database systems don&#8217;t allow deleting a column):</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE table_name<br />
DROP COLUMN column_name</td>
</tr>
</tbody>
</table>
<p>To change the data type of a column in a table, use the following syntax:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE table_name<br />
ALTER COLUMN column_name datatype</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL ALTER TABLE Example</h2>
<p>Look at the &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to add a column named &#8220;DateOfBirth&#8221; in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD DateOfBirth date</td>
</tr>
</tbody>
</table>
<p>Notice that the new column, &#8220;DateOfBirth&#8221;, is of type date and is going to hold a date. The data type specifies what type of data the column can hold. For a complete reference of all the data types available in MS Access, MySQL, and SQL Server, go to our complete <a href="http://www.w3schools.com/SQl/sql_datatypes.asp">Data Types reference</a>.</p>
<p>The &#8220;Persons&#8221; table will now like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
<td><strong>DateOfBirth</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Change Data Type Example</h2>
<p>Now we want to change the data type of the column named &#8220;DateOfBirth&#8221; in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ALTER COLUMN DateOfBirth year</td>
</tr>
</tbody>
</table>
<p>Notice that the &#8220;DateOfBirth&#8221; column is now of type year and is going to hold a year in a two-digit or four-digit format.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>DROP COLUMN Example</h2>
<p>Next, we want to delete the column named &#8220;DateOfBirth&#8221; in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP COLUMN DateOfBirth</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table will now like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<h1 align="center"> </h1>
<h1 align="center">SQL AUTO INCREMENT Field</h1>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p>Auto-increment allows a unique number to be generated when a new record is inserted into a table.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>AUTO INCREMENT a Field</h2>
<p>Very often we would like the value of the primary key field to be created automatically every time a new record is inserted.</p>
<p>We would like to create an auto-increment field in a table.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Syntax for MySQL</h2>
<p>The following SQL statement defines the &#8220;P_Id&#8221; column to be an auto-increment primary key field in the &#8220;Persons&#8221; table:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL AUTO_INCREMENT,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
PRIMARY KEY (P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p>MySQL uses the AUTO_INCREMENT keyword to perform an auto-increment feature.</p>
<p>By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record.</p>
<p>To let the AUTO_INCREMENT sequence start with another value, use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>ALTER TABLE Persons AUTO_INCREMENT=100</td>
</tr>
</tbody>
</table>
<p>To insert a new record into the &#8220;Persons&#8221; table, we will not have to specify a value for the &#8220;P_Id&#8221; column (a unique value will be added automatically):</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>INSERT INTO Persons (FirstName,LastName)<br />
VALUES (&#8216;Lars&#8217;,'Monsen&#8217;)</td>
</tr>
</tbody>
</table>
<p>The SQL statement above would insert a new record into the &#8220;Persons&#8221; table. The &#8220;P_Id&#8221; column would be assigned a unique value. The &#8220;FirstName&#8221; column would be set to &#8220;Lars&#8221; and the &#8220;LastName&#8221; column would be set to &#8220;Monsen&#8221;.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Syntax for SQL Server</h2>
<p>The following SQL statement defines the &#8220;P_Id&#8221; column to be an auto-increment primary key field in the &#8220;Persons&#8221; table:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int PRIMARY KEY IDENTITY,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>The MS SQL Server uses the IDENTITY keyword to perform an auto-increment feature.</p>
<p>By default, the starting value for IDENTITY is 1, and it will increment by 1 for each new record.</p>
<p>To specify that the &#8220;P_Id&#8221; column should start at value 10 and increment by 5, change the identity to IDENTITY(10,5).</p>
<p>To insert a new record into the &#8220;Persons&#8221; table, we will not have to specify a value for the &#8220;P_Id&#8221; column (a unique value will be added automatically):</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>INSERT INTO Persons (FirstName,LastName)<br />
VALUES (&#8216;Lars&#8217;,'Monsen&#8217;)</td>
</tr>
</tbody>
</table>
<p>The SQL statement above would insert a new record into the &#8220;Persons&#8221; table. The &#8220;P_Id&#8221; column would be assigned a unique value. The &#8220;FirstName&#8221; column would be set to &#8220;Lars&#8221; and the &#8220;LastName&#8221; column would be set to &#8220;Monsen&#8221;.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Syntax for Access</h2>
<p>The following SQL statement defines the &#8220;P_Id&#8221; column to be an auto-increment primary key field in the &#8220;Persons&#8221; table:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id PRIMARY KEY AUTOINCREMENT,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>The MS Access uses the AUTOINCREMENT keyword to perform an auto-increment feature.</p>
<p>By default, the starting value for AUTOINCREMENT is 1, and it will increment by 1 for each new record.</p>
<p>To specify that the &#8220;P_Id&#8221; column should start at value 10 and increment by 5, change the autoincrement to AUTOINCREMENT(10,5).</p>
<p>To insert a new record into the &#8220;Persons&#8221; table, we will not have to specify a value for the &#8220;P_Id&#8221; column (a unique value will be added automatically):</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>INSERT INTO Persons (FirstName,LastName)<br />
VALUES (&#8216;Lars&#8217;,'Monsen&#8217;)</td>
</tr>
</tbody>
</table>
<p>The SQL statement above would insert a new record into the &#8220;Persons&#8221; table. The &#8220;P_Id&#8221; column would be assigned a unique value. The &#8220;FirstName&#8221; column would be set to &#8220;Lars&#8221; and the &#8220;LastName&#8221; column would be set to &#8220;Monsen&#8221;.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Syntax for Oracle</h2>
<p>In Oracle the code is a little bit more tricky.</p>
<p>You will have to create an auto-increment field with the sequence object (this object generates a number sequence).</p>
<p>Use the following CREATE SEQUENCE syntax:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE SEQUENCE seq_person<br />
MINVALUE 1<br />
START WITH 1<br />
INCREMENT BY 1<br />
CACHE 10</td>
</tr>
</tbody>
</table>
<p>The code above creates a sequence object called seq_person, that starts with 1 and will increment by 1. It will also cache up to 10 values for performance. The cache option specifies how many sequence values will be stored in memory for faster access.</p>
<p>To insert a new record into the &#8220;Persons&#8221; table, we will have to use the nextval function (this function retrieves the next value from seq_person sequence):</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>INSERT INTO Persons (P_Id,FirstName,LastName)<br />
VALUES (seq_person.nextval,&#8217;Lars&#8217;,'Monsen&#8217;)</td>
</tr>
</tbody>
</table>
<p>The SQL statement above would insert a new record into the &#8220;Persons&#8221; table. The &#8220;P_Id&#8221; column would be assigned the next number from the seq_person sequence. The &#8220;FirstName&#8221; column would be set to &#8220;Lars&#8221; and the &#8220;LastName&#8221; column would be set to &#8220;Monsen&#8221;.</p>
<table width="560" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="10">&nbsp;</td>
<td>
<h1> </h1>
<h1 align="center">SQL Views</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p>A view is a virtual table.</p>
<p>This chapter shows how to create, update, and delete a view.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL CREATE VIEW Statement</h2>
<p>In SQL, a view is a virtual table based on the result-set of an SQL statement.</p>
<p>A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.</p>
<p>You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from one single table.</p>
<h3>SQL CREATE VIEW Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE VIEW view_name AS<br />
SELECT column_name(s)<br />
FROM table_name<br />
WHERE condition</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> A view always shows up-to-date data! The database engine recreates the data, using the view&#8217;s SQL statement, every time a user queries a view.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL CREATE VIEW Examples</h2>
<p>If you have the Northwind database you can see that it has several views installed by default.</p>
<p>The view &#8220;Current Product List&#8221; lists all active products (products that are not discontinued) from the &#8220;Products&#8221; table. The view is created with the following SQL:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE VIEW [Current Product List] AS<br />
SELECT ProductID,ProductName<br />
FROM Products<br />
WHERE Discontinued=No</td>
</tr>
</tbody>
</table>
<p>We can query the view above as follows:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM [Current Product List]</td>
</tr>
</tbody>
</table>
<p>Another view in the Northwind sample database selects every product in the &#8220;Products&#8221; table with a unit price higher than the average unit price:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE VIEW [Products Above Average Price] AS<br />
SELECT ProductName,UnitPrice<br />
FROM Products<br />
WHERE UnitPrice&gt;(SELECT AVG(UnitPrice) FROM Products)</td>
</tr>
</tbody>
</table>
<p>We can query the view above as follows:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM [Products Above Average Price]</td>
</tr>
</tbody>
</table>
<p>Another view in the Northwind database calculates the total sale for each category in 1997. Note that this view selects its data from another view called &#8220;Product Sales for 1997&#8243;:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE VIEW [Category Sales For 1997] AS<br />
SELECT DISTINCT CategoryName,Sum(ProductSales) AS CategorySales<br />
FROM [Product Sales for 1997]<br />
GROUP BY CategoryName</td>
</tr>
</tbody>
</table>
<p>We can query the view above as follows:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM [Category Sales For 1997]</td>
</tr>
</tbody>
</table>
<p>We can also add a condition to the query. Now we want to see the total sale only for the category &#8220;Beverages&#8221;:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM [Category Sales For 1997]<br />
WHERE CategoryName=&#8217;Beverages&#8217;</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Updating a View</h2>
<p>You can update a view by using the following syntax:</p>
<h3>SQL CREATE OR REPLACE VIEW Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE OR REPLACE VIEW view_name AS<br />
SELECT column_name(s)<br />
FROM table_name<br />
WHERE condition</td>
</tr>
</tbody>
</table>
<p>Now we want to add the &#8220;Category&#8221; column to the &#8220;Current Product List&#8221; view. We will update the view with the following SQL:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>CREATE VIEW [Current Product List] AS<br />
SELECT ProductID,ProductName,Category<br />
FROM Products<br />
WHERE Discontinued=No</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Dropping a View</h2>
<p>You can delete a view with the DROP VIEW command.</p>
<h3>SQL DROP VIEW Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>DROP VIEW view_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</td>
</tr>
</tbody>
</table>
<h1 align="center">SQL Date Functions</h1>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Dates</h2>
<p>The most difficult part when working with dates is to be sure that the format of the date you are trying to insert, matches the format of the date column in the database.</p>
<p>As long as your data contains only the date portion, your queries will work as expected. However, if a time portion is involved, it gets complicated.</p>
<p>Before talking about the complications of querying for dates, we will look at the most important built-in functions for working with dates.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>MySQL Date Functions</h2>
<p>The following table lists the most important built-in date functions in MySQL:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="22%"><strong>Function</strong></td>
<td width="78%"><strong>Description</strong></td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_now.asp">NOW()</a></td>
<td>Returns the current date and time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_curdate.asp">CURDATE()</a></td>
<td>Returns the current date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_curtime.asp">CURTIME()</a></td>
<td>Returns the current time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_date.asp">DATE()</a></td>
<td>Extracts the date part of a date or date/time expression</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_extract.asp">EXTRACT()</a></td>
<td>Returns a single part of a date/time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_date_add.asp">DATE_ADD()</a></td>
<td>Adds a specified time interval to a date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_date_sub.asp">DATE_SUB()</a></td>
<td>Subtracts a specified time interval from a date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_datediff_mysql.asp">DATEDIFF()</a></td>
<td>Returns the number of days between two dates</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_date_format.asp">DATE_FORMAT()</a></td>
<td>Displays date/time data in different formats</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Server Date Functions</h2>
<p>The following table lists the most important built-in date functions in SQL Server:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="22%"><strong>Function</strong></td>
<td width="78%"><strong>Description</strong></td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_getdate.asp">GETDATE()</a></td>
<td>Returns the current date and time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_datepart.asp">DATEPART()</a></td>
<td>Returns a single part of a date/time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_dateadd.asp">DATEADD()</a></td>
<td>Adds or subtracts a specified time interval from a date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_datediff.asp">DATEDIFF()</a></td>
<td>Returns the time between two dates</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/SQl/func_convert.asp">CONVERT()</a></td>
<td>Displays date/time data in different formats</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Date Data Types</h2>
<p><strong>MySQL</strong> comes with the following data types for storing a date or a date/time value in the database:</p>
<ul>
<li>DATE &#8211; format YYYY-MM-DD</li>
<li>DATETIME &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>TIMESTAMP &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>YEAR &#8211; format YYYY or YY</li>
</ul>
<p><strong>SQL Server</strong> comes with the following data types for storing a date or a date/time value in the database:</p>
<ul>
<li>DATE &#8211; format YYYY-MM-DD</li>
<li>DATETIME &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>SMALLDATETIME &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>TIMESTAMP &#8211; format: a unique number</li>
</ul>
<p><strong>Note:</strong> The date types are chosen for a column when you create a new table in your database!</p>
<p>For an overview of all data types available, go to our complete <a href="http://www.w3schools.com/SQl/sql_datatypes.asp">Data Types reference</a>.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Working with Dates</h2>
<p>You can compare two dates easily if there is no time component involved!</p>
<p>Assume we have the following &#8220;Orders&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="20%"><strong>OrderId</strong></td>
<td width="45%"><strong>ProductName</strong></td>
<td width="35%"><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Geitost</td>
<td>2008-11-11</td>
</tr>
<tr>
<td>2</td>
<td>Camembert Pierrot</td>
<td>2008-11-09</td>
</tr>
<tr>
<td>3</td>
<td>Mozzarella di Giovanni</td>
<td>2008-11-11</td>
</tr>
<tr>
<td>4</td>
<td>Mascarpone Fabioli</td>
<td>2008-10-29</td>
</tr>
</tbody>
</table>
<p>Now we want to select the records with an OrderDate of &#8220;2008-11-11&#8243; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Orders WHERE OrderDate=&#8217;2008-11-11&#8242;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="20%"><strong>OrderId</strong></td>
<td width="45%"><strong>ProductName</strong></td>
<td width="35%"><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Geitost</td>
<td>2008-11-11</td>
</tr>
<tr>
<td>3</td>
<td>Mozzarella di Giovanni</td>
<td>2008-11-11</td>
</tr>
</tbody>
</table>
<p>Now, assume that the &#8220;Orders&#8221; table looks like this (notice the time component in the &#8220;OrderDate&#8221; column):</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="20%"><strong>OrderId</strong></td>
<td width="45%"><strong>ProductName</strong></td>
<td width="35%"><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Geitost</td>
<td>2008-11-11 13:23:44</td>
</tr>
<tr>
<td>2</td>
<td>Camembert Pierrot</td>
<td>2008-11-09 15:45:21</td>
</tr>
<tr>
<td>3</td>
<td>Mozzarella di Giovanni</td>
<td>2008-11-11 11:12:01</td>
</tr>
<tr>
<td>4</td>
<td>Mascarpone Fabioli</td>
<td>2008-10-29 14:56:59</td>
</tr>
</tbody>
</table>
<p>If we use the same SELECT statement as above:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT * FROM Orders WHERE OrderDate=&#8217;2008-11-11&#8242;</td>
</tr>
</tbody>
</table>
<p>we will get no result! This is because the query is looking only for dates with no time portion.</p>
<p><strong>Tip:</strong> If you want to keep your queries simple and easy to maintain, do not allow time components in your dates!</p>
<h1 align="center">SQL NULL Values</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p>NULL values represent missing unknown data.</p>
<p>By default, a table column can hold NULL values.</p>
<p>This chapter will explain the IS NULL and IS NOT NULL operators.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL NULL Values</h2>
<p>If a column in a table is optional, we can insert a new record or update an existing record without adding a value to this column. This means that the field will be saved with a NULL value.</p>
<p>NULL values are treated differently from other values.</p>
<p>NULL is used as a placeholder for unknown or inapplicable values.</p>
<p><strong>Note:</strong> It is not possible to compare NULL and 0; they are not equivalent.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Working with NULL Values</h2>
<p>Look at the following &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>&nbsp;</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>&nbsp;</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Suppose that the &#8220;Address&#8221; column in the &#8220;Persons&#8221; table is optional. This means that if we insert a record with no value for the &#8220;Address&#8221; column, the &#8220;Address&#8221; column will be saved with a NULL value.</p>
<p>How can we test for NULL values?</p>
<p>It is not possible to test for NULL values with comparison operators, such as =, &lt;, or &lt;&gt;.</p>
<p>We will have to use the IS NULL and IS NOT NULL operators instead.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL IS NULL</h2>
<p>How do we select only the records with NULL values in the &#8220;Address&#8221; column?</p>
<p>We will have to use the IS NULL operator:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LastName,FirstName,Address FROM Persons<br />
WHERE Address IS NULL</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p><strong>Tip:</strong> Always use IS NULL to look for NULL values.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL IS NOT NULL</h2>
<p>How do we select only the records with no NULL values in the &#8220;Address&#8221; column?</p>
<p>We will have to use the IS NOT NULL operator:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LastName,FirstName,Address FROM Persons<br />
WHERE Address IS NOT NULL</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
</tr>
<tr>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
</tr>
</tbody>
</table>
<p>In the next chapter we will look at the ISNULL(), NVL(), IFNULL() and COALESCE() functions.</p>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL NULL Functions</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL ISNULL(), NVL(), IFNULL() and COALESCE() Functions</h2>
<p>Look at the following &#8220;Products&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>UnitPrice</strong></td>
<td><strong>UnitsInStock</strong></td>
<td><strong>UnitsOnOrder</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg</td>
<td>10.45</td>
<td>16</td>
<td>15</td>
</tr>
<tr>
<td>2</td>
<td>Mascarpone</td>
<td>32.56</td>
<td>23</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>3</td>
<td>Gorgonzola</td>
<td>15.67</td>
<td>9</td>
<td>20</td>
</tr>
</tbody>
</table>
<p>Suppose that the &#8220;UnitsOnOrder&#8221; column is optional, and may contain NULL values.</p>
<p>We have the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT ProductName,UnitPrice*(UnitsInStock+UnitsOnOrder)<br />
FROM Products</td>
</tr>
</tbody>
</table>
<p>In the example above, if any of the &#8220;UnitsOnOrder&#8221; values are NULL, the result is NULL.</p>
<p>Microsoft&#8217;s ISNULL() function is used to specify how we want to treat NULL values.</p>
<p>The NVL(), IFNULL(), and COALESCE() functions can also be used to achieve the same result.</p>
<p>In this case we want NULL values to be zero.</p>
<p>Below, if &#8220;UnitsOnOrder&#8221; is NULL it will not harm the calculation, because ISNULL() returns a zero if the value is NULL:</p>
<p><strong>SQL Server / MS Access</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT ProductName,UnitPrice*(UnitsInStock+ISNULL(UnitsOnOrder,0))<br />
FROM Products</td>
</tr>
</tbody>
</table>
<p><strong>Oracle</strong></p>
<p>Oracle does not have an ISNULL() function. However, we can use the NVL() function to achieve the same result:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT ProductName,UnitPrice*(UnitsInStock+NVL(UnitsOnOrder,0))<br />
FROM Products</td>
</tr>
</tbody>
</table>
<p><strong>MySQL</strong></p>
<p>MySQL does have an ISNULL() function. However, it works a little bit different from Microsoft&#8217;s ISNULL() function.</p>
<p>In MySQL we can use the IFNULL() function, like this:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT ProductName,UnitPrice*(UnitsInStock+IFNULL(UnitsOnOrder,0))<br />
FROM Products</td>
</tr>
</tbody>
</table>
<p>or we can use the COALESCE() function, like this:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT ProductName,UnitPrice*(UnitsInStock+COALESCE(UnitsOnOrder,0))<br />
FROM Products</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1 align="center">SQL Data Types</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p>Data types and ranges for Microsoft Access, MySQL and SQL Server.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>Microsoft Access Data Types</h2>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Data type</strong></td>
<td valign="top" width="70%"><strong>Description</strong></td>
<td valign="top" width="10%"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">Text</td>
<td valign="top">Use for text or combinations of text and numbers. 255 characters maximum</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">Memo</td>
<td valign="top">Memo is used for larger amounts of text. Stores up to 65,536 characters. <strong>Note:</strong> You cannot sort a memo field. However, they are searchable</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">Byte</td>
<td valign="top">Allows whole numbers from 0 to 255</td>
<td valign="top">1 byte</td>
</tr>
<tr>
<td valign="top">Integer</td>
<td valign="top">Allows whole numbers between -32,768 and 32,767</td>
<td valign="top">2 bytes</td>
</tr>
<tr>
<td valign="top">Long</td>
<td valign="top">Allows whole numbers between -2,147,483,648 and 2,147,483,647</td>
<td valign="top">4 bytes</td>
</tr>
<tr>
<td valign="top">Single</td>
<td valign="top">Single precision floating-point. Will handle most decimals</td>
<td valign="top">4 bytes</td>
</tr>
<tr>
<td valign="top">Double</td>
<td valign="top">Double precision floating-point. Will handle most decimals</td>
<td valign="top">8 bytes</td>
</tr>
<tr>
<td valign="top">Currency</td>
<td valign="top">Use for currency. Holds up to 15 digits of whole dollars, plus 4 decimal places. <strong>Tip:</strong> You can choose which country&#8217;s currency to use</td>
<td valign="top">8 bytes</td>
</tr>
<tr>
<td valign="top">AutoNumber</td>
<td valign="top">AutoNumber fields automatically give each record its own number, usually starting at 1</td>
<td valign="top">4 bytes</td>
</tr>
<tr>
<td valign="top">Date/Time</td>
<td valign="top">Use for dates and times</td>
<td valign="top">8 bytes</td>
</tr>
<tr>
<td valign="top">Yes/No</td>
<td valign="top">A logical field can be displayed as Yes/No, True/False, or On/Off. In code, use the constants True and False (equivalent to -1 and 0). <strong>Note:</strong> Null values are not allowed in Yes/No fields</td>
<td valign="top">1 bit</td>
</tr>
<tr>
<td valign="top">Ole Object</td>
<td valign="top">Can store pictures, audio, video, or other BLOBs (Binary Large OBjects)</td>
<td valign="top">up to 1GB</td>
</tr>
<tr>
<td valign="top">Hyperlink</td>
<td valign="top">Contain links to other files, including web pages</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">Lookup Wizard</td>
<td valign="top">Let you type a list of options, which can then be chosen from a drop-down list</td>
<td valign="top">4 bytes</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>MySQL Data Types</h2>
<p>In MySQL there are three main types : text, number, and Date/Time types.</p>
<p><strong>Text types:</strong></p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Data type</strong></td>
<td valign="top" width="80%"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">CHAR(size)</td>
<td valign="top">Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. Can store up to 255 characters</td>
</tr>
<tr>
<td valign="top">VARCHAR(size)</td>
<td valign="top">Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. Can store up to 255 characters. <strong>Note:</strong> If you put a greater value than 255 it will be converted to a TEXT type</td>
</tr>
<tr>
<td valign="top">TINYTEXT</td>
<td valign="top">Holds a string with a maximum length of 255 characters</td>
</tr>
<tr>
<td valign="top">TEXT</td>
<td valign="top">Holds a string with a maximum length of 65,535 characters</td>
</tr>
<tr>
<td valign="top">BLOB</td>
<td valign="top">For BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data</td>
</tr>
<tr>
<td valign="top">MEDIUMTEXT</td>
<td valign="top">Holds a string with a maximum length of 16,777,215 characters</td>
</tr>
<tr>
<td valign="top">MEDIUMBLOB</td>
<td valign="top">For BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data</td>
</tr>
<tr>
<td valign="top">LONGTEXT</td>
<td valign="top">Holds a string with a maximum length of 4,294,967,295 characters</td>
</tr>
<tr>
<td valign="top">LONGBLOB</td>
<td valign="top">For BLOBs (Binary Large OBjects). Holds up to 4,294,967,295 bytes of data</td>
</tr>
<tr>
<td valign="top">ENUM(x,y,z,etc.)</td>
<td valign="top">Let you enter a list of possible values. You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted.</p>
<p><strong>Note:</strong> The values are sorted in the order you enter them.</p>
<p>You enter the possible values in this format: ENUM(&#8216;X&#8217;,'Y&#8217;,'Z&#8217;)</td>
</tr>
<tr>
<td valign="top">SET</td>
<td valign="top">Similar to ENUM except that SET may contain up to 64 list items and can store more than one choice</td>
</tr>
</tbody>
</table>
<p><strong>Number types:</strong></p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Data type</strong></td>
<td valign="top" width="80%"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">TINYINT(size)</td>
<td valign="top">-128 to 127 normal. 0 to 255 UNSIGNED*. The maximum number of digits may be specified in parenthesis</td>
</tr>
<tr>
<td valign="top">SMALLINT(size)</td>
<td valign="top">-32768 to 32767 normal. 0 to 65535 UNSIGNED*. The maximum number of digits may be specified in parenthesis</td>
</tr>
<tr>
<td valign="top">MEDIUMINT(size)</td>
<td valign="top">-8388608 to 8388607 normal. 0 to 16777215 UNSIGNED*. The maximum number of digits may be specified in parenthesis</td>
</tr>
<tr>
<td valign="top">INT(size)</td>
<td valign="top">-2147483648 to 2147483647 normal. 0 to 4294967295 UNSIGNED*. The maximum number of digits may be specified in parenthesis</td>
</tr>
<tr>
<td valign="top">BIGINT(size)</td>
<td valign="top">-9223372036854775808 to 9223372036854775807 normal. 0 to 18446744073709551615 UNSIGNED*. The maximum number of digits may be specified in parenthesis</td>
</tr>
<tr>
<td valign="top">FLOAT(size,d)</td>
<td valign="top">A small number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter</td>
</tr>
<tr>
<td valign="top">DOUBLE(size,d)</td>
<td valign="top">A large number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter</td>
</tr>
<tr>
<td valign="top">DECIMAL(size,d)</td>
<td valign="top">A DOUBLE stored as a string , allowing for a fixed decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter</td>
</tr>
</tbody>
</table>
<p>*The integer types have an extra option called UNSIGNED. Normally, the integer goes from an negative to positive value. Adding the UNSIGNED attribute will move that range up so it starts at zero instead of a negative number.</p>
<p><strong>Date types:</strong></p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Data type</strong></td>
<td valign="top" width="80%"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">DATE()</td>
<td valign="top">A date. Format: YYYY-MM-DD</p>
<p><strong>Note:</strong> The supported range is from &#8217;1000-01-01&#8242; to &#8217;9999-12-31&#8242;</td>
</tr>
<tr>
<td valign="top">DATETIME()</td>
<td valign="top">*A date and time combination. Format: YYYY-MM-DD HH:MM:SS</p>
<p><strong>Note:</strong> The supported range is from &#8217;1000-01-01 00:00:00&#8242; to &#8217;9999-12-31 23:59:59&#8242;</td>
</tr>
<tr>
<td valign="top">TIMESTAMP()</td>
<td valign="top">*A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch (&#8217;1970-01-01 00:00:00&#8242; UTC). Format: YYYY-MM-DD HH:MM:SS</p>
<p><strong>Note:</strong> The supported range is from &#8217;1970-01-01 00:00:01&#8242; UTC to &#8217;2038-01-09 03:14:07&#8242; UTC</td>
</tr>
<tr>
<td valign="top">TIME()</td>
<td valign="top">A time. Format: HH:MM:SS</p>
<p><strong>Note:</strong> The supported range is from &#8216;-838:59:59&#8242; to &#8217;838:59:59&#8242;</td>
</tr>
<tr>
<td valign="top">YEAR()</td>
<td valign="top">A year in two-digit or four-digit format.</p>
<p><strong>Note:</strong> Values allowed in four-digit format: 1901 to 2155. Values allowed in two-digit format: 70 to 69, representing years from 1970 to 2069</td>
</tr>
</tbody>
</table>
<p>*Even if DATETIME and TIMESTAMP return the same format, they work very differently. In an INSERT or UPDATE query, the TIMESTAMP automatically set itself to the current date and time. TIMESTAMP also accepts various formats, like YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD, or YYMMDD.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Server Data Types</h2>
<p><strong>Character strings:</strong></p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Data type</strong></td>
<td valign="top" width="70%"><strong>Description</strong></td>
<td valign="top" width="10%"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">char(n)</td>
<td valign="top">Fixed-length character string. Maximum 8,000 characters</td>
<td valign="top">n</td>
</tr>
<tr>
<td valign="top">varchar(n)</td>
<td valign="top">Variable-length character string. Maximum 8,000 characters</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">varchar(max)</td>
<td valign="top">Variable-length character string. Maximum 1,073,741,824 characters</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">text</td>
<td valign="top">Variable-length character string. Maximum 2GB of text data</td>
<td valign="top">&nbsp;</td>
</tr>
</tbody>
</table>
<p><strong>Unicode strings:</strong></p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Data type</strong></td>
<td valign="top" width="70%"><strong>Description</strong></td>
<td valign="top" width="10%"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">nchar(n)</td>
<td valign="top">Fixed-length Unicode data. Maximum 4,000 characters</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">nvarchar(n)</td>
<td valign="top">Variable-length Unicode data. Maximum 4,000 characters</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">nvarchar(max)</td>
<td valign="top">Variable-length Unicode data. Maximum 536,870,912 characters</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">ntext</td>
<td valign="top">Variable-length Unicode data. Maximum 2GB of text data</td>
<td valign="top">&nbsp;</td>
</tr>
</tbody>
</table>
<p><strong>Binary types:</strong></p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Data type</strong></td>
<td valign="top" width="70%"><strong>Description</strong></td>
<td valign="top" width="10%"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">bit</td>
<td valign="top">Allows 0, 1, or NULL</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">binary(n)</td>
<td valign="top">Fixed-length binary data. Maximum 8,000 bytes</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">varbinary(n)</td>
<td valign="top">Variable-length binary data. Maximum 8,000 bytes</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">varbinary(max)</td>
<td valign="top">Variable-length binary data. Maximum 2GB</td>
<td valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">image</td>
<td valign="top">Variable-length binary data. Maximum 2GB</td>
<td valign="top">&nbsp;</td>
</tr>
</tbody>
</table>
<p><strong>Number types:</strong></p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Data type</strong></td>
<td valign="top" width="70%"><strong>Description</strong></td>
<td valign="top" width="10%"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">tinyint</td>
<td valign="top">Allows whole numbers from 0 to 255</td>
<td valign="top">1 byte</td>
</tr>
<tr>
<td valign="top">smallint</td>
<td valign="top">Allows whole numbers between -32,768 and 32,767</td>
<td valign="top">2 bytes</td>
</tr>
<tr>
<td valign="top">int</td>
<td valign="top">Allows whole numbers between -2,147,483,648 and 2,147,483,647</td>
<td valign="top">4 bytes</td>
</tr>
<tr>
<td valign="top">bigint</td>
<td valign="top">Allows whole numbers between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807</td>
<td valign="top">8 bytes</td>
</tr>
<tr>
<td valign="top">decimal(p,s)</td>
<td valign="top">Fixed precision and scale numbers.</p>
<p>Allows numbers from -10^38 +1 to 10^38 –1.</p>
<p>The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18.</p>
<p>The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default value is 0</td>
<td valign="top">5-17 bytes</td>
</tr>
<tr>
<td valign="top">numeric(p,s)</td>
<td valign="top">Fixed precision and scale numbers.</p>
<p>Allows numbers from -10^38 +1 to 10^38 –1.</p>
<p>The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18.</p>
<p>The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default value is 0</td>
<td valign="top">5-17 bytes</td>
</tr>
<tr>
<td valign="top">smallmoney</td>
<td valign="top">Monetary data from -214,748.3648 to 214,748.3647</td>
<td valign="top">4 bytes</td>
</tr>
<tr>
<td valign="top">money</td>
<td valign="top">Monetary data from -922,337,203,685,477.5808 to 922,337,203,685,477.5807</td>
<td valign="top">8 bytes</td>
</tr>
<tr>
<td valign="top">float(n)</td>
<td valign="top">Floating precision number data from -1.79E + 308 to 1.79E + 308.</p>
<p>The n parameter indicates whether the field should hold 4 or 8 bytes. float(24) holds a 4-byte field and float(53) holds an 8-byte field. Default value of n is 53.</td>
<td valign="top">4 or 8 bytes</td>
</tr>
<tr>
<td valign="top">real</td>
<td valign="top">Floating precision number data from -3.40E + 38 to 3.40E + 38</td>
<td valign="top">4 bytes</td>
</tr>
</tbody>
</table>
<p><strong>Date types:</strong></p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Data type</strong></td>
<td valign="top" width="70%"><strong>Description</strong></td>
<td valign="top" width="10%"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">datetime</td>
<td valign="top">From January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds</td>
<td valign="top">8 bytes</td>
</tr>
<tr>
<td valign="top">datetime2</td>
<td valign="top">From January 1, 0001 to December 31, 9999 with an accuracy of 100 nanoseconds</td>
<td valign="top">6-8 bytes</td>
</tr>
<tr>
<td valign="top">smalldatetime</td>
<td valign="top">From January 1, 1900 to June 6, 2079 with an accuracy of 1 minute</td>
<td valign="top">4 bytes</td>
</tr>
<tr>
<td valign="top">date</td>
<td valign="top">Store a date only. From January 1, 0001 to December 31, 9999</td>
<td valign="top">3 bytes</td>
</tr>
<tr>
<td valign="top">time</td>
<td valign="top">Store a time only to an accuracy of 100 nanoseconds</td>
<td valign="top">3-5 bytes</td>
</tr>
<tr>
<td valign="top">datetimeoffset</td>
<td valign="top">The same as datetime2 with the addition of a time zone offset</td>
<td valign="top">8-10 bytes</td>
</tr>
<tr>
<td valign="top">timestamp</td>
<td valign="top">Stores a unique number that gets updated every time a row gets created or modified. The timestamp value is based upon an internal clock and does not correspond to real time. Each table may have only one timestamp variable</td>
<td valign="top">&nbsp;</td>
</tr>
</tbody>
</table>
<p><strong>Other data types:</strong></p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Data type</strong></td>
<td valign="top" width="80%"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">sql_variant</td>
<td valign="top">Stores up to 8,000 bytes of data of various data types, except text, ntext, and timestamp</td>
</tr>
<tr>
<td valign="top">uniqueidentifier</td>
<td valign="top">Stores a globally unique identifier (GUID)</td>
</tr>
<tr>
<td valign="top">xml</td>
<td valign="top">Stores XML formatted data. Maximum 2GB</td>
</tr>
<tr>
<td valign="top">cursor</td>
<td valign="top">Stores a reference to a cursor used for database operations</td>
</tr>
<tr>
<td valign="top">table</td>
<td valign="top">Stores a result-set for later processing</td>
</tr>
</tbody>
</table>
<h1 align="center"> </h1>
<h1 align="center">SQL Functions</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p>SQL has many built-in functions for performing calculations on data.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Aggregate Functions</h2>
<p>SQL aggregate functions return a single value, calculated from values in a column.</p>
<p>Useful aggregate functions:</p>
<ul>
<li>AVG() &#8211; Returns the average value</li>
<li>COUNT() &#8211; Returns the number of rows</li>
<li>FIRST() &#8211; Returns the first value</li>
<li>LAST() &#8211; Returns the last value</li>
<li>MAX() &#8211; Returns the largest value</li>
<li>MIN() &#8211; Returns the smallest value</li>
<li>SUM() &#8211; Returns the sum</li>
</ul>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL Scalar functions</h2>
<p>SQL scalar functions return a single value, based on the input value.</p>
<p>Useful scalar functions:</p>
<ul>
<li>UCASE() &#8211; Converts a field to upper case</li>
<li>LCASE() &#8211; Converts a field to lower case</li>
<li>MID() &#8211; Extract characters from a text field</li>
<li>LEN() &#8211; Returns the length of a text field</li>
<li>ROUND() &#8211; Rounds a numeric field to the number of decimals specified</li>
<li>NOW() &#8211; Returns the current system date and time</li>
<li>FORMAT() &#8211; Formats how a field is to be displayed</li>
</ul>
<p><strong>Tip:</strong> The aggregate functions and the scalar functions will be explained in details in the next chapters.</p>
<table width="560" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="10">&nbsp;</td>
<td>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL AVG() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The AVG() Function</h2>
<p>The AVG() function returns the average value of a numeric column.</p>
<h3>SQL AVG() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT AVG(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL AVG() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the average value of the &#8220;OrderPrice&#8221; fields.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT AVG(OrderPrice) AS OrderAverage FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>OrderAverage</strong></td>
</tr>
<tr>
<td>950</td>
</tr>
</tbody>
</table>
<p>Now we want to find the customers that have an OrderPrice value higher than the average OrderPrice value.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Customer FROM Orders<br />
WHERE OrderPrice&gt;(SELECT AVG(OrderPrice) FROM Orders)</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>Hansen</td>
</tr>
<tr>
<td>Nilsen</td>
</tr>
<tr>
<td>Jensen</td>
</tr>
</tbody>
</table>
<p>&nbsp;</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL COUNT() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p>The COUNT() function returns the number of rows that matches a specified criteria.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h3>SQL COUNT(column_name) Syntax</h3>
<p>The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT COUNT(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<h3>SQL COUNT(*) Syntax</h3>
<p>The COUNT(*) function returns the number of records in a table:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT COUNT(*) FROM table_name</td>
</tr>
</tbody>
</table>
<h3>SQL COUNT(DISTINCT column_name) Syntax</h3>
<p>The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT COUNT(DISTINCT column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> COUNT(DISTINCT) works with ORACLE and Microsoft SQL Server, but not with Microsoft Access.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL COUNT(column_name) Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to count the number of orders from &#8220;Customer Nilsen&#8221;.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT COUNT(Customer) AS CustomerNilsen FROM Orders<br />
WHERE Customer=&#8217;Nilsen&#8217;</td>
</tr>
</tbody>
</table>
<p>The result of the SQL statement above will be 2, because the customer Nilsen has made 2 orders in total:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>CustomerNilsen</strong></td>
</tr>
<tr>
<td>2</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL COUNT(*) Example</h2>
<p>If we omit the WHERE clause, like this:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT COUNT(*) AS NumberOfOrders FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>NumberOfOrders</strong></td>
</tr>
<tr>
<td>6</td>
</tr>
</tbody>
</table>
<p>which is the total number of rows in the table.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL COUNT(DISTINCT column_name) Example</h2>
<p>Now we want to count the number of unique customers in the &#8220;Orders&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT COUNT(DISTINCT Customer) AS NumberOfCustomers FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>NumberOfCustomers</strong></td>
</tr>
<tr>
<td>3</td>
</tr>
</tbody>
</table>
<p>which is the number of unique customers (Hansen, Nilsen, and Jensen) in the &#8220;Orders&#8221; table.</p>
<table width="560" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="10">&nbsp;</td>
<td>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL FIRST() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The FIRST() Function</h2>
<p>The FIRST() function returns the first value of the selected column.</p>
<h3>SQL FIRST() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT FIRST(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL FIRST() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the first value of the &#8220;OrderPrice&#8221; column.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT FIRST(OrderPrice) AS FirstOrderPrice FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>FirstOrderPrice</strong></td>
</tr>
<tr>
<td>1000</td>
</tr>
</tbody>
</table>
<p>&nbsp;</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL LAST() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The LAST() Function</h2>
<p>The LAST() function returns the last value of the selected column.</p>
<h3>SQL LAST() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LAST(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL LAST() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the last value of the &#8220;OrderPrice&#8221; column.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LAST(OrderPrice) AS LastOrderPrice FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="96%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="2"><strong>LastOrderPrice</strong></td>
</tr>
<tr>
<td colspan="2">100</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td colspan="2">
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL MAX() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The MAX() Function</h2>
<p>The MAX() function returns the largest value of the selected column.</p>
<h3>SQL MAX() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT MAX(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL MAX() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the largest value of the &#8220;OrderPrice&#8221; column.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT MAX(OrderPrice) AS LargestOrderPrice FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LargestOrderPrice</strong></td>
</tr>
<tr>
<td>2000</td>
</tr>
</tbody>
</table>
<p>&nbsp;</td>
</tr>
<tr>
<td width="100"> </td>
<td width="311"> </td>
<td width="311"> </td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL MIN() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The MIN() Function</h2>
<p>The MIN() function returns the smallest value of the selected column.</p>
<h3>SQL MIN() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT MIN(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL MIN() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the smallest value of the &#8220;OrderPrice&#8221; column.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT MIN(OrderPrice) AS SmallestOrderPrice FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>SmallestOrderPrice</strong></td>
</tr>
<tr>
<td>100</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL SUM() Function</h1>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>The SUM() Function</h2>
<p>The SUM() function returns the total sum of a numeric column.</p>
<h3>SQL SUM() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT SUM(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL SUM() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the sum of all &#8220;OrderPrice&#8221; fields&#8221;.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT SUM(OrderPrice) AS OrderTotal FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>OrderTotal</strong></td>
</tr>
<tr>
<td>5700</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL GROUP BY Statement</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<p>Aggregate functions often need an added GROUP BY statement.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The GROUP BY Statement</h2>
<p>The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.</p>
<h3>SQL GROUP BY Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name, aggregate_function(column_name)<br />
FROM table_name<br />
WHERE column_name operator value<br />
GROUP BY column_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL GROUP BY Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the total sum (total order) of each customer.</p>
<p>We will have to use the GROUP BY statement to group the customers.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Customer,SUM(OrderPrice) FROM Orders<br />
GROUP BY Customer</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>Customer</strong></td>
<td><strong>SUM(OrderPrice)</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>2000</td>
</tr>
<tr>
<td>Nilsen</td>
<td>1700</td>
</tr>
<tr>
<td>Jensen</td>
<td>2000</td>
</tr>
</tbody>
</table>
<p>Nice! Isn&#8217;t it? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Let&#8217;s see what happens if we omit the GROUP BY statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Customer,SUM(OrderPrice) FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>Customer</strong></td>
<td><strong>SUM(OrderPrice)</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>5700</td>
</tr>
<tr>
<td>Nilsen</td>
<td>5700</td>
</tr>
<tr>
<td>Hansen</td>
<td>5700</td>
</tr>
<tr>
<td>Hansen</td>
<td>5700</td>
</tr>
<tr>
<td>Jensen</td>
<td>5700</td>
</tr>
<tr>
<td>Nilsen</td>
<td>5700</td>
</tr>
</tbody>
</table>
<p>The result-set above is not what we wanted.</p>
<p><strong>Explanation of why the above SELECT statement cannot be used:</strong> The SELECT statement above has two columns specified (Customer and SUM(OrderPrice). The &#8220;SUM(OrderPrice)&#8221; returns a single value (that is the total sum of the &#8220;OrderPrice&#8221; column), while &#8220;Customer&#8221; returns 6 values (one value for each row in the &#8220;Orders&#8221; table). This will therefore not give us the correct result. However, you have seen that the GROUP BY statement solves this problem.</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>GROUP BY More Than One Column</h2>
<p>We can also use the GROUP BY statement on more than one column, like this:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="2">SELECT Customer,OrderDate,SUM(OrderPrice) FROM Orders<br />
GROUP BY Customer,OrderDate</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td>
<h1 align="center">SQL HAVING Clause</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The HAVING Clause</h2>
<p>The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.</p>
<h3>SQL HAVING Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT column_name, aggregate_function(column_name)<br />
FROM table_name<br />
WHERE column_name operator value<br />
GROUP BY column_name<br />
HAVING aggregate_function(column_name) operator value</td>
</tr>
</tbody>
</table>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL HAVING Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find if any of the customers have a total order of less than 2000.</p>
<p>We use the following SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Customer,SUM(OrderPrice) FROM Orders<br />
GROUP BY Customer<br />
HAVING SUM(OrderPrice)&lt;2000</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>Customer</strong></td>
<td><strong>SUM(OrderPrice)</strong></td>
</tr>
<tr>
<td>Nilsen</td>
<td>1700</td>
</tr>
</tbody>
</table>
<p>Now we want to find if the customers &#8220;Hansen&#8221; or &#8220;Jensen&#8221; have a total order of more than 1500.</p>
<p>We add an ordinary WHERE clause to the SQL statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT Customer,SUM(OrderPrice) FROM Orders<br />
WHERE Customer=&#8217;Hansen&#8217; OR Customer=&#8217;Jensen&#8217;<br />
GROUP BY Customer<br />
HAVING SUM(OrderPrice)&gt;1500</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>Customer</strong></td>
<td><strong>SUM(OrderPrice)</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>2000</td>
</tr>
<tr>
<td>Jensen</td>
<td>2000</td>
</tr>
</tbody>
</table>
<p>&nbsp;</td>
</tr>
</tbody>
</table>
<h1 align="center">SQL UCASE() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The UCASE() Function</h2>
<p>The UCASE() function converts the value of a field to uppercase.</p>
<h3>SQL UCASE() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT UCASE(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<h3>Syntax for SQL Server</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT UPPER(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL UCASE() Example</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the content of the &#8220;LastName&#8221; and &#8220;FirstName&#8221; columns above, and convert the &#8220;LastName&#8221; column to uppercase.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT UCASE(LastName) as LastName,FirstName FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
</tr>
<tr>
<td>HANSEN</td>
<td>Ola</td>
</tr>
<tr>
<td>SVENDSON</td>
<td>Tove</td>
</tr>
<tr>
<td>PETTERSEN</td>
<td>Kari</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL LCASE() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The LCASE() Function</h2>
<p>The LCASE() function converts the value of a field to lowercase.</p>
<h3>SQL LCASE() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LCASE(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<h3>Syntax for SQL Server</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LOWER(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL LCASE() Example</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the content of the &#8220;LastName&#8221; and &#8220;FirstName&#8221; columns above, and convert the &#8220;LastName&#8221; column to lowercase.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LCASE(LastName) as LastName,FirstName FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
</tr>
<tr>
<td>hansen</td>
<td>Ola</td>
</tr>
<tr>
<td>svendson</td>
<td>Tove</td>
</tr>
<tr>
<td>pettersen</td>
<td>Kari</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL MID() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The MID() Function</h2>
<p>The MID() function is used to extract characters from a text field.</p>
<h3>SQL MID() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT MID(column_name,start[,length]) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Parameter</strong></td>
<td valign="top" width="80%"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">column_name</td>
<td valign="top">Required. The field to extract characters from</td>
</tr>
<tr>
<td valign="top">start</td>
<td valign="top">Required. Specifies the starting position (starts at 1)</td>
</tr>
<tr>
<td valign="top">length</td>
<td valign="top">Optional. The number of characters to return. If omitted, the MID() function returns the rest of the text</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL MID() Example</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to extract the first four characters of the &#8220;City&#8221; column above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT MID(City,1,4) as SmallCity FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>SmallCity</strong></td>
</tr>
<tr>
<td>Sand</td>
</tr>
<tr>
<td>Sand</td>
</tr>
<tr>
<td>Stav</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1 align="center">SQL LEN() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The LEN() Function</h2>
<p>The LEN() function returns the length of the value in a text field.</p>
<h3>SQL LEN() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LEN(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL LEN() Example</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn 10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn 23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt 20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the length of the values in the &#8220;Address&#8221; column above.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT LEN(Address) as LengthOfAddress FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>LengthOfAddress</strong></td>
</tr>
<tr>
<td>12</td>
</tr>
<tr>
<td>9</td>
</tr>
<tr>
<td>9</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL ROUND() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The ROUND() Function</h2>
<p>The ROUND() function is used to round a numeric field to the number of decimals specified.</p>
<h3>SQL ROUND() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT ROUND(column_name,decimals) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Parameter</strong></td>
<td valign="top" width="80%"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">column_name</td>
<td valign="top">Required. The field to round.</td>
</tr>
<tr>
<td valign="top">decimals</td>
<td valign="top">Required. Specifies the number of decimals to be returned.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL ROUND() Example</h2>
<p>We have the following &#8220;Products&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>Prod_Id</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>Unit</strong></td>
<td><strong>UnitPrice</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg</td>
<td>1000 g</td>
<td>10.45</td>
</tr>
<tr>
<td>2</td>
<td>Mascarpone</td>
<td>1000 g</td>
<td>32.56</td>
</tr>
<tr>
<td>3</td>
<td>Gorgonzola</td>
<td>1000 g</td>
<td>15.67</td>
</tr>
</tbody>
</table>
<p>Now we want to display the product name and the price rounded to the nearest integer.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT ProductName, ROUND(UnitPrice,0) as UnitPrice FROM Products</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>ProductName</strong></td>
<td><strong>UnitPrice</strong></td>
</tr>
<tr>
<td>Jarlsberg</td>
<td>10</td>
</tr>
<tr>
<td>Mascarpone</td>
<td>33</td>
</tr>
<tr>
<td>Gorgonzola</td>
<td>16</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL NOW() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The NOW() Function</h2>
<p>The NOW() function returns the current system date and time.</p>
<h3>SQL NOW() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT NOW() FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL NOW() Example</h2>
<p>We have the following &#8220;Products&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>Prod_Id</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>Unit</strong></td>
<td><strong>UnitPrice</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg</td>
<td>1000 g</td>
<td>10.45</td>
</tr>
<tr>
<td>2</td>
<td>Mascarpone</td>
<td>1000 g</td>
<td>32.56</td>
</tr>
<tr>
<td>3</td>
<td>Gorgonzola</td>
<td>1000 g</td>
<td>15.67</td>
</tr>
</tbody>
</table>
<p>Now we want to display the products and prices per today&#8217;s date.</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT ProductName, UnitPrice, Now() as PerDate FROM Products</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>ProductName</strong></td>
<td><strong>UnitPrice</strong></td>
<td><strong>PerDate</strong></td>
</tr>
<tr>
<td>Jarlsberg</td>
<td>10.45</td>
<td>10/7/2008 11:25:02 AM</td>
</tr>
<tr>
<td>Mascarpone</td>
<td>32.56</td>
<td>10/7/2008 11:25:02 AM</td>
</tr>
<tr>
<td>Gorgonzola</td>
<td>15.67</td>
<td>10/7/2008 11:25:02 AM</td>
</tr>
</tbody>
</table>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1 align="center">SQL FORMAT() Function</h1>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>The FORMAT() Function</h2>
<p>The FORMAT() function is used to format how a field is to be displayed.</p>
<h3>SQL FORMAT() Syntax</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT FORMAT(column_name,format) FROM table_name</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="20%"><strong>Parameter</strong></td>
<td valign="top" width="80%"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">column_name</td>
<td valign="top">Required. The field to be formatted.</td>
</tr>
<tr>
<td valign="top">format</td>
<td valign="top">Required. Specifies the format.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<h2>SQL FORMAT() Example</h2>
<p>We have the following &#8220;Products&#8221; table:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>Prod_Id</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>Unit</strong></td>
<td><strong>UnitPrice</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg</td>
<td>1000 g</td>
<td>10.45</td>
</tr>
<tr>
<td>2</td>
<td>Mascarpone</td>
<td>1000 g</td>
<td>32.56</td>
</tr>
<tr>
<td>3</td>
<td>Gorgonzola</td>
<td>1000 g</td>
<td>15.67</td>
</tr>
</tbody>
</table>
<p>Now we want to display the products and prices per today&#8217;s date (with today&#8217;s date displayed in the following format &#8220;YYYY-MM-DD&#8221;).</p>
<p>We use the following SELECT statement:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>SELECT ProductName, UnitPrice, FORMAT(Now(),&#8217;YYYY-MM-DD&#8217;) as PerDate<br />
FROM Products</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong>ProductName</strong></td>
<td><strong>UnitPrice</strong></td>
<td><strong>PerDate</strong></td>
</tr>
<tr>
<td>Jarlsberg</td>
<td>10.45</td>
<td>2008-10-07</td>
</tr>
<tr>
<td>Mascarpone</td>
<td>32.56</td>
<td>2008-10-07</td>
</tr>
<tr>
<td>Gorgonzola</td>
<td>15.67</td>
<td>2008-10-07</td>
</tr>
</tbody>
</table>
<h1 align="center"> </h1>
<h1 align="center"> </h1>
<h1 align="center">SQL Quick Reference</h1>
<p align="center"> </p>
<div align="center">
<hr align="center" noshade="noshade" size="1" width="100%" />
</div>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="27%"><strong>SQL Statement</strong></td>
<td valign="top" width="73%"><strong>Syntax</strong></td>
</tr>
<tr>
<td valign="top">AND / OR</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name<br />
WHERE condition<br />
AND|OR condition</td>
</tr>
<tr>
<td valign="top">ALTER TABLE</td>
<td valign="top">ALTER TABLE table_name<br />
ADD column_name datatype</p>
<p>or</p>
<p>ALTER TABLE table_name<br />
DROP COLUMN column_name</td>
</tr>
<tr>
<td valign="top">AS (alias)</td>
<td valign="top">SELECT column_name AS column_alias<br />
FROM table_name</p>
<p>or</p>
<p>SELECT column_name<br />
FROM table_name  AS table_alias</td>
</tr>
<tr>
<td valign="top">BETWEEN</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name<br />
BETWEEN value1 AND value2</td>
</tr>
<tr>
<td valign="top">CREATE DATABASE</td>
<td valign="top">CREATE DATABASE database_name</td>
</tr>
<tr>
<td valign="top">CREATE TABLE</td>
<td valign="top">CREATE TABLE table_name<br />
(<br />
column_name1 data_type,<br />
column_name2 data_type,<br />
column_name2 data_type,<br />
&#8230;<br />
)</td>
</tr>
<tr>
<td valign="top">CREATE INDEX</td>
<td valign="top">CREATE INDEX index_name<br />
ON table_name (column_name)</p>
<p>or</p>
<p>CREATE UNIQUE INDEX index_name<br />
ON table_name (column_name)</td>
</tr>
<tr>
<td valign="top">CREATE VIEW</td>
<td valign="top">CREATE VIEW view_name AS<br />
SELECT column_name(s)<br />
FROM table_name<br />
WHERE condition</td>
</tr>
<tr>
<td valign="top">DELETE</td>
<td valign="top">DELETE FROM table_name<br />
WHERE some_column=some_value</p>
<p>or</p>
<p>DELETE FROM table_name<br />
(<strong>Note: </strong>Deletes the entire table!!)</p>
<p>DELETE * FROM table_name<br />
(<strong>Note: </strong>Deletes the entire table!!)</td>
</tr>
<tr>
<td valign="top">DROP DATABASE</td>
<td valign="top">DROP DATABASE database_name</td>
</tr>
<tr>
<td valign="top">DROP INDEX</td>
<td valign="top">DROP INDEX table_name.index_name (SQL Server)<br />
DROP INDEX index_name ON table_name (MS Access)<br />
DROP INDEX index_name (DB2/Oracle)<br />
ALTER TABLE table_name<br />
DROP INDEX index_name (MySQL)</td>
</tr>
<tr>
<td valign="top">DROP TABLE</td>
<td valign="top">DROP TABLE table_name</td>
</tr>
<tr>
<td valign="top">GROUP BY</td>
<td valign="top">SELECT column_name, aggregate_function(column_name)<br />
FROM table_name<br />
WHERE column_name operator value<br />
GROUP BY column_name</td>
</tr>
<tr>
<td valign="top">HAVING</td>
<td valign="top">SELECT column_name, aggregate_function(column_name)<br />
FROM table_name<br />
WHERE column_name operator value<br />
GROUP BY column_name<br />
HAVING aggregate_function(column_name) operator value</td>
</tr>
<tr>
<td valign="top">IN</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name<br />
IN (value1,value2,..)</td>
</tr>
<tr>
<td valign="top">INSERT INTO</td>
<td valign="top">INSERT INTO table_name<br />
VALUES (value1, value2, value3,&#8230;.)</p>
<p><em>or</em></p>
<p>INSERT INTO table_name<br />
(column1, column2, column3,&#8230;)<br />
VALUES (value1, value2, value3,&#8230;.)</td>
</tr>
<tr>
<td valign="top">INNER JOIN</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name1<br />
INNER JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
<tr>
<td valign="top">LEFT JOIN</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name1<br />
LEFT JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
<tr>
<td valign="top">RIGHT JOIN</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name1<br />
RIGHT JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
<tr>
<td valign="top">FULL JOIN</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name1<br />
FULL JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
<tr>
<td valign="top">LIKE</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name LIKE pattern</td>
</tr>
<tr>
<td valign="top">ORDER BY</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name<br />
ORDER BY column_name [ASC|DESC]</td>
</tr>
<tr>
<td valign="top">SELECT</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name</td>
</tr>
<tr>
<td valign="top">SELECT *</td>
<td valign="top">SELECT *<br />
FROM table_name</td>
</tr>
<tr>
<td valign="top">SELECT DISTINCT</td>
<td valign="top">SELECT DISTINCT column_name(s)<br />
FROM table_name</td>
</tr>
<tr>
<td valign="top">SELECT INTO</td>
<td valign="top">SELECT *<br />
INTO new_table_name [IN externaldatabase]<br />
FROM old_table_name</p>
<p><em>or</em></p>
<p>SELECT column_name(s)<br />
INTO new_table_name [IN externaldatabase]<br />
FROM old_table_name</td>
</tr>
<tr>
<td valign="top">SELECT TOP</td>
<td valign="top">SELECT TOP number|percent column_name(s)<br />
FROM table_name</td>
</tr>
<tr>
<td valign="top">TRUNCATE TABLE</td>
<td valign="top">TRUNCATE TABLE table_name</td>
</tr>
<tr>
<td valign="top">UNION</td>
<td valign="top">SELECT column_name(s) FROM table_name1<br />
UNION<br />
SELECT column_name(s) FROM table_name2</td>
</tr>
<tr>
<td valign="top">UNION ALL</td>
<td valign="top">SELECT column_name(s) FROM table_name1<br />
UNION ALL<br />
SELECT column_name(s) FROM table_name2</td>
</tr>
<tr>
<td valign="top">UPDATE</td>
<td valign="top">UPDATE table_name<br />
SET column1=value, column2=value,&#8230;<br />
WHERE some_column=some_value</td>
</tr>
<tr>
<td valign="top">WHERE</td>
<td valign="top">SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name operator value</td>
</tr>
</tbody>
</table>
<p> &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;</p>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/dbms-commandsnotes/'>DBMS - COMMANDS(Notes)</a> Tagged: <a href='http://meherchilakalapudi.wordpress.com/tag/database-management-system/'>database management system</a>, <a href='http://meherchilakalapudi.wordpress.com/tag/query-language-sql/'>query language sql</a>, <a href='http://meherchilakalapudi.wordpress.com/tag/relational-database-management/'>relational database management</a>, <a href='http://meherchilakalapudi.wordpress.com/tag/relational-database-management-system/'>relational database management system</a>, <a href='http://meherchilakalapudi.wordpress.com/tag/structured-query-language/'>structured query language</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1438/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1438/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1438/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1438/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1438/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1438/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1438/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1438/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1438/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1438/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1438/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1438/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1438/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1438/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1438&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/12/31/dbms-commandsnotes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>
	</item>
		<item>
		<title>Virtual Memory in Operating System</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/12/18/virtual-memory-in-operating-system/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/12/18/virtual-memory-in-operating-system/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 06:34:28 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[Virtual Memory in Operating System]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1411</guid>
		<description><![CDATA[&#160; Virtual Memory   ..meher    1.Background 2.Demand Paging 3.Copy-on-Write 4.Page Replacement 5.Allocation of Frames 6.Thrashing 7.Memory-Mapped Files 8.Allocating Kernel Memory 9.Other Considerations 10.Operating-System Examples     Objectives     1.To describe the benefits of a virtual memory system 2.To explain the concepts of demand paging, page-replacement algorithms, and allocation of page frames 3.To discuss [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1411&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<h1 style="text-align:center;"><span style="text-decoration:underline;"><span style="color:#0000ff;"><strong>Virtual Memory</strong></span></span></h1>
<h2 style="text-align:right;"> </h2>
<h1 style="text-align:right;"><span style="color:#0000ff;">..meher</span></h1>
<h1 style="text-align:left;">  </h1>
<div>
<div>1.Background</p>
<div>
<div>2.Demand Paging</div>
<div>3.Copy-on-Write</div>
<div>4.Page Replacement</div>
<div>5.Allocation of Frames</div>
<div>6.Thrashing</div>
<div>7.Memory-Mapped Files</div>
<div>8.Allocating Kernel Memory</div>
<div>9.Other Considerations</div>
<div>10.Operating-System Examples</div>
<div> </div>
<div> </p>
<div><strong>Objectives</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.To describe the benefits of a virtual memory system</div>
<div>2.To explain the concepts of demand paging, page-replacement algorithms, and allocation of page frames</div>
<div>3.To discuss the principle of the working-set model</div>
<div> </div>
<div> </p>
<div><strong>Background</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.<strong>Virtual memory</strong> – separation of user logical memory from physical memory.</div>
<div>1.Only part of the program needs to be in memory for execution</div>
<div>2.Logical address space can therefore be much larger than physical address space</div>
<div>3.Allows address spaces to be shared by several processes</div>
<div>4.Allows for more efficient process creation</div>
<div>2.Virtual memory can be implemented via:</div>
<div>1.Demand paging</div>
<div>2.Demand segmentation</div>
<div> </div>
<div> </p>
<div><strong>Virtual Memory That is Larger Than Physical Memory</strong></div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/65.jpg"><img class="aligncenter size-medium wp-image-1412" title="65" src="http://meherchilakalapudi.files.wordpress.com/2011/12/65.jpg?w=300&#038;h=230" alt="" width="300" height="230" /></a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div> </div>
<div> </p>
<div><strong>Virtual-address Space</strong></div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/66.jpg"><img class="aligncenter size-medium wp-image-1413" title="66" src="http://meherchilakalapudi.files.wordpress.com/2011/12/66.jpg?w=126&#038;h=300" alt="" width="126" height="300" /></a></strong></div>
<div><strong><strong> </strong></strong></p>
<div><strong>Shared Library Using Virtual Memory</strong></div>
<div><strong></strong> </div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/67.jpg"><img class="aligncenter size-medium wp-image-1414" title="67" src="http://meherchilakalapudi.files.wordpress.com/2011/12/67.jpg?w=300&#038;h=199" alt="" width="300" height="199" /></a></div>
<div><strong></strong> </div>
<div><strong><strong> </strong></strong></p>
<div><strong>Demand Paging</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Bring a page into memory only when it is needed</div>
<div>1.Less I/O needed</div>
<div>2.Less memory needed</div>
<div>3.Faster response</div>
<div>4.More users</div>
<div>2.Page is needed Þ reference to it</div>
<div>1.invalid reference Þ abort</div>
<div>2.not-in-memory Þ bring to memory</div>
<div>3.<strong>Lazy swapper</strong> – never swaps a page into memory unless page will be needed</div>
<div>1.Swapper that deals with pages is a <strong>pager </strong></div>
<div> </div>
<div> </p>
<div><strong>Transfer of a Paged Memory to Contiguous Disk Space</strong></div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/68.jpg"><img class="aligncenter size-medium wp-image-1415" title="68" src="http://meherchilakalapudi.files.wordpress.com/2011/12/68.jpg?w=300&#038;h=273" alt="" width="300" height="273" /></a></strong></div>
<div><strong><strong> </strong></strong></p>
<div><strong>Valid-Invalid Bit</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>With each page table entry a valid–invalid bit is associated<br />
(<strong>v</strong> Þ in-memory, <strong>i</strong> Þ not-in-memory)</div>
<div>Initially valid–invalid bit is set to<strong> i </strong>on all entries</div>
<div>Example of a page table snapshot:</div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/69.jpg"> </a></p>
<div>
<div> </div>
</div>
<div>During address translation, if valid–invalid bit in page table entry</div>
<div>      is<strong> I</strong> Þ page fault</div>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/69.jpg"><img class="aligncenter size-medium wp-image-1416" title="69" src="http://meherchilakalapudi.files.wordpress.com/2011/12/69.jpg?w=265&#038;h=300" alt="" width="265" height="300" /></a></div>
<div>  </p>
<div><strong>Page Table When Some Pages Are Not in Main Memory</strong></div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/70.jpg"><img class="aligncenter size-medium wp-image-1417" title="70" src="http://meherchilakalapudi.files.wordpress.com/2011/12/70.jpg?w=300&#038;h=283" alt="" width="300" height="283" /></a></strong></div>
<div><strong><strong> </strong></strong></p>
<div><strong>Page Fault</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.If there is a reference to a page, first reference to that page will trap to operating system:</div>
<div>2.              <strong>page fault </strong></div>
<div>3.Operating system looks at another table to decide:</div>
<div>1.Invalid reference Þ abort</div>
<div>2.Just not in memory</div>
<div>4.Get empty frame</div>
<div>5.Swap page into frame</div>
<div>6.Reset tables</div>
<div>7.Set validation bit = <strong>v</strong></div>
<div>8.Restart the instruction that caused the page fault</div>
<div> </div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/71.jpg"> </a></p>
<div><strong>Steps in Handling a Page Fault</strong></div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/72.jpg"><img class="aligncenter size-medium wp-image-1419" title="72" src="http://meherchilakalapudi.files.wordpress.com/2011/12/72.jpg?w=300&#038;h=255" alt="" width="300" height="255" /></a></strong></div>
<div><strong></strong> </div>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/71.jpg"> </a></p>
<div><strong>Performance of Demand Paging</strong></div>
<div> <img class="aligncenter  wp-image-1418" title="71" src="http://meherchilakalapudi.files.wordpress.com/2011/12/71.jpg?w=300&#038;h=186" alt="" width="300" height="186" /></div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Performance of Demand Paging</strong></div>
</div>
<div> </div>
<div> </p>
<div>
<div>1.Page Fault Rate 0 £ <em>p</em> £ 1.0</div>
<div>1.if <em>p</em> = 0 no page faults</div>
<div>2.if <em>p</em> = 1, every reference is a fault</div>
<div>2.Effective Access Time (EAT)</div>
<div>3. EAT = (1 – <em>p</em>) x memory access</div>
<div>4. + <em>p</em> (page fault overhead</div>
<div>5.            + swap page out</div>
<div>6.            + swap page in</div>
<div>7.            + restart overhead</div>
<div>8.                                                     )</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Demand Paging Example</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Memory access time = 200 nanoseconds</div>
<div> </div>
<div>2.Average page-fault service time = 8 milliseconds</div>
<div>3.EAT = (1 – p) x 200 + p (8 milliseconds)</div>
<div>4.         = (1 – p  x 200 + p x 8,000,000</div>
<div>5.              = 200 + p x 7,999,800</div>
<div> </div>
<div>6.If one access out of 1,000 causes a page fault, then</div>
<div>7.         EAT = 8.2 microseconds.</div>
<div>8.      This is a slowdown by a factor of 40!!</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Process Creation</strong></div>
<div><strong></strong> </div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Virtual memory allows other benefits during process creation:</div>
<div>2. &#8211; Copy-on-Write</div>
<div>3. &#8211; Memory-Mapped Files (later)</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Copy-on-Write</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Copy-on-Write (COW) allows both parent and child processes to initially <em>share</em> the same pages in memory</p>
<p>If either process modifies a shared page, only then is the page copied</p></div>
<div> </div>
<div>2.COW allows more efficient process creation as only modified pages are copied</div>
<div> </div>
<div>3.Free pages are allocated from a <strong>pool</strong> of zeroed-out pages</div>
<div> </div>
<div> </p>
<div><strong>Before Process 1 Modifies Page C</strong></div>
<div><strong></strong> </div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/73.jpg"><img class="aligncenter size-medium wp-image-1420" title="73" src="http://meherchilakalapudi.files.wordpress.com/2011/12/73.jpg?w=300&#038;h=126" alt="" width="300" height="126" /></a></div>
<div><strong><strong> </strong></strong></p>
<div><strong>After Process 1 Modifies Page C</strong></div>
<div><strong></strong> </div>
<div><strong></strong> </div>
<div><img class="aligncenter" title="73" src="http://meherchilakalapudi.files.wordpress.com/2011/12/73.jpg?w=300&#038;h=126" alt="" width="300" height="126" /></div>
</div>
<div><strong></strong> </div>
<div> </p>
<div><strong>What happens if there is no free frame?</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Page replacement – find some page in memory, but not really in use, swap it out</div>
<div>1.algorithm</div>
<div>2.performance – want an algorithm which will result in minimum number of page faults</div>
<div>2.Same page may be brought into memory several times</div>
<div> </div>
<div> </p>
<div><strong>Page Replacement</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Prevent over-allocation of memory by modifying page-fault service routine to include page replacement</div>
<div>2.Use <strong>modify (dirty) bit</strong><strong> </strong>to reduce overhead of page transfers – only modified pages are written to disk</div>
<div>3.Page replacement completes separation between logical memory and physical memory – large virtual memory can be provided on a smaller physical memory</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Need For Page Replacement</strong></div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/74.jpg"><img class="size-medium wp-image-1421 aligncenter" title="74" src="http://meherchilakalapudi.files.wordpress.com/2011/12/74.jpg?w=300&#038;h=224" alt="" width="300" height="224" /></a></strong></div>
<div><strong><strong> </strong></strong></p>
<div><strong>Basic Page Replacement</strong></div>
<div><strong></strong> </div>
<div><strong><strong> </strong></strong></p>
<div>
<div>1.Find the location of the desired page on disk</div>
<div>2.Find a free frame:<br />
   -  If there is a free frame, use it<br />
   -  If there is no free frame, use a page replacement algorithm to select a <strong>victim</strong> frame</div>
<div>3.Bring  the desired page into the (newly) free frame; update the page and frame tables</div>
<div>4.Restart the process</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Page Replacement</strong></div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/75.jpg"><img class="aligncenter size-medium wp-image-1422" title="75" src="http://meherchilakalapudi.files.wordpress.com/2011/12/75.jpg?w=300&#038;h=252" alt="" width="300" height="252" /></a></strong></div>
<div><strong></strong> </div>
</div>
</div>
</div>
<div><strong></strong> </div>
<div><strong></strong> </div>
</div>
<div><strong></strong> </div>
<div><strong></strong> </div>
<div><strong></strong>  </p>
<div><strong>Page Replacement Algorithms</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Want lowest page-fault rate</div>
<div> </div>
<div>2.Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string</div>
<div> </div>
<div>3.In all our examples, the reference string is</div>
<div>4.   </div>
<div>5.               <strong>1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 </strong></div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Graph of Page Faults Versus The Number of Frames</strong></div>
<div><strong></strong> </div>
<div> </div>
<div> </div>
<div> </div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/76.jpg"><img class="size-medium wp-image-1423 aligncenter" title="76" src="http://meherchilakalapudi.files.wordpress.com/2011/12/76.jpg?w=300&#038;h=187" alt="" width="300" height="187" /></a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div><strong></strong> </div>
<div><strong></strong> <a href="http://meherchilakalapudi.files.wordpress.com/2011/12/77.jpg"><img class="aligncenter size-medium wp-image-1424" title="77" src="http://meherchilakalapudi.files.wordpress.com/2011/12/77.jpg?w=300&#038;h=255" alt="" width="300" height="255" /></a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div> <a href="http://meherchilakalapudi.files.wordpress.com/2011/12/78.jpg"><img class="aligncenter size-medium wp-image-1425" title="78" src="http://meherchilakalapudi.files.wordpress.com/2011/12/78.jpg?w=300&#038;h=92" alt="" width="300" height="92" /></a></div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/79.jpg"><img class="aligncenter size-medium wp-image-1426" title="79" src="http://meherchilakalapudi.files.wordpress.com/2011/12/79.jpg?w=300&#038;h=244" alt="" width="300" height="244" /></a></div>
<div> </div>
<div>  </p>
<div><strong>Optimal Page Replacement</strong></div>
<div><strong></strong> </div>
<div><strong></strong> </div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/791.jpg"><img class="aligncenter size-medium wp-image-1427" title="79" src="http://meherchilakalapudi.files.wordpress.com/2011/12/791.jpg?w=300&#038;h=244" alt="" width="300" height="244" /></a></strong></div>
<div><strong><strong> </strong></strong></p>
<div><strong>LRU Page Replacement</strong></div>
<div><strong></strong> </div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/80.jpg"><img class="aligncenter size-medium wp-image-1428" title="80" src="http://meherchilakalapudi.files.wordpress.com/2011/12/80.jpg?w=300&#038;h=251" alt="" width="300" height="251" /></a></div>
</div>
</div>
<div>  </p>
<div>
<div>1.Stack implementation – keep a stack of page numbers in a double link form:</div>
<div>1.Page referenced:</div>
<div>1.move it to the top</div>
<div>2.requires 6 pointers to be changed</div>
<div>2.No search for replacement</div>
<div>  </div>
<div>
<div><strong>Second-Chance (clock) Page-Replacement Algorithm</strong></div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/81.jpg"><img class="aligncenter size-medium wp-image-1429" title="81" src="http://meherchilakalapudi.files.wordpress.com/2011/12/81.jpg?w=300&#038;h=278" alt="" width="300" height="278" /></a></strong></div>
<div><strong></strong> </div>
<div><strong><strong> </strong></strong></p>
<div><strong>Counting Algorithms</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Keep a counter of the number of references that have been made to each page</div>
<div>2.<strong>LFU Algorithm</strong>:  replaces page with smallest count</div>
<div>3.<strong>MFU Algorithm</strong>: based on the argument that the page with the smallest count was probably just brought in and has yet to be used</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Allocation of Frames</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Each process needs <em>minimum</em> number of pages</div>
<div>2.Example:  IBM 370 – 6 pages to handle SS MOVE instruction:</div>
<div>1.instruction is 6 bytes, might span 2 pages</div>
<div>2.2 pages to handle <em>from </em></div>
<div>3.2 pages to handle <em>to </em></div>
<div>3.Two major allocation schemes</div>
<div>1.fixed allocation</div>
<div>2.priority allocation</div>
<div> </div>
<div> </p>
<div><strong>Fixed Allocation</strong></div>
<div><strong><img class="aligncenter size-medium wp-image-1430" title="82" src="http://meherchilakalapudi.files.wordpress.com/2011/12/82.jpg?w=300&#038;h=253" alt="" width="300" height="253" /></strong></div>
<div> </div>
<div> </p>
<div><strong>Priority Allocation</strong></div>
<div><strong></strong> </div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Use a proportional allocation scheme using priorities rather than size</div>
<div>2.If process <em>P</em><em>i</em> generates a page fault,</div>
<div>1.select for replacement one of its frames</div>
<div>2.select for replacement a frame from a process with lower priority number</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Global vs. Local Allocation</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.<strong>Global replacement</strong> – process selects a replacement frame from the set of all frames; one process can take a frame from another</div>
<div>2.<strong>Local replacement</strong> – each process selects from only its own set of allocated frames</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Thrashing</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.If a process does not have “enough” pages, the page-fault rate is very high.  This leads to:</div>
<div>1.low CPU utilization</div>
<div>2.operating system thinks that it needs to increase the degree of multiprogramming</div>
<div>3.another process added to the system</div>
<div>2.<strong>Thrashing</strong> º a process is busy swapping pages in and out</div>
<div> </div>
<div> </p>
<div><strong>Demand Paging and Thrashing </strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Why does demand paging work?<br />
Locality model</div>
<div>1.Process migrates from one locality to another</div>
<div>2.Localities may overlap</div>
<div> </div>
<div>2.Why does thrashing occur?<br />
S size of locality &gt; total memory size</div>
<div> </div>
<div> </p>
<div><strong>Memory-Mapped Files</strong></div>
<div><strong></strong> </div>
<div><strong><strong> </strong></strong></p>
<div>
<div>1.Memory-mapped file I/O allows file I/O to be treated as routine memory access by <strong>mapping</strong> a disk block to a page in memory</div>
<div> </div>
<div>2.A file is initially read using demand paging. A page-sized portion of the file is read from the file system into a physical page. Subsequent reads/writes to/from the file are treated as ordinary memory accesses.</div>
<div> </div>
<div>3.Simplifies file access by treating file I/O through memory rather than <strong>read()</strong> <strong>write()</strong> system calls</div>
<div> </div>
<div>4.Also allows several processes to map the same file allowing the pages in memory to be shared</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Memory Mapped Files</strong></div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/83.jpg"><img class="aligncenter size-medium wp-image-1431" title="83" src="http://meherchilakalapudi.files.wordpress.com/2011/12/83.jpg?w=300&#038;h=241" alt="" width="300" height="241" /></a></strong></div>
<div><strong></strong> </div>
</div>
</div>
</div>
<div><strong></strong> </div>
<div> </p>
<div><strong>Memory-Mapped Shared Memory in Windows</strong></div>
<div><strong></strong> </div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/84.jpg"><img class="aligncenter size-medium wp-image-1432" title="84" src="http://meherchilakalapudi.files.wordpress.com/2011/12/84.jpg?w=300&#038;h=124" alt="" width="300" height="124" /></a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Allocating Kernel Memory</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Treated differently from user memory</div>
<div>2.Often allocated from a free-memory pool</div>
<div>1.Kernel requests memory for structures of varying sizes</div>
<div>2.Some kernel memory needs to be contiguous</div>
<div> </div>
<div> </div>
<div> </div>
</div>
</div>
</div>
<div> </div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<h4 style="text-align:left;"> </h4>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/virtual-memory-in-operating-system/'>Virtual Memory in Operating System</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1411/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1411&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/12/18/virtual-memory-in-operating-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/65.jpg?w=300" medium="image">
			<media:title type="html">65</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/66.jpg?w=126" medium="image">
			<media:title type="html">66</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/67.jpg?w=300" medium="image">
			<media:title type="html">67</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/68.jpg?w=300" medium="image">
			<media:title type="html">68</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/69.jpg?w=265" medium="image">
			<media:title type="html">69</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/70.jpg?w=300" medium="image">
			<media:title type="html">70</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/72.jpg?w=300" medium="image">
			<media:title type="html">72</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/71.jpg?w=300" medium="image">
			<media:title type="html">71</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/73.jpg?w=300" medium="image">
			<media:title type="html">73</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/73.jpg?w=300" medium="image">
			<media:title type="html">73</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/74.jpg?w=300" medium="image">
			<media:title type="html">74</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/75.jpg?w=300" medium="image">
			<media:title type="html">75</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/76.jpg?w=300" medium="image">
			<media:title type="html">76</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/77.jpg?w=300" medium="image">
			<media:title type="html">77</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/78.jpg?w=300" medium="image">
			<media:title type="html">78</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/79.jpg?w=300" medium="image">
			<media:title type="html">79</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/791.jpg?w=300" medium="image">
			<media:title type="html">79</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/80.jpg?w=300" medium="image">
			<media:title type="html">80</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/81.jpg?w=300" medium="image">
			<media:title type="html">81</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/82.jpg?w=300" medium="image">
			<media:title type="html">82</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/83.jpg?w=300" medium="image">
			<media:title type="html">83</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/84.jpg?w=300" medium="image">
			<media:title type="html">84</media:title>
		</media:content>
	</item>
		<item>
		<title>Deadlocks In Operating System</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/12/13/deadlocks-in-operating-system/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/12/13/deadlocks-in-operating-system/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 14:05:46 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[Deadlocks In Operating System]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1399</guid>
		<description><![CDATA[:  Deadlocks In Operating System : ..meher 1.     The Deadlock Problem 2.     System Model 3.     Deadlock Characterization 4.     Methods for Handling Deadlocks 5.     Deadlock Prevention 6.     Deadlock Avoidance 7.     Deadlock Detection 8.     Recovery from Deadlock   1.     To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks 2.     To [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1399&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="text-align:center;"><span style="text-decoration:underline;"><strong>:  Deadlocks In Operating System :</strong></span></h2>
<h2 style="text-align:right;"><span style="text-decoration:underline;">..meher</span></h2>
<ol>
<li style="text-align:left;"><strong>1.     </strong><strong>The Deadlock Problem</strong></li>
<li><strong>2.     </strong><strong>System Model</strong></li>
<li><strong>3.     </strong><strong>Deadlock Characterization</strong></li>
<li><strong>4.     </strong><strong>Methods for Handling Deadlocks</strong></li>
<li><strong>5.     </strong><strong>Deadlock Prevention</strong></li>
<li><strong>6.     </strong><strong>Deadlock Avoidance</strong></li>
<li><strong>7.     </strong><strong>Deadlock Detection </strong></li>
<li><strong>8.     </strong><strong>Recovery from Deadlock </strong></li>
</ol>
<p><strong> </strong></p>
<ol>
<li><strong>1.     </strong><strong>To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks</strong></li>
<li><strong>2.     </strong><strong>To present a number of different methods for preventing or avoiding deadlocks in a computer system.<a href="http://meherchilakalapudi.files.wordpress.com/2011/12/57.jpg"><img class="aligncenter  wp-image-1400" title="57" src="http://meherchilakalapudi.files.wordpress.com/2011/12/57.jpg?w=333&#038;h=118" alt="" width="333" height="118" /></a></strong></li>
</ol>
<ol>
<li><strong>1.     </strong><strong>Traffic only in one direction.</strong></li>
<li><strong>2.     </strong><strong>Each section of a bridge can be viewed as a resource.</strong></li>
<li><strong>3.     </strong><strong>If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback).</strong></li>
<li><strong>4.     </strong><strong>Several cars may have to be backed up if a deadlock occurs.</strong></li>
<li><strong>5.     </strong><strong>Starvation is possible.</strong></li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>System Model</strong></p>
<p><strong> </strong></p>
<ol>
<li>Resource types <em>R</em>1, <em>R</em>2, . . ., <em>R</em>m
<ol>
<li><em>1.     </em><em>CPU cycles, memory space, I/O devices</em></li>
</ol>
</li>
<li>Each resource type <em>R</em>i has <em>W</em>i instances.</li>
<li>Each process utilizes a resource as follows:
<ol>
<li>request</li>
<li>use</li>
<li>release</li>
</ol>
</li>
</ol>
<p>&nbsp;</p>
<p><strong>Deadlock Characterization</strong></p>
<p>&nbsp;</p>
<ol>
<li><strong>Mutual exclusion:</strong>  only one process at a time can use a resource.</li>
<li><strong>Hold and wait:</strong>  a process holding at least one resource is waiting to acquire additional resources held by other processes.</li>
<li><strong>No preemption:</strong>  a resource can be released only voluntarily by the process holding it, after that process has completed its task.</li>
<li><strong>Circular wait:</strong>  there exists a set {<em>P</em>0, <em>P</em>1, …, <em>P</em>0} of waiting processes such that <em>P</em>0 is waiting for a resource that is held by <em>P</em>1, <em>P</em>1 is waiting for a resource that is held by</li>
<li><em>          P</em>2, …, <em>Pn</em>–1 is waiting for a resource that is held by<br />
<em>P</em>n, and <em>P</em>0 is waiting for a resource that is held by <em>P</em>0.</li>
</ol>
<p>&nbsp;</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Resource-Allocation Graph</strong></p>
<p><strong> </strong></p>
<p>A set of vertices <em>V</em> and a set of edges <em>E</em>.</p>
<p>&nbsp;</p>
<ol>
<li>V is partitioned into two types:
<ol>
<li><em>P</em> = {<em>P</em>1, <em>P</em>2, …, <em>Pn</em>}, the set consisting of all the processes in the system.</li>
<li><em>R</em> = {<em>R</em>1, <em>R</em>2, …, <em>Rm</em>}, the set consisting of all resource types in the system.</li>
</ol>
</li>
<li><em>2.     </em>request edge – directed edge <em>P</em>1 ® <em>Rj</em></li>
<li>assignment edge – directed edge <em>Rj </em>® <em>Pi</em></li>
</ol>
<p><em></em> </p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/58.jpg"><img class="aligncenter  wp-image-1401" title="58" src="http://meherchilakalapudi.files.wordpress.com/2011/12/58.jpg?w=439&#038;h=313" alt="" width="439" height="313" /></a></p>
<p><strong> </strong></p>
<p><strong>Example of a Resource Allocation Graph</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/59.jpg"><img class="aligncenter size-medium wp-image-1402" title="59" src="http://meherchilakalapudi.files.wordpress.com/2011/12/59.jpg?w=191&#038;h=300" alt="" width="191" height="300" /></a></strong></p>
<p><strong>Resource Allocation Graph With A Deadlock</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/60.jpg"><img class="aligncenter size-medium wp-image-1403" title="60" src="http://meherchilakalapudi.files.wordpress.com/2011/12/60.jpg?w=190&#038;h=300" alt="" width="190" height="300" /></a></p>
<p><strong>Graph With A Cycle But No Deadlock</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/61.jpg"><img class="aligncenter size-medium wp-image-1404" title="61" src="http://meherchilakalapudi.files.wordpress.com/2011/12/61.jpg?w=252&#038;h=300" alt="" width="252" height="300" /></a></p>
<p><strong>Basic Facts</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ol>
<li>If graph contains no cycles Þ no deadlock.</li>
<li>If graph contains a cycle Þ
<ol>
<li>if only one instance per resource type, then deadlock.</li>
<li>if several instances per resource type, possibility of deadlock.</li>
</ol>
</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Methods for Handling Deadlocks</strong></p>
<p>&nbsp;</p>
<ol>
<li>Ensure that the system will <em>never</em> enter a deadlock state.</li>
<li>Allow the system to enter a deadlock state and then recover.</li>
<li>Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX.</li>
</ol>
<p>&nbsp;</p>
<p><strong>Deadlock Prevention</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Restrain the ways request can be made.</p>
<p>&nbsp;</p>
<ol>
<li><strong>Mutual Exclusion</strong> – not required for sharable resources; must hold for nonsharable resources.</li>
<li><strong>Hold and Wait</strong>– must guarantee that whenever a process requests a resource, it does not hold any other resources.
<ol>
<li>Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none.</li>
<li>Low resource utilization; starvation possible.</li>
</ol>
</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ol>
<li><strong>No Preemption</strong>–
<ol>
<li>If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released.</li>
<li>Preempted resources are added to the list of resources for which the process is waiting.</li>
<li>Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting.</li>
</ol>
</li>
<li><strong>Circular Wait</strong> – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration.</li>
</ol>
<p>&nbsp;</p>
<p><strong>Deadlock Avoidance</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Requires that the system has some additional <em>a priori </em>information<br />
available.</p>
<p>&nbsp;</p>
<ol>
<li>Simplest and most useful model requires that each process declare the <em>maximum number</em> of resources of each type that it may need.</li>
<li>The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition.</li>
<li>Resource-allocation <em>state</em> is defined by the number of available and allocated resources, and the maximum demands of the processes.</li>
</ol>
<p>&nbsp;</p>
<p><strong>Safe State</strong></p>
<p>&nbsp;</p>
<ol>
<li>When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state.</li>
<li>System is in safe state if there exists a sequence &lt;<em>P1, P2, …, Pn</em>&gt; of ALL the  processes  is the systems such that  for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the <em>Pj</em>, with<em> j </em>&lt; <em>i</em>.</li>
<li>That is:
<ol>
<li>If Pi resource needs are not immediately available, then <em>Pi</em> can wait until all <em>Pj </em>have finished.</li>
<li>When <em>Pj</em> is finished, <em>Pi</em> can obtain needed resources, execute, return allocated resources, and terminate.</li>
<li>When <em>Pi</em> terminates, <em>Pi </em>+1 can obtain its needed resources, and so on.</li>
</ol>
</li>
</ol>
<p>&nbsp;</p>
<p><strong>Basic Facts</strong></p>
<p>&nbsp;</p>
<ol>
<li>If a system is in safe state Þ no deadlocks.</li>
<li>If a system is in unsafe state Þ possibility of deadlock.</li>
<li>Avoidance Þ ensure that a system will never enter an unsafe state.</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Safe, Unsafe , Deadlock State </strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/62.jpg"><img class="aligncenter size-medium wp-image-1405" title="62" src="http://meherchilakalapudi.files.wordpress.com/2011/12/62.jpg?w=300&#038;h=291" alt="" width="300" height="291" /></a></p>
<p><strong>Avoidance algorithms</strong></p>
<p>&nbsp;</p>
<ol>
<li>Single instance of a resource type.  Use a resource-allocation graph</li>
</ol>
<p>&nbsp;</p>
<ol>
<li>Multiple instances of a resource type.  Use the banker’s algorithm</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Resource-Allocation Graph Scheme</strong></p>
<p>&nbsp;</p>
<ol>
<li><em>Claim edge</em> <em>Pi</em> ® <em>Rj</em> indicated that process <em>Pj</em> may request resource <em>Rj</em>; represented by a dashed line.</li>
<li>Claim edge converts to request edge when a process requests a resource.</li>
<li>Request edge converted to an assignment edge when the  resource is allocated to the process.</li>
</ol>
<p>&nbsp;</p>
<ol>
<li>When a resource is released by a process, assignment edge reconverts to a claim edge.</li>
<li>Resources must be claimed <em>a priori</em> in the system.</li>
</ol>
<p>&nbsp;</p>
<p><strong>Resource-Allocation Graph</strong></p>
<p><strong></strong> </p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/63.jpg"><img class="aligncenter size-medium wp-image-1406" title="63" src="http://meherchilakalapudi.files.wordpress.com/2011/12/63.jpg?w=284&#038;h=300" alt="" width="284" height="300" /></a></strong></p>
<p><strong>Resource-Allocation Graph Algorithm</strong></p>
<p>&nbsp;</p>
<ol>
<li><em>1.     </em>Suppose that process<em> Pi</em> requests a resource <em>Rj</em></li>
</ol>
<p><em> </em></p>
<ol>
<li>The request can be granted only if converting the request edge to an assignment edge does not result in the formation of a cycle in the resource allocation graph</li>
</ol>
<p>&nbsp;</p>
<p><strong>Banker’s Algorithm</strong></p>
<p>&nbsp;</p>
<ol>
<li>Multiple instances.</li>
<li>Each process must a priori claim maximum use.</li>
<li>When a process requests a resource it may have to wait. </li>
<li>When a process gets all its resources it must return them in a finite amount of time.</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Data Structures for the Banker’s Algorithm </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong><em>Available</em></strong><em>:</em>  Vector of length <em>m</em>. If available [<em>j</em>] = <em>k</em>, there are<em> k</em> instances of resource type <em>Rj</em>  available.</li>
<li><strong><em>Max</em></strong><em>: n x m</em> matrix.  If <em>Max </em>[<em>i,j</em>] = <em>k</em>, then process <em>Pi </em>may request at most<em> k </em>instances of resource type <em>Rj</em>.</li>
<li><strong><em>Allocation</em></strong><em>:  n </em>x<em> m</em> matrix.  If Allocation[<em>i,j</em>] = <em>k</em> then<em> Pi</em> is currently allocated <em>k</em> instances of <em>Rj.</em></li>
<li><strong><em>Need</em></strong><em>:  n </em>x<em> m</em> matrix. If <em>Need</em>[<em>i,j</em>] =<em> k</em>, then<em> Pi</em> may need <em>k</em> more instances of <em>Rj</em>to complete its task.
<ol>
<li>
<em>Need</em> [<em>i,j]</em> = <em>Max</em>[<em>i,j</em>] – <em>Allocation</em> [<em>i,j</em>].</li>
</ol>
</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Safety Algorithm</strong></p>
<p>&nbsp;</p>
<ol>
<li>1.       Let <strong><em>Work</em></strong><em> </em>and <strong><em>Finish</em></strong> be vectors of length<em> m</em> and<em> n</em>, respectively.  Initialize:
<ol>
<li><em>Work </em>= <em>Available </em></li>
<li><em>Finish </em>[<em>i</em>] =<em> false </em>for<em> i</em> = 0, 1, …, <em>n- </em>1<em>.</em></li>
</ol>
</li>
<li>2.       Find and <em>i </em>such that both:
<ol>
<li>(a) <em>Finish</em> [<em>i</em>] = <em>false</em></li>
<li>(b) <em>Needi</em> £ <em>Work </em></li>
<li>If no such <em>i </em>exists, go to step 4.</li>
</ol>
</li>
<li>3.       <em>Work</em> = <em>Work </em>+ <em>Allocationi</em><br />
<em>Finish</em>[<em>i</em>] =<em> true</em><br />
go to step 2.</li>
<li>4.       If <em>Finish</em> [<em>i</em>] == true for all <em>i</em>, then the system is in a safe state.</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Resource-Request Algorithm for Process <em>Pi</em></strong></p>
<p>&nbsp;</p>
<ol>
<li><em>      Request</em> = request vector for process <em>Pi</em>.  If <em>Requesti</em> [<em>j</em>] = <em>k</em> then process <em>Pi</em> wants <em>k</em> instances of resource type <em>Rj</em>.
<ol>
<li>1.       If <em>Requesti </em>£ <em>Needi </em>go to step 2.  Otherwise, raise error condition, since process has exceeded its maximum claim.</li>
<li>2.       If <em>Requesti</em> £ <em>Available</em>, go to step 3.  Otherwise <em>Pi</em>  must wait, since resources are not available.</li>
<li>3.       Pretend to allocate requested resources to <em>Pi</em>by modifying the state as follows:
<ol>
<li>                   <em>Available</em> = <em>Available  </em>–<em> Request; </em></li>
<li>                   <em>Allocationi</em> = <em>Allocationi</em> + <em>Requesti</em>;</li>
<li>                   <em>Needi </em>=<em> Needi</em> – <em>Requesti; </em></li>
<li><em>If safe </em>Þ<em> the resources are allocated to Pi. </em></li>
<li><em>If unsafe </em>Þ<em> Pi must wait, and the old resource-allocation state is restored </em></li>
</ol>
</li>
</ol>
</li>
</ol>
<p>&nbsp;</p>
<p><strong>Example of Banker’s Algorithm</strong></p>
<p>&nbsp;</p>
<ol>
<li>5 processes <em>P</em>0  through <em>P</em>4;</li>
<li>      3 resource types:</li>
<li>              <em>A</em> (10 instances),  <em>B</em> (5instances), and <em>C</em> (7 instances).</li>
<li>Snapshot at time <em>T</em>0:</li>
<li>                             <em><span style="text-decoration:underline;">Allocation</span>   <span style="text-decoration:underline;">Max</span>   <span style="text-decoration:underline;">Available</span> </em></li>
<li><em>                             A B C          A B C          A B C </em></li>
<li>                   <em>P</em>0     0 1 0  7 5 3 3 3 2</li>
<li>                    <em>P</em>1    2 0 0 3 2 2 </li>
<li>                    <em>P</em>2    3 0 2 9 0 2</li>
<li>                    <em>P</em>3    2 1 1 2 2 2</li>
<li>                    <em>P</em>4    0 0 2  4 3 3                      </li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ol>
<li>The content of the matrix <em>Need</em> is defined to be <em>Max</em> – <em>Allocation</em>.</li>
<li>                             <em><span style="text-decoration:underline;">Need</span></em></li>
<li>                             <em>A B C </em></li>
<li>                    <em>P</em>0    7 4 3</li>
<li>                    <em>P</em>1    1 2 2</li>
<li>                    <em>P</em>2    6 0 0</li>
<li>                    <em>P</em>3    0 1 1</li>
<li>                    <em>P</em>4    4 3 1</li>
<li>The system is in a safe state since the sequence &lt; <em>P</em>1, <em>P</em>3, <em>P</em>4, <em>P</em>2, <em>P</em>0&gt; satisfies safety criteria.</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Example:  <em>P</em>1 Request (1,0,2)</strong></p>
<p>&nbsp;</p>
<ol>
<li>Check that Request £ Available (that is, (1,0,2) £ (3,3,2) Þ true<em>. </em></li>
<li><em>                             <span style="text-decoration:underline;">Allocation</span>   <span style="text-decoration:underline;">Need</span>  <span style="text-decoration:underline;">Available</span> </em></li>
<li><em>                             A B C          A B C          A B C </em></li>
<li>                   <em>P</em>0     0 1 0 7 4 3 2 3 0</li>
<li>                   <em>P</em>1     3 0 2  0 2 0  </li>
<li>                   <em>P</em>2     3 0 1 6 0 0</li>
<li>                   <em>P</em>3     2 1 1 0 1 1</li>
<li>                   <em>P</em>4     0 0 2 4 3 1</li>
<li>Executing safety algorithm shows that sequence &lt; <em>P</em>1, <em>P</em>3, <em>P</em>4, <em>P</em>0, <em>P</em>2&gt; satisfies safety requirement.</li>
<li>Can request for (3,3,0) by <em>P</em>4 be granted?</li>
<li>Can request for (0,2,0) by <em>P</em>0 be granted?</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Deadlock Detection</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ol>
<li>Allow system to enter deadlock state</li>
<li>Detection algorithm</li>
<li>Recovery scheme</li>
</ol>
<p>&nbsp;</p>
<p><strong>Single Instance of Each Resource Type</strong></p>
<p>&nbsp;</p>
<ol>
<li>Maintain <em>wait-for</em>graph
<ol>
<li>Nodes are processes.</li>
<li><em>Pi</em> ® <em>Pj   </em>if <em>Pi </em>is waiting for<em> Pj.</em></li>
</ol>
</li>
<li>Periodically invoke an algorithm that searches for a cycle in the graph. If there is a cycle, there exists a deadlock.</li>
<li>An algorithm to detect a cycle in a graph requires an order of<em> n</em>2 operations, where <em>n</em> is the number of vertices in the graph.</li>
</ol>
<p>&nbsp;</p>
<p><strong>Resource-Allocation Graph and Wait-for Graph</strong></p>
<p>&nbsp;</p>
<p><strong> </strong></p>
<p><strong>The Deadlock Problem</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>1.     </strong><strong>A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.</strong></li>
<li><strong>2.     </strong><strong>Example </strong>
<ol>
<li><strong>1.     </strong><strong>System has 2 disk drives.</strong></li>
<li><strong>2.     </strong><strong><em>P</em></strong><strong>1 and <em>P</em>2 each hold one disk drive and each needs another one.</strong></li>
</ol>
</li>
<li><strong>3.     </strong><strong>Example </strong>
<ol>
<li><strong>1.     </strong><strong>semaphores <em>A</em> and<em> B</em>, initialized to 1</strong>
<ol>
<li><strong>1.     </strong><strong>    <em>P</em>0              <em>P</em>1</strong></li>
<li><strong>2.     </strong><strong>wait (A);              wait(B)</strong></li>
<li><strong>3.     </strong><strong>wait (B);               wait(A)</strong></li>
</ol>
</li>
</ol>
</li>
</ol>
<p><strong></strong> <img class="aligncenter size-medium wp-image-1408" title="64" src="http://meherchilakalapudi.files.wordpress.com/2011/12/641.jpg?w=300&#038;h=264" alt="" width="300" height="264" /></p>
<p><strong></strong> </p>
<p>Resource-Allocation Graph    Corresponding wait-for graph</p>
<p>&nbsp;</p>
<p><strong>Several Instances of a Resource Type</strong></p>
<p>&nbsp;</p>
<ol>
<li><strong><em>Available</em></strong><em>:</em>  A vector of length <em>m</em> indicates the number of available resources of each type.</li>
<li><strong><em>Allocation</em></strong><em>:</em>  An <em>n </em>x<em> m</em> matrix defines the number of resources of each type currently allocated to each process.</li>
<li><strong><em>Request</em></strong><em>:</em>  An <em>n </em>x<em> m</em> matrix indicates the current request  of each process.  If <em>Request </em>[<em>ij</em>] = <em>k</em>, then process<em> Pi</em> is requesting<em> k</em> more instances of resource type. <em>Rj</em>.</li>
</ol>
<p>&nbsp;</p>
<p><strong>Detection Algorithm</strong></p>
<p>&nbsp;</p>
<p>1.       Let <em>Work</em> and <em>Finish</em> be vectors of length <em>m</em> and <em>n</em>, respectively Initialize:</p>
<p>(a) <em>Work</em> = <em>Available</em></p>
<p>(b)     For <em>i</em> = 1,2, …,<em> n</em>, if <em>Allocationi</em> ¹ 0, then<br />
<em>Finish</em>[i] = false;otherwise, <em>Finish</em>[i] = <em>true</em>.</p>
<p>2.       Find an index <em>i </em>such that both:</p>
<p>(a)     <em>Finish</em>[<em>i</em>] == <em>false</em></p>
<p>(b)     <em>Requesti</em> £ <em>Work</em></p>
<p>If no such <em>i</em> exists, go to step 4.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>3.       <em>Work</em> = <em>Work</em> + <em>Allocationi</em><br />
<em>Finish</em>[<em>i</em>] = <em>true</em><br />
go to step 2.</p>
<p>4.       If <em>Finish</em>[<em>i</em>] == false, for some <em>i</em>, 1 £ <em>i</em> £  <em>n</em>, then the system is in deadlock state. Moreover, if <em>Finish</em>[<em>i</em>] == <em>false</em>, then <em>Pi</em> is deadlocked.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Algorithm requires an order of O(<em>m </em>x<em> n</em>2) operations to detect whether the system is in deadlocked state</strong>.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Example of Detection Algorithm</strong></p>
<p>&nbsp;</p>
<ol>
<li>Five processes <em>P</em>0 through <em>P</em>4; three resource types<br />
A (7 instances), <em>B </em>(2 instances), and <em>C</em> (6 instances).</li>
<li>Snapshot at time <em>T</em>0:</li>
<li>                              <em><span style="text-decoration:underline;">Allocation</span>  <span style="text-decoration:underline;">Request</span>       <span style="text-decoration:underline;">Available </span></em></li>
<li>                             <em>A B C          A B C          A B C </em></li>
<li>                   <em>P</em>0     0 1 0 0 0 0 0 0 0</li>
<li>                   <em>P</em>1     2 0 0 2 0 2</li>
<li>                   <em>P</em>2     3 0 3  0 0 0</li>
<li>                   <em>P</em>3     2 1 1 1 0 0</li>
<li>                   <em>P</em>4     0 0 2 0 0 2</li>
<li>Sequence &lt;<em>P</em>0, <em>P</em>2, <em>P</em>3, <em>P</em>1, <em>P</em>4&gt; will result in <em>Finish</em>[<em>i</em>] = true for all <em>i</em>.</li>
</ol>
<p>&nbsp;</p>
<ol>
<li><em>P</em>2 requests an additional instance of type<em> C</em>.</li>
<li>                             <em><span style="text-decoration:underline;">Request</span> </em></li>
<li><em>                             A B C </em></li>
<li>                    <em>P</em>0    0 0 0</li>
<li>                    <em>P</em>1    2 0 1</li>
<li>                   <em>P</em>2     0 0 1</li>
<li>                   <em>P</em>3     1 0 0</li>
<li>                   <em>P</em>4     0 0 2</li>
<li>State of system?
<ol>
<li>Can reclaim resources held by process <em>P</em>0, but insufficient resources to fulfill other processes; requests.</li>
<li>Deadlock exists, consisting of processes <em>P</em>1,  <em>P</em>2, <em>P</em>3, and <em>P</em>4.</li>
</ol>
</li>
</ol>
<p>&nbsp;</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Detection-Algorithm Usage</strong></p>
<p><strong> </strong></p>
<ol>
<li>When, and how often, to invoke depends on:
<ol>
<li>How often a deadlock is likely to occur?</li>
<li>How many processes will need to be rolled back?
<ol>
<li>one for each disjoint cycle</li>
</ol>
</li>
</ol>
</li>
<li>If detection algorithm is invoked arbitrarily, there may be many cycles in the resource graph and so we would not be able to tell which of the many deadlocked processes “caused” the deadlock.</li>
</ol>
<p>&nbsp;</p>
<p><strong>Recovery from Deadlock:  Process Termination</strong></p>
<p>&nbsp;</p>
<ol>
<li>Abort all deadlocked processes.</li>
<li>Abort one process at a time until the deadlock cycle is eliminated.</li>
<li>In which order should we choose to abort?
<ol>
<li>Priority of the process.</li>
<li>How long process has computed, and how much longer to completion.</li>
<li>Resources the process has used.</li>
<li>Resources process needs to complete.</li>
<li>How many processes will need to be terminated.</li>
<li>Is process interactive or batch?</li>
</ol>
</li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Recovery from Deadlock: Resource Preemption</strong></p>
<p><strong> </strong></p>
<ol>
<li>Selecting a victim – minimize cost.</li>
<li>Rollback – return to some safe state, restart process for that state.</li>
<li>Starvation –  same process may always be picked as victim, include number of rollback in cost factor.</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>………………………………………………………………………………&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/deadlocks-in-operating-system/'>Deadlocks In Operating System</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1399/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1399&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/12/13/deadlocks-in-operating-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/57.jpg?w=300" medium="image">
			<media:title type="html">57</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/58.jpg?w=300" medium="image">
			<media:title type="html">58</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/59.jpg?w=191" medium="image">
			<media:title type="html">59</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/60.jpg?w=190" medium="image">
			<media:title type="html">60</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/61.jpg?w=252" medium="image">
			<media:title type="html">61</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/62.jpg?w=300" medium="image">
			<media:title type="html">62</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/63.jpg?w=284" medium="image">
			<media:title type="html">63</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/641.jpg?w=300" medium="image">
			<media:title type="html">64</media:title>
		</media:content>
	</item>
		<item>
		<title>CPU Scheduling in Operating system</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/12/04/cpu-scheduling-in-operating-system/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/12/04/cpu-scheduling-in-operating-system/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 12:19:55 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[CPU Scheduling in Operating system]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1373</guid>
		<description><![CDATA[ CPU Scheduling(Chapter -5) Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Thread Scheduling Operating Systems Examples Java Thread Scheduling Algorithm Evaluation &#160; Basic Concepts   Maximum CPU utilization obtained with multiprogramming CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait CPU burst distribution   Alternating Sequence [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1373&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="text-align:center;"><span style="text-decoration:underline;"><strong> CPU Scheduling(Chapter -5)</strong></span></h2>
<ol>
<li>Basic Concepts</li>
<li>Scheduling Criteria</li>
<li>Scheduling Algorithms</li>
<li>Multiple-Processor Scheduling</li>
<li>Real-Time Scheduling</li>
<li>Thread Scheduling</li>
<li>Operating Systems Examples</li>
<li>Java Thread Scheduling</li>
<li>Algorithm Evaluation</li>
</ol>
<p>&nbsp;</p>
<p><strong>Basic Concepts</strong><strong></strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Maximum CPU utilization obtained with multiprogramming</strong></li>
<li><strong>CPU–I/O Burst Cycle – Process execution consists of a <em>cycle</em> of CPU execution and I/O wait</strong></li>
<li><strong>CPU burst distribution</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong>Alternating Sequence of CPU And I/O Bursts</strong></p>
<p style="text-align:center;"><img class="aligncenter size-medium wp-image-1374" title="34" src="http://meherchilakalapudi.files.wordpress.com/2011/12/34.jpg?w=153&#038;h=300" alt="" width="153" height="300" /></p>
<p style="text-align:center;"><strong>Histogram of CPU-burst Times</strong><strong></strong></p>
<p style="text-align:center;"><img class="aligncenter  wp-image-1375" title="35" src="http://meherchilakalapudi.files.wordpress.com/2011/12/35.jpg?w=300&#038;h=204" alt="" width="300" height="204" /></p>
<p><strong>CPU Scheduler</strong></p>
<p>&nbsp;</p>
<ol>
<li>Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them</li>
<li>CPU scheduling decisions may take place when a process:</li>
<ol>
<li>1.         Switches from running to waiting state</li>
<li>2.         Switches from running to ready state</li>
<li>3.         Switches from waiting to ready</li>
<li>4.         Terminates</li>
</ol>
<li>Scheduling under 1 and 4 is <em>nonpreemptive</em></li>
<li>All other scheduling is <em>preemptive</em></li>
</ol>
<p><strong> </strong></p>
<p><strong>Dispatcher</strong></p>
<p><strong> </strong></p>
<ol>
<li>Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves:</li>
<ol>
<li>switching context</li>
<li>switching to user mode</li>
<li>jumping to the proper location in the user program to restart that program</li>
</ol>
<li><em>Dispatch latency</em> – time it takes for the dispatcher to stop one process and start another running</li>
</ol>
<p>&nbsp;</p>
<p><strong>Scheduling Criteria</strong></p>
<p>&nbsp;</p>
<ol>
<li>CPU utilization – keep the CPU as busy as possible</li>
<li>Throughput – # of processes that complete their execution per time unit</li>
<li>Turnaround time – amount of time to execute a particular process</li>
<li>Waiting time – amount of time a process has been waiting in the ready queue</li>
<li>Response time – amount of time it takes from when a request was submitted until the first response is produced, <strong>not</strong> output  (for time-sharing environment)</li>
</ol>
<p>&nbsp;</p>
<p><strong>Optimization Criteria</strong></p>
<p>&nbsp;</p>
<ol>
<li>Max CPU utilization</li>
<li>Max throughput</li>
<li>Min turnaround time</li>
<li>Min waiting time</li>
<li>Min response time</li>
</ol>
<p>&nbsp;</p>
<p><strong>First-Come, First-Served (FCFS) Scheduling</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/36.jpg"><img class="aligncenter size-medium wp-image-1376" title="36" src="http://meherchilakalapudi.files.wordpress.com/2011/12/36.jpg?w=300&#038;h=199" alt="" width="300" height="199" /></a></strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/37.jpg"><img class="aligncenter size-medium wp-image-1377" title="37" src="http://meherchilakalapudi.files.wordpress.com/2011/12/37.jpg?w=300&#038;h=192" alt="" width="300" height="192" /></a></strong></p>
<p><strong>Shortest-Job-First (SJF) Scheduling</strong></p>
<p><strong> </strong></p>
<ol>
<li>Associate with each process the length of its next CPU burst.  Use these lengths to schedule the process with the shortest time</li>
<li>Two schemes:</li>
</ol>
<ol>
<li>nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU burst</li>
<li>preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt.  This scheme is know as the<br />
Shortest-Remaining-Time-First (SRTF)</li>
</ol>
<ol start="3">
<li>SJF is optimal – gives minimum average waiting time for a given set of processes</li>
</ol>
<p>&nbsp;</p>
<p><strong>Example of Non-Preemptive SJF</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/38.jpg"><img class="aligncenter size-medium wp-image-1378" title="38" src="http://meherchilakalapudi.files.wordpress.com/2011/12/38.jpg?w=300&#038;h=201" alt="" width="300" height="201" /></a></strong></p>
<p><strong>Example of Preemptive SJF</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/39.jpg"><img class="aligncenter size-medium wp-image-1379" title="39" src="http://meherchilakalapudi.files.wordpress.com/2011/12/39.jpg?w=300&#038;h=225" alt="" width="300" height="225" /></a></strong></p>
<p><strong><strong>Determining Length of Next CPU Burst</strong></strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/40.jpg"><img class="aligncenter size-medium wp-image-1380" title="40" src="http://meherchilakalapudi.files.wordpress.com/2011/12/40.jpg?w=300&#038;h=142" alt="" width="300" height="142" /></a></strong></p>
<p><strong>Prediction of the Length of the Next CPU Burst</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/41.jpg"><img class="aligncenter size-medium wp-image-1381" title="41" src="http://meherchilakalapudi.files.wordpress.com/2011/12/41.jpg?w=300&#038;h=225" alt="" width="300" height="225" /></a></strong></p>
<p><strong>Examples of Exponential Averaging</strong></p>
<p>&nbsp;</p>
<ol>
<li>a =0</li>
<ol>
<li>tn+1 = tn</li>
<li>Recent history does not count</li>
</ol>
<li>a =1</li>
<ol>
<li> tn+1 = a <em>t</em>n</li>
<li>Only the actual last CPU burst counts</li>
</ol>
<li>If we expand the formula, we get:</li>
<ol>
<ol>
<li>t<em>n</em>+1 = a t<em>n</em>+(1<em> &#8211; </em>a<em>)</em>a <em>tn </em>-1<em> </em>+ …</li>
<li>            <em>+(</em>1 &#8211; a <em>)j</em> a <em>tn</em> -<em>j </em>+ …</li>
<li>            <em>+(</em>1 &#8211; a <em>)n</em> +1 t0</li>
</ol>
</ol>
<li>Since both a and (1 &#8211; a) are less than or equal to 1, each successive term has less weight than its predecessor</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Priority Scheduling</strong></p>
<ol>
<li>A priority number (integer) is associated with each process</li>
<li>The CPU is allocated to the process with the highest priority (smallest integer º highest priority)</li>
<ol>
<li>Preemptive</li>
<li>nonpreemptive</li>
</ol>
<li>SJF is a priority scheduling where priority is the predicted next CPU burst time</li>
<li>Problem º Starvation – low priority processes may never execute</li>
<li>Solution º Aging – as time progresses increase the priority of the process</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Round Robin (RR)</strong></p>
<p>&nbsp;</p>
<ol>
<li>Each process gets a small unit of CPU time (<em>time quantum</em>), usually 10-100 milliseconds.  After this time has elapsed, the process is preempted and added to the end of the ready queue.</li>
<li>If there are <em>n</em> processes in the ready queue and the time quantum is <em>q</em>, then each process gets 1/<em>n</em> of the CPU time in chunks of at most <em>q</em> time units at once.  No process waits more than (<em>n</em>-1)<em>q </em>time units.</li>
<li>Performance</li>
<ol>
<li><em>q</em> large Þ FIFO</li>
<li><em>q </em>small Þ <em>q </em>must be large with respect to context switch, otherwise overhead is too high</li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Example of RR with Time Quantum = 20</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/42.jpg"><img class="aligncenter size-medium wp-image-1382" title="42" src="http://meherchilakalapudi.files.wordpress.com/2011/12/42.jpg?w=300&#038;h=180" alt="" width="300" height="180" /></a></strong></p>
<p><strong>Time Quantum and Context Switch Time</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/43.jpg"><img class="aligncenter size-medium wp-image-1383" title="43" src="http://meherchilakalapudi.files.wordpress.com/2011/12/43.jpg?w=300&#038;h=155" alt="" width="300" height="155" /></a></strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/44.jpg"><img class="aligncenter size-medium wp-image-1384" title="44" src="http://meherchilakalapudi.files.wordpress.com/2011/12/44.jpg?w=300&#038;h=255" alt="" width="300" height="255" /></a></strong></p>
<p>                 <strong>Multilevel Queue</strong></p>
<p>&nbsp;</p>
<ol>
<li>Ready queue is partitioned into separate queues:<br />
foreground (interactive)<br />
background (batch)</li>
<li>Each queue has its own scheduling algorithm</li>
</ol>
<ol>
<li>foreground – RR</li>
<li>background – FCFS</li>
<li>Fixed priority scheduling; (i.e., serve all from foreground then from background).  Possibility of starvation.</li>
<li>Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR</li>
<li>20% to background in FCFS</li>
</ol>
<ol start="3">
<li>Scheduling must be done between the queues</li>
</ol>
<p>&nbsp;</p>
<p><strong>Multilevel Queue Scheduling</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/45.jpg"><img class="aligncenter size-medium wp-image-1385" title="45" src="http://meherchilakalapudi.files.wordpress.com/2011/12/45.jpg?w=300&#038;h=200" alt="" width="300" height="200" /></a></strong></p>
<p><strong>Multilevel Feedback Queue</strong></p>
<ol>
<li>A process can move between the various queues; aging can be implemented this way</li>
<li>Multilevel-feedback-queue scheduler defined by the following parameters:</li>
<ol>
<li>number of queues</li>
<li>scheduling algorithms for each queue</li>
<li>method used to determine when to upgrade a process</li>
<li>method used to determine when to demote a process</li>
<li>method used to determine which queue a process will enter when that process needs service</li>
</ol>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Example of Multilevel Feedback Queue</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ol>
<li>Three queues:</li>
<ol>
<li><em>Q</em>0 – RR with time quantum 8 milliseconds</li>
<li><em>Q</em>1 – RR time quantum 16 milliseconds</li>
<li><em>Q</em>2 – FCFS</li>
</ol>
<li>Scheduling</li>
<ol>
<li>A new job enters queue <em>Q0 </em>which is served<em> </em>FCFS. When it gains CPU, job receives 8 milliseconds.  If it does not finish in 8 milliseconds, job is moved to queue <em>Q</em>1.</li>
<li>At <em>Q</em>1 job is again served FCFS and receives 16 additional milliseconds.  If it still does not complete, it is preempted and moved to queue <em>Q</em>2.</li>
</ol>
</ol>
<p> <strong>Multilevel Feedback Queues</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/46.jpg"><img class="aligncenter size-medium wp-image-1386" title="46" src="http://meherchilakalapudi.files.wordpress.com/2011/12/46.jpg?w=300&#038;h=197" alt="" width="300" height="197" /></a></strong></p>
<p><strong>Multiple-Processor Scheduling</strong></p>
<p>&nbsp;</p>
<ol>
<li>CPU scheduling more complex when multiple CPUs are available</li>
<li><em>Homogeneous processors</em> within a multiprocessor</li>
<li><em>Load sharing</em></li>
<li><em>Asymmetric multiprocessing</em> – only one processor accesses the system data structures, alleviating the need for data sharing</li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Real-Time Scheduling</strong></p>
<p><strong> </strong></p>
<ol>
<li><em>Hard real-time</em> systems – required to complete a critical task within a guaranteed amount of time</li>
<li><em>Soft real-time</em> computing – requires that critical processes receive priority over less fortunate ones</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Thread Scheduling</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ol>
<li>Local Scheduling – How the threads library decides which thread to put onto an available LWP</li>
<li>Global Scheduling – How the kernel decides which kernel thread to run next</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Pthread Scheduling API</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>#include &lt;pthread.h&gt;</p>
<p>#include &lt;stdio.h&gt;</p>
<p>#define NUM THREADS 5</p>
<p>int main(int argc, char *argv[])</p>
<p>{</p>
<p>             int i;</p>
<p>            pthread t tid[NUM THREADS];</p>
<p>            pthread attr t attr;</p>
<p>            /* get the default attributes */</p>
<p>            pthread attr init(&amp;attr);</p>
<p>            /* set the scheduling algorithm to PROCESS or SYSTEM */</p>
<p>            pthread attr setscope(&amp;attr, PTHREAD SCOPE SYSTEM);</p>
<p>            /* set the scheduling policy &#8211; FIFO, RT, or OTHER */</p>
<p>            pthread attr setschedpolicy(&amp;attr, SCHED OTHER);</p>
<p>            /* create the threads */</p>
<p>            for (i = 0; i &lt; NUM THREADS; i++)</p>
<p>                        pthread create(&amp;tid[i],&amp;attr,runner,NULL);</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Pthread Scheduling API</strong></p>
<p>&nbsp;</p>
<p>            /* now join on each thread */</p>
<p>            for (i = 0; i &lt; NUM THREADS; i++)</p>
<p>                        pthread join(tid[i], NULL);</p>
<p>}</p>
<p> /* Each thread will begin control in this function */</p>
<p>void *runner(void *param)</p>
<p>{</p>
<p>            printf(&#8220;I am a thread\n&#8221;);</p>
<p>            pthread exit(0);</p>
<p>}</p>
<p> <strong>Operating System Examples</strong></p>
<p><strong> </strong></p>
<ol>
<li>Solaris scheduling</li>
<li>Windows XP scheduling</li>
<li>Linux scheduling</li>
</ol>
<p>&nbsp;</p>
<p><strong>Solaris 2 Scheduling</strong></p>
<p><strong></strong> <a href="http://meherchilakalapudi.files.wordpress.com/2011/12/47.jpg"><img class="aligncenter size-medium wp-image-1387" title="47" src="http://meherchilakalapudi.files.wordpress.com/2011/12/47.jpg?w=294&#038;h=300" alt="" width="294" height="300" /></a></p>
<p><strong></strong> </p>
<p><strong>Windows XP Priorities</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/48.jpg"><img class="aligncenter size-medium wp-image-1388" title="48" src="http://meherchilakalapudi.files.wordpress.com/2011/12/48.jpg?w=300&#038;h=126" alt="" width="300" height="126" /></a></strong></p>
<p><strong>Linux Scheduling</strong></p>
<p><strong> </strong></p>
<ol>
<li>Two algorithms: time-sharing and real-time</li>
<li>Time-sharing</li>
<ol>
<li>Prioritized credit-based – process with most credits is scheduled next</li>
<li>Credit subtracted when timer interrupt occurs</li>
<li>When credit = 0, another process chosen</li>
<li>When all processes have credit = 0, recrediting occurs</li>
<ol>
<li>Based on factors including priority and history</li>
</ol>
</ol>
<li>Real-time</li>
<ol>
<li>Soft real-time</li>
<li>Posix.1b compliant – two classes</li>
<ol>
<li>FCFS and RR</li>
<li>Highest priority process always runs first</li>
</ol>
</ol>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>The Relationship Between Priorities and Time-slice length</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/49.jpg"><img class="aligncenter size-medium wp-image-1389" title="49" src="http://meherchilakalapudi.files.wordpress.com/2011/12/49.jpg?w=300&#038;h=183" alt="" width="300" height="183" /></a></strong></p>
<p><strong></strong> <a href="http://meherchilakalapudi.files.wordpress.com/2011/12/50.jpg"><img class="aligncenter size-medium wp-image-1390" title="50" src="http://meherchilakalapudi.files.wordpress.com/2011/12/50.jpg?w=300&#038;h=162" alt="" width="300" height="162" /></a></p>
<p><strong>Algorithm Evaluation</strong></p>
<p>&nbsp;</p>
<ol>
<li>Deterministic modeling – takes a particular predetermined workload and defines the performance of each algorithm  for that workload</li>
<li>Queueing models</li>
<li>Implementation<a href="http://meherchilakalapudi.files.wordpress.com/2011/12/52.jpg"><img class="aligncenter size-medium wp-image-1392" title="52" src="http://meherchilakalapudi.files.wordpress.com/2011/12/52.jpg?w=300&#038;h=108" alt="" width="300" height="108" /></a><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/51.jpg"><img class="aligncenter size-medium wp-image-1391" title="51" src="http://meherchilakalapudi.files.wordpress.com/2011/12/51.jpg?w=300&#038;h=177" alt="" width="300" height="177" /></a></li>
</ol>
<p>&nbsp;</p>
<p><img class="aligncenter size-medium wp-image-1393" title="53" src="http://meherchilakalapudi.files.wordpress.com/2011/12/53.jpg?w=300&#038;h=47" alt="" width="300" height="47" /></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/54.jpg"><img class="aligncenter size-medium wp-image-1395" title="54" src="http://meherchilakalapudi.files.wordpress.com/2011/12/54.jpg?w=300&#038;h=49" alt="" width="300" height="49" /></a></p>
<p>&nbsp;</p>
<p><img class="aligncenter size-medium wp-image-1394" title="55" src="http://meherchilakalapudi.files.wordpress.com/2011/12/55.jpg?w=300&#038;h=51" alt="" width="300" height="51" /></p>
<p><strong>Dispatch Latency</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/12/56.jpg"><img class="aligncenter size-medium wp-image-1396" title="56" src="http://meherchilakalapudi.files.wordpress.com/2011/12/56.jpg?w=300&#038;h=222" alt="" width="300" height="222" /></a></strong></p>
<p><strong>Java Thread Scheduling</strong></p>
<p>&nbsp;</p>
<ol>
<li>JVM Uses a Preemptive, Priority-Based Scheduling Algorithm</li>
<li>FIFO Queue is Used if There Are Multiple Threads With the Same Priority</li>
</ol>
<p>&nbsp;</p>
<p>JVM Schedules a Thread to Run When:</p>
<ol>
<ol>
<li>The Currently Running Thread Exits the Runnable State</li>
<li>A Higher Priority Thread Enters the Runnable State</li>
</ol>
</ol>
<p>* Note – the JVM Does Not Specify Whether Threads are Time-Sliced or Not</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Time-Slicing</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Since the JVM Doesn’t Ensure Time-Slicing, the yield() Method</p>
<p>May Be Used:</p>
<p>            while (true) {</p>
<p>                        // perform CPU-intensive task</p>
<p>                        . . .</p>
<p>                        Thread.yield();</p>
<p>            }</p>
<p>This Yields Control to Another Thread of Equal Priority</p>
<p><strong>Thread Priorities</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong><span style="text-decoration:underline;">Priority</span>                                   <span style="text-decoration:underline;">Comment </span></strong></p>
<p>Thread.MIN_PRIORITY                   Minimum Thread Priority</p>
<p>Thread.MAX_PRIORITY                    Maximum Thread Priority</p>
<p>Thread.NORM_PRIORITY                  Default Thread Priority</p>
<p>Priorities May Be Set Using setPriority() method:</p>
<p>            setPriority(Thread.NORM_PRIORITY + 2);</p>
<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..</p>
<p><strong></strong> </p>
<p><strong></strong> </p>
<p><strong></strong> </p>
<p><strong></strong> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/cpu-scheduling-in-operating-system/'>CPU Scheduling in Operating system</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1373/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1373&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/12/04/cpu-scheduling-in-operating-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/34.jpg?w=153" medium="image">
			<media:title type="html">34</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/35.jpg?w=300" medium="image">
			<media:title type="html">35</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/36.jpg?w=300" medium="image">
			<media:title type="html">36</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/37.jpg?w=300" medium="image">
			<media:title type="html">37</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/38.jpg?w=300" medium="image">
			<media:title type="html">38</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/39.jpg?w=300" medium="image">
			<media:title type="html">39</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/40.jpg?w=300" medium="image">
			<media:title type="html">40</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/41.jpg?w=300" medium="image">
			<media:title type="html">41</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/42.jpg?w=300" medium="image">
			<media:title type="html">42</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/43.jpg?w=300" medium="image">
			<media:title type="html">43</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/44.jpg?w=300" medium="image">
			<media:title type="html">44</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/45.jpg?w=300" medium="image">
			<media:title type="html">45</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/46.jpg?w=300" medium="image">
			<media:title type="html">46</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/47.jpg?w=294" medium="image">
			<media:title type="html">47</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/48.jpg?w=300" medium="image">
			<media:title type="html">48</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/49.jpg?w=300" medium="image">
			<media:title type="html">49</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/50.jpg?w=300" medium="image">
			<media:title type="html">50</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/52.jpg?w=300" medium="image">
			<media:title type="html">52</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/51.jpg?w=300" medium="image">
			<media:title type="html">51</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/53.jpg?w=300" medium="image">
			<media:title type="html">53</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/54.jpg?w=300" medium="image">
			<media:title type="html">54</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/55.jpg?w=300" medium="image">
			<media:title type="html">55</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/12/56.jpg?w=300" medium="image">
			<media:title type="html">56</media:title>
		</media:content>
	</item>
		<item>
		<title>Operating Systems Introduction-1</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/11/20/operating-systems-introduction-1/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/11/20/operating-systems-introduction-1/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 09:03:51 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[Operating Systems Introduction-1]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1328</guid>
		<description><![CDATA[Operating Systems Introduction   Chapter 1: Introduction What Operating Systems Do Computer-System Organization Computer-System Architecture Operating-System Structure Operating-System Operations Process Management Memory Management Storage Management Protection and Security Distributed Systems Special-Purpose Systems Computing Environments   Objectives To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1328&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1 style="text-align:center;"><span style="text-decoration:underline;"><span style="color:#0000ff;text-decoration:underline;">Operating Systems Introduction</span></span></h1>
<h1 style="text-align:center;"> </h1>
<p><strong>Chapter 1: Introduction</strong><strong></strong></p>
<ol>
<li><strong>What Operating Systems Do</strong></li>
<li><strong>Computer-System Organization</strong></li>
<li><strong>Computer-System Architecture</strong></li>
<li><strong>Operating-System Structure</strong></li>
<li><strong>Operating-System Operations</strong></li>
<li><strong>Process Management</strong></li>
<li><strong>Memory Management</strong></li>
<li><strong>Storage Management</strong></li>
<li><strong>Protection and Security</strong></li>
<li><strong>Distributed Systems</strong></li>
<li><strong>Special-Purpose Systems</strong></li>
<li><strong>Computing Environments</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong>Objectives</strong></p>
<ol>
<li><strong>To provide a grand tour of the major operating systems components</strong></li>
<li><strong>To provide coverage of basic computer system organization</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>What is an Operating System?</strong><strong></strong></p>
<ol>
<li><strong>A program that acts as an intermediary between a user of a computer and the computer hardware.</strong></li>
<li><strong>Operating system goals:</strong></li>
<ol>
<li><strong>Execute user programs and make solving user problems easier.</strong></li>
<li><strong>Make the computer system convenient to use.</strong></li>
</ol>
<li><strong>Use the computer hardware in an efficient manner.</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Computer System Structure</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Computer system can be divided into four components</strong></li>
<ol>
<li><strong>Hardware – provides basic computing resources</strong></li>
<ol>
<li><strong>CPU, memory, I/O devices</strong></li>
</ol>
<li><strong>Operating system</strong></li>
<ol>
<li><strong>Controls and coordinates use of hardware among various applications and users</strong></li>
</ol>
<li><strong>Application programs – define the ways in which the system resources are used to solve the computing problems of the users</strong></li>
<ol>
<li><strong>Word processors, compilers, web browsers, database systems, video games</strong></li>
</ol>
<li><strong>Users</strong></li>
<ol>
<li><strong>People, machines, other computers</strong></li>
</ol>
</ol>
</ol>
<p><strong><img class="aligncenter size-medium wp-image-1329" title="1" src="http://meherchilakalapudi.files.wordpress.com/2011/11/1.jpg?w=300&#038;h=244" alt="" width="300" height="244" /></strong></p>
<p><strong></strong> </p>
<p><strong>Operating System Definition</strong></p>
<ol>
<li><strong>OS is a resource allocator</strong></li>
<ol>
<li><strong>Manages all resources</strong></li>
<li><strong>Decides between conflicting requests for efficient and fair resource use</strong></li>
</ol>
<li><strong>OS is a control program</strong></li>
<ol>
<li><strong>Controls execution of programs to prevent errors and improper use of the computer</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<ol start="3">
<li><strong>No universally accepted definition</strong></li>
<li><strong>“Everything a vendor ships when you order an operating system” is good approximation</strong></li>
<ol>
<li><strong>But varies wildly</strong></li>
</ol>
<li><strong>“The one program running at all times on the computer” is the kernel.  Everything else is either a system program (ships with the operating system) or an application program</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong>Computer Startup</strong><strong></strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>bootstrap program</strong><strong> is loaded at power-up or reboot</strong></li>
<ol>
<li><strong>Typically stored in ROM or EPROM, generally known as firmware</strong></li>
<li><strong>Initializates all aspects of system</strong></li>
<li><strong>Loads operating system kernel and starts execution</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Computer System Organization</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Computer-system operation</strong></li>
<ol>
<li><strong>One or more CPUs, device controllers connect through common bus providing access to shared memory</strong></li>
<li><strong>Concurrent execution of CPUs and devices competing for memory cycles</strong></li>
</ol>
</ol>
<p><strong><img class="aligncenter size-medium wp-image-1330" title="2" src="http://meherchilakalapudi.files.wordpress.com/2011/11/2.jpg?w=300&#038;h=162" alt="" width="300" height="162" /></strong></p>
<p><strong></strong> </p>
<p><strong>Computer-System Operation</strong></p>
<ol>
<li><strong>I/O devices and the CPU can execute concurrently.</strong></li>
<li><strong>Each device controller is in charge of a particular device type.</strong></li>
<li><strong>Each device controller has a local buffer.</strong></li>
<li><strong>CPU moves data from/to main memory to/from local buffers</strong></li>
<li><strong>I/O is from the device to local buffer of controller.</strong></li>
<li><strong>Device controller informs CPU that it has finished its operation by causing an <em>interrupt</em>.</strong></li>
</ol>
<p><strong>Common Functions of Interrupts</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Interrupt transfers control to the interrupt service routine generally, through the <em>interrupt vector</em>, which contains the addresses of all the service routines.</strong></li>
<li><strong>Interrupt architecture must save the address of the interrupted instruction.</strong></li>
<li><strong>Incoming interrupts are <em>disabled</em> while another interrupt is being processed to prevent a <em>lost interrupt</em>.</strong></li>
<li><strong>A <em>trap</em> is a software-generated interrupt caused either by an error or a user request.</strong></li>
<li><strong>An operating system is <em>interrupt</em> driven.</strong></li>
</ol>
<p><strong>Interrupt Handling</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>The operating system preserves the state of the CPU by storing registers and the program counter.</strong></li>
<li><strong>Determines which type of interrupt has occurred:</strong></li>
<ol>
<li><strong><em>polling</em></strong></li>
<li><strong><em>vectored</em> interrupt system</strong></li>
</ol>
<li><strong>Separate segments of code determine what action should be taken for each type of interrupt</strong></li>
</ol>
<p><strong>Interrupt Timeline</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/3.jpg"><img class="aligncenter size-medium wp-image-1331" title="3" src="http://meherchilakalapudi.files.wordpress.com/2011/11/3.jpg?w=300&#038;h=152" alt="" width="300" height="152" /></a></p>
<p><strong>I/O Structure</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>After I/O starts, control returns to user program only upon I/O completion.</strong></li>
<ol>
<li><strong>Wait instruction idles the CPU until the next interrupt</strong></li>
<li><strong>Wait loop (contention for memory access).</strong></li>
<li><strong>At most one I/O request is outstanding at a time, no simultaneous I/O processing.</strong></li>
</ol>
<li><strong>After I/O starts, control returns to user program without waiting for I/O completion.</strong></li>
<ol>
<li><strong><em>System call</em> – request to the operating system to allow user to wait for I/O completion.</strong></li>
<li><strong><em>Device-status table</em> contains entry for each I/O device indicating its type, address, and state.</strong></li>
<li><strong>Operating system indexes into I/O device table to determine device status and to modify table entry to include interrupt.</strong></li>
</ol>
</ol>
<p><strong>Two I/O Methods</strong></p>
<p><strong></strong> </p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/4.jpg"><img class="aligncenter size-medium wp-image-1332" title="4" src="http://meherchilakalapudi.files.wordpress.com/2011/11/4.jpg?w=300&#038;h=146" alt="" width="300" height="146" /></a></p>
<p><strong>Device-Status Table</strong></p>
<p><strong></strong> </p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/5.jpg"><img class="aligncenter size-medium wp-image-1333" title="5" src="http://meherchilakalapudi.files.wordpress.com/2011/11/5.jpg?w=300&#038;h=177" alt="" width="300" height="177" /></a></p>
<p><strong>Direct Memory Access Structure</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Used for high-speed I/O devices able to transmit information at close to memory speeds.</strong></li>
<li><strong>Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention.</strong></li>
<li><strong>Only one interrupt is generated per block, rather than the one interrupt per byte.</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Storage Structure</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Main memory – only large storage media that the CPU can access directly.</strong></li>
<li><strong>Secondary storage – extension of main memory that provides large nonvolatile storage capacity.</strong></li>
<li><strong>Magnetic disks – rigid metal or glass platters covered with magnetic recording material </strong></li>
<ol>
<li><strong>Disk surface is logically divided into <em>tracks</em>, which are subdivided into <em>sectors</em>.</strong></li>
<li><strong>The <em>disk controller</em> determines the logical interaction between the device and the computer. </strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Storage Hierarchy</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Storage systems organized in hierarchy.</strong></li>
<ol>
<li><strong>Speed</strong></li>
<li><strong>Cost</strong></li>
<li><strong>Volatility</strong></li>
</ol>
<li><strong><em>Caching</em> – copying information into faster storage system; main memory can be viewed as a last <em>cache</em> for secondary storage.</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Storage-Device Hierarchy</strong><strong></strong></p>
<p><strong> <img class="aligncenter  wp-image-1334" title="6" src="http://meherchilakalapudi.files.wordpress.com/2011/11/6.jpg?w=300&#038;h=263" alt="" width="300" height="263" /></strong></p>
<p><strong>Caching</strong></p>
<ol>
<li><strong>Important principle, performed at many levels in a computer (in hardware, operating system, software)</strong></li>
<li><strong>Information in use copied from slower to faster storage temporarily</strong></li>
<li><strong>Faster storage (cache) checked first to determine if information is there</strong></li>
<ol>
<li><strong>If it is, information used directly from the cache (fast)</strong></li>
<li><strong>If not, data copied to cache and used there</strong></li>
</ol>
<li><strong>Cache smaller than storage being cached</strong></li>
<ol>
<li><strong>Cache management important design problem</strong></li>
<li><strong>Cache size and replacement policy</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Performance of Various Levels of Storage</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Movement between levels of storage hierarchy can be explicit or implicit<a href="http://meherchilakalapudi.files.wordpress.com/2011/11/7.jpg"><img class="aligncenter size-medium wp-image-1335" title="7" src="http://meherchilakalapudi.files.wordpress.com/2011/11/7.jpg?w=300&#038;h=131" alt="" width="300" height="131" /></a></strong></li>
</ol>
<p><strong>Migration of Integer A from Disk to Register</strong></p>
<p><strong> </strong></p>
<p><strong>Multitasking environments must be careful to use most recent value, no matter where it is stored in the storage hierarchy</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/8.jpg"><img class="aligncenter size-medium wp-image-1336" title="8" src="http://meherchilakalapudi.files.wordpress.com/2011/11/8.jpg?w=300&#038;h=41" alt="" width="300" height="41" /></a></p>
<ol>
<li><strong> </strong></li>
<li><strong>Multiprocessor environment must provide cache coherency in hardware such that all CPUs have the most recent value in their cache</strong></li>
<li><strong>Distributed environment situation even more complex</strong></li>
<ol>
<li><strong>Several copies of a datum can exist</strong></li>
<li><strong>Various solutions covered in Chapter 17</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong>Operating System Structure</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Multiprogramming</strong><strong> needed for efficiency</strong></li>
<ol>
<li><strong>Single user cannot keep CPU and I/O devices busy at all times</strong></li>
<li><strong>Multiprogramming organizes jobs (code and data) so CPU always has one to execute</strong></li>
<li><strong>A subset of total jobs in system is kept in memory</strong></li>
<li><strong>One job selected and run via job scheduling</strong></li>
<li><strong>When it has to wait (for I/O for example), OS switches to another job</strong></li>
</ol>
<li><strong>Timesharing (multitasking)</strong><strong> is logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing</strong></li>
<ol>
<li><strong>Response time</strong><strong> should be &lt; 1 second</strong></li>
<li><strong>Each user has at least one program executing in memory </strong><strong>[process</strong></li>
<li><strong>If several jobs ready to run at the same time </strong><strong>[ CPU scheduling</strong></li>
<li><strong>If processes don’t fit in memory, swapping moves them in and out to run</strong></li>
<li><strong>Virtual memory</strong><strong> allows execution of processes not completely in memory</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong>Memory Layout for Multiprogrammed System</strong></p>
<p><strong></strong> </p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/9.jpg"><img class="aligncenter size-medium wp-image-1337" title="9" src="http://meherchilakalapudi.files.wordpress.com/2011/11/9.jpg?w=178&#038;h=300" alt="" width="178" height="300" /></a></strong></p>
<p><strong>Operating-System Operations</strong><strong></strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Interrupt driven by hardware</strong></li>
<li><strong>Software error or request creates exception or trap</strong></li>
<ol>
<li><strong>Division by zero, request for operating system service</strong></li>
</ol>
<li><strong>Other process problems include infinite loop, processes modifying each other or the operating system</strong></li>
<li><strong>Dual-mode</strong><strong> operation allows OS to protect itself and other system components</strong></li>
<ol>
<li><strong>User mode</strong><strong> and kernel mode </strong></li>
<li><strong>Mode bit</strong><strong> provided by hardware</strong></li>
<ol>
<li><strong>Provides ability to distinguish when system is running user code or kernel code</strong></li>
<li><strong>Some instructions designated as privileged, only executable in kernel mode</strong></li>
<li><strong>System call changes mode to kernel, return from call resets it to user</strong></li>
</ol>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Transition from User to Kernel Mode</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Timer to prevent infinite loop / process hogging resources</strong></li>
<ol>
<li><strong>Set interrupt after specific period</strong></li>
<li><strong>Operating system decrements counter</strong></li>
<li><strong>When counter zero generate an interrupt</strong></li>
<li><strong>Set up before scheduling process to regain control or terminate program that exceeds allotted time</strong></li>
</ol>
</ol>
<p><strong> <a href="http://meherchilakalapudi.files.wordpress.com/2011/11/10.jpg"><img class="aligncenter size-medium wp-image-1338" title="10" src="http://meherchilakalapudi.files.wordpress.com/2011/11/10.jpg?w=300&#038;h=99" alt="" width="300" height="99" /></a></strong></p>
<p><strong>Process Management</strong></p>
<ol>
<li><strong>A process is a program in execution. It is a unit of work within the system. Program is a <em>passive entity</em>, process is an <em>active entity</em>.</strong></li>
<li><strong>Process needs resources to accomplish its task</strong></li>
<ol>
<li><strong>CPU, memory, I/O, files</strong></li>
<li><strong>Initialization data</strong></li>
</ol>
<li><strong>Process termination requires reclaim of any reusable resources</strong></li>
<li><strong>Single-threaded process has one program counter specifying location of next instruction to execute</strong></li>
<ol>
<li><strong>Process executes instructions sequentially, one at a time, until completion</strong></li>
</ol>
<li><strong>Multi-threaded process has one program counter per thread</strong></li>
<li><strong>Typically system has many processes, some user, some operating system running concurrently on one or more CPUs</strong></li>
<ol>
<li><strong>Concurrency by multiplexing the CPUs among the processes / threads</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Process Management Activities</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>The operating system is responsible for the following activities in  connection with process management:</strong></li>
<li><strong>Creating and deleting both user and system processes</strong></li>
<li><strong>Suspending and resuming processes</strong></li>
<li><strong>Providing mechanisms for process synchronization</strong></li>
<li><strong>Providing mechanisms for process communication</strong></li>
<li><strong>Providing mechanisms for deadlock handling</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong>Memory Management</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>All data in memory before and after processing</strong></li>
<li><strong>All instructions in memory in order to execute</strong></li>
<li><strong>Memory management determines what is in memory when</strong></li>
<ol>
<li><strong>Optimizing CPU utilization and computer response to users</strong></li>
</ol>
<li><strong>Memory management activities</strong></li>
<ol>
<li><strong>Keeping track of which parts of memory are currently being used and by whom</strong></li>
<li><strong>Deciding which processes (or parts thereof) and data to move into and out of memory</strong></li>
<li><strong>Allocating and deallocating memory space as needed</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Storage Management</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>OS provides uniform, logical view of information storage</strong></li>
<ol>
<li><strong>Abstracts physical properties to logical storage unit  &#8211; file</strong></li>
<li><strong>Each medium is controlled by device (i.e., disk drive, tape drive)</strong></li>
<ol>
<li><strong>Varying properties include access speed, capacity, data-transfer rate, access method (sequential or random)</strong></li>
</ol>
</ol>
<li><strong>File-System management</strong></li>
<ol>
<li><strong>Files usually organized into directories</strong></li>
<li><strong>Access control on most systems to determine who can access what</strong></li>
<li><strong>OS activities include</strong></li>
<ol>
<li><strong>Creating and deleting files and directories</strong></li>
<li><strong>Primitives to manipulate files and dirs</strong></li>
<li><strong>Mapping files onto secondary storage</strong></li>
<li><strong>Backup files onto stable (non-volatile) storage media</strong></li>
</ol>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Mass-Storage Management</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Usually disks used to store data that does not fit in main memory or data that must be kept for a “long” period of time.</strong></li>
<li><strong>Proper management is of central importance</strong></li>
<li><strong>Entire speed of computer operation hinges on disk subsystem and its algorithms</strong></li>
<li><strong>OS activities</strong></li>
<ol>
<li><strong>Free-space management</strong></li>
<li><strong>Storage allocation</strong></li>
<li><strong>Disk scheduling</strong></li>
</ol>
<li><strong>Some storage need not be fast</strong></li>
<ol>
<li><strong>Tertiary storage includes optical storage, magnetic tape</strong></li>
<li><strong>Still must be managed</strong></li>
<li><strong>Varies between WORM (write-once, read-many-times) and RW (read-write)</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong>I/O Subsystem</strong><strong></strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>One purpose of OS is to hide peculiarities of hardware devices from the user</strong></li>
<li><strong>I/O subsystem responsible for</strong></li>
<ol>
<li><strong>Memory management of I/O including buffering (storing data temporarily while it is being transferred), caching (storing parts of data in faster storage for performance), spooling (the overlapping of output of one job with input of other jobs)</strong></li>
<li><strong>General device-driver interface</strong></li>
<li><strong>Drivers for specific hardware devices</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Protection and Security</strong><strong></strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Protection</strong><strong> – any mechanism for controlling access of processes or users to resources defined by the OS</strong></li>
<li><strong>Security</strong><strong> – defense of the system against internal and external attacks</strong></li>
<ol>
<li><strong>Huge range, including denial-of-service, worms, viruses, identity theft, theft of service</strong></li>
</ol>
<li><strong>Systems generally first distinguish among users, to determine who can do what</strong></li>
<ol>
<li><strong>User identities (user IDs, security IDs) include name and associated number, one per user</strong></li>
<li><strong>User ID then associated with all files, processes of that user to determine access control</strong></li>
<li><strong>Group identifier (group ID) allows set of users to be defined and controls managed, then also associated with each process, file</strong></li>
<li><strong>Privilege escalation</strong><strong> allows user to change to effective ID with more rights</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Computing Environments </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Traditional computer</strong></li>
<ol>
<li><strong>Blurring over time</strong></li>
<li><strong>Office environment</strong></li>
</ol>
</ol>
<p><strong>                                                              i.      </strong><strong>PCs connected to a network, terminals attached to mainframe or minicomputers providing batch and timesharing</strong></p>
<p><strong>                                                            ii.      </strong><strong>Now portals allowing networked and remote systems access to same resources</strong></p>
<ol>
<ol start="3">
<li><strong>Home networks</strong></li>
</ol>
</ol>
<p><strong>                                                              i.      </strong><strong>Used to be single system, then modems</strong></p>
<p><strong>                                                            ii.      </strong><strong>Now firewalled, networked</strong></p>
<p><strong> </strong></p>
<ol start="2">
<li><strong>Client-Server Computing</strong></li>
<ol>
<li><strong>Dumb terminals supplanted by smart PCs</strong></li>
<li><strong>Many systems now servers, responding to requests generated by clients</strong></li>
</ol>
</ol>
<p><strong>                                                              i.      </strong><strong>Compute-server</strong><strong> provides an interface to client to request services (i.e. database)</strong></p>
<p><strong>                                                            ii.      </strong><strong>File-server</strong><strong> provides interface for clients to store and retrieve files</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/11.jpg"><img class="aligncenter size-medium wp-image-1339" title="11" src="http://meherchilakalapudi.files.wordpress.com/2011/11/11.jpg?w=300&#038;h=90" alt="" width="300" height="90" /></a></p>
<p><strong>Peer-to-Peer Computing</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Another model of distributed system</strong></li>
<li><strong>P2P does not distinguish clients and servers</strong></li>
<ol>
<li><strong>Instead all nodes are considered peers</strong></li>
<li><strong>May each act as client, server or both</strong></li>
<li><strong>Node must join P2P network</strong></li>
<ol>
<li><strong>Registers its service with central lookup service on network, or</strong></li>
<li><strong>Broadcast request for service and respond to requests for service via <em>discovery protocol</em></strong></li>
</ol>
<li><strong>Examples include<em> Napster </em>and<em> Gnutella</em></strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Web-Based Computing</strong><strong></strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Web has become ubiquitous</strong></li>
<li><strong>PCs most prevalent devices</strong></li>
<li><strong>More devices becoming networked to allow web access</strong></li>
<li><strong>New category of devices to manage web traffic among similar servers: load balancers</strong></li>
<li><strong>Use of operating systems like Windows 95, client-side, have evolved into Linux and Windows XP, which can be clients and servers</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Chapter 2:  Operating-System Structures</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Operating System Services</strong></li>
<li><strong>User Operating System Interface</strong></li>
<li><strong>System Calls</strong></li>
<li><strong>Types of System Calls</strong></li>
<li><strong>System Programs</strong></li>
<li><strong>Operating System Design and Implementation</strong></li>
<li><strong>Operating System Structure</strong></li>
<li><strong>Virtual Machines</strong></li>
<li><strong>Operating System Generation</strong></li>
<li><strong>System Boot</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Objectives</strong><strong></strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>To describe the services an operating system provides to users, processes, and other systems</strong></li>
<li><strong>To discuss the various ways of structuring an operating system</strong></li>
<li><strong>To explain how operating systems are installed and customized and how they boot</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong>Operating System Services</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>One set of operating-system services provides functions that are helpful to the user:</strong></li>
<ol>
<li><strong>User interface &#8211; Almost all operating systems have a user interface (UI)</strong></li>
</ol>
</ol>
<p><strong>                                                              i.      </strong><strong>Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch</strong></p>
<ol>
<ol start="2">
<li><strong>Program execution &#8211; The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally (indicating error)</strong></li>
<li><strong>I/O operations -  A running program may require I/O, which may involve a file or an I/O device. </strong></li>
<li><strong>File-system manipulation -  The file system is of particular interest. Obviously, programs need to read and write files and directories, create and delete them, search them, list file Information, permission management.</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<ol start="2">
<li><strong>One set of operating-system services provides functions that are helpful to the user (Cont):</strong></li>
<ol>
<li><strong>Communications – Processes may exchange information, on the same computer or between computers over a network</strong></li>
</ol>
</ol>
<p><strong>                                                              i.      </strong><strong>Communications may be via shared memory or through message passing (packets moved by the OS)</strong></p>
<ol start="2">
<ol start="2">
<li><strong>Error detection – OS needs to be constantly aware of possible errors</strong></li>
</ol>
</ol>
<p><strong>                                                              i.      </strong><strong>May occur in the CPU and memory hardware, in I/O devices, in user program</strong></p>
<p><strong>                                                            ii.      </strong><strong>For each type of error, OS should take the appropriate action to ensure correct and consistent computing</strong></p>
<p><strong>                                                          iii.      </strong><strong>Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing</strong></li>
<ol>
<li><strong>Resource allocation &#8211; </strong><strong>When  multiple users or multiple jobs running concurrently, resources must be allocated to each of them</strong></li>
<ol>
<li><strong>Many types of resources -  Some (such as CPU cycles,mainmemory, and file storage) may have special allocation code, others (such as I/O devices) may have general request and release code. </strong></li>
</ol>
<li><strong>Accounting -</strong><strong> To keep track of which users use how much and what kinds of computer resources</strong></li>
<li><strong>Protection and security &#8211; </strong><strong>The owners of information stored in a multiuser or networked computer system may want to control use of that information, concurrent processes should not interfere with each other</strong></li>
<ol>
<li><strong>Protection</strong><strong> involves ensuring that all access to system resources is controlled</strong></li>
<li><strong>Security</strong><strong> of the system from outsiders requires user authentication, extends to defending external I/O devices from invalid access attempts</strong></li>
<li><strong>If a system is to be protected and secure, precautions must be instituted throughout it. A chain is only as strong as its weakest link</strong></li>
</ol>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>User Operating System Interface &#8211; CLI</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>CLI allows direct command entry</strong></li>
<ol>
<ol>
<li><strong>Sometimes implemented in kernel, sometimes by systems program</strong></li>
<li><strong>Sometimes multiple flavors implemented – shells</strong></li>
<li><strong>Primarily fetches a command from user and executes it</strong></li>
<ol>
<li><strong>Sometimes commands built-in, sometimes just names of programs</strong></li>
<ol>
<li><strong>If the latter, adding new features doesn’t require shell modification</strong></li>
</ol>
</ol>
</ol>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>User Operating System Interface &#8211; GUI</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>User-friendly desktop metaphor interface</strong></li>
<ol>
<li><strong>Usually mouse, keyboard, and monitor</strong></li>
<li><strong>Icons</strong><strong> represent files, programs, actions, etc</strong></li>
<li><strong>Various mouse buttons over objects in the interface cause various actions (provide information, options, execute function, open directory (known as a folder)</strong></li>
<li><strong>Invented at Xerox PARC</strong></li>
</ol>
<li><strong>Many systems now include both CLI and GUI interfaces</strong></li>
<ol>
<li><strong>Microsoft Windows is GUI with CLI “command” shell</strong></li>
<li><strong>Apple Mac OS X as “Aqua” GUI interface with UNIX kernel underneath and shells available</strong></li>
<li><strong>Solaris is CLI with optional GUI interfaces (Java Desktop, KDE)</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>System Calls</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Programming interface to the services provided by the OS</strong></li>
<li><strong>Typically written in a high-level language (C or C++)</strong></li>
<li><strong>Mostly accessed by programs via a high-level Application Program Interface (API) rather than direct system call use</strong></li>
<li><strong>Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM)</strong></li>
<li><strong>Why use APIs rather than system calls?</strong></li>
<li><strong>(Note that the system-call names used throughout this text are generic)</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Example of System Calls</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong>System call sequence to copy the contents of one file to another file</strong></p>
<p><strong></strong> </p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/12.jpg"><img class="aligncenter size-medium wp-image-1340" title="12" src="http://meherchilakalapudi.files.wordpress.com/2011/11/12.jpg?w=300&#038;h=201" alt="" width="300" height="201" /></a></p>
<p><strong>Example of Standard API</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Consider the ReadFile() function in the</strong></li>
<li><strong><strong><strong>Win32 API—a function for reading from a file</strong></strong></strong><img class="aligncenter size-medium wp-image-1341" title="13" src="http://meherchilakalapudi.files.wordpress.com/2011/11/13.jpg?w=300&#038;h=113" alt="" width="300" height="113" />
<ol>
<li><strong>A description of the parameters passed to ReadFile()</strong></li>
<ol>
<li><strong>HANDLE file—the file to be read</strong></li>
<li><strong>LPVOID buffer—a buffer where the data will be read into and written from</strong></li>
<li><strong>DWORD bytesToRead—the number of bytes to be read into the buffer</strong></li>
<li><strong>LPDWORD bytesRead—the number of bytes read during the last read</strong></li>
<li><strong>LPOVERLAPPED ovl—indicates if overlapped I/O is being used</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>System Call Implementation</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Typically, a number associated with each system call</strong></li>
<ol>
<li><strong>System-call interface maintains a table indexed according to these numbers</strong></li>
</ol>
<li><strong>The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values</strong></li>
<li><strong>The caller need know nothing about how the system call is implemented</strong></li>
<ol>
<li><strong>Just needs to obey API and understand what OS will do as a result call</strong></li>
<li><strong>Most details of  OS interface hidden from programmer by API  </strong></li>
<ol>
<li><strong>Managed by run-time support library (set of functions built into libraries included with compiler)</strong></li>
</ol>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong>API – System Call – OS Relationship</strong><strong></strong></p>
<p><strong> <a href="http://meherchilakalapudi.files.wordpress.com/2011/11/14.jpg"><img class="aligncenter size-medium wp-image-1342" title="14" src="http://meherchilakalapudi.files.wordpress.com/2011/11/14.jpg?w=300&#038;h=228" alt="" width="300" height="228" /></a></strong></li>
</ol>
<p><strong>Standard C Library Example</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>C program invoking printf() library call, which calls write() system call</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/15.jpg"><img class="aligncenter size-medium wp-image-1343" title="15" src="http://meherchilakalapudi.files.wordpress.com/2011/11/15.jpg?w=262&#038;h=300" alt="" width="262" height="300" /></a></p>
<p><strong>System Call Parameter Passing</strong><strong></strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Often, more information is required than simply identity of desired system call</strong></li>
<ol>
<li><strong>Exact type and amount of information vary according to OS and call</strong></li>
</ol>
<li><strong>Three general methods used to pass parameters to the OS</strong></li>
<ol>
<li><strong>Simplest:  pass the parameters in <em>registers</em></strong></li>
<ol>
<li><strong> In some cases, may be more parameters than registers</strong></li>
</ol>
<li><strong>Parameters stored in a <em>block, </em>or table, in memory, and address of block passed as a parameter in a register </strong></li>
<ol>
<li><strong>This approach taken by Linux and Solaris</strong></li>
</ol>
<li><strong>Parameters placed, or <em>pushed, </em>onto the <em>stack </em>by the program and <em>popped </em>off the stack by the operating system</strong></li>
<li><strong>Block and stack methods do not limit the number or length of parameters being passed</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Parameter Passing via Table</strong><strong></strong></p>
<p><strong> <img class="aligncenter size-medium wp-image-1344" title="17" src="http://meherchilakalapudi.files.wordpress.com/2011/11/17.jpg?w=300&#038;h=267" alt="" width="300" height="267" /></strong></p>
<p><strong>Types of System Calls</strong><strong></strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Process control</strong></li>
<li><strong>File management</strong></li>
<li><strong>Device management</strong></li>
<li><strong>Information maintenance</strong></li>
<li><strong>Communications</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>MS-DOS execution</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/18.jpg"><img class="aligncenter size-medium wp-image-1345" title="18" src="http://meherchilakalapudi.files.wordpress.com/2011/11/18.jpg?w=300&#038;h=298" alt="" width="300" height="298" /></a></strong></p>
<p>(a) At system startup (b) running a program</p>
<p> <strong>FreeBSD Running Multiple Programs</strong></p>
<p><img class="aligncenter size-medium wp-image-1346" title="19" src="http://meherchilakalapudi.files.wordpress.com/2011/11/19.jpg?w=289&#038;h=300" alt="" width="289" height="300" /></p>
<p><strong>System Programs</strong></p>
<ol>
<li><strong>System programs provide a convenient environment for program development and execution.  The can be divided into:</strong></li>
<ol>
<li><strong>File manipulation </strong></li>
<li><strong>Status information</strong></li>
<li><strong>File modification</strong></li>
<li><strong>Programming language support</strong></li>
<li><strong>Program loading and execution</strong></li>
<li><strong>Communications</strong></li>
<li><strong>Application programs</strong></li>
</ol>
<li><strong>Most users’ view of the operation system is defined by system programs, not the actual system calls</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Solaris 10 dtrace Following System Call</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong>System Programs</strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Provide a convenient environment for program development and execution</strong></li>
<ol>
<li><strong>Some of them are simply user interfaces to system calls; others are considerably more complex</strong></li>
</ol>
<li><strong>File management &#8211; Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories</strong></li>
<li><strong>Status information</strong></li>
<ol>
<li><strong>Some ask the system for info &#8211; date, time, amount of available memory, disk space, number of users</strong></li>
<li><strong>Others provide detailed performance, logging, and debugging information</strong></li>
<li><strong>Typically, these programs format and print the output to the terminal or other output devices</strong></li>
<li><strong>Some systems implement  a registry &#8211; used to store and retrieve configuration information</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol start="4">
<li><strong>File modification</strong></li>
<ol>
<li><strong>Text editors to create and modify files</strong></li>
<li><strong>Special commands to search contents of files or perform transformations of the text</strong></li>
</ol>
<li><strong>Programming-language support &#8211; Compilers, assemblers, debuggers and interpreters sometimes provided</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol start="6">
<li><strong>Program loading and execution- Absolute loaders, relocatable loaders, linkage editors, and overlay-loaders, debugging systems for higher-level and machine language</strong></li>
<li><strong>Communications &#8211; Provide the mechanism for creating virtual connections among processes, users, and computer systems</strong></li>
<ol>
<li><strong>Allow users to send messages to one another’s screens, browse web pages, send electronic-mail messages, log in remotely, transfer files from one machine to another</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Operating System Design and Implementation</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Design and Implementation of OS not “solvable”, but some approaches have proven successful</strong></li>
<li><strong>Internal structure of different Operating Systems  can vary widely</strong></li>
<li><strong>Start by defining goals and specifications </strong></li>
<li><strong>Affected by choice of hardware, type of system</strong></li>
<li><strong><em>User</em> goals and <em>System</em> goals</strong></li>
<ol>
<li><strong>User goals – operating system should be convenient to use, easy to learn, reliable, safe, and fast</strong></li>
<li><strong>System goals – operating system should be easy to design, implement, and maintain, as well as flexible, reliable, error-free, and efficient</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<ol start="6">
<li><strong>Important principle to separate</strong></li>
</ol>
<p><strong>                                                                                                                                                                                                              i.      </strong><strong>Policy:   </strong><strong>What will be done?<br />
Mechanism:  How to do it?</strong></p>
<ol start="7">
<li><strong>Mechanisms determine how to do something, policies decide what will be done</strong></li>
<ol>
<li><strong>The separation of policy from mechanism is a very important principle, it allows maximum flexibility if policy decisions are to be changed later</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Simple Structure </strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>MS-DOS – written to provide the most functionality in the least space</strong></li>
<ol>
<li><strong>Not divided into modules</strong></li>
<li><strong>Although MS-DOS has some structure, its interfaces and levels of functionality are not well separated</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>MS-DOS Layer Structure</strong></p>
<p><strong>Layered Approach</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>The operating system is divided into a number of layers (levels), each built on top of lower layers.  The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface.</strong></li>
<li><strong>With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong>Layered Operating System</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/20.jpg"><img class="aligncenter size-medium wp-image-1347" title="20" src="http://meherchilakalapudi.files.wordpress.com/2011/11/20.jpg?w=300&#038;h=300" alt="" width="300" height="300" /></a></strong></p>
<p><strong>UNIX</strong></p>
<ol>
<li>UNIX – limited by hardware functionality, the original UNIX operating system had limited structuring.  The UNIX OS consists of two separable parts</li>
<ol>
<li>Systems programs</li>
<li>The kernel</li>
<ol>
<li>Consists of everything below the system-call interface and above the physical hardware</li>
<li>Provides the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level</li>
</ol>
</ol>
</ol>
<p><strong>UNIX System Structure</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/21.jpg"><img class="aligncenter size-medium wp-image-1348" title="21" src="http://meherchilakalapudi.files.wordpress.com/2011/11/21.jpg?w=300&#038;h=181" alt="" width="300" height="181" /></a> </p>
<p><strong>Microkernel System Structure </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Moves as much from the kernel into “<em>user</em>” space</strong></li>
<li><strong>Communication takes place between user modules using message passing</strong></li>
<li><strong>Benefits:</strong></li>
<ol>
<li><strong>Easier to extend a microkernel</strong></li>
<li><strong>Easier to port the operating system to new architectures</strong></li>
<li><strong>More reliable (less code is running in kernel mode)</strong></li>
<li><strong>More secure</strong></li>
</ol>
<li><strong>Detriments:</strong></li>
<ol>
<li><strong>Performance overhead of user space to kernel space communication</strong></li>
</ol>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Mac OS X Structure</strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/22.jpg"><img class="aligncenter size-medium wp-image-1349" title="22" src="http://meherchilakalapudi.files.wordpress.com/2011/11/22.jpg?w=300&#038;h=180" alt="" width="300" height="180" /></a></strong></p>
<p><strong>Modules</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Most modern operating systems implement kernel modules</strong></li>
<ol>
<li><strong>Uses object-oriented approach</strong></li>
<li><strong>Each core component is separate</strong></li>
<li><strong>Each talks to the others over known interfaces</strong></li>
<li><strong>Each is loadable as needed within the kernel</strong></li>
</ol>
<li><strong>Overall, similar to layers but with more flexible</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Solaris Modular Approach</strong><strong></strong></p>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/23.jpg"><img class="aligncenter size-medium wp-image-1350" title="23" src="http://meherchilakalapudi.files.wordpress.com/2011/11/23.jpg?w=300&#038;h=203" alt="" width="300" height="203" /></a> </strong></p>
<p><strong>Virtual Machines</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>A <em>virtual machine</em> takes the layered approach to its logical conclusion.  It treats hardware and the operating system kernel as though they were all hardware</strong></li>
<li><strong>A virtual machine provides an interface <em>identical</em> to the underlying bare hardware</strong></li>
<li><strong>The operating system creates the illusion of multiple processes, each executing on its own processor with its own (virtual) memory</strong></li>
</ol>
<p><strong> </strong></p>
<ol start="4">
<li><strong>The resources of the physical computer are shared to create the virtual machines</strong></li>
<ol>
<li><strong>CPU scheduling can create the appearance that users have their own processor</strong></li>
<li><strong>Spooling and a file system can provide virtual card readers and virtual line printers</strong></li>
<li><strong>A normal user time-sharing terminal serves as the virtual machine operator’s console</strong></li>
<ol>
<li><strong>The virtual-machine concept provides complete protection of system resources since each virtual machine is isolated from all other virtual machines.  This isolation, however, permits no direct sharing of resources.</strong></li>
<li><strong>A virtual-machine system is a perfect vehicle for operating-systems research and development.  System development is done on the virtual machine, instead of on a physical machine and so does not disrupt normal system operation.</strong></li>
<li><strong>The virtual machine concept is difficult to implement due to the effort required to provide an <em>exact</em> duplicate to the underlying machine</strong></li>
</ol>
</ol>
</ol>
<p><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/24.jpg"><img class="aligncenter size-medium wp-image-1351" title="24" src="http://meherchilakalapudi.files.wordpress.com/2011/11/24.jpg?w=300&#038;h=219" alt="" width="300" height="219" /></a></strong></p>
<p><strong></strong> </p>
<p><strong>The Java Virtual Machine</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/25.jpg"><img class="aligncenter size-medium wp-image-1352" title="25" src="http://meherchilakalapudi.files.wordpress.com/2011/11/25.jpg?w=300&#038;h=143" alt="" width="300" height="143" /></a></p>
<p><strong>Operating System Generation</strong></p>
<ol>
<li><strong>Operating systems are designed to run on any of a class of machines; the system must be configured for each specific computer site</strong></li>
<li><strong>SYSGEN program obtains information concerning the specific configuration of the hardware system</strong></li>
<li><strong><em>Booting</em> – starting a computer by loading the kernel</strong></li>
<li><strong><em>Bootstrap program</em> – code stored in ROM that is able to locate the kernel, load it into memory, and start its execution</strong></li>
</ol>
<p><strong> </strong></p>
<p><strong>System Boot</strong><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<ol>
<li><strong>Operating system must be made available to hardware so hardware can start it</strong></li>
<ol>
<li><strong>Small piece of code – bootstrap loader, locates the kernel, loads it into memory, and starts it</strong></li>
<li><strong>Sometimes two-step process where boot block at fixed location loads bootstrap loader</strong></li>
<li><strong>When power initialized on system, execution starts at a fixed memory location</strong></li>
<ol>
<li><strong>Firmware used to hold initial boot code.</strong></li>
<li><strong>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</strong></li>
</ol>
</ol>
</ol>
<p><strong></strong>  </p>
<div><strong>Chapter 3:  Processes</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div><strong>1.Process Concept</strong></div>
<div><strong>2.Process Scheduling</strong></div>
<div><strong>3.Operations on Processes</strong></div>
<div><strong>4.Cooperating Processes</strong></div>
<div><strong>5.Interprocess Communication</strong></div>
<div><strong>6.Communication in Client-Server Systems</strong></div>
<div><strong></strong> </div>
<div> </p>
<div><strong>Process Concept:</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div><strong>1.An operating system executes a variety of programs:</strong></div>
<div><strong>1.Batch system – jobs</strong></div>
<div><strong>2.Time-shared systems – user programs or tasks</strong></div>
<div><strong>2.Textbook uses the terms <em>job</em> and <em>process</em> almost interchangeably</strong></div>
<div><strong>3.Process – a program in execution; process execution must progress in sequential fashion</strong></div>
<div><strong>4.A process includes:</strong></div>
<div><strong>1.program counter</strong></div>
<div><strong>2.stack</strong></div>
<div><strong>3.data section</strong></div>
<div><strong> </strong></div>
</div>
</div>
</div>
</div>
</div>
<p><strong>  </strong></p>
<div><strong>Process in Memory:</strong></div>
<div><strong><img class="aligncenter size-medium wp-image-1362" title="26" src="http://meherchilakalapudi.files.wordpress.com/2011/11/26.jpg?w=198&#038;h=300" alt="" width="198" height="300" /></strong></div>
<div> </div>
<div> </p>
<div><strong>Process State:</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.As a process executes, it changes <em>state</em></div>
<div>1.<strong>new</strong>:  The process is being created</div>
<div>2.<strong>running</strong>:  Instructions are being executed</div>
<div>3.<strong>waiting</strong>:  The process is waiting for some event to occur</div>
<div>4.<strong>ready</strong>:  The process is waiting to be assigned to a processor</div>
<div>5.<strong>terminated</strong>:  The process has finished execution</div>
<div> </div>
<div> </p>
<div><strong>Diagram of Process State</strong></div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/27.jpg"><img class="aligncenter size-medium wp-image-1363" title="27" src="http://meherchilakalapudi.files.wordpress.com/2011/11/27.jpg?w=300&#038;h=137" alt="" width="300" height="137" /></a></strong></div>
<div><strong></strong> </div>
<div><strong><strong> </strong></strong></p>
<div><strong>Process Control Block (PCB):</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.Information associated with each process</div>
<div>2.Process state</div>
<div>3.Program counter</div>
<div>4.CPU registers</div>
<div>5.CPU scheduling information</div>
<div>6.Memory-management information</div>
<div>7.Accounting information</div>
<div>8.I/O status information</div>
<div> </div>
<div></div>
<div> </div>
<div> </p>
<div><strong>CPU Switch From Process to Process:</strong></div>
<div><strong></strong> </div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/29.jpg"><img class="aligncenter size-medium wp-image-1365" title="29" src="http://meherchilakalapudi.files.wordpress.com/2011/11/29.jpg?w=300&#038;h=201" alt="" width="300" height="201" /></a></div>
<div><strong></strong> </div>
<div><strong><strong> </strong></strong></p>
<div><strong>Process Scheduling Queues:</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.<strong>Job queue</strong> – set of all processes in the system</div>
<div>2.<strong>Ready queue</strong> – set of all processes residing in main memory, ready and waiting to execute</div>
<div>3.<strong>Device queues</strong> – set of processes waiting for an I/O device</div>
<div>4.Processes migrate among the various queues</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Ready Queue And Various I/O Device Queues:</strong></div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/30.jpg"><img class="aligncenter size-medium wp-image-1366" title="30" src="http://meherchilakalapudi.files.wordpress.com/2011/11/30.jpg?w=300&#038;h=264" alt="" width="300" height="264" /></a></strong></div>
<div><strong></strong> </div>
<div><strong></strong> </div>
<div><strong></strong> </div>
</div>
</div>
</div>
</div>
<div><strong></strong> </div>
<div><strong></strong>  </p>
<div><strong>Representation of Process Scheduling:</strong></div>
<div><strong></strong> </div>
<div><strong></strong> </div>
<div><strong><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/31.jpg"><img class="aligncenter size-medium wp-image-1367" title="31" src="http://meherchilakalapudi.files.wordpress.com/2011/11/31.jpg?w=300&#038;h=198" alt="" width="300" height="198" /></a></strong></div>
<div><strong><strong> </strong></strong></p>
<div><strong>Schedulers:</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>1.<strong>Long-term scheduler</strong>  (or job scheduler) – selects which processes should be brought into the ready queue</div>
<div>2.<strong>Short-term scheduler</strong>  (or CPU scheduler) – selects which process should be executed next and allocates CPU</div>
<div>  </div>
<div>
<div><strong>Addition of Medium Term Scheduling:</strong></div>
<div><strong></strong> </div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/32.jpg"><img class="aligncenter size-medium wp-image-1368" title="32" src="http://meherchilakalapudi.files.wordpress.com/2011/11/32.jpg?w=300&#038;h=114" alt="" width="300" height="114" /></a></div>
<div><strong></strong> </div>
<div><strong><strong> </strong></strong></p>
<div>
<div>1.Short-term scheduler is invoked very frequently (milliseconds) Þ (must be fast)</div>
<div>2.Long-term scheduler is invoked very infrequently (seconds, minutes) Þ (may be slow)</div>
<div>3.The long-term scheduler controls the <em>degree of multiprogramming </em></div>
<div>4.Processes can be described as either:</div>
<div>1.<strong>I/O-bound process</strong> – spends more time doing I/O than computations, many short CPU bursts</div>
<div>2.<strong>CPU-bound process</strong> – spends more time doing computations; few very long CPU bursts</div>
<div> </div>
<div> </p>
<div>
<div>1.When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process</div>
<div>2.Context-switch time is overhead; the system does no useful work while switching</div>
<div>3.Time dependent on hardware support</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>Process Creation</strong></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div><strong></strong>  </p>
<div>
<div>1.Parent process create children processes, which, in turn create other processes, forming a tree of processes</div>
<div>2.Resource sharing</div>
<div>1.Parent and children share all resources</div>
<div>2.Children share subset of parent’s resources</div>
<div>3.Parent and child share no resources</div>
<div>3.Execution</div>
<div>1.Parent and children execute concurrently</div>
<div>2.Parent waits until children terminate</div>
<div> </div>
<div> </div>
<div> </p>
<div>
<div>1.Address space</div>
<div>1.Child duplicate of parent</div>
<div>2.Child has a program loaded into it</div>
<div>2.UNIX examples</div>
<div>1.<strong>fork</strong> system call creates new process</div>
<div>2.<strong>exec</strong> system call used after a <strong>fork</strong> to replace the process’ memory space with a new program</div>
<div>  </p>
<div><strong>Process Creation</strong></div>
<div><a href="http://meherchilakalapudi.files.wordpress.com/2011/11/33.jpg"><img class="aligncenter size-medium wp-image-1369" title="33" src="http://meherchilakalapudi.files.wordpress.com/2011/11/33.jpg?w=300&#038;h=84" alt="" width="300" height="84" /></a></div>
<div><strong></strong> </div>
<div><strong><strong> </strong></strong></p>
<div><strong>C Program Forking Separate Process</strong></div>
<div><strong></strong> </div>
<div> </p>
<div>
<div>int main()</div>
<div>{</div>
<div>pid_t  pid;</div>
<div>/* fork another process */</div>
<div>pid = fork();</div>
<div>if (pid &lt; 0) { /* error occurred */</div>
<div>fprintf(stderr, &#8220;Fork Failed&#8221;);</div>
<div>exit(-1);</div>
<div>}</div>
<div>else if (pid == 0) { /* child process */</div>
<div>execlp(&#8220;/bin/ls&#8221;, &#8220;ls&#8221;, NULL);</div>
<div>}</div>
<div>else { /* parent process */</div>
<div>/* parent will wait for the child to complete */</div>
<div>wait (NULL);</div>
<div>printf (&#8220;Child Complete&#8221;);</div>
<div>exit(0);</div>
<div>}</div>
<div>}</div>
<div> </div>
<div> </div>
<div> </p>
<div><strong>A tree of processes on a typical Solaris</strong></div>
</div>
</div>
</div>
</div>
<div><strong></strong> </div>
<div><strong></strong> </div>
</div>
</div>
</div>
</div>
</div>
<div><strong></strong> </div>
<div><strong></strong> </div>
</div>
</div>
<div> </div>
</div>
</div>
</div>
<div><strong></strong> </div>
<div><strong></strong> </div>
<div><strong></strong> </div>
<div><strong></strong> </div>
</div>
</div>
</div>
</div>
<div> </div>
<div> </div>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/operating-systems-introduction-1/'>Operating Systems Introduction-1</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1328/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1328&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/11/20/operating-systems-introduction-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/1.jpg?w=300" medium="image">
			<media:title type="html">1</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/2.jpg?w=300" medium="image">
			<media:title type="html">2</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/3.jpg?w=300" medium="image">
			<media:title type="html">3</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/4.jpg?w=300" medium="image">
			<media:title type="html">4</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/5.jpg?w=300" medium="image">
			<media:title type="html">5</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/6.jpg?w=300" medium="image">
			<media:title type="html">6</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/7.jpg?w=300" medium="image">
			<media:title type="html">7</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/8.jpg?w=300" medium="image">
			<media:title type="html">8</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/9.jpg?w=178" medium="image">
			<media:title type="html">9</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/10.jpg?w=300" medium="image">
			<media:title type="html">10</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/11.jpg?w=300" medium="image">
			<media:title type="html">11</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/12.jpg?w=300" medium="image">
			<media:title type="html">12</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/13.jpg?w=300" medium="image">
			<media:title type="html">13</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/14.jpg?w=300" medium="image">
			<media:title type="html">14</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/15.jpg?w=262" medium="image">
			<media:title type="html">15</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/17.jpg?w=300" medium="image">
			<media:title type="html">17</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/18.jpg?w=300" medium="image">
			<media:title type="html">18</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/19.jpg?w=289" medium="image">
			<media:title type="html">19</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/20.jpg?w=300" medium="image">
			<media:title type="html">20</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/21.jpg?w=300" medium="image">
			<media:title type="html">21</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/22.jpg?w=300" medium="image">
			<media:title type="html">22</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/23.jpg?w=300" medium="image">
			<media:title type="html">23</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/24.jpg?w=300" medium="image">
			<media:title type="html">24</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/25.jpg?w=300" medium="image">
			<media:title type="html">25</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/26.jpg?w=198" medium="image">
			<media:title type="html">26</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/27.jpg?w=300" medium="image">
			<media:title type="html">27</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/29.jpg?w=300" medium="image">
			<media:title type="html">29</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/30.jpg?w=300" medium="image">
			<media:title type="html">30</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/31.jpg?w=300" medium="image">
			<media:title type="html">31</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/32.jpg?w=300" medium="image">
			<media:title type="html">32</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/11/33.jpg?w=300" medium="image">
			<media:title type="html">33</media:title>
		</media:content>
	</item>
		<item>
		<title>C- Lab Programs</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/11/12/c-lab-programs/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/11/12/c-lab-programs/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 06:35:33 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[C-LabProgrames]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1325</guid>
		<description><![CDATA[W.A.P to initialize all data type variables and display the output? &#160; #include&#60;stdio.h&#62; #include&#60;conio.h&#62; void main() { int  n=123; char ch=&#8217;h'; float f=123.123; double db=123456.123456; clrscr(); printf(&#8220;\nGiven integer value   : %d&#8221;,n); printf(&#8220;\nGiven character value : %c&#8221;,ch); printf(&#8220;\nGiven float value     : %f&#8221;,f); printf(&#8220;\nGiven double value    : %lf&#8221;,db); getch(); }          ………………………………………………………………………………………………………………………………………. W.A.P to accept rollnumber and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1325&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>W.A.P to initialize all data type variables and display the output?</strong></p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int  n=123;</strong></p>
<p><strong>char ch=&#8217;h';</strong></p>
<p><strong>float f=123.123;</strong></p>
<p><strong>double db=123456.123456;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>printf(&#8220;\nGiven integer value   : %d&#8221;,n);</strong></p>
<p><strong>printf(&#8220;\nGiven character value : %c&#8221;,ch);</strong></p>
<p><strong>printf(&#8220;\nGiven float value     : %f&#8221;,f);</strong></p>
<p><strong>printf(&#8220;\nGiven double value    : %lf&#8221;,db);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>         ……………………………………………………………………………………………………………………………………….</strong></p>
<p><strong>W.A.P to accept rollnumber and marks and find the average of marks?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong> int sno,m1,m2,m3;</strong></p>
<p><strong> char sna[10];</strong></p>
<p><strong> float tot,avg;</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> printf(&#8220;Enter student no:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;sno);</strong></p>
<p><strong> printf(&#8220;Enter student name:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%s&#8221;,&amp;sna);</strong></p>
<p><strong> printf(&#8220;Enter m1 marks:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;m1);</strong></p>
<p><strong> printf(&#8220;Enter m2 marks:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;m2);</strong></p>
<p><strong> printf(&#8220;Enter m3 marks:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;m3);</strong></p>
<p><strong> tot=m1+m2+m3;</strong></p>
<p><strong> avg=tot/3;</strong></p>
<p><strong> if(m1&gt;=35 &amp;&amp; m2&gt;=35 &amp;&amp; m3&gt;=35)</strong></p>
<p><strong> {</strong></p>
<p><strong>  printf(&#8220;\n passed\n&#8221;);</strong></p>
<p><strong>  if(avg&gt;=75)</strong></p>
<p><strong>     printf(&#8220;distenction&#8221;);</strong></p>
<p><strong>  else if(avg&gt;=60)</strong></p>
<p><strong>     printf(&#8220;First class&#8221;);</strong></p>
<p><strong>  else if(avg&gt;=50)</strong></p>
<p><strong>     printf(&#8220;Second class&#8221;);</strong></p>
<p><strong>  else if(avg&gt;=35)</strong></p>
<p><strong>     printf(&#8220;Third class&#8221;);</strong></p>
<p><strong>  }</strong></p>
<p><strong>  else</strong></p>
<p><strong>    {</strong></p>
<p><strong>      printf(&#8220;\n Failed\n&#8221;);</strong></p>
<p><strong>      printf(&#8220;no division&#8221;);</strong></p>
<p><strong>      }</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>…………………………………………………………………………………………………………………………………………………</strong></p>
<p><strong>W.A.P to calculate area of the triangle when accepting base and height?</strong></p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong>#include&lt;math.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong> int h,b;</strong></p>
<p><strong> float area;</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> printf(&#8220;Enter the base:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;b);</strong></p>
<p><strong> printf(&#8220;Enter the height&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;h);</strong></p>
<p><strong> area=b*h/2;</strong></p>
<p><strong> printf(&#8220;\n area of the triangle is:%f&#8221;,area);</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p>&nbsp;</p>
<p><strong>……………………………………………………………………………………………………………………………………………………….</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to calculate area of the triangle when accepting three sides?</strong></p>
<p>&nbsp;</p>
<p><strong>/* formula is sqrt(s(s-a)*(s-b)*(s-c))*/</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong>#include&lt;math.h&gt;</strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int a,b,c,p;</strong></p>
<p><strong>float s,area;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>printf(&#8220;\n enter the 3 sides of a traingle:&#8221;);</strong></p>
<p><strong>scanf(&#8220;%d %d %d&#8221;,&amp;a,&amp;b,&amp;c);</strong></p>
<p><strong>p=a+b+c;</strong></p>
<p><strong>s=p/2;</strong></p>
<p><strong>area=sqrt(s*(s-a)*(s-b)*(s-c));</strong></p>
<p><strong>printf(&#8220;\n area of traingle: %f&#8221;,area);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>…………………………………………………………………………………………………………………………………………………..</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to interchange the value present in two variables?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int a,b;</strong></p>
<p><strong>a=10;</strong></p>
<p><strong>b=5;</strong></p>
<p><strong>printf(&#8220;\n before swapping=&gt; a=%d, b=%d&#8221;,a,b);</strong></p>
<p><strong>swap(&amp;a,&amp;b);</strong></p>
<p><strong>printf(&#8220;\n after swapping=&gt;a=%d,b=%d&#8221;,a,b);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p><strong>int swap(int *x,int *y)</strong></p>
<p><strong>{</strong></p>
<p><strong>  int t;</strong></p>
<p><strong>  t=*x;</strong></p>
<p><strong>  *x=*y;</strong></p>
<p><strong>  *y=t;</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p><strong>……………………………………………………………………………………………………………………………………………………….</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to find the biggest of two numbers?</strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong> int a,b;</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> printf(&#8220;Enter A value:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;a);</strong></p>
<p><strong> printf(&#8220;Enter B value:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;b);</strong></p>
<p><strong> if(a&gt;b)</strong></p>
<p><strong>   printf(&#8220;A value is big&#8221;);</strong></p>
<p><strong> else if(b&gt;a)</strong></p>
<p><strong>   printf(&#8220;B value is big&#8221;);</strong></p>
<p><strong> else</strong></p>
<p><strong>   printf(&#8220;Both are equal&#8221;);</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p>&nbsp;</p>
<p><strong>……………………………………………………………………………………………………………………………………………………….</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to find the biggest of three numbers?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong> int a,b,c;</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> printf(&#8220;Enter A value:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;a);</strong></p>
<p><strong> printf(&#8220;Enter B value:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;b);</strong></p>
<p><strong> printf(&#8220;Enter c value:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;c);</strong></p>
<p><strong> if((a&gt;b)&amp;&amp;(a&gt;c))</strong></p>
<p><strong> printf(&#8220;A value is big&#8221;);</strong></p>
<p><strong> else if((b&gt;a)&amp;&amp;(b&gt;c))</strong></p>
<p><strong> printf(&#8220;B value is big&#8221;);</strong></p>
<p><strong> else if((c&gt;a)&amp;&amp;(c&gt;b))</strong></p>
<p><strong> printf(&#8220;C value is big&#8221;);</strong></p>
<p><strong> else</strong></p>
<p><strong> printf(&#8220;All are Equal&#8221;);</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p>&nbsp;</p>
<p><strong>…………………………………………………………………………………………………………………………………………………………..</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to find whether the given number is even or odd?</strong></p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int x;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>printf(&#8220;Enter x value:&#8221;);</strong></p>
<p><strong>scanf(&#8220;%d&#8221;,&amp;x);</strong></p>
<p><strong>if(x%2==0)</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(&#8220;%d: is even no&#8221;);</strong></p>
<p><strong>}</strong></p>
<p><strong>else</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(&#8220;%d: is odd no&#8221;);</strong></p>
<p><strong>}</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p><strong>……………………………………………………………………………………………………………………………………………………</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to print the multiplication table of a given number?</strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int i,j;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>for(i=1;i&lt;=20;i++)</strong></p>
<p><strong>{</strong></p>
<p><strong>for(j=1;j&lt;=20;j++)</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(&#8220;%d x %d = %d\n&#8221;,i,j,i*j);</strong></p>
<p><strong>}</strong></p>
<p><strong>printf(&#8220;\n press any key to continue:\n&#8221;);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>………………………………………………………………………………………………………….</strong></p>
<p><strong>W.A.P to display n natural numbers from 1?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int i=1;</strong></p>
<p><strong>while(i&lt;=10)</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(&#8220;%d&#8221;,i);</strong></p>
<p><strong>i++;</strong></p>
<p><strong>}</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p><strong>……………………………………………………………………………………………………………………………………………………….</strong></p>
<p><strong>W.A.P to find the sum of n natural numbers?</strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p>&nbsp;</p>
<p><strong>{</strong></p>
<p><strong> int n,i;</strong></p>
<p><strong> int sum=0;</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> printf(&#8220;Enter number:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;n);</strong></p>
<p><strong> i=1;</strong></p>
<p><strong> while(i&lt;=n)</strong></p>
<p><strong> {</strong></p>
<p><strong>  sum=sum+n;</strong></p>
<p><strong>  printf(&#8220;%d +&#8221;,i);</strong></p>
<p><strong>  i++;</strong></p>
<p>&nbsp;</p>
<p><strong> }</strong></p>
<p><strong> printf(&#8220;\b \b=%d&#8221;,sum);</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p><strong>………………………………………………………………………………………………………………………………………………………………….</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>W.A.P to accept a value between 1 and 4 and find addition, subtraction, multiplication and division based on that value using switch case?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong> int fno,sno,ch;</strong></p>
<p><strong> float res;</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> gotoxy(26,5);</strong></p>
<p><strong> printf(&#8220;*********************************\n&#8221;);</strong></p>
<p><strong> gotoxy(26,6);</strong></p>
<p><strong> printf(&#8220;          1.Addition.             \n&#8221;);</strong></p>
<p><strong> gotoxy(26,7);</strong></p>
<p><strong> printf(&#8220;          2.Subtraction           \n&#8221;);</strong></p>
<p><strong> gotoxy(26,8);</strong></p>
<p><strong> printf(&#8220;          3.Multiplication         \n&#8221;);</strong></p>
<p><strong> gotoxy(26,9);</strong></p>
<p><strong> printf(&#8220;          4.Division               \n&#8221;);</strong></p>
<p><strong> gotoxy(26,10);</strong></p>
<p><strong> printf(&#8220;***********************************\n&#8221;);</strong></p>
<p><strong> gotoxy(26,12);</strong></p>
<p><strong> printf(&#8220;Enter 1st no:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;fno);</strong></p>
<p><strong> gotoxy(26,15);</strong></p>
<p><strong> printf(&#8220;Enter 2nd no:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;sno);</strong></p>
<p><strong> gotoxy(26,18);</strong></p>
<p><strong> printf(&#8220;Enter choice:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;ch);</strong></p>
<p><strong> switch(ch)</strong></p>
<p><strong> {</strong></p>
<p><strong> case 1:</strong></p>
<p><strong>                {</strong></p>
<p><strong>                  res=fno+sno;</strong></p>
<p><strong>                  printf(&#8220;Addition value is:%7.2f\n&#8221;,res);break;</strong></p>
<p><strong>                }</strong></p>
<p>&nbsp;</p>
<p><strong> case 2:</strong></p>
<p><strong>                {</strong></p>
<p><strong>                  res=fno-sno;</strong></p>
<p><strong>                  printf(&#8220;Subtraction value is:%7.2f\n&#8221;,res);break;</strong></p>
<p><strong>                }</strong></p>
<p>&nbsp;</p>
<p><strong> case 3:</strong></p>
<p><strong>                {</strong></p>
<p><strong>                  res=fno*sno;</strong></p>
<p><strong>                  printf(&#8220;Multiplication value is:%7.2f\n&#8221;,res);break;</strong></p>
<p><strong>                }</strong></p>
<p>&nbsp;</p>
<p><strong> case 4:</strong></p>
<p><strong>                {</strong></p>
<p><strong>                  res=fno/sno;</strong></p>
<p><strong>                  printf(&#8220;Divsion value is:%7.2f\n&#8221;,res);break;</strong></p>
<p><strong>                }</strong></p>
<p><strong>                default:printf(&#8220;wrong option:&#8221;);</strong></p>
<p><strong>  }</strong></p>
<p><strong>  getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>………………………………………………………………………………………………………………………………………………………………..</strong></p>
<p><strong>W.A.P to print the given number is palindrome or not?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>                #include&lt;stdio.h&gt;</strong></p>
<p><strong>                #include&lt;conio.h&gt;</strong></p>
<p><strong>                void main()</strong></p>
<p><strong>                {</strong></p>
<p><strong>                 int rev=0,n,m;</strong></p>
<p><strong>                 clrscr();</strong></p>
<p><strong>                 printf(&#8220;Enter any number :&#8221;);</strong></p>
<p><strong>                 scanf(&#8220;%d&#8221;,&amp;n);</strong></p>
<p><strong>                 m=n;</strong></p>
<p><strong>                 while(m&gt;0)</strong></p>
<p><strong>                 {</strong></p>
<p><strong>                  rev=rev*10+(m%10);</strong></p>
<p><strong>                  m=m/10;</strong></p>
<p><strong>                 }</strong></p>
<p><strong>                 if(rev==n)</strong></p>
<p><strong>                  printf(&#8220;Given no is palindrome&#8221;);</strong></p>
<p><strong>                 else</strong></p>
<p><strong>                  printf(&#8220;Given no is not palindrome&#8221;);</strong></p>
<p><strong>                  getch();</strong></p>
<p><strong>                 }</strong></p>
<p>&nbsp;</p>
<p><strong>…………………………………………………………………………………………………………………………………………………………</strong></p>
<p><strong>W.A.P to print the given number is armstrong or not?</strong></p>
<p><strong>/* Arm strong no 153 it means sum of the cubes */</strong></p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong> int n,t,s=0,r;</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> printf(&#8220;Enter any no:&#8221;);</strong></p>
<p><strong> scanf(&#8220;%d&#8221;,&amp;n);</strong></p>
<p><strong> t=n;</strong></p>
<p><strong> while(t&gt;0)</strong></p>
<p><strong> {</strong></p>
<p><strong> r=t%10;</strong></p>
<p><strong> s=s+r*r*r;</strong></p>
<p><strong> t=t/10;</strong></p>
<p><strong> }</strong></p>
<p><strong> if(s==n)</strong></p>
<p><strong> {</strong></p>
<p><strong> printf(&#8220;%d is armstrong no&#8221;,n);</strong></p>
<p><strong> }</strong></p>
<p><strong> else</strong></p>
<p><strong> {</strong></p>
<p><strong> printf(&#8220;%d is not armstrong no&#8221;,n);</strong></p>
<p><strong> }</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p><strong>………………………………………………………………………………………………………………………………………………………………..</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to print the reverse of given number?</strong></p>
<p>&nbsp;</p>
<p><strong>                #include&lt;stdio.h&gt;</strong></p>
<p><strong>                #include&lt;conio.h&gt;</strong></p>
<p><strong>                void main()</strong></p>
<p><strong>                {</strong></p>
<p><strong>                 int n;</strong></p>
<p><strong>                 unsigned long rev=0;</strong></p>
<p><strong>                 clrscr();</strong></p>
<p><strong>                 printf(&#8220;Enter any number :&#8221;);</strong></p>
<p><strong>                 scanf(&#8220;%d&#8221;,&amp;n);</strong></p>
<p><strong>                 for(;n&gt;0;n=n/10)</strong></p>
<p><strong>                 {</strong></p>
<p><strong>                  rev=rev*10+(n%10);</strong></p>
<p><strong>                 }</strong></p>
<p><strong>                 printf(&#8220;reverse no is  : %lu&#8221;,rev);</strong></p>
<p><strong>                 getch();</strong></p>
<p><strong>                }</strong></p>
<p>&nbsp;</p>
<p><strong>…………………………………………………………………………………………………………………………………………………………….</strong></p>
<ol start="1">
<li><strong>W.A.P to print the following pattern:</strong></li>
</ol>
<p>&nbsp;</p>
<p><strong>i)   *   *    *   *                            *                                       </strong></p>
<p><strong>          *   *    *   *                            *    * </strong></p>
<p><strong>          *   *    *   *                            *    *    *</strong></p>
<p><strong>          *   *    *   *                            *    *    *     *</strong></p>
<p>&nbsp;</p>
<p><strong>      ii)1                                            1</strong></p>
<p><strong>1         2                                     2     2</strong></p>
<p><strong>1    2    3                               3     3    3</strong></p>
<p><strong>1    2    3   4                          4     4    4     4</strong></p>
<p>&nbsp;</p>
<p><strong>1(b)</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h.</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong> int r,c;</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> r=1;</strong></p>
<p><strong> while(r&lt;=5)</strong></p>
<p><strong> {</strong></p>
<p><strong> c=1;</strong></p>
<p><strong> while(c&lt;=5)</strong></p>
<p><strong> {</strong></p>
<p><strong> if(r&gt;=c)</strong></p>
<p><strong> printf(&#8220;%-3c&#8221;,&#8217;*');</strong></p>
<p><strong> else</strong></p>
<p><strong> printf(&#8220;%c&#8221;,32);</strong></p>
<p><strong> c++;</strong></p>
<p><strong> }</strong></p>
<p><strong> r++;</strong></p>
<p><strong> printf(&#8220;\n&#8221;);</strong></p>
<p><strong> }</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p><strong> </strong></p>
<p><strong>……………………………………………………………………………………………………………………………………………………</strong></p>
<p><strong> </strong></p>
<p><strong>    #include&lt;stdio.h&gt;</strong></p>
<p><strong>    #include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>    void main()</strong></p>
<p><strong>    {</strong></p>
<p><strong>      int r,c;</strong></p>
<p><strong>      clrscr();</strong></p>
<p><strong>      r=1;</strong></p>
<p><strong>                      while(r&lt;=5)</strong></p>
<p><strong>                      {</strong></p>
<p><strong>                                       c=1;</strong></p>
<p><strong>                                       while(c&lt;=5-r)</strong></p>
<p><strong>                                       {</strong></p>
<p><strong>                                                printf(&#8220;%-3c&#8221;,32);</strong></p>
<p><strong>                                                 c++;</strong></p>
<p><strong>                                       }</strong></p>
<p><strong>                                                c=1;</strong></p>
<p><strong>                                                while(c&lt;=2*r-1)</strong></p>
<p><strong>                                       {</strong></p>
<p><strong>                                                if(r&gt;=c)</strong></p>
<p><strong>                                                printf(&#8220;%-3d&#8221;,c);</strong></p>
<p><strong>                                                else</strong></p>
<p><strong>                                                printf(&#8220;%-3d&#8221;,2*r-c);</strong></p>
<p><strong>                                                c++;</strong></p>
<p><strong>                                                }</strong></p>
<p><strong>                                                r++;</strong></p>
<p><strong>                                                printf(&#8220;\n&#8221;);</strong></p>
<p><strong>                                }</strong></p>
<p><strong>                getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>………………………………………………………………………………………………………………………………………………………………</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>W.A.P to initialize single dimensional array and display the array elements?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int all[10];</strong></p>
<p><strong>int i;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>/*string the values into array */</strong></p>
<p><strong>for(i=1;i&lt;=10;i++)</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(&#8220;Enter the cell value:&#8221;);</strong></p>
<p><strong>scanf(&#8220;%d&#8221;,&amp;all[i]);</strong></p>
<p><strong>}</strong></p>
<p><strong>/* printf the values of an array */</strong></p>
<p><strong>for(i=1;i&lt;=10;i++)</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(&#8220;%d\t&#8221;,all[i]);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>………………………………………………………………………………………………………………………………………………………….</strong></p>
<p><strong>W.A.P to accept two dimensional array and display array elements?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int arr[5][5];</strong></p>
<p><strong>int i,j;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>for(i=1;i&lt;=5;i++)</strong></p>
<p><strong>                for(j=1;j&lt;=5;j++)</strong></p>
<p><strong>                {</strong></p>
<p><strong>                                if((i+j)==6)</strong></p>
<p><strong>                                arr[i][j]=9;</strong></p>
<p><strong>                                else</strong></p>
<p><strong>                                arr[i][j]=1;</strong></p>
<p><strong>                                                for(i=1;i&lt;=5;i++)</strong></p>
<p><strong>                                                {</strong></p>
<p><strong>                                                                for(j=1;j&lt;=5;j++)</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>                                                                printf(&#8220;%d\t&#8221;,arr[i][j]);</strong></p>
<p><strong>                                                                printf(&#8220;\n&#8221;);</strong></p>
<p>&nbsp;</p>
<p><strong>                }                              }</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>………………………………………………………………………………………………………………………………………………………..</strong></p>
<p><strong>W.A.P to find the multiplication of two matrices?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong>#include&lt;process.h&gt;</strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>                void accept(int [][20],int,int);</strong></p>
<p><strong>                void disp(int [][20],int,int);</strong></p>
<p><strong>                void mul_arr(int [][20],int [][20],int [][20],int,int,int);</strong></p>
<p><strong>                int a[20][20],b[20][20],mul[20][20],m,n,p,q;</strong></p>
<p><strong>                clrscr();</strong></p>
<p><strong>                printf(&#8220;Enter no of rows and cols into Matrix A:&#8221;);</strong></p>
<p><strong>                scanf(&#8220;%d%d&#8221;,&amp;m,&amp;n);</strong></p>
<p><strong>                printf(&#8220;Enter no of rows and cols into Matrix B:&#8221;);</strong></p>
<p><strong>                scanf(&#8220;%d%d&#8221;,&amp;p,&amp;q);</strong></p>
<p><strong>                if( n != p )</strong></p>
<p><strong>                {</strong></p>
<p><strong>                                printf(&#8220;Multiplication is not possible&#8221;);</strong></p>
<p><strong>                                getch();</strong></p>
<p><strong>                                exit(0);</strong></p>
<p><strong>                }</strong></p>
<p><strong>                printf(&#8220;Enter array elements into A:&#8221;);</strong></p>
<p><strong>                accept(a,m,n);</strong></p>
<p><strong>                printf(&#8220;Enter array elements into B:&#8221;);</strong></p>
<p><strong>                accept(b,p,q);</strong></p>
<p><strong>                mul_arr(a,b,mul,m,n,q);</strong></p>
<p><strong>                printf(&#8220;Array elements in Matrix A:\n&#8221;);</strong></p>
<p><strong>                disp(a,m,n);</strong></p>
<p><strong>                printf(&#8220;\nArray elements in Matrix B:\n&#8221;);</strong></p>
<p><strong>                disp(b,p,q);</strong></p>
<p><strong>                printf(&#8220;\nArray elements in Multiplication Matrix:\n&#8221;);</strong></p>
<p><strong>                disp(mul,m,q);</strong></p>
<p><strong>                getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>void accept(int a[][20],int r,int c)</strong></p>
<p><strong>{</strong></p>
<p><strong>                int i,j;</strong></p>
<p><strong>                for(i=0;i&lt;r;i++)</strong></p>
<p><strong>                {</strong></p>
<p><strong>                                for(j=0;j&lt;c;j++)</strong></p>
<p><strong>                                {</strong></p>
<p><strong>                                                scanf(&#8220;%d&#8221;,&amp;a[i][j]);</strong></p>
<p><strong>                                }</strong></p>
<p><strong>                }</strong></p>
<p><strong>}</strong></p>
<p><strong>void disp(int a[][20],int r,int c)</strong></p>
<p><strong>{</strong></p>
<p><strong>                int i,j;</strong></p>
<p><strong>                for(i=0;i&lt;r;i++)</strong></p>
<p><strong>                {</strong></p>
<p><strong>                                for(j=0;j&lt;c;j++)</strong></p>
<p><strong>                                {</strong></p>
<p><strong>                                                printf(&#8220;%5d&#8221;,a[i][j]);</strong></p>
<p><strong>                                }</strong></p>
<p><strong>                                printf(&#8220;\n&#8221;);</strong></p>
<p><strong>                }</strong></p>
<p><strong>}</strong></p>
<p><strong>void mul_arr(int a[][20],int b[][20],int mul[][20],int m,int n,int q)</strong></p>
<p><strong>{</strong></p>
<p><strong>                int i,j,k;</strong></p>
<p><strong>                for(i=0;i&lt;m;i++)</strong></p>
<p><strong>                {</strong></p>
<p><strong>                                for(j=0;j&lt;q;j++)</strong></p>
<p><strong>                                {</strong></p>
<p><strong>                                                mul[i][j]=0;</strong></p>
<p><strong>                                                for(k=0;k&lt;n;k++)</strong></p>
<p><strong>                                                {</strong></p>
<p><strong>                                                                mul[i][j]=mul[i][j]+a[i][k]*b[k][j];</strong></p>
<p><strong>                                                }</strong></p>
<p><strong>                                }</strong></p>
<p><strong>                }</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p><strong>………………………………………………………………………………………………………………………………………………………..</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to find the addition of two matrices?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>//W.a.p to accept any two dimensional array and calculate and display</strong></p>
<p><strong>//            transpose of the given matrix using functions.</strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>                void accept(int [][20],int,int);</strong></p>
<p><strong>                void disp(int [][20],int,int);</strong></p>
<p><strong>                void trans_mat(int [][20],int [][20],int,int);</strong></p>
<p><strong>                int a[20][20],b[20][20],trans[20][20],r,c;</strong></p>
<p><strong>                clrscr();</strong></p>
<p><strong>                printf(&#8220;Enter no of rows and cols:&#8221;);</strong></p>
<p><strong>                scanf(&#8220;%d%d&#8221;,&amp;r,&amp;c);</strong></p>
<p><strong>                printf(&#8220;Enter array elements into A:&#8221;);</strong></p>
<p><strong>                accept(a,r,c);</strong></p>
<p><strong>                trans_mat(a,trans,r,c);</strong></p>
<p><strong>                printf(&#8220;Given array elements in A:\n&#8221;);</strong></p>
<p><strong>                disp(a,r,c);</strong></p>
<p><strong>                printf(&#8220;\nTranspose of given array :\n&#8221;);</strong></p>
<p><strong>                disp(trans,c,r);</strong></p>
<p><strong>                getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>void accept(int x[][20],int r,int c)</strong></p>
<p><strong>{</strong></p>
<p><strong>                int i,j;</strong></p>
<p><strong>                for(i=0;i&lt;r;i++)</strong></p>
<p><strong>                {</strong></p>
<p><strong>                                for(j=0;j&lt;c;j++)</strong></p>
<p><strong>                                {</strong></p>
<p><strong>                                                scanf(&#8220;%d&#8221;,&amp;x[i][j]);</strong></p>
<p><strong>                                }</strong></p>
<p><strong>                }</strong></p>
<p><strong>}</strong></p>
<p><strong>void disp(int x[][20],int r,int c)</strong></p>
<p><strong>{</strong></p>
<p><strong>                int i,j;</strong></p>
<p><strong>                for(i=0;i&lt;r;i++)</strong></p>
<p><strong>                {</strong></p>
<p><strong>                                for(j=0;j&lt;c;j++)</strong></p>
<p><strong>                                {</strong></p>
<p><strong>                                                printf(&#8220;%5d&#8221;,x[i][j]);</strong></p>
<p><strong>                                }</strong></p>
<p><strong>                                printf(&#8220;\n&#8221;);</strong></p>
<p><strong>                }</strong></p>
<p><strong>}</strong></p>
<p><strong>void trans_mat(int a[][20],int trans[][20],int r,int c)</strong></p>
<p><strong>{</strong></p>
<p><strong>                int i,j;</strong></p>
<p><strong>                for(i=0;i&lt;r;i++)</strong></p>
<p><strong>                {</strong></p>
<p><strong>                                for(j=0;j&lt;c;j++)</strong></p>
<p><strong>                                {</strong></p>
<p><strong>                                                trans[j][i]=a[i][j];</strong></p>
<p><strong>                                }</strong></p>
<p><strong>                }</strong></p>
<p><strong>}</strong></p>
<p><strong>…………………………………………………………………………………………………………………………………………………….</strong></p>
<p><strong>W.A.P to demonstrate function declaration, calling and definition?</strong></p>
<p>&nbsp;</p>
<p><strong>                #include&lt;stdio.h&gt;</strong></p>
<p><strong>                #include&lt;conio.h&gt;</strong></p>
<p><strong>                void main()</strong></p>
<p><strong>                {</strong></p>
<p><strong>                 void disp(int);</strong></p>
<p><strong>                 clrscr();</strong></p>
<p><strong>                 disp(100);</strong></p>
<p><strong>                 getch();</strong></p>
<p><strong>                }</strong></p>
<p><strong>                void disp(int x)</strong></p>
<p><strong>                {</strong></p>
<p><strong>                 printf(&#8220;  x = %d&#8221;,x);</strong></p>
<p><strong>                }</strong></p>
<p><strong>………………………………………………………………………………………………………………………………………………………&#8230;</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to swap two number using function?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int a,b;</strong></p>
<p><strong>a=10;</strong></p>
<p><strong>b=5;</strong></p>
<p><strong>printf(&#8220;\n before swapping=&gt; a=%d, b=%d&#8221;,a,b);</strong></p>
<p><strong>swap(&amp;a,&amp;b);</strong></p>
<p><strong>printf(&#8220;\n after swapping=&gt;a=%d,b=%d&#8221;,a,b);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p><strong>int swap(int *x,int *y)</strong></p>
<p><strong>{</strong></p>
<p><strong>  int t;</strong></p>
<p><strong>  t=*x;</strong></p>
<p><strong>  *x=*y;</strong></p>
<p><strong>  *y=t;</strong></p>
<p><strong>}</strong></p>
<p><strong>……………………………………………………………………………………………………………………………………………………………</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to concat two strings using string handling function?</strong></p>
<p><strong>/* string functions strcat() */</strong></p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int a;</strong></p>
<p><strong>char s1[20],s2[20];</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>printf(&#8220;Enter first string:&#8221;);</strong></p>
<p><strong>gets(s1);</strong></p>
<p><strong>printf(&#8220;Enter second string:&#8221;);</strong></p>
<p><strong>gets(s2);</strong></p>
<p><strong>a=strcat(s1,s2);</strong></p>
<p><strong>puts(a);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p><strong>…………………………………………………………………………………………………………………………………………………….</strong></p>
<p><strong>W.A.P to convert lower case characters into upper case?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>/* strupr(),strlwr()*/</strong></p>
<p>&nbsp;</p>
<p><strong>main()</strong></p>
<p><strong>{</strong></p>
<p><strong> int a,b;</strong></p>
<p><strong> char s1[20],s2[20];</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> printf(&#8220;Enter 1st string:&#8221;);</strong></p>
<p><strong> gets(s1);</strong></p>
<p><strong> printf(&#8220;Enter 2nd string:&#8221;);</strong></p>
<p><strong> gets(s2);</strong></p>
<p><strong> a=strupr(s1);</strong></p>
<p><strong> b=strlwr(s2);</strong></p>
<p><strong> puts(a);</strong></p>
<p><strong> puts(b);</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p><strong>…………………………………………………………………………………………………………………………………………………..</strong></p>
<p><strong>W.A.P create a pointer and to access the value present in the address using pointer?</strong></p>
<p>&nbsp;</p>
<p><strong>/* pointers*/</strong></p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p>&nbsp;</p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int n,*p;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>n=200;</strong></p>
<p><strong>printf(&#8220;The value stored in N is:%d\n&#8221;,n);</strong></p>
<p><strong>*p=&amp;n;</strong></p>
<p><strong>printf(&#8220;The value of pointer p is also:%d&#8221;,*p);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p><strong>……………………………………………………………………………………………………………………………………………………………….</strong></p>
<p><strong>W.A.P to accept employee data using call by reference and display?</strong></p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>main()</strong></p>
<p><strong>{</strong></p>
<p><strong>FILE *fp;</strong></p>
<p><strong>char ch=&#8217;y';</strong></p>
<p><strong>struct emp</strong></p>
<p><strong>{</strong></p>
<p><strong>char name[40];</strong></p>
<p><strong>int age,bs;</strong></p>
<p><strong>};</strong></p>
<p><strong>struct emp e;</strong></p>
<p><strong>fp=fopen(&#8220;Employ.dat&#8221;,&#8221;w&#8221;);</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>while((ch==&#8217;y')||(ch==&#8217;Y'))</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(&#8220;\n Enter name,age and basic salary&#8221;);</strong></p>
<p><strong>scanf(&#8220;%s %d %d&#8221;,&amp;e.name,&amp;e.age,&amp;e.bs);</strong></p>
<p><strong>fprintf(fp,&#8221;%s\t%d\t%d\n&#8221;,e.name,e.age,e.bs);</strong></p>
<p><strong>printf(&#8220;Add another Record(y/n)?&#8221;);</strong></p>
<p><strong>fflush(stdin);</strong></p>
<p><strong>ch=getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>fclose(fp);</strong></p>
<p><strong>}</strong></p>
<p><strong>…………………………………………………………………………………………………………………………………………………</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to accept a structure from keyboard and display the given data?</strong></p>
<p><strong>/* structures */</strong></p>
<p>&nbsp;</p>
<p><strong>struct marks</strong></p>
<p><strong>{</strong></p>
<p><strong>int sno,m1,m2,m3,tot;</strong></p>
<p><strong>char sna[10];</strong></p>
<p><strong>float avg;</strong></p>
<p><strong>}x;</strong></p>
<p><strong>main()</strong></p>
<p><strong>{</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>printf (&#8220;Enter student no:&#8221;);</strong></p>
<p><strong>scanf(&#8220;%d&#8221;,&amp;x.sno);</strong></p>
<p><strong>printf(&#8220;Enter student name:&#8221;);</strong></p>
<p><strong>scanf(&#8220;%s&#8221;,&amp;x.sna);</strong></p>
<p><strong>printf(&#8220;Enter word marks:&#8221;);</strong></p>
<p><strong>scanf(&#8220;%d&#8221;,x.m1);</strong></p>
<p><strong>printf(&#8220;Enter excel marks:&#8221;);</strong></p>
<p><strong>scanf(&#8220;%d&#8221;,&amp;x.m3);</strong></p>
<p><strong>x.tot=x.m1+x.m2+x.m3;</strong></p>
<p><strong>x.avg=x.tot/3;</strong></p>
<p><strong>printf(&#8220;Student no:%d&#8221;,x.sno);</strong></p>
<p><strong>printf(&#8220;Student name:%s&#8221;,x.sna);</strong></p>
<p><strong>printf(&#8220;Marks in word:%d&#8221;,x.m1);</strong></p>
<p><strong>printf(&#8220;Marks in excel:%d&#8221;,x.m2);</strong></p>
<p><strong>printf(&#8220;Marks in Access:%d&#8221;,x.m3);</strong></p>
<p><strong>printf(&#8220;Total marks:%d&#8221;,x.tot);</strong></p>
<p><strong>printf(&#8220;Average Marks:%f&#8221;,x.avg);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p><strong>……………………………………………………………………………………………………………………………………………………</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to accept a union from keyboard and display the given data?</strong></p>
<p>&nbsp;</p>
<p><strong>                #include&lt;stdio.h&gt;</strong></p>
<p><strong>                #include&lt;conio.h&gt;</strong></p>
<p><strong>                union emp</strong></p>
<p><strong>                {</strong></p>
<p><strong>                 int eno;</strong></p>
<p><strong>                 char ename[10];</strong></p>
<p><strong>                 float esal;</strong></p>
<p><strong>                }e;</strong></p>
<p><strong>                void main()</strong></p>
<p><strong>                {</strong></p>
<p><strong>                 clrscr();</strong></p>
<p><strong>                 printf(&#8221; Enter emp no :&#8221;);</strong></p>
<p><strong>                 scanf(&#8220;%d&#8221;,&amp;e.eno);</strong></p>
<p><strong>                 printf(&#8220;Enter emp name :&#8221;);</strong></p>
<p><strong>                 fflush(stdin);</strong></p>
<p><strong>                 gets(e.ename);</strong></p>
<p><strong>                 printf(&#8220;Enter emp salary :&#8221;);</strong></p>
<p><strong>                 scanf(&#8220;%f&#8221;,&amp;e.esal);</strong></p>
<p><strong>                 printf(&#8220;\nEmp number : %d&#8221;,e.eno);</strong></p>
<p><strong>                 printf(&#8220;\nEmp name   : %s&#8221;,e.ename);</strong></p>
<p><strong>                 printf(&#8220;\nEmp salary : %.2f&#8221;,e.esal);</strong></p>
<p><strong>                 getch();</strong></p>
<p><strong>                }</strong></p>
<p><strong>……………………………………………………………………………………………………………………………………………………………</strong></p>
<p>&nbsp;</p>
<p><strong>W.A.P to read a string and store in a file?</strong></p>
<p><strong>And</strong></p>
<p><strong>W.A.P to accept employee details and store in a file?</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>main()</strong></p>
<p><strong>{</strong></p>
<p><strong>FILE *fp;</strong></p>
<p><strong>char name[40];</strong></p>
<p><strong>int age,bs;</strong></p>
<p><strong>fp=fopen(&#8220;employ.txt&#8221;,&#8221;r&#8221;);</strong></p>
<p><strong>if(fp==NULL)</strong></p>
<p><strong>{</strong></p>
<p><strong>puts(&#8220;cannot open file!&#8221;);</strong></p>
<p><strong>exit(0);</strong></p>
<p><strong>}</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>while(fscanf(fp,&#8221;%s\t%d\t%d&#8221;,&amp;name,&amp;age,&amp;bs)!=EOF)</strong></p>
<p><strong>printf(&#8220;\n %s\t%d\t%d&#8221;,name,age,bs);</strong></p>
<p><strong>fclose(fp);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p>&nbsp;</p>
<p><strong>………………………………………………………………………………………………………………………………………………………..</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/c-labprogrames/'>C-LabProgrames</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1325/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1325&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/11/12/c-lab-programs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>
	</item>
		<item>
		<title>Function and Arrays in C-Language</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/10/09/function-and-arrays-in-c-language/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/10/09/function-and-arrays-in-c-language/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 14:19:08 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[Function and Arrays in C-Language]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1295</guid>
		<description><![CDATA[Functions and Arrays                                                  FUNCTIONS                                                  ———     Function:   ———                 It is a self contained block of statements and is used several   times in a program but defined only once.     library function(or)predefined functions:-   —————————————–               The functions which are inbuilt with the compiler is called as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1295&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="post-563">
<h2><a title="Permanent link to Functions and Arrays" href="http://sailjamehra.wordpress.com/2009/04/29/functions-and-arrays/" rel="bookmark">Functions and Arrays</a></h2>
<div>
<p><strong>                                                 FUNCTIONS</strong></p>
<p><strong>                                                 ———</strong></p>
<p><strong> </strong></p>
<p><strong>  Function:</strong></p>
<p><strong>  ———</strong></p>
<p><strong> </strong></p>
<p><strong>              It is a self contained block of statements and is used several</strong></p>
<p><strong>  times in a program but defined only once.</strong></p>
<p><strong> </strong></p>
<p><strong>  library function(or)predefined functions:-</strong></p>
<p><strong>  —————————————–</strong></p>
<p><strong>              The functions which are inbuilt with the compiler is called as</strong></p>
<p><strong>              library function.</strong></p>
<p><strong>           ex:- printf(),scanf(),getch(),…..etc</strong></p>
<p><strong> </strong></p>
<p><strong>  User defined functions:-</strong></p>
<p><strong>  ————————</strong></p>
<p><strong>              User can defined functions to do a task relavent to their program.</strong></p>
<p><strong>   such functions are called user defined functions.</strong></p>
<p><strong> </strong></p>
<p><strong>            Any function has 3 things.</strong></p>
<p><strong>            1) Function declaration</strong></p>
<p><strong>            2) Function definition</strong></p>
<p><strong>            3) Function calling.</strong></p>
<p><strong> </strong></p>
<p><strong>            In case of library functions the function declaration is in headers,</strong></p>
<p><strong>            definition is in C libraries and calling is in your source program.</strong></p>
<p><strong> </strong></p>
<p><strong>            In case of user defined functions all the three things are in your</strong></p>
<p><strong>            source program.</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Function declaration:-</strong></p>
<p><strong>———————</strong></p>
<p><strong>                    syn:-  returntype  func_name([arg_list]);</strong></p>
<p><strong>                    ex:-  void sum(int,int);</strong></p>
<p><strong> </strong></p>
<p><strong>Function definition:-</strong></p>
<p><strong>——————-</strong></p>
<p><strong>              syn:-  returntype func_name([arg_list])</strong></p>
<p><strong>                              {</strong></p>
<p><strong>                                      body;</strong></p>
<p><strong>                              }</strong></p>
<p><strong> </strong></p>
<p><strong>Function calling:-</strong></p>
<p><strong>—————-</strong></p>
<p><strong>                     syn:-  func_name([arg_list]);</strong></p>
<p><strong>                     ex:-  sum(a,b);</strong></p>
<p><strong> </strong></p>
<p><strong>NOTE:-  The arguments which are given at the time of function declaration and</strong></p>
<p><strong>            function definion are called arguments (or) formal arguments.</strong></p>
<p><strong>          The arguments which are given at the time of function calling</strong></p>
<p><strong>            are known as parameters (or) actual arguments.</strong></p>
<p><strong> </strong></p>
<p><strong>Void :-  Empty data type.</strong></p>
<p><strong> </strong></p>
<p><strong>  RULES FOR CREATING AND ACCESSING USER DEFINED FUNCTIONS:</strong></p>
<p><strong>  ——————————————————-</strong></p>
<p><strong>1.A function can be called by any no of times.</strong></p>
<p><strong>2.A function may or may not return a value.</strong></p>
<p><strong>3.A function may or may not receive arguments</strong></p>
<p><strong>4.If a function does not return any value,the function will be specified as</strong></p>
<p><strong>   void.</strong></p>
<p><strong>5.If a function returns a value only one value can be returned.</strong></p>
<p><strong>6.If a function returns a value the returning value must be returned with a</strong></p>
<p><strong>  statement “return”.</strong></p>
<p><strong>7.If a function returns a value the execution of return statement should be</strong></p>
<p><strong>  last.</strong></p>
<p><strong>8.A function returns an integer value by default;</strong></p>
<p><strong>9.If a function returns a value , the returning value should be match with</strong></p>
<p><strong>  the function return data type.</strong></p>
<p><strong>10.A function is defined after (or) before main function.</strong></p>
<p><strong>11.Before calling a function , the function declaration (or) definition</strong></p>
<p><strong>    is must and should.</strong></p>
<p><strong>12.If a function declaration is specified before the function call,The function</strong></p>
<p><strong> fn    definition can be specified any where in the program.</strong></p>
<p><strong>13.If a function definition is specified before the function call,then the</strong></p>
<p><strong>   function declaration is not necessary.</strong></p>
<p><strong>14.A function is executed when the function is call by its name.</strong></p>
<p><strong>15.The function defintion should not be terminated with semicolon.</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>RETURN:-</strong></p>
<p><strong>——-</strong></p>
<p><strong>           Exits immediately from the corresponding executing function to the</strong></p>
<p><strong>           calling. return  Optionlly returning a value.</strong></p>
<p><strong>           syntax:-  return [&lt;expression&gt;];</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Function prototypes (or) Function categories:-</strong></p>
<p><strong>———————————————-</strong></p>
<p><strong>   A Function depending on whether arguments are present (or) not and whether</strong></p>
<p><strong>a value is returning or not .They belong to one of the following categories.</strong></p>
<p><strong>  1)Function with no arguments and no return value</strong></p>
<p><strong>  2)Function with arguments and no return value.</strong></p>
<p><strong>  3)Function with arguments and return value.</strong></p>
<p><strong>  4)Function with no orguements and return value.</strong></p>
<p><strong>Recursive function:-</strong></p>
<p><strong>——————-</strong></p>
<p><strong>   Calling a function with in same function is known as recursion (or)</strong></p>
<p><strong>Recursive function.If we want to work with recursive function we must follow</strong></p>
<p><strong>the two conditions.</strong></p>
<p><strong>  1. Termination condition.</strong></p>
<p><strong>  2. Calling by itself.</strong></p>
<p><strong> </strong></p>
<p><strong>gotoxy():-</strong></p>
<p><strong>———-</strong></p>
<p><strong>gotoxy moves the cursor to the given position in the current text window.</strong></p>
<p><strong> </strong></p>
<p><strong>Declaration:  void gotoxy(int x, int y);</strong></p>
<p><strong>            here x=columns y=rows</strong></p>
<p><strong>            IN textmode 25 rows and 80 columns are there.</strong></p>
<p><strong>_setcursortype():-</strong></p>
<p><strong>——————</strong></p>
<p><strong>   Selects cursor appearance</strong></p>
<p><strong> </strong></p>
<p><strong> Declaration:  void _setcursortype(int cur_t);</strong></p>
<p><strong> </strong></p>
<p><strong> Remarks:</strong></p>
<p><strong>Sets the cursor type to one of the following:</strong></p>
<p><strong>  þ _NOCURSOR     (turns off the cursor)</strong></p>
<p><strong>  þ _SOLIDCURSOR  (solid block cursor)</strong></p>
<p><strong>  þ _NORMALCURSOR (normal underscore cursor)</strong></p>
<p><strong> </strong></p>
<p><strong>kbhit():-</strong></p>
<p><strong>———–</strong></p>
<p><strong>  Checks for currently available keystrokes</strong></p>
<p><strong> </strong></p>
<p><strong>Declaration:  int kbhit(void);</strong></p>
<p><strong> </strong></p>
<p><strong>delay():-         &lt;dos.h&gt;</strong></p>
<p><strong>——–</strong></p>
<p><strong>     It suspends execution for an interval(milli seconds).</strong></p>
<p><strong>    syn:-  void delay(unsigned milliseconds);</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>gets:-</strong></p>
<p><strong>          It gets a string from stdin.</strong></p>
<p><strong>          declaration:-  char * gets(char *s);</strong></p>
<p><strong> </strong></p>
<p><strong>puts:-</strong></p>
<p><strong>          It outputs a string to stdout and appends a new line character.</strong></p>
<p><strong>          declaration:-  int puts(const char *s);</strong></p>
<p><strong> </strong></p>
<p><strong>getch():-</strong></p>
<p><strong>          It gets a character from console but does not echoes to the screen.</strong></p>
<p><strong>       declaration:-  int getch(void);</strong></p>
<p><strong> </strong></p>
<p><strong>getche():-</strong></p>
<p><strong>          It gets a character from console but it echoes to the screen.</strong></p>
<p><strong>          declaration:- int getche(void);</strong></p>
<p><strong> </strong></p>
<p><strong>getchar():-</strong></p>
<p><strong>          getchar is a macro that gets a character from stdin</strong></p>
<p><strong>          Declaration:</strong></p>
<p><strong>                    int getchar(void);</strong></p>
<p><strong> </strong></p>
<p><strong>putchar():-</strong></p>
<p><strong>          It is a macro that outputs a character on stdout</strong></p>
<p><strong>          Declaration:</strong></p>
<p><strong>                    int putchar(int c);</strong></p>
<p><strong> </strong></p>
<p><strong>                         STRING HANDLING FUNCTIONS    &lt;string.h&gt;</strong></p>
<p><strong>                         ————————-</strong></p>
<p><strong>1) strlen():-</strong></p>
<p><strong>          It calculates the length(no of characters) of the given string.</strong></p>
<p><strong>          declaration:-</strong></p>
<p><strong>                   size_t strlen(const char *s);</strong></p>
<p><strong> </strong></p>
<p><strong>2)strrev():-</strong></p>
<p><strong>          It reverses the all characters in the given string(except terminating</strong></p>
<p><strong>                   null character ( ).</strong></p>
<p><strong>          declaration:-</strong></p>
<p><strong>                   char *strrev(char *s);</strong></p>
<p><strong> </strong></p>
<p><strong>3)strcpy():-</strong></p>
<p><strong>          It copies all characters in the given string into destination string</strong></p>
<p><strong>          declaration:-</strong></p>
<p><strong>                   char *strcpy(char *dest,const char *src);</strong></p>
<p><strong> </strong></p>
<p><strong>4)strcat():-</strong></p>
<p><strong>          Appends one string to another.</strong></p>
<p><strong>          Declaration:</strong></p>
<p><strong>                    char *strcat(char *dest, const char *src);</strong></p>
<p><strong> </strong></p>
<p><strong>5)strlwr():-</strong></p>
<p><strong>          It converts all characters in given string into lowercase.</strong></p>
<p><strong>          declaration:-</strong></p>
<p><strong>                   char *strlwr(char *s);</strong></p>
<p><strong> </strong></p>
<p><strong>6)strupr():-</strong></p>
<p><strong>          It converts all characters in given string into uppercase.</strong></p>
<p><strong>          declaration:-</strong></p>
<p><strong>                   char *strupr(char *s);</strong></p>
<p><strong> </strong></p>
<p><strong>7)strncpy():-</strong></p>
<p><strong>          It is used to copy specified no of characters into destination string.</strong></p>
<p><strong>          declaration:-</strong></p>
<p><strong>                   char *strncpy(char *dest, const char *src, size_t maxlen);</strong></p>
<p><strong> </strong></p>
<p><strong>8)strcmp():-</strong></p>
<p><strong>              It compares two strings with case sensitivity.</strong></p>
<p><strong>              declaration:-</strong></p>
<p><strong>                       int strcmp(const char *s1, const char*s2);</strong></p>
<p><strong> </strong></p>
<p><strong>9)stricmp():-</strong></p>
<p><strong>             It is a function which is used to compare two strings without</strong></p>
<p><strong>                   case sensitivity.</strong></p>
<p><strong>             declaration:-</strong></p>
<p><strong>                    int strcmpi(const char *s1, const char *s2);</strong></p>
<p><strong> </strong></p>
<p><strong>10)strcmpi():-</strong></p>
<p><strong>            It is a macro which is used to compare two strings without</strong></p>
<p><strong>                   case sensitivity.</strong></p>
<p><strong>            declaration:</strong></p>
<p><strong>                    int stricmp(const char *s1, const char *s2);</strong></p>
<p><strong> </strong></p>
<p><strong>Return Value:</strong></p>
<p><strong>These routines return an int value that is</strong></p>
<p><strong>   &lt;  0  if s1 &lt;  s2</strong></p>
<p><strong>   == 0  if s1 == s2</strong></p>
<p><strong>   &gt;  0  if s1 &gt;  s2</strong></p>
<p><strong> </strong></p>
<p><strong>Two dimensional character arrays:-</strong></p>
<p><strong>———————————</strong></p>
<p><strong>          A list of names can be treated as a table of strings and two-dimensional</strong></p>
<p><strong>character array can be used to store the entire list.</strong></p>
<p><strong>For example:-</strong></p>
<p><strong>          char st[20][20] may be used to store a list of 20 strings,each of</strong></p>
<p><strong>length mot more than 20 characters.</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>                                       ARRAYS</strong></p>
<p><strong>                                       ——</strong></p>
<p><strong>Definition:-</strong></p>
<p><strong>               A Group of data items of same data type stored in a continuous</strong></p>
<p><strong>   Memory allocation and it can be represented by a single identifier.</strong></p>
<p><strong>               That means a group of data items that share a common name. A</strong></p>
<p><strong>   Perticular value is indicated by writing a number called index(or)subscript</strong></p>
<p><strong>   in square braces( [] ) after the array name.</strong></p>
<p><strong>   C supports 3 types of arrays. They are</strong></p>
<p><strong>   1.single dimensional arrays (or) One dimensional arrays.</strong></p>
<p><strong>   2.Two dimensional arrays (or) double dimensional arrays.</strong></p>
<p><strong>   3.Multi dimensional arrays.</strong></p>
<p><strong>1.Single dimensional arrays:-</strong></p>
<p><strong>   A list of items can be given one variable name using only one index.such</strong></p>
<p><strong>   a variable is called single dimensional arrays.</strong></p>
<p><strong>      In single dimensional array the elements are represented one after the</strong></p>
<p><strong>      Other in edges of Memory bytes.</strong></p>
<p><strong>      syn:-  data type arr_name[size];</strong></p>
<p><strong>      ex:-  int a[5];</strong></p>
<p><strong>      here elements are:-   a[0],a[1],a[2],a[3],a[4];</strong></p>
<p><strong>  In any array the array index is 0 to n-1.</strong></p>
<p><strong>Initialization:-</strong></p>
<p><strong>  syn:- data type arr_name[]={val-1,val-2,val-3,……..val-n};</strong></p>
<p><strong>  ex:-   int a[]={1,2,3,4,5,6,……};</strong></p>
<p><strong> </strong></p>
<p><strong>2.Two dymensional arrays :-</strong></p>
<p><strong>   A two dimensional array can store a table of values which contains rows</strong></p>
<p><strong>   and columns . In two dimensional arrays we use two index values.One for</strong></p>
<p><strong>   Rows and another for columns.</strong></p>
<p><strong>   Declaration:-  data type arr_name[row_size][col_size];</strong></p>
<p><strong>   ex:-  int a[2][3];</strong></p>
<p><strong>   here elements:-  a[0][0]  a[0][1]  a[0][2]</strong></p>
<p><strong>                       a[1][0]  a[1][1]  a[1][2]</strong></p>
<p><strong>   Initialization :-</strong></p>
<p><strong>     Form:1:</strong></p>
<p><strong>   datatype arr_name[rowsize][colsize]={val-1,val-2,………,val-n};</strong></p>
<p><strong>   ex:- int a[2][3]={1,2,3,4,5,6};</strong></p>
<p><strong>   Form:2:</strong></p>
<p><strong>           datatype  arr_name[rowsize][colsize]={ {val-1,val-2,……},</strong></p>
<p><strong>                   {val-1,val-2,…val-n},{val-1,val-2,….val-n}………..};</strong></p>
<p><strong>     ex:- int a[2][3]={ {1,3,4},{2,3,4} };</strong></p>
<p><strong> </strong></p>
<p><strong>3.Multi Dimensional arrays:-</strong></p>
<p><strong>          C  supports arrays of 3 or more dimensions.In multi dimensional</strong></p>
<p><strong>     arrays we use more than two index values.</strong></p>
<p><strong>     syn:- data type arr_name[s1][s2][s3]……[sn];</strong></p>
<p><strong>     where s1,s2,s3,……sn are the sizes of the array.</strong></p>
<p><strong>   ex:-  int a[2][2][3];</strong></p>
<p><strong>   here elements are:-</strong></p>
<p><strong>                          a[0][0][0]    a[0][0][1]   a[0][0][2]</strong></p>
<p><strong>                          a[0][1][0]    a[0][1][1]   a[0][1][2]</strong></p>
<p><strong> </strong></p>
<p><strong>                          a[1][0][0]    a[1][0][1]   a[1][0][2]</strong></p>
<p><strong>                          a[1][1][0]    a[1][1][1]   a[1][1][2]</strong></p>
<p><strong> </strong></p>
<p><strong>Program 1:</strong></p>
<p><strong>/* display */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>  int i;</strong></p>
<p><strong>  clrscr();</strong></p>
<p><strong>  for(i=1;i&lt;=100;i++)</strong></p>
<p><strong>  display(i);</strong></p>
<p><strong>  getch();</strong></p>
<p><strong>  }</strong></p>
<p><strong>  display(int n)</strong></p>
<p><strong>  {</strong></p>
<p><strong>    printf(“%d\t”,n);</strong></p>
<p><strong>  }</strong></p>
<p><strong> </strong></p>
<p><strong>Program2:</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>/* gets(),puts() */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>char name[20];</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>printf(“Enter your name:”);</strong></p>
<p><strong>gets(name);</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>puts(“Hello!…”);</strong></p>
<p><strong>puts(name);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 3:</strong></p>
<p><strong> </strong></p>
<p><strong>/* order(),reverse() */</strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>order()</strong></p>
<p><strong>{</strong></p>
<p><strong>int i;</strong></p>
<p><strong>for(i=1;i&lt;=10;i++)</strong></p>
<p><strong>printf(“%d\n”,i);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>reverse()</strong></p>
<p><strong>{</strong></p>
<p><strong> int i;</strong></p>
<p><strong> for(i=10;i&gt;=1;i–)</strong></p>
<p><strong> printf(“%d\n”,i);</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p><strong> </strong></p>
<p><strong> void main()</strong></p>
<p><strong> {</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> printf(“The Numbers in Assending Order:\n”);</strong></p>
<p><strong> order();</strong></p>
<p><strong> printf(“The numbers in Desseding Order:\n”);</strong></p>
<p><strong> reverse();</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Program 4:</strong></p>
<p><strong> </strong></p>
<p><strong>/* square value */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int a,b;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>printf(“\n enter any no:”);</strong></p>
<p><strong>scanf(“%d”,&amp;a);</strong></p>
<p><strong>b=square(a);</strong></p>
<p><strong>printf(“\n square of %d is %d”,a,b);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>square(int x)</strong></p>
<p><strong>{</strong></p>
<p><strong>int y;</strong></p>
<p><strong>y=x*x;</strong></p>
<p><strong>return(y);</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 5:</strong></p>
<p><strong> </strong></p>
<p><strong>/* passing values between functions */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int a,b,c,sum;</strong></p>
<p><strong>printf(“\n Enter any 3 no:”);</strong></p>
<p><strong>scanf(“%d %d %d”,&amp;a,&amp;b,&amp;c);</strong></p>
<p><strong>sum=calsum(a,b,c);</strong></p>
<p><strong>printf(“\n sum=%d”,sum);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong>calsum(x,y,z)</strong></p>
<p><strong>int x,y,z;</strong></p>
<p><strong>{</strong></p>
<p><strong>int d;</strong></p>
<p><strong>d=x+y+z;</strong></p>
<p><strong>return(d);</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 6:</strong></p>
<p><strong> </strong></p>
<p><strong>/* string functions strcat() */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int a;</strong></p>
<p><strong>char s1[20],s2[20];</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>printf(“Enter first string:”);</strong></p>
<p><strong>gets(s1);</strong></p>
<p><strong>printf(“Enter second string:”);</strong></p>
<p><strong>gets(s2);</strong></p>
<p><strong>a=strcat(s1,s2);</strong></p>
<p><strong>puts(a);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 7:</strong></p>
<p><strong> </strong></p>
<p><strong>/*strcmp() */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>char string1[]=”ABC”;</strong></p>
<p><strong>char string2[]=”BBC”;</strong></p>
<p><strong>int i;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>i=strcmp(“string1,string2″);</strong></p>
<p><strong>printf(“%d\n”,i);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 8:</strong></p>
<p><strong> </strong></p>
<p><strong>/* strcpy() */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>char s1[]=”meher”;</strong></p>
<p><strong>char s2[20];</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>strcpy(s2,s1);</strong></p>
<p><strong>puts(s1);</strong></p>
<p><strong>puts(s2);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 8:</strong></p>
<p><strong> </strong></p>
<p><strong>/* strlen() */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int l;</strong></p>
<p><strong>char name[20];</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>printf(“Enter a string:”);</strong></p>
<p><strong>gets(name);</strong></p>
<p><strong>l=strlen(name);</strong></p>
<p><strong>puts(name);</strong></p>
<p><strong>printf(“The length of a string a is:%d”,l);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 9:</strong></p>
<p><strong> </strong></p>
<p><strong>/* strrev() */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int a;</strong></p>
<p><strong>char st[20];</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>printf(“Enter any string:”);</strong></p>
<p><strong>gets(st);</strong></p>
<p><strong>a=strrev(st);</strong></p>
<p><strong>puts(a);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 10:</strong></p>
<p><strong> </strong></p>
<p><strong>/* strupr(),strlwr()*/</strong></p>
<p><strong> </strong></p>
<p><strong>main()</strong></p>
<p><strong>{</strong></p>
<p><strong> int a,b;</strong></p>
<p><strong> char s1[20],s2[20];</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> printf(“Enter 1st string:”);</strong></p>
<p><strong> gets(s1);</strong></p>
<p><strong> printf(“Enter 2nd string:”);</strong></p>
<p><strong> gets(s2);</strong></p>
<p><strong> a=strupr(s1);</strong></p>
<p><strong> b=strlwr(s2);</strong></p>
<p><strong> puts(a);</strong></p>
<p><strong> puts(b);</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p><strong> </strong></p>
<p><strong>Program 11:</strong></p>
<p><strong> </strong></p>
<p><strong>/* USER DEFINED FUNCTIONS */</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>meher()</strong></p>
<p><strong>{</strong></p>
<p><strong> </strong></p>
<p><strong>  int i;</strong></p>
<p><strong>  for(i=0;i&lt;=40;i++)</strong></p>
<p><strong>  printf(“*”);</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong> clrscr();</strong></p>
<p><strong> gotoxy(15,6);</strong></p>
<p><strong> meher();</strong></p>
<p><strong> gotoxy(26,7);</strong></p>
<p><strong> printf(“CH.MEHER BABU”);</strong></p>
<p><strong> gotoxy(26,8);</strong></p>
<p><strong> printf(“Door no:9-32-9″);</strong></p>
<p><strong> gotoxy(26,9);</strong></p>
<p><strong> printf(“kothapet”);</strong></p>
<p><strong> gotoxy(26,10);</strong></p>
<p><strong> printf(“Vijayawada-520001″);</strong></p>
<p><strong> gotoxy(15,11);</strong></p>
<p><strong> meher();</strong></p>
<p><strong> getch();</strong></p>
<p><strong> }</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Program 12:</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>/* print 1 to 10 numbers using with single diamention array */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int all[10];</strong></p>
<p><strong>int i;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>/*string the values into array */</strong></p>
<p><strong>for(i=1;i&lt;=10;i++)</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(“Enter the cell value:”);</strong></p>
<p><strong>scanf(“%d”,&amp;all[i]);</strong></p>
<p><strong>}</strong></p>
<p><strong>/* printf the values of an array */</strong></p>
<p><strong>for(i=1;i&lt;=10;i++)</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(“%d\t”,all[i]);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 13:</strong></p>
<p><strong> </strong></p>
<p><strong>/* print small,capital,symbols using with single diamention array*/</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>  int i;</strong></p>
<p><strong>  char st[256];</strong></p>
<p><strong>  clrscr();</strong></p>
<p><strong>  for(i=0;i&lt;256;i++)</strong></p>
<p><strong>  {</strong></p>
<p><strong>  st[i]=1+i;</strong></p>
<p><strong>  }</strong></p>
<p><strong>  for(i=0;i&lt;256;i++)</strong></p>
<p><strong>  {</strong></p>
<p><strong>   printf(“%c\t”,st[i]);</strong></p>
<p><strong>  }</strong></p>
<p><strong>  getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 14:</strong></p>
<p><strong> </strong></p>
<p><strong>/* call by value using with single diamention array */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int i;</strong></p>
<p><strong>int marks[]={56,65,75,56,78,90}</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>for(i=0;i&lt;=6;i++)</strong></p>
<p><strong>{</strong></p>
<p><strong>display(marks[i]);</strong></p>
<p><strong>}</strong></p>
<p><strong>display(int m);</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 15:</strong></p>
<p><strong> </strong></p>
<p><strong>/*conversion of numbers to text */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int a[3],i;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>for(i=0;i&lt;=3;i++)</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(“Enter any no:”);</strong></p>
<p><strong>scanf(“%d\t”,&amp;a[i]);</strong></p>
<p><strong>for(i=0;i&lt;=3;i++)</strong></p>
<p><strong>printf(“%c\t”,a[i]);</strong></p>
<p><strong>}</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 16:</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>int arr[5][5];</strong></p>
<p><strong>int i,j;</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>for(i=1;i&lt;=5;i++)</strong></p>
<p><strong>          for(j=1;j&lt;=5;j++)</strong></p>
<p><strong>          {</strong></p>
<p><strong>                   if((i+j)==6)</strong></p>
<p><strong>                   arr[i][j]=9;</strong></p>
<p><strong>                   else</strong></p>
<p><strong>                   arr[i][j]=1;</strong></p>
<p><strong>                             for(i=1;i&lt;=5;i++)</strong></p>
<p><strong>                             {</strong></p>
<p><strong>                                      for(j=1;j&lt;=5;j++)</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>                                      printf(“%d\t”,arr[i][j]);</strong></p>
<p><strong>                                      printf(“\n”);</strong></p>
<p><strong> </strong></p>
<p><strong>          }                 }</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 17:</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>/* print lowercase letters using with single diamention array */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong> </strong></p>
<p><strong>int i;</strong></p>
<p><strong>char st[26];</strong></p>
<p><strong>clrscr();</strong></p>
<p><strong>for(i=0;i&lt;26;i++)</strong></p>
<p><strong>{</strong></p>
<p><strong>st[i]=97+i;</strong></p>
<p><strong>}</strong></p>
<p><strong>for(i=0;i&lt; 26;i++)</strong></p>
<p><strong>{</strong></p>
<p><strong>printf(“%c\t”,st[i]);</strong></p>
<p><strong>}</strong></p>
<p><strong>getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 18:</strong></p>
<p><strong> </strong></p>
<p><strong>/* password program */</strong></p>
<p><strong> </strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>#include&lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>  char passwd[10]=”meher”;</strong></p>
<p><strong>  char tpasswd[10];</strong></p>
<p><strong>  clrscr();</strong></p>
<p><strong>  printf(“\n Enter pass word:”);</strong></p>
<p><strong>  fflush(stdin);</strong></p>
<p><strong>  scanf(“%s”,tpasswd);</strong></p>
<p><strong>  if(strcmp(tpasswd,passwd)!=0)</strong></p>
<p><strong>  {</strong></p>
<p><strong>  printf(“\n wrong pass word:”);</strong></p>
<p><strong>  exit(0);</strong></p>
<p><strong>  }</strong></p>
<p><strong>  getch();</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p><strong>Program 19:</strong></p>
<p><strong>/*Sorting */</strong></p>
<p><strong>#include&lt;stdio.h&gt;</strong></p>
<p><strong>          #include&lt;conio.h&gt;</strong></p>
<p><strong>          void main()</strong></p>
<p><strong>          {</strong></p>
<p><strong>           int a[20],n,i,j,t;</strong></p>
<p><strong>           clrscr();</strong></p>
<p><strong>           printf(“Enter no of elements :”);</strong></p>
<p><strong>           scanf(“%d”,&amp;n);</strong></p>
<p><strong>           printf(“Enter array elements :”);</strong></p>
<p><strong>           for(i=0;i&lt;n;i++)</strong></p>
<p><strong>           {</strong></p>
<p><strong>            scanf(“%d”,&amp;a[i]);</strong></p>
<p><strong>           }</strong></p>
<p><strong>           printf(“\nGiven array elements :”);</strong></p>
<p><strong>           for(i=0;i&lt;n;i++)</strong></p>
<p><strong>           {</strong></p>
<p><strong>            printf(“\t%d”,a[i]);</strong></p>
<p><strong>           }</strong></p>
<p><strong>           /* sorting */</strong></p>
<p><strong>           for(i=0;i&lt;n-1;i++)</strong></p>
<p><strong>           {</strong></p>
<p><strong>            for(j=i+1;j&lt;n;j++)</strong></p>
<p><strong>            {</strong></p>
<p><strong>             if(a[i]&gt;a[j])</strong></p>
<p><strong>             {</strong></p>
<p><strong>              t=a[i];</strong></p>
<p><strong>              a[i]=a[j];</strong></p>
<p><strong>              a[j]=t;</strong></p>
<p><strong>             }</strong></p>
<p><strong>            }</strong></p>
<p><strong>           }</strong></p>
<p><strong>           printf(“\nafter sorting :\n”);</strong></p>
<p><strong>           for(i=0;i&lt;n;i++)</strong></p>
<p><strong>           {</strong></p>
<p><strong>            printf(“\t%d”,a[i]);</strong></p>
<p><strong>           }</strong></p>
<p><strong>           getch();</strong></p>
<p><strong>          }</strong></p>
<p><strong> </strong></p>
<p><strong>Program 20:</strong></p>
<p><strong>/*searching*/</strong></p>
<p><strong>          #include&lt;stdio.h&gt;</strong></p>
<p><strong>          #include&lt;conio.h&gt;</strong></p>
<p><strong>          void main()</strong></p>
<p><strong>          {</strong></p>
<p><strong>           int a[20],i,n,se,ck=0;</strong></p>
<p><strong>           clrscr();</strong></p>
<p><strong>           printf(“Enter no elements :”);</strong></p>
<p><strong>           scanf(“%d”,&amp;n);</strong></p>
<p><strong>           printf(“Enter array elements :”);</strong></p>
<p><strong>           for(i=0;i&lt;n;i++)</strong></p>
<p><strong>           {</strong></p>
<p><strong>            scanf(“%d”,&amp;a[i]);</strong></p>
<p><strong>           }</strong></p>
<p><strong>           printf(“Given array elements :\n”);</strong></p>
<p><strong>           for(i=0;i&lt;n;i++)</strong></p>
<p><strong>           {</strong></p>
<p><strong>            printf(“\t%d”,a[i]);</strong></p>
<p><strong>           }</strong></p>
<p><strong>           printf(“\nEnter searching element :”);</strong></p>
<p><strong>           scanf(“%d”,&amp;se);</strong></p>
<p><strong>           /* searching */</strong></p>
<p><strong>           for(i=0;i&lt;n;i++)</strong></p>
<p><strong>           {</strong></p>
<p><strong>            if(a[i]==se)</strong></p>
<p><strong>            {</strong></p>
<p><strong>             ck=1;</strong></p>
<p><strong>             printf(” %d is found at a[%d] “,se,i);</strong></p>
<p><strong>            }</strong></p>
<p><strong>           }</strong></p>
<p><strong>           if(ck==0)</strong></p>
<p><strong>            printf(” %d is not found “,se);</strong></p>
<p><strong>           getch();</strong></p>
<p><strong>          }</strong></p>
</div>
</div>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/function-and-arrays-in-c-language/'>Function and Arrays in C-Language</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1295/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1295&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/10/09/function-and-arrays-in-c-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>
	</item>
		<item>
		<title></title>
		<link>http://meherchilakalapudi.wordpress.com/2011/10/02/1290/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/10/02/1290/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 15:00:36 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[wireless security]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1290</guid>
		<description><![CDATA[    Wireless (In)Security  &#8230; written by meher   802.11 refers to a family of specifications developed by the IEEE for wireless lan technology. 802.11 specifies an over-the-air interface between a wireless client and a base station or between two wireless clients. The IEEE accepted the specification in 1997. There are several specifications in the 802.11 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1290&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h4> </h4>
<h4> </h4>
<div id="post-972">
<h2 style="text-align:center;"><a title="Permanent link to Wireless (In)Security" href="http://sailjamehra.wordpress.com/2010/02/11/wireless-insecurity/" rel="bookmark">Wireless (In)Security</a></h2>
<h3 style="text-align:right;"> &#8230; written by meher</h3>
<div>
<h4><strong> </strong></h4>
<h4><strong><em>802.11</em> refers to a family of specifications developed by the IEEE for wireless lan technology. 802.11 specifies an over-the-air interface between a wireless client and a base station or between two wireless clients. The IEEE accepted the specification in 1997. </strong></h4>
<h4><strong>There are several specifications in the 802.11 family: </strong></h4>
<ul>
<li>
<h4><strong>802.11 — applies to wireless LANs and provides 1 or 2 Mbps transmission in the 2.4 GHz band using either frequency hopping spread spectrum (FHSS) or direct sequence spread spectrum (DSSS). </strong></h4>
</li>
<li>
<h4><strong>802.11a — an extension to 802.11 that applies to wireless LANs and provides up to 54 Mbps in the 5GHz band. 802.11a uses an orthogonal frequency division multiplexing encoding scheme rather than FHSS or DSSS. </strong></h4>
</li>
<li>
<h4><strong>802.11b (also referred to as <em>802.11 High Rate</em> or Wi-Fi) — an extension to 802.11 that applies to wireless LANS and provides 11 Mbps transmission (with a fallback to 5.5, 2 and 1 Mbps) in the 2.4 GHz band. 802.11b uses only DSSS. 802.11b was a 1999 ratification to the original 802.11 standard, allowing wireless functionality comparable to Ethernet. </strong></h4>
</li>
<li>
<h4><strong>802.11g — applies to wireless LANs and provides 20+ Mbps in the 2.4 GHz band</strong></h4>
</li>
</ul>
<h4><strong> </strong></h4>
<h4><em><strong>Frequency Hopping Spread Spectrum</strong></em></h4>
<h4><strong>Frequency hopping is one of two basic modulation techniques used in spread spectrum signal transmission. It is the repeated switching of frequencies during radio transmission, often to minimize the effectiveness of “electronic warfare” – that is, the unauthorized interception or jamming of telecommunications. It also is known as frequency- hopping code division multiple access (FH-CDMA). </strong></h4>
<h4><strong>Spread spectrum modulation techniques have become more common in recent years. Spread spectrum enables a signal to be transmitted across a frequency band that is much wider than the minimum bandwidth required by the information signal. The transmitter “spreads” the energy, originally concentrated in narrowband, across a number of frequency band channels on a wider electromagnetic spectrum. Benefits include improved privacy, decreased narrowband interference, and increased signal capacity. </strong></h4>
<h4><strong>In an FH-CDMA system, a transmitter “hops” between available frequencies according to a specified algorithm, which can be either random or preplanned. The transmitter operates in synchronization with a receiver, which remains tuned to the same center frequency as the transmitter. A short burst of data is transmitted on a narrowband. Then, the transmitter tunes to another frequency and transmits again. The receiver thus is capable of hopping its frequency over a given bandwidth several times a second, transmitting on one frequency for a certain period of time, then hopping to another frequency and transmitting again. Frequency hopping requires a much wider bandwidth than is needed to transmit the same information using only one carrier frequency. </strong></h4>
<h4><strong>The spread spectrum approach that is an alternative to FH-CDMA is direct sequence code division multiple access (DS-CDMA), which chops the data into small pieces and spreads them across the frequency domain. FH-CDMA devices use less power and are generally cheaper, but the performance of DS-CDMA systems is usually better and more reliable. The biggest advantage of frequency hopping lies in the coexistence of several access points in the same area, something not possible with direct sequence. </strong></h4>
<h4><strong>Certain rules govern how frequency-hopping devices are used. In North America, the Industrial, Scientific, and Medial (ISM) waveband is divided into 75 hopping channels, with power transmission not to exceed 1 watt on each channel. These restrictions ensure that a single device does not consume too much bandwidth or linger too long on a single frequency. </strong></h4>
<h4><strong>The Federal Communications Commission (Fcc) has amended rules to allow frequency hopping spread spectrum systems in the unregulated 2.4 GHz band. The rule change is designed to allow wider bandwidths, thus enabling Internet devices to operate at higher speeds and fostering development of wireless LANs and wireless cable modems. </strong></h4>
<h4><strong>Movie star Hedy Lamarr is generally credited as co-originator of the idea of spread spectrum transmission. She and her pianist were issued a patent for the technique during World War II. They discovered the technique using a player piano to control the frequency hops, and envisioned it as a way to provide secure communications during wartime. The pair never made any money off the invention and their patent eventually expired. Sylvania introduced a similar concept in the 1950s and coined the term “spread spectrum.” </strong></h4>
<table dir="ltr" width="2" border="0" cellspacing="0" cellpadding="0" align="left"> <br />
<col width="2" />   </p>
<tbody>
<tr>
<td width="2">
<h4><strong> </strong></h4>
</td>
</tr>
<tr>
<td width="2">
<h4><strong><img src="http://sailjamehra.wordpress.com/Documents%20and%20Settings/sasi/Desktop/ccna0/Wireless%20(In)Security_files/spacer.gif" alt="" width="2" height="10" align="bottom" border="0" /></strong></h4>
</td>
</tr>
<p> </tbody>
</table>
<h4><em><strong>Direct Sequence Spread Spectrum</strong></em></h4>
<h4><strong>Direct sequence spread spectrum, also known as direct sequence code division multiple access (DS-CDMA), is one of two approaches to spread spectrum modulation for digital signal transmission over the airwaves. In direct sequence spread spectrum, the stream of information to be transmitted is divided into small pieces, each of which is allocated across to a frequency channel across the spectrum. A data signal at the point of transmission is combined with a higher data-rate bit sequence (also known as a <em>chipping code</em>) that divides the data according to a spreading ratio. The redundant chipping code helps the signal resist interference and also enables the original data to be recovered if data bits are damaged during transmission. </strong></h4>
<h4><strong>Direct sequence contrasts with the other spread spectrum process, known as frequency hopping spread spectrum, or frequency hopping code division multiple access (FH-CDMA), in which a broad slice of the bandwidth spectrum is divided into many possible broadcast frequencies. In general, frequency-hopping devices use less power and are cheaper, but the performance of DS-CDMA systems is usually better and more reliable. </strong></h4>
<h4><strong>Spread spectrum first was developed for use by the military because it uses wideband signals that are difficult to detect and that resist attempts at jamming. In recent years, researchers have turned their attention to applying spread spectrum processes for commercial purposes, especially in local area wireless networks. </strong></h4>
<h4>Wireless LAN Standards</h4>
<h4>
<strong>Use this chart to get some quick information to help you differentiate between the available wireless networking standards and choose which standard might be the right fit for your business. See the links below the chart for further information on wireless networking standards. </strong></h4>
<table width="90%" border="1" cellspacing="0" cellpadding="4"> <br />
<col width="75" />
<col width="44" />
<col width="94" />
<col width="104" />
<col width="198" />   </p>
<tbody>
<tr>
<td width="75"><strong>Standard</strong></td>
<td width="44"><strong>Data Rate</strong></td>
<td width="94"><strong>Modulation Scheme</strong></td>
<td width="104"><strong>Security</strong></td>
<td width="198"><strong>Pros/Cons</strong></td>
</tr>
<tr>
<td width="75"><strong>IEEE 802.11 </strong></td>
<td width="44"><strong>Up to 2Mbps in the 2.4GHz band </strong></td>
<td width="94"><strong>FHSS or DSSS </strong></td>
<td width="104"><strong>WEP &amp; WPA </strong></td>
<td width="198"><strong>This specification has been extended into 802.11b. </strong></td>
</tr>
<tr>
<td width="75"><strong>IEEE 802.11a<br />
(Wi-Fi) </strong></td>
<td width="44"><strong>Up to 54Mbps in the 5GHz band </strong></td>
<td width="94"><strong>OFDM </strong></td>
<td width="104"><strong>WEP &amp; WPA </strong></td>
<td width="198"><strong>Products that adhere to this standard are considered “Wi-Fi Certified.” Eight available channels. Less potential for RF interference than 802.11b and 802.11g. Better than 802.11b at supporting multimedia voice, video and large-image applications in densely populated user environments. Relatively shorter range than 802.11b. Not interoperable with 802.11b. </strong></td>
</tr>
<tr>
<td width="75"><strong>IEEE 802.11b<br />
(Wi-Fi) </strong></td>
<td width="44"><strong>Up to 11Mbps in the 2.4GHz band </strong></td>
<td width="94"><strong>DSSS with CCK </strong></td>
<td width="104"><strong>WEP &amp; WPA </strong></td>
<td width="198"><strong>Products that adhere to this standard are considered “Wi-Fi Certified.” Not interoperable with 802.11a. Requires fewer access points than 802.11a for coverage of large areas. Offers high-speed access to data at up to 300 feet from base station. 14 channels available in the 2.4GHz band (only 11 of which can be used in the U.S. due to FCC regulations) with only three non-overlapping channels. </strong></td>
</tr>
<tr>
<td width="75"><strong>IEEE 802.11g<br />
(Wi-Fi) </strong></td>
<td width="44"><strong>Up to 54Mbps in the 2.4GHz band </strong></td>
<td width="94"><strong>OFDM above 20Mbps, DSSS with CCK below 20Mbps </strong></td>
<td width="104"><strong>WEP &amp; WPA </strong></td>
<td width="198"><strong>Products that adhere to this standard are considered “Wi-Fi Certified.” May replace 802.11b. Improved security enhancements over 802.11. Compatible with 802.11b. 14 channels available in the 2.4GHz band (only 11 of which can be used in the U.S. due to FCC regulations) with only three non-overlapping channels. </strong></td>
</tr>
<tr>
<td width="75"><strong>Bluetooth </strong></td>
<td width="44"><strong>Up to 2Mbps in the 2.45GHz band </strong></td>
<td width="94"><strong>FHSS </strong></td>
<td width="104"><strong>PPTP, SSL or VPN </strong></td>
<td width="198"><strong>No native support for IP, so it does not support TCP/IP and wireless LAN applications well. Not originally created to support wireless LANs. Best suited for connecting PDAs, cell phones and PCs in short intervals. </strong></td>
</tr>
<tr>
<td width="75"><strong>HomeRF </strong></td>
<td width="44"><strong>Up to 10Mbps in the 2.4GHZ band </strong></td>
<td width="94"><strong>FHSS </strong></td>
<td width="104"><strong>Independent network IP addresses for each network. Data is sent with a 56-bit encryption algorithm. </strong></td>
<td width="198"><strong>Note: HomeRF is no longer being supported by any vendors or working groups. Intended for use in homes, not enterprises. Range is only 150 feet from base station. Relatively inexpensive to set up and maintain. Voice quality is always good because it continuously reserves a chunk of bandwidth for voice services. Responds well to interference because of frequency-hopping modulation. </strong></td>
</tr>
<tr>
<td width="75"><strong>HiperLAN/1 (Europe) </strong></td>
<td width="44"><strong>Up to 20Mbps in the 5GHz band </strong></td>
<td width="94"><strong>CSMA/CA </strong></td>
<td width="104"><strong>Per-session encryption and individual authentication. </strong></td>
<td width="198"><strong>Only in Europe. HiperLAN is totally ad-hoc, requiring no configuration and no central controller. Doesn’t provide real isochronous services. Relatively expensive to operate and maintain. No guarantee of bandwidth. </strong></td>
</tr>
<tr>
<td width="75"><strong>HiperLAN/2 (Europe) </strong></td>
<td width="44"><strong>Up to 54Mbps in the 5GHz band </strong></td>
<td width="94"><strong>OFDM </strong></td>
<td width="104"><strong>Strong security features with support for individual authentication and per-session encryption keys. </strong></td>
<td width="198"><strong>Only in Europe. Designed to carry ATM cells, IP packets, Firewire packets (IEEE 1394) and digital voice (from cellular phones). Better quality of service than HiperLAN/1 and guarantees bandwidth. </strong></td>
</tr>
<p> </tbody>
</table>
<h4><strong> </strong></h4>
<h4>Wireless Network Architecture</h4>
<h4><strong>Access Point</strong></h4>
<h4><strong>An access point is the same as a 10/100 BaseT hub except that it connects using an antenna instead of wires. Wireless network cards are installed on workstations to connect to the access points. An access point almost always has at least one 10/100 BaseT port so that it can be connected to a wired network if needed. Access points can also be used to route or bridge to other access points, which allows wireless networks to extend their range. </strong></h4>
<h4><strong>Ad Hoc</strong></h4>
<h4><strong>An ad hoc network is one that doesn’t use access points. It is more commonly used for smaller workgroup configurations. A small office with five computers may utilize an ad hoc configuration. In such a configuration, all workstations communicate with each other through their wireless network cards. </strong></h4>
<h4>Securing the Wireless Network</h4>
<h4><strong>Most access points these days have a number of security features available, but by default, they are almost always turned off. This is one of the main reasons wireless networks can be so insecure. More often than not, they are configured with default out-of-the-box settings, which mean there is no security at all. Each feature has a weakness, but by using a combination of some or all of the features, you can make a wireless network very secure—secure enough for almost any library environment. The type of wireless security features implemented can widely vary depending on the size and needs of a library. Many of the out-of-box solutions in this section are optimal for smaller libraries with limited IT staff. Please see the section on “Public Wireless Access for Enterprise Solutions” for larger scale solutions. </strong></h4>
<h4><strong>Default Password</strong></h4>
<h4><strong>After connecting to an access point for the first time, the first security consideration should be renaming the default password. Without other security features enabled, anyone could guess the default out-of-box IP address assigned to an access point and then have full administrative access to it. Not changing the default password on an access point is equivalent to leaving your front door open. </strong></h4>
<h4><strong>SSID/Network ID</strong></h4>
<h4><strong>The SSID is a 7-digit alphanumeric identifier that is set on the access point. When a client connects to an access point, it transmits a SSID to associate itself with that network. There are two modes, closed and open. In open mode, any client can connect to the access point regardless of what SSID it has. In closed mode, a client must have the correct SSID to connect. There is also a common setting that determines whether or not an access point is to advertise its SSID. By default, most access points use their company name as the SSID (i.e. “linksys” or “3COM”), are in open mode and will advertise their SSID. Therefore, to optimize maximum security using the SSID feature, you should:</strong></h4>
<ol>
<li>
<h4><strong>Change the default SSID </strong></h4>
</li>
<li>
<h4><strong>Set the SSID mode to closed </strong></h4>
</li>
<li>
<h4><strong>Set the access to not broadcast/advertise its SSID </strong></h4>
</li>
</ol>
<h4><strong>Complying with all the above steps is not a foolproof security solution. The SSID is transmitted in clear text unless encryption is enabled (see section on encryption). It is unlikely but possible for someone with the correct knowledge and tools to reveal an SSID. </strong></h4>
<h4><strong>WEP (Wired Equivalency Protocol) Encryption</strong></h4>
<h4><strong>WEP is a protocol that encrypts data sent back and forth between the access point and a client. WEP can be enabled at two different levels: 40-bit and 128-bit. Encryption keys (passwords of a sort) can be defined on the access point. One or more keys entered on the client must match those configured on the access point in order to connect. Once connected, the data is then encrypted. This prevents someone from using a packet sniffer program to retrieve data and review its contents. </strong></h4>
<h4><strong>WEP has security flaws. Articles have been published outlining its weaknesses. Additionally, there are readily available tools that can crack encryption keys. Therefore, using 128-bit encryption compared to 40-bit is not necessarily important. Despite its weaknesses, WEP offers yet another line of defense from attackers breaking in to a network. Because there are so many wireless networks out there with even less security, the average hacker will more likely move on to one of those rather than spend time infiltrating one with WEP. </strong></h4>
<h4><strong>MAC Address Filtering</strong></h4>
<h4><strong>Most access points offer a feature that defines which clients may connect determined by their MAC address. A MAC address (media access layer) is a hard-coded identifying address on a network interface card that is different from an IP address. A MAC address is usually static and never changes—even when the card is removed from the computer. With MAC address filtering turned on, a workstation will not be able to connect unless its MAC address has been defined on the access point. This security feature is useful in smaller networks, although keeping a list of updated MAC addresses for a large network can be too difficult to manage. </strong></h4>
<h4><strong>Although the list of accepted MAC addresses is difficult, if not impossible, to extract from most access points, it is possible but unlikely for someone with the right tools and knowledge to discover one of the MAC addresses already in use on a network. An attacker could then configure a workstation to masquerade as a legitimate workstation with the “stolen” MAC address. </strong></h4>
<h4><strong>Control your broadcast area</strong></h4>
<h4><strong>Many wireless APs let you adjust the signal strength; some even let you adjust signal direction. Begin by placing your APs as far away from exterior walls and windows as possible, then play around with signal strength so you can just barely get connections near exterior walls. This isn’t enough, though. Sensitive snooping equipment can pick up wireless signals from an AP at distances of several hundred feet or more. So even with optimal AP placement, the signal may leak.</strong></h4>
<h4><strong>Ban rogue access points</strong></h4>
<h4><strong>If an AP is connected to your home or office network, make sure you or the network administrator put it there. Bob in Accounting isn’t likely to secure his rogue AP before he connects it. Free software like NetStumbler (</strong><a href="http://www.netstumbler.com/" target="_blank"><strong>www.netstumbler.com</strong></a><strong>) lets you sweep for unauthorized APs.</strong></h4>
<h4><strong>Understanding EAP Types</strong></h4>
<h4><strong>Different types of EAP have been defined to support authentication methods and associated network security policies. The most widely-deployed EAP types are summarized in the following table.</strong></h4>
<table width="558" border="1" cellspacing="0" cellpadding="2"> <br />
<col width="97" />
<col width="101" />
<col width="73" />
<col width="81" />
<col width="78" />
<col width="102" />   </p>
<tbody>
<tr valign="top">
<td width="97">
<h4><strong> </strong></h4>
</td>
<td width="101">
<h4><strong>EAP-MD5</strong></h4>
</td>
<td width="73">
<h4><strong>LEAP</strong></h4>
</td>
<td width="81">
<h4><strong>EAP-TLS</strong></h4>
</td>
<td width="78">
<h4><strong>EAP-TTLS</strong></h4>
</td>
<td width="102">
<h4><strong>PEAP</strong></h4>
</td>
</tr>
<tr valign="top">
<td width="97">
<h4><strong>Server Authentication</strong></h4>
</td>
<td width="101">
<h4><strong>None</strong></h4>
</td>
<td width="73">
<h4><strong>Password Hash</strong></h4>
</td>
<td width="81">
<h4><strong>Public Key (Certificate)</strong></h4>
</td>
<td width="78">
<h4><strong>Public Key (Certificate)</strong></h4>
</td>
<td width="102">
<h4><strong>Public Key (Certificate)</strong></h4>
</td>
</tr>
<tr valign="top">
<td width="97">
<h4><strong>Supplicant Authentication</strong></h4>
</td>
<td width="101">
<h4><strong>Password Hash</strong></h4>
</td>
<td width="73">
<h4><strong>Password Hash</strong></h4>
</td>
<td width="81">
<h4><strong>Public Key (Certificate or Smart Card)</strong></h4>
</td>
<td width="78">
<h4><strong>CHAP, PAP, MS-CHAP(v2), EAP</strong></h4>
</td>
<td width="102">
<h4><strong>Any EAP, like EAP-MS-CHAPv2 or Public Key</strong></h4>
</td>
</tr>
<tr valign="top">
<td width="97">
<h4><strong>Dynamic Key Delivery</strong></h4>
</td>
<td width="101">
<h4><strong>No</strong></h4>
</td>
<td width="73">
<h4><strong>Yes</strong></h4>
</td>
<td width="81">
<h4><strong>Yes</strong></h4>
</td>
<td width="78">
<h4><strong>Yes</strong></h4>
</td>
<td width="102">
<h4><strong>Yes</strong></h4>
</td>
</tr>
<tr valign="top">
<td width="97">
<h4><strong>Security Risks</strong></h4>
</td>
<td width="101">
<h4><strong>Identity exposed, Dictionary attack, Man-in-the-Middle (MitM) attack, Session hijacking</strong></h4>
</td>
<td width="73">
<h4><strong>Identity exposed, Dictionary attack</strong></h4>
</td>
<td width="81">
<h4><strong>Identity exposed</strong></h4>
</td>
<td width="78">
<h4><strong>MitM attack</strong></h4>
</td>
<td width="102">
<h4><strong>MitM attack</strong></h4>
</td>
</tr>
<p> </tbody>
</table>
<h4><strong>EAP-MD5 lets a RADIUS server authenticate LAN stations by verifying an MD5 hash of each user’s password. This is a simple and reasonable choice for trusted Ethernets where there is low risk of outsider sniffing or active attack. However, EAP-MD5 is not suitable for public Ethernets or wireless LANs because outsiders can easily sniff station identities and password hashes, or masquerade as access points to trick stations into authenticating with them instead of the real deal.</strong></h4>
<h4><strong>Cisco’s Lightweight EAP (LEAP) goes a notch beyond EAP-MD5 by requiring mutual authentication and delivering keys used for WLAN encryption. Mutual authentication reduces the risk of access point masquerading — a type of Man-in-the-Middle (MitM) attack. However, station identities and passwords remain vulnerable to attackers armed with sniffers and dictionary attack tools. LEAP is mostly attractive to organizations that use Cisco access points and cards and want to modestly raise the security bar.</strong></h4>
<h4><strong>EAP with Transport Layer Security (EAP-TLS) is the only standard secure option for wireless LANs at this time. EAP-TLS requires the station and RADIUS server to both prove their identities via public key cryptography (i.e., digital certificates or smart cards). This exchange is secured by an encrypted TLS tunnel, making EAP-TLS very resistant to dictionary or other MitM attacks. However, the station’s identity — the name bound to the certificate — can still be sniffed by outsiders. EAP-TLS is most attractive to large enterprises that use only Windows XP/2000/2003 with deployed certificates.</strong></h4>
<h4><strong>EAP with Tunneled TLS (EAP-TTLS) and Protected EAP (PEAP) are Internet Drafts that have been proposed to simplify 802.1X deployment. Both require certificate-based RADIUS server authentication, but support an extensible set of user authentication methods. Organizations that have not yet issued certificates to every station and don’t want to just for 802.1X can use Windows logins and passwords instead. RADIUS servers that support EAP-TTLS and PEAP can check LAN access requests with Windows Domain Controllers, Active Directories, and other existing user databases. From a sniffing perspective, these options are just as strong as EAP-TLS. However, user passwords are still more likely to be guessed, shared, or disclosed through social engineering than client-side certificates.</strong></h4>
<h4><strong>When planning your rollout, keep in mind that EAP types like EAP-TTLS and PEAP are not yet finalized. Additional EAP types are also still being defined, including EAP-SIM (to support GSM devices with SIM cards) and EAP-SecurID (to support two-factor hardware tokens). In fact, both EAP and 802.1X are still being tweaked to overcome issues encountered by early adopters. As these solutions mature, you should anticipate the need to upgrade installed 802.1X/EAP software. To manage this cost, you may want to start with a modest 802.1X rollout. Learn the ropes and get familiar with both the benefits and challenges of 802.1X. Start improving WLAN security with 802.1X today and you’ll be better prepared for company-wide deployment in the future.</strong></h4>
<h4><em><strong>EAP Authentication</strong></em></h4>
<h4><strong>Five components are required to implement 802.1x authentication: </strong></h4>
<ul>
<li>
<h4><strong>Compatible client device: Typical clients include notebook computers and personal digital assistants (PDAs). A device that requests to join a wireless network is known as a supplicant.</strong></h4>
</li>
<li>
<h4><strong>Supplicant software: This software provides the logic that a device needs to present its credentials and follow the proper protocol for joining the network as a client. </strong></h4>
</li>
<li>
<h4><strong>Authenticator: The authenticator is a wireless access point that must verify the identity of a supplicant before granting the device network access.</strong></h4>
</li>
<li>
<h4><strong>Authentication server: The authentication server is a separate system—typically running the Remote Authentication Dial-In User Service (RADIUS) or another service supporting the Extensible Authentication Protocol (EAP)—that handles authentication requests relayed by authenticators from supplicants.</strong></h4>
</li>
<li>
<h4><strong>User database: The user database is a list of valid users and their credentials that the authentication server consults to validate authentication requests. This database may be a simple flat file or a service provided by a directory infrastructure, such as the Microsoft<sup>®</sup>  Active Directory<sup>®</sup>  directory service or the Lightweight Directory Access Protocol (LDAP).</strong></h4>
</li>
</ul>
<h4><strong>The authentication process begins when a client attempts to connect to the access point, which will open a restricted port. This port allows the client to pass only EAP packets to the authentication server on the wired side of the access point. All other traffic, such as HTTP or Dynamic Host Configuration Protocol (DHCP) traffic, is blocked. The 802.1x protocol involves seven basic steps (see Figure 1):</strong></h4>
<ol>
<li>
<h4><strong>Request access. The supplicant presents the authenticator with an EAP response/identity request.</strong></h4>
</li>
<li>
<h4><strong>Limit access to authentication server. The authenticator relays the request to the authentication server; at this point, the supplicant’s access is restricted to the authentication server. </strong></h4>
</li>
<li>
<h4><strong>Issue challenge. The server issues a challenge and passes it back to the supplicant.</strong></h4>
</li>
<li>
<h4><strong>Answer challenge. The supplicant answers the challenge by sending the necessary credentials back to the authentication server. </strong></h4>
</li>
<li>
<h4><strong>Validate response. The server verifies the credentials against the user database; if valid, the server responds with a success message.</strong></h4>
</li>
<li>
<h4><strong>Allow access to network. The authenticator increases the scope of the client’s access.</strong></h4>
</li>
<li>
<h4><strong>Use other network devices. The authenticator notifies the client that it may now participate on the network</strong></h4>
</li>
<li>
<h4><strong> </strong></h4>
</li>
</ol>
<h4><a href="http://sailjamehra.files.wordpress.com/2010/02/ps3q03-lowerywireless1.jpg"><strong><img title="ps3q03-lowerywireless1" src="http://sailjamehra.files.wordpress.com/2010/02/ps3q03-lowerywireless1.jpg?w=432&#038;h=414&#038;h=414" alt="" width="432" height="414" /></strong></a></h4>
<h4><strong>Consider VPNs</strong></h4>
<h4><strong>Most people agree that the best method of securing your wireless network is by using a combination of the suggestions above. However, the most effective strategy would be to use VPN technology. If a library has data sensitive enough to necessitate higher security than what is provided out-of-box, then VPN technology is probably the answer. To set up such a solution, access points need to be placed in the DMZ (open to the Internet) which are then connected to a VPN server. A wireless workstation connects to the VPN server using the access point and then “tunnels” into the network. The VPN client takes care of the password and data transmission encryption. </strong></h4>
<h4>Analyzing the failure of WEP</h4>
<h4><strong>Although WEP incorporates several mechanisms to help secure wireless traffic, many attacks have surfaced over time, demonstrating that the design goals were not achieved. Analysis of these attacks confirms that WEP fails to enforce access control, and cannot guarantee privacy or integrity of data transmissions.</strong></h4>
<h4><strong>Shared authentication puts access control in jeopardy<br />
Access control to the network is most at risk when using shared authentication. Although challenging a new client to ensure it has the correct secret key may seem to enforce greater protection, this handshake provides an eavesdropper with useful information that can compromise network access. </strong></h4>
<h4><strong>By listening to the handshake, the eavesdropper obtains the initial unencrypted challenge message that the access point sent, as well as the encrypted message that the joining client returned. Given these two pieces of information—both plaintext and corresponding ciphertext—the eavesdropper can conduct a known plaintext attack. By forcing reuse of the compromised IV, the eavesdropper can use the known associated keystream to correctly answer the access point’s challenge. In this way, an attacker can join the network without even knowing the secret key. </strong></h4>
<h4><strong>Keystream collisions compromise privacy<br />
The authentication attack is a specific instance of a more general attack in which the privacy of any transmission can be compromised. Message privacy is at risk when any two messages are encrypted with the same keystream using a stream cipher. Because the keystream depends on a combination of the secret key and an IV, and because the secret key is constant, an eavesdropper can determine that two messages are encrypted with the same keystream—an occurrence known as a collision—simply by comparing their IVs, which are always sent unencrypted. </strong></h4>
<h4><strong>When an XOR operation is performed on two encrypted messages with identical IVs, the result equals the XOR result of the two messages before they were encrypted. Therefore, if parts of one unencrypted message (the plaintext) are known or can be guessed, an attacker can easily deduce corresponding parts of the other message, regardless of the size of the secret key. Given predictable message formats such as e-mail headers, some plaintext can be easily guessed. Because most wireless access points are connected to a wired network, attackers often can choose plaintext to be sent over the wireless network by sending it from a wired station—<em>a chosen plaintext attack</em>.</strong></h4>
<h4><strong>Such attacks would not be possible if the IV were non-repeating. However, with a 24-bit IV, at most 2<sup>24</sup> (16 million) possible values exist. In high-traffic environments, IVs are guaranteed to repeat in a matter of hours. Even worse, many vendors choose to reinitialize the IV to zero every time the access point or client is started, and subsequently increment the IV for each transmitted packet. This practice means the IV is likely to be a low-value number that was recently used, resulting in even more collisions. Consider a case in which hundreds of clients, such as notebook computers, are started at nearly the same time—for example, when users arrive at work. Because they all share the same secret key, and they all start their IV counters at zero, multiple collisions are practically guaranteed. Predicting the next IV in the sequence also becomes easier, which furthers the attacker’s goals.</strong></h4>
<h4><strong>Over time, attackers can completely compromise privacy using a <em>dictionary attack</em>. As collisions occur, attackers build a table that lists the keystream corresponding to each IV. Once every IV value has been observed in collision, all transmissions are compromised. </strong></h4>
<h4><strong>Checksum and keystream weaknesses invite attacks on data integrity<br />
CRC-32’s linearity and independence from the secret key and IV can compromise data integrity. CRCs are designed to detect random errors, not malicious or intentional modifications. The receiver accepts the message after decryption if the checksum appended to the message matches the checksum computed on the received data. Because CRC-32 is a linear function, the checksum of a message can easily be modified to pass inspection. If an attacker modifies a data packet, and changes the appended checksum to reflect this modification, the receiver will unknowingly accept the message as unaltered.</strong></h4>
<h4><strong>Attackers also can compromise data transfer integrity by injecting a new message into the network. Again, by knowing a message in unencrypted and encrypted forms, attackers can determine the keystream. Using this keystream and the corresponding IV, attackers can inject a new message with the correctly calculated checksum into the network. The receiver simply verifies that the checksum is correct and accepts the message. Note that in all these attacks the eavesdropper is never required to know the secret key, and that the length of the key is irrelevant.</strong></h4>
<h4>The Future of Wireless</h4>
<h4><strong>Although nearing completion, the 802.11i standard is still some time away from reaching the market. Wireless vendors have released key components of 802.11i technology now, under the name Wireless-Fidelity, or Wi-Fi, Protected Access. WPA has the following features:</strong></h4>
<ul>
<li>
<h4><strong>Backward compatibility with 802.11 hardware </strong></h4>
</li>
<li>
<h4><strong>Software or firmware upgrade</strong></h4>
</li>
<li>
<h4><strong>802.1x</strong></h4>
</li>
<li>
<h4><strong>TKIP</strong></h4>
</li>
<li>
<h4><strong>Michael algorithm</strong></h4>
</li>
<li>
<h4><strong>Key management and key hierarchy</strong></h4>
</li>
</ul>
<h4><strong>Some 802.11i features do not appear in WPA because they require a hardware upgrade. Other 802.11i features are not perceived as urgent, or are not yet sufficiently specified:</strong></h4>
<ul>
<li>
<h4><strong>AES: Implementing this feature would require a hardware upgrade, because the encryption and decryption functions cannot be performed quickly enough in software.</strong></h4>
</li>
<li>
<h4><strong>CCMP and WRAP: The Counter with Cipher Block Chaining Message Authentication Code Protocol (CCMP) and Wireless Robust Authenticated Protocol (WRAP) are AES-based replacements for TKIP. Whereas TKIP is an evolution of WEP, CCMP and WRAP have been designed exclusively for 802.11i and offer improved security. Because these protocols are AES-based, they require a hardware upgrade.</strong></h4>
</li>
<li>
<h4><strong>IBSS: 802.11i will address independent basic service sets (IBSSs), also known as ad hoc or peer-to-peer wireless networks. WPA instead focuses on extended service sets (ESSs), which are networks formed around wireless access points. An IBSS has no access point; an ESS has multiple access points.</strong></h4>
</li>
<li>
<h4><strong>Preauthentication: For applications that require minimal latency, such as voice over IP (VoIP), 802.11i will provide preauthentication as a way to reduce latency during hand-off between basic service sets (BSSs). A BSS is a network of wireless devices sharing the same access point. Preauthentication will essentially reduce the time necessary for communication to resume when a client moves between access points. This feature is not perceived as urgent.</strong></h4>
</li>
</ul>
<h4><strong>The figure below shows the expected progression of wireless security technology. The original combination of 802.11 and WEP has already been successfully augmented by the 802.1x authentication protocol. The introduction of WPA by the Wi-Fi Alliance makes the most important features of 802.11i available now, requiring only software upgrades. When 802.11i is ready, it will be marketed as WPA-2, offering forward compatibility with WPA. Through hardware upgrades additional features will become available, such as the stronger AES cipher and improved security protocols using AES, IBSS support, and preauthentication support. As security standards for wireless networking improve, business and government organizations may feel more confident about adopting this technology—giving them the opportunity to reap its productivity benefits.</strong></h4>
<h4><strong>.</strong><a href="http://sailjamehra.files.wordpress.com/2010/02/ps3q03-lowerywireless2.jpg"><strong><img title="ps3q03-lowerywireless2" src="http://sailjamehra.files.wordpress.com/2010/02/ps3q03-lowerywireless2.jpg?w=432&#038;h=386&#038;h=386" alt="" width="432" height="386" /></strong></a></h4>
</div>
</div>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/wireless-security/'>wireless security</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1290/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1290&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/10/02/1290/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>

		<media:content url="http://sailjamehra.wordpress.com/Documents%20and%20Settings/sasi/Desktop/ccna0/Wireless%20(In)Security_files/spacer.gif" medium="image" />

		<media:content url="http://sailjamehra.files.wordpress.com/2010/02/ps3q03-lowerywireless1.jpg?w=432&#38;h=414" medium="image">
			<media:title type="html">ps3q03-lowerywireless1</media:title>
		</media:content>

		<media:content url="http://sailjamehra.files.wordpress.com/2010/02/ps3q03-lowerywireless2.jpg?w=432&#38;h=386" medium="image">
			<media:title type="html">ps3q03-lowerywireless2</media:title>
		</media:content>
	</item>
		<item>
		<title>Java viva Questions</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/09/26/java-viva-questions/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/09/26/java-viva-questions/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 09:11:05 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[Java viva Questions]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1280</guid>
		<description><![CDATA[)What is OOPs? Ans: Object oriented programming organizes a program around its data,i.e.,objects and a set of well defined interfaces to that data.An object-oriented program can be characterized as data controlling access to code. 2)what is the difference between Procedural and OOPs? Ans: a) In procedural program, programming logic follows certain procedures and the instructions [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1280&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>)What is OOPs?</p>
<p>Ans: Object oriented programming organizes a program around its data,i.e.,objects and a set of well defined interfaces to that data.An object-oriented program can be characterized as data controlling access to code.</p>
<p>2)what is the difference between Procedural and OOPs?</p>
<p>Ans: a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOPs program, unit of program is object, which is nothing but combination of data and code.</p>
<p>b) In procedural program,data is exposed to the whole program whereas in OOPs program,it is accessible with in the object and which in turn assures the security of the code.</p>
<p>3)What are Encapsulation, Inheritance and Polymorphism?</p>
<p>Ans: Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse.Inheritance is the process by which one object acquires the properties of another object.Polymorphism is the feature that allows one interface to be used general class actions.</p>
<p>4)What is the difference between Assignment and Initialization?</p>
<p>Ans: Assignment can be done as many times as desired whereas initialization can be done only once.</p>
<p>5)What are Class, Constructor and Primitive data types?</p>
<p>Ans: Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created.</p>
<p>Primitive data types are 8 types and they are:</p>
<p>byte, short, int, long</p>
<p>float, double</p>
<p>boolean</p>
<p>char</p>
<p>&nbsp;</p>
<p>6)What is an Object and how do you allocate memory to it?</p>
<p>Ans: Object is an instance of a class and it is a software unit that combines a structured set of data with a set of  operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.</p>
<p>7)What is the difference between constructor and method?  Ans: Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.</p>
<p>8)What are methods and how are they defined?</p>
<p>Ans: Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes.</p>
<p>Method definition has four parts.</p>
<p>they are name of the method,</p>
<p> type of object or primitive type the method returns,</p>
<p>a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.</p>
<p>9)What is the use of bin and lib in JDK?</p>
<p>Ans: Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.</p>
<p>10)What is casting?</p>
<p>Ans: Casting is used to convert the value of one type to another.</p>
<p>11)How many ways can an argument be passed to a subroutine and explain them?</p>
<p>Ans: An argument can be passed in two ways. They are passing by value and passing by reference.Passing by value: This method copies the value of an argument into the formal parameter of the subroutine.Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.</p>
<p>12)What is the difference between an argument and a parameter?</p>
<p>Ans: While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.</p>
<p>13)What are different types of access modifiers?</p>
<p>Ans: public: Any thing declared as public can be accessed from anywhere.</p>
<p>private: Any thing declared as private can’t be seen outside of its class.</p>
<p>protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages.</p>
<p>default modifier : Can be accessed only to classes in the same package.</p>
<p>14)What is final, finalize() and finally?</p>
<p>Ans: final : final keyword can be used for class, method and variables.A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods.A final method can’ t be overriddenA final variable can’t change from its initialized value.finalize( ) : finalize( ) method is used just before an object is destroyed and can be called just prior to garbage collecollection   finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. this For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address</p>
<p>contingency.      </p>
<p>15)What is UNICODE?</p>
<p>Ans: Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.</p>
<p>16)What is Garbage Collection and how to call it explicitly?</p>
<p>Ans: When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection.System.gc() method may be used to call it explicitly.</p>
<p>17)What is  finalize() method ?</p>
<p>Ans: finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.</p>
<p>18)What are Transient and Volatile Modifiers?</p>
<p>Ans: Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized.Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.</p>
<p>19)What is method overloading and method overriding?</p>
<p>Ans: Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading.</p>
<p>Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.</p>
<p>20)What is difference between overloading and overriding?</p>
<p>Ans: a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.</p>
<p>b)    Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.</p>
<p>c)     In overloading, separate methods share the same name whereas in overriding,subclass method replaces the superclass.</p>
<p>d)    Overloading must have different method signatures whereas overriding  must have same signature.</p>
<p>&nbsp;</p>
<p>21) What is meant by Inheritance and what are its advantages?</p>
<p>Ans: Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.</p>
<p>22)What is the difference between this() and super()?</p>
<p>Ans: this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.</p>
<p>23)What is the difference between superclass and subclass?</p>
<h2>Ans: A super class is a class that is inherited whereas sub class is a classthat does the inheriting.</h2>
<p>24) What modifiers may be used with top-level class?</p>
<p>Ans: public, abstract and final can be used for top-level class.</p>
<p>25)What are inner class and anonymous class?</p>
<p>Ans: Inner class  : classes defined in other classes, including those defined in methods are called  inner classes. An inner class can have any accessibility including private.Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.</p>
<p>26)What is a package?</p>
<p>Ans: A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.</p>
<h3>27)          What is a reflection package? </h3>
<p>Ans: java.lang.reflect package has the ability to analyze itself in runtime.</p>
<h3>28)          What is interface and its use?</h3>
<p>Ans:Interface is similar to a class which may contain method’s signature only but not bodies and  it is</p>
<p>a formal set of method and constant declarations that must be defined by the class that implements it.</p>
<p>Interfaces are useful for:</p>
<p>a)Declaring methods that one or more classes are expected to implement</p>
<p>b)Capturing similarities between unrelated classes without forcing a class relationship.</p>
<p>c)Determining an object’s programming interface without revealing the actual body of the class.</p>
<h3>29)          What is an abstract class?</h3>
<p>Ans: An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete. </p>
<h3>30)          What is the difference between Integer and int?</h3>
<p>Ans: a) Integer is a class defined in the java.lang package, whereas int is a primitive data type defined in the Java language itself. Java does not automatically convert from one to the other.</p>
<p>b)    Integer can be used as an argument for a method that requires an object, whereas int can be used for</p>
<p>calculations.</p>
<h3>31)           What is a cloneable interface and how many methods does it contain?</h3>
<p>Ans- It is not having any method because it is a TAGGED or MARKER interface.</p>
<h3>32)          What is the difference between abstract class and interface?</h3>
<p>Ans: a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract.</p>
<p>b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods.</p>
<p>c)     Abstract class must have subclasses whereas interface can’t have subclasses.</p>
<p>&nbsp;</p>
<h3>33)          Can you have an inner class inside a method and what variables can you access?</h3>
<p>Ans: Yes, we can have an inner class inside a method and final variables can be accessed.</p>
<h3>34)          What is the difference between String and String Buffer?</h3>
<p>Ans: a) String objects are constants and immutable whereasStringBuffer objects are not.</p>
<p>b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings.</p>
<h3>35)          What is the difference between Array and vector?</h3>
<p>Ans: Array is a set of related data type and static whereas vector is a growable array of objects and dynamic.</p>
<h3>36)          What is the difference between exception and error?</h3>
<p>Ans: The exception class defines mild error conditions that your program encounters.Ex: Arithmetic Exception, FilenotFound exception Exceptions can occur when try to open the file, which does not exist</p>
<ul>
<li>the network connection is disrupted</li>
<li>operands being manipulated are out of prescribed ranges</li>
<li>the class file you are interested in loading is missing</li>
</ul>
<p>The error class defines serious error conditions that you should not  attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.</p>
<p>Ex: Running out of memory error, Stack overflow error.</p>
<h3>37)          What is the difference between process and thread?</h3>
<p>Ans: Process is a program in execution whereas thread is a separate path of execution in a program.</p>
<h3>38)          What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined?</h3>
<p>Ans: Multithreading is the mechanism in which more than one thread run independent of each other within the process.</p>
<p>wait (), notify () and notifyAll() methods can be used for inter-thread communication and these methods are in Object class.</p>
<p>wait( ) : When a thread executes a call to wait( ) method, it surrenders the object lock and enters into a waiting state.</p>
<p>notify( ) or notifyAll( ) : To remove a thread from the waiting state, some other thread must make a call to  notify( ) or notifyAll( ) method on the same object.</p>
<p>39)          What is the class and interface in java to create thread and which is the most advantageous method?</p>
<p>Ans: Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.</p>
<h3>40)          What are the states associated in the thread?</h3>
<p>Ans: Thread contains ready, running, waiting and dead states.</p>
<h3>41)           What is synchronization?</h3>
<p>Ans: Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time.</p>
<h3>42)          When you will synchronize a piece of your code?</h3>
<p>Ans: When you expect your code will be accessed by different threads and these threads may change a particular data causing data corruption.</p>
<h3>43)          What is deadlock?</h3>
<p>Ans: When two threads are waiting each other and can’t precede the program is said to be deadlock.</p>
<h3>44)          What is daemon thread and which method is used to create the daemon thread?</h3>
<p>Ans: Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.</p>
<h3>45)          Are there any global variables in Java, which can be accessed by other part of your program?</h3>
<p>Ans: No, it is not the main method in which you define variables. Global variables is not possible because concept of encapsulation is eliminated here.</p>
<p>46)What is an applet?</p>
<p>Ans: Applet is a dynamic and interactive program that runs inside a web page displayed by a java capable browser.</p>
<p>47)What is the difference between applications and applets?</p>
<p>Ans: a)Application must be run on local machine whereas applet needs no explicit installation on local machine.</p>
<p>b)Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser.</p>
<p>d)Application starts execution with its main method whereas applet starts execution with its init method.</p>
<p>e)Application can run with or without graphical user interface whereas applet must run within a graphical user interface.</p>
<p>48)How does applet recognize the height and  width?</p>
<p>Ans:Using getParameters()  method.</p>
<p>&nbsp;</p>
<p>49)When do you use codebase in applet?</p>
<p>Ans:When the applet class file is not in the same directory, codebase is used.</p>
<p>50)What is the lifecycle of an applet?</p>
<p>Ans:init( ) method        -  Can be called when an applet is first loaded</p>
<p>         start( ) method      -  Can be called each time an applet is started</p>
<p>         paint( ) method     -  Can be called when the applet is minimized or maximized</p>
<p>         stop( ) method      -  Can be used when the browser moves off the applet’s page</p>
<p>destroy( ) method -  Can be called when the browser is finished with the applet</p>
<p>51)How do you set security in applets?</p>
<p>Ans: using  setSecurityManager() method</p>
<p>&nbsp;</p>
<h4>52)          What is an event and what are the models available for event handling?</h4>
<p>Ans: An event is an event object that describes a state of change in a source. In other words, event occurs when an</p>
<p>action is generated, like pressing button, clicking mouse, selecting a list, etc.</p>
<p>There are two types of models for handling events and they are:</p>
<h5>a)             event-inheritance model and b) event-delegation model</h5>
<h4>53)          What are the advantages of the event-delegation  model over the event-inheritance model?</h4>
<p>Ans: The event-delegation model has two advantages over the event-inheritance model. They are:</p>
<p>a)It enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component’s design and its use.</p>
<p>b)It performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to be repeatedly process unhandled events as is the case of the event-inheritance.</p>
<p>54)What is source and listener ?</p>
<p>Ans: source : A source is an object that generates an event. This occurs when the internal state of that object changes in some way.</p>
<p>listener : A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events. Second, it must implement methods to receive and process these notifications. </p>
<h4>55)          What is adapter class?</h4>
<p>Ans: An adapter class provides an empty implementation of all methods in an event listener interface. Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface. You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested.For example, the MouseMotionAdapter class has two methods, mouseDragged( )and mouseMoved(). The</p>
<p>signatures of these empty are exactly as defined in the  MouseMotionListener interface. If you are interested in only mouse drag events, then you could simply extend MouseMotionAdapter and implement mouseDragged( ) .</p>
<p>56)What is meant by controls and what are different types of controls in AWT?</p>
<p>Ans: Controls are components that allow a user to interact with your application and the AWT supports the following types of controls:Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components.These controls are subclasses of Component.</p>
<h4>57)          What is the difference between choice and list?</h4>
<p>Ans: A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices and only one item may be selected from a choice.A List may be displayed in such a way that several list items are visible and it supports the selection of one or more list items.</p>
<h4>58)          What is the difference between scrollbar and scrollpane?</h4>
<p>Ans: A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and handles its own events and perform its own scrolling.</p>
<p>59)          What is a layout manager and what are different types of layout managers available in java.awt?</p>
<p>Ans: A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout,Null layout/Custom layout</p>
<h4>60)          How are the elements of different layouts organized?</h4>
<p>Ans: FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container.</p>
<p>CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards.GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid. GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.</p>
<h4>61)           Which containers use a Border layout as their default layout?      </h4>
<p>Ans:  Window, Frame and Dialog classes use a BorderLayout as their layout.</p>
<h4>62)          Which containers use a Flow layout as their default layout?</h4>
<p>Ans: Panel and Applet classes use the FlowLayout as their default layout.</p>
<h4>63)          What are wrapper classes?</h4>
<p>Ans: Wrapper classes are classes that allow primitive types to be accessed as objects.</p>
<h4>64)          What are Vector, Hashtable, LinkedList and Enumeration?</h4>
<p>Ans: Vector : The Vector class provides the capability to implement a growable array of objects.Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object’s keys. Hash codes are integer values that identify objects.</p>
<p>LinkedList: Removing or inserting elements in the middle of an array can be done using LinkedList. A</p>
<p>LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations.</p>
<p>Enumeration: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements( ) and nextElement( ). HasMoreElemnts( ) tests if this enumeration has more elements and nextElement method returns successive elements of the series.</p>
<h4>65)          What is the difference between set and list?</h4>
<p>Ans: Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an ordered way but may contain duplicate elements.</p>
<h4>66)          What is a stream and what are the types of Streams and classes of the Streams?</h4>
<p>Ans: A Stream is an abstraction that either produces or consumes information. There are two types of Streams and they are:</p>
<p>Byte Streams: Provide a convenient means for handling input and output of bytes.Character  Streams:  Provide a convenient means for handling input &amp; output of characters.Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream.Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.</p>
<h4>67)          What is the difference between Reader/Writer and InputStream/Output Stream?</h4>
<p>Ans: The Reader/Writer class is character-oriented and the InputStream/OutputStream class is byte-oriented.</p>
<h4>68)          What is an I/O filter?</h4>
<p>Ans: An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.</p>
<h4>69)          What is serialization and deserialization?</h4>
<p>Ans: Serialization is the process of writing the state of an object to a byte stream.Deserialization is the process of restoring these objects.</p>
<h4>70)          What is JDBC?</h4>
<p>Ans: JDBC is a set of Java API for executing SQL statements. This API consists of a set of  classes and interfaces</p>
<p>to enable programs to write pure Java Database applications.</p>
<p>71)           What are drivers available?</p>
<p>Ans:  a)     JDBC-ODBC Bridge driver</p>
<p>       b)     Native API Partly-Java driver</p>
<p>c)     JDBC-Net Pure Java driver</p>
<p>d)    Native-Protocol Pure Java driver</p>
<h4>72)          What is the difference between JDBC and ODBC?</h4>
<p>Ans:  a)     ODBC is for Microsoft and JDBC is for Java applications.</p>
<p>b)            ODBC can’t be directly used with Java because it uses a C interface.</p>
<h5>c)             ODBC  makes use of pointers which have been removed totally from Java.</h5>
<p>d)    ODBC mixes simple and advanced features together and has complex options for simple queries. But JDBC is designed to keep things simple while allowing advanced capabilities when required.</p>
<p>e)     ODBC requires manual installation of the ODBC driver manager and driver on all client machines. JDBC drivers are written in Java and JDBC code is automatically installable, secure, and portable on all platforms.</p>
<p>f)     JDBC API is a natural Java interface and is built on ODBC. JDBC retains some of the basic features of ODBC.</p>
<h4>73)          What are the types of JDBC Driver Models and explain them?</h4>
<p>Ans: There are two types of  JDBC Driver Models and they are:</p>
<p>a)     Two tier model and b) Three tier modelTwo tier model: In this model, Java applications interact directly with the database. A JDBC driver is required to communicate with the particular database management system that is being accessed. SQL statements are sent to the database and the results are given to user. This model is referred to as client/server configuration where user is the client and the machine that has the database is called as the server.</p>
<p>Three tier model: A middle tier is introduced in this model. The functions of this model are:</p>
<p>a)     Collection of SQL statements from the client and handing it over to the database,</p>
<p>b)    Receiving results from database to the client and</p>
<p>c)     Maintaining control over accessing and updating of the above.</p>
<h4>74)          What are the steps involved for making a connection with a database or how do you connect to a database?</h4>
<p>Ans: a)    Loading the driver : To load the driver, Class.forName( ) method is used.</p>
<p>                     Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);</p>
<p>                When the driver is loaded, it registers itself with the java.sql.DriverManager class as an available  database driver.</p>
<p>b)    Making a connection with database : To open a connection to a given database, DriverManager.getConnection( ) method is used.</p>
<p>Connection con = DriverManager.getConnection (“jdbc:odbc:somedb”, “user”,  “password”);</p>
<p>c)     Executing SQL statements : To execute a SQL query, java.sql.statements class is used.  </p>
<p>createStatement( ) method of Connection to obtain a new Statement object.</p>
<p>Statement stmt  = con.createStatement( );</p>
<p>A query that returns data can be executed using the executeQuery( ) method of  Statement. This method</p>
<p>executes the statement and returns a java.sql.ResultSet that encapsulates the retrieved data:</p>
<p>ResultSet rs = stmt.executeQuery(“SELECT * FROM some table”);</p>
<p>d)    Process the results : ResultSet returns one row at a time. Next( ) method of ResultSet  object can be called to move to the next row.  The getString( ) and getObject( ) methods are used for retrieving  column values:</p>
<p>while(rs.next( ) ) {</p>
<p>String event = rs.getString(“event”);</p>
<p>Object count = (Integer) rs.getObject(“count”);</p>
<h4>75)          What type of driver did you use in project?</h4>
<p>Ans: JDBC-ODBC Bridge driver (is a driver that uses native(C language) libraries and makes calls to an existing</p>
<p>ODBC driver to access a database engine).</p>
<h4>76)          What are the types of statements in JDBC?</h4>
<p>Ans: Statement                — To be used createStatement() method for executing single SQL statement</p>
<p>PreparedStatement  — To be used preparedStatement() method for executing same SQL statement over and</p>
<p>over</p>
<p>CallableStatement    — To be used prepareCall( ) method for multiple SQL statements over and over</p>
<p>&nbsp;</p>
<h4>77)          What is stored procedure?</h4>
<p>Ans: Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task. Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and executed with different parameters and results and may have any combination of input/output parameters.</p>
<h4>78)          How to create and call stored procedures?</h4>
<p>Ans:   To create stored procedures: Create procedure procedurename (specify in, out and in out parameters)</p>
<h3>BEGIN</h3>
<p>Any multiple SQL statement;</p>
<p>END;</p>
<p>To call stored procedures:</p>
<p>CallableStatement  csmt  = con.prepareCall(“{call procedure name(?,?)}”);</p>
<p>csmt.registerOutParameter(column no., data type);</p>
<p>csmt.setInt(column no., column name)</p>
<p>csmt.execute( ); </p>
<h4>——79)                What is servlet?</h4>
<p>Ans: Servlets are modules that extend request/response-oriented servers, such as java-enabled web servers.For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.</p>
<h4>80)          What are the classes and  interfaces for servlets?</h4>
<p>Ans: There are two packages in servlets and they are javax.servlet and javax.servlet.http.</p>
<p>Javax.servlet contains:</p>
<p>               Interfaces                       Classes</p>
<p>               Servlet                            Generic Servlet</p>
<p>               ServletRequest               ServletInputStream</p>
<p>               ServletResponse             ServletOutputStream</p>
<p>               ServletConfig                 ServletException</p>
<p>               ServletContext                UnavailableException</p>
<p>SingleThreadModel</p>
<p>Javax.servlet.http contains:</p>
<p>               Interfaces                                 Classes</p>
<p>               HttpServletRequest                  Cookie</p>
<p>               HttpServletResponse                HttpServlet</p>
<p>               HttpSession                               HttpSessionBindingEvent</p>
<p>               HttpSessionContext                  HttpUtils</p>
<p>HttpSessionBindingListener</p>
<h4>81)           What is the difference between an applet and a servlet?</h4>
<p>Ans: a)       Servlets are to servers what applets are to browsers.</p>
<p>   b)    Applets must have graphical user interfaces whereas servlets have no graphical                                                                              user interfaces.</p>
<p>&nbsp;</p>
<h4>82)          What is the difference between doPost and doGet methods?</h4>
<p>Ans: a) doGet() method is used to get information, while doPost( ) method is used for posting information.</p>
<p>b) doGet() requests can’t send large amount of information and is limited to 240-255 characters. However, doPost( )requests passes all of its data, of unlimited length.</p>
<p>c)     A doGet( ) request is appended to the request URL in a query string and this allows the exchange is visible to the client, whereas a doPost() request passes directly over the  socket connection as part of its HTTP request body and the exchange are invisible to the client.</p>
<h4>83)          What is the life cycle of a servlet?</h4>
<p>Ans: Each Servlet has the same life cycle:</p>
<p>a)     A server loads and initializes the servlet by init( ) method.</p>
<p>b)    The servlet  handles zero or more client’s requests through service( ) method.</p>
<p>c)     The server removes the servlet through destroy() method.        </p>
<h4>84)          Who is loading the init() method of servlet?</h4>
<p>Ans: Web server</p>
<h4>85)          What are the different servers available for developing and deploying Servlets?</h4>
<p>Ans:  a)    Java Web Server</p>
<p>      b)      JRun</p>
<p>g)     Apache Server</p>
<p>h)     Netscape Information Server</p>
<p>i)      Web Logic       </p>
<h4>86)          How many ways can we track client  and what are they?</h4>
<p>Ans: The servlet API provides two ways to track client state and they are:</p>
<h5>a)             Using Session tracking and b) Using Cookies.</h5>
<h4>87)          What is session tracking and how do you track a user session in servlets?</h4>
<p>Ans: Session tracking is a mechanism that servlets use to maintain state about a series requests from the same user across some period of time. The methods used for session tracking are:</p>
<p>a)     User Authentication – occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized username and password</p>
<p>b)    Hidden form fields – fields are added to an HTML form that are not displayed in the client’s browser. When the form containing the fields is submitted, the fields are sent back to the server</p>
<p>c)     URL rewriting – every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change.</p>
<p>d)    Cookies – a bit of information that is sent by a web server to a browser and which can later be read back from that browser.</p>
<p>e)     HttpSession- places a limit on the number of sessions that can exist in memory. This limit is set in the session.maxresidents property</p>
<h4>88)          What is Server-Side Includes (SSI)?</h4>
<p>Ans: Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page. This is accomplished using a special internal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension is requested. So HTML files that include  server-side includes must be stored with an .shtml extension.</p>
<h4>89)          What are cookies and how will you use them?</h4>
<p>Ans: Cookies are a mechanism that a servlet uses to have a client hold a small amount of state-information associated with the user.</p>
<p>a)             Create a cookie with the Cookie constructor:</p>
<p>public Cookie(String name, String value)</p>
<p>b)    A servlet can send a cookie to the client by passing a Cookie object to the addCookie() method of HttpServletResponse:public void HttpServletResponse.addCookie(Cookie cookie)</p>
<p>c)     A servlet retrieves cookies by calling the getCookies() method of HttpServletRequest:</p>
<p>public Cookie[ ] HttpServletRequest.getCookie( ).</p>
<h4>90)          Is it possible to communicate from an applet to servlet and how many ways and how?</h4>
<p>Ans: Yes, there are three ways to communicate from an applet to servlet and they are:</p>
<p>a)     HTTP Communication(Text-based and object-based)</p>
<p>b)    Socket Communication</p>
<p>c)     RMI Communication</p>
<p>(You can say, by using URL object open the connection to server and get the InputStream from</p>
<p>URLConnection  object).</p>
<p>Steps involved for applet-servlet communication:</p>
<h5>1)             Get the server URL.</h5>
<p>URL url = new URL();</p>
<h5>2)            Connect to the host</h5>
<p>URLConnection Con = url.openConnection();</p>
<h5>3)            Initialize the connection</h5>
<p>Con.setUseCatches(false):</p>
<p>Con.setDoOutput(true);</p>
<p>Con.setDoInput(true);</p>
<h5>4)            Data will be written to a byte array buffer so that we can tell the server the length of the data.</h5>
<p>ByteArrayOutputStream byteout  = new ByteArrayOutputStream();</p>
<h5>5)            Create the OutputStream to be used to write the data to the buffer.</h5>
<p>DataOutputStream out = new DataOutputStream(byteout);</p>
<h4>91)           What is connection pooling?</h4>
<p>Ans: With servlets, opening a database connection is a major bottleneck because we are creating and tearing down a new connection for every page request and the time taken to create connection will be more. Creating a connection pool is an ideal approach for a complicated servlet. With a connection pool, we can duplicate only the resources we need to duplicate rather than the entire servlet. A connection pool can also  intelligently manage the size of the pool and make sure each connection remains valid. A number of connection pool packages are currently available. Some like DbConnectionBroker are freely available from Java Exchange Works by creating an object that dispenses connections and connection Ids on request.The ConnectionPool class maintains a Hastable, using Connection objects as keys and Boolean values as stored values. The Boolean value indicates whether a connection is in use or not. A program calls getConnection( ) method of the ConnectionPool for getting  Connection object it can use; it calls returnConnection( ) to give the connection back to the pool.</p>
<h4>92)          Why should we go for interservlet communication?</h4>
<p>Ans: Servlets running together in the same server communicate with each other in several ways.The three major reasons to use interservlet communication are:</p>
<p>a)     Direct servlet manipulation – allows to gain access to the other currently loaded servlets and perform certain tasks (through the ServletContext object)</p>
<p>b)    Servlet reuse – allows the servlet to reuse the public methods of another servlet.</p>
<p>c)     Servlet collaboration – requires to communicate with each other by sharing specific information (through method invocation)</p>
<h4>93)          Is it possible to call servlet with parameters in the URL?</h4>
<p>Ans: Yes. You can call a servlet with parameters in the syntax as (?Param1 = xxx || m2 = yyy).</p>
<h4>94)          What is Servlet chaining?</h4>
<p>Ans: Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request.In servlet chaining, one servlet’s output is piped to the next servlet’s input. This process continues until the last servlet is reached. Its output is then sent back to the client.</p>
<h4>95)          How do servlets handle multiple simultaneous requests?</h4>
<p>Ans: The server has multiple threads that are available to handle requests. When a request comes in, it is assigned to a thread, which calls a service method (for example: doGet(), doPost( ) and service( ) ) of the servlet. For this reason, a single servlet object can have its service methods called by many threads at once.</p>
<h4>96)          What is the difference between TCP/IP and UDP?</h4>
<p>Ans: TCP/IP is a two-way communication between the client and the server and it is a reliable and there is a confirmation regarding reaching the message to the destination. It is like a phone call. UDP is a one-way communication only between the client and the server and it is not a reliable and there is no confirmation regarding reaching the message to the destination. It is like a postal mail.</p>
<h4>97)          What is Inet address?</h4>
<p>Ans: Every computer connected to a network has an IP address. An IP address is a number that uniquely identifies each computer on the Net. An IP address is a 32-bit number.</p>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/java-viva-questions/'>Java viva Questions</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1280/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1280&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/09/26/java-viva-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>
	</item>
		<item>
		<title>Know About Accounts</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/09/24/know-about-accounts/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/09/24/know-about-accounts/#comments</comments>
		<pubDate>Sat, 24 Sep 2011 14:44:04 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[Know About Accounts]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1278</guid>
		<description><![CDATA[Capital and Revenue   Index   Capital and Revenue Expenditure Distinction between capital expenditure and Revenue Expenditure capital and Revenue receipts problems &#160; capital and revenue expenditure Capital expenditure is the outflow of funds to acquire an asset that will benefit the business more the one accounting period. A capital expenditure takes place when an [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1278&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="text-align:center;"><span style="text-decoration:underline;">Capital and Revenue</span></h2>
<p align="center"> </p>
<p align="center">Index</p>
<p align="center"> </p>
<ol>
<li>Capital and Revenue Expenditure</li>
<li>Distinction between capital expenditure and Revenue Expenditure</li>
<li>capital and Revenue receipts</li>
<li>problems</li>
</ol>
<p>&nbsp;</p>
<ol>
<li>capital and revenue expenditure</li>
</ol>
<p>Capital expenditure is the outflow of funds to acquire an asset that will benefit the business <em>more the one accounting period. </em>A capital expenditure takes place when an asset or service is acquired or improvement of a fixed asset is effected.</p>
<p>Revenue expenditure is the outflow of funds to meet the running expenses of a business and it will be of benefit for the current period only. A revenue expenditure is incurred to carry on the normal course of business or maintain the capital assets in a good condition.</p>
<p>&nbsp;</p>
<ol>
<li>distinction between capital expenditure and Revenue expenditure</li>
</ol>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="63">S.No.</td>
<td valign="top" width="237">Capital Expenditure</td>
<td valign="top" width="57">S.No.</td>
<td valign="top" width="253">Revenue Expenditure</td>
</tr>
<tr>
<td valign="top" width="63">1.</td>
<td valign="top" width="237">Capital expenditure are incurred for more than one accounting period.</td>
<td valign="top" width="57">1.</td>
<td valign="top" width="253">Revenue expenditures are incurred for a particular accounting period.</td>
</tr>
<tr>
<td valign="top" width="63">2.</td>
<td valign="top" width="237">Capital expenditure are of non-recurring nature.</td>
<td valign="top" width="57">2.</td>
<td valign="top" width="253">Revenue expenditures are of recurring nature.</td>
</tr>
<tr>
<td valign="top" width="63">3.</td>
<td valign="top" width="237">All capital expenditures eventually become revenue expenditures.</td>
<td valign="top" width="57">3.</td>
<td valign="top" width="253">Revenue expenditures are not generally capital expenditures.</td>
</tr>
<tr>
<td valign="top" width="63">4.</td>
<td valign="top" width="237">Capital expenditures are not matched with capital receipts.</td>
<td valign="top" width="57">4.</td>
<td valign="top" width="253">All revenue expenditures are matched with revenue receipts.</td>
</tr>
<tr>
<td valign="top" width="63">5.</td>
<td valign="top" width="237">Capital expenditures are incurred before or after the commencement of the business.</td>
<td valign="top" width="57">5.</td>
<td valign="top" width="253">Revenue expenditures are incurred always after the commencement of the business.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<ol>
<li>capital and Revenue receipts</li>
</ol>
<p>A receipt of money may be of a capital or revenue nature. A clear distinction, therefore, should be made between capital receipts and revenue receipts.</p>
<p>A receipt of money is considered as capital receipts when a contribution is made by the proprietor towards the capital of the business or a contribution of capital to the business by someone outside the business.</p>
<p>&nbsp;</p>
<p>A receipt of money is considered as revenue receipt when it is received from customers for goods supplied, or fees received for services rendered in the ordinary course of business, which is a result of the firm’s activity in the current period.</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="54">S.No.</td>
<td valign="top" width="245">Capital Receipts</td>
<td valign="top" width="61">S. No.</td>
<td valign="top" width="269">Revenue Receipts</td>
</tr>
<tr>
<td valign="top" width="54">1.</td>
<td valign="top" width="245">Capital receipts are not available for distribution as profits.</td>
<td valign="top" width="61">1.</td>
<td valign="top" width="269">Revenue receipts are available for distribution as profits only after deducting revenue expenditure.</td>
</tr>
<tr>
<td valign="top" width="54">2.</td>
<td valign="top" width="245">Capital receipts cannot be utilized for creating a reserve fund.</td>
<td valign="top" width="61">2.</td>
<td valign="top" width="269">Revenue receipts can be utilized for creating a reserve fund after deducting revenue expenses.</td>
</tr>
<tr>
<td valign="top" width="54">3.</td>
<td valign="top" width="245">A business can survive without any capital receipts during an accounting period.</td>
<td valign="top" width="61">3.</td>
<td valign="top" width="269">The survival of a business mainly depends on the revenue receipts during an accounting period.</td>
</tr>
<tr>
<td valign="top" width="54">4.</td>
<td valign="top" width="245">Capital receipts are the sources for creating capital reserves.</td>
<td valign="top" width="61">4.</td>
<td valign="top" width="269">Revenue receipts are the sources for creating revenue reserves.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<ol>
<li>Problems</li>
</ol>
<p>Illustration: 1</p>
<p>State whether the following are capital, revenue or deferred revenue expenditure.</p>
<p>i)         Carriage of Rs.7,500 spent on machinery purchased and installed.</p>
<p>ii)       Heavy advertising costs Rs.20,000 spent on the launching of a company’s new product.</p>
<p>iii)    Rs.200 paid for servicing the company vehicle, including Rs.50 paid for changing the oil.</p>
<p>iv)      Construction of basement costing Rs.1,95,000 at the factory premises.</p>
<p>&nbsp;</p>
<p>Illustration: 2</p>
<p>State whether the following are capital or revenue expenditure.</p>
<p>i)         Paid a bill of Rs.10,000 of Mr. Kumar, who was engaged as the erection engineer to set up a new automatic machine costing Rs.20,000 at the new factory site.</p>
<p>ii)       Incurred Rs.26,000 expenditure on varied advertisement campaigns undertaken yearly, on a regular basis, during the peak festival season.</p>
<p>iii)    In accordance with the long – term plan of providing a well – equipped labour welfare centre, spent Rs.90,000 being the budgeted allocation for the year 1997.</p>
<p>&nbsp;</p>
<p>Illustration: 3</p>
<p>Classify the following items as capital or revenue expenditure: (i) An extension of railway tracks in the factory area; (ii) wages paid to machine operators; (iii) Installation costs of new production machine; (iv) Materials for extensions to foremen’s offices in the factory; (v) rent paid for the factory; (vi) payment for computer time to operate a new stores control system; (vii) Wages paid to own employees for building the foremen’s offices. Give reasons for your classification.</p>
<p>&nbsp;</p>
<p>Illustration: 4</p>
<p>For each of the cases numbered (i) to (iv) below, indicate whether the income / expenditure is capital or revenue.</p>
<p>i)         Payment of wages to one’s own employees for building a new office extension.</p>
<p>ii)       Regular hiring of computer time for the preparation of the firm’s accounts.</p>
<p>iii)    The purchase of a new computer for use in the business.</p>
<p>iv)      The use of motor vehicle, hired for five years, but paid at every six months.</p>
<p>&nbsp;</p>
<p>Illustration: 5</p>
<p>State whether the following are capital or revenue expenditure.</p>
<p>i)         Freight and cartage on the new machine Rs.150, and erection charges Rs.500</p>
<p>ii)       Fixtures of the book value of Rs.2,500 sold off at Rs.1,600 and new fixtures of the value of Rs.4,000 were acquired, cartage on purchase Rs.5.</p>
<p>iii)    A sum of Rs.400 was spent on painting the factory.</p>
<p>iv)      Rs.8,200 spent on repairs before using a second hand car purchased recently, to put it in usable condition.</p>
<p>&nbsp;</p>
<p>Illustration: 6</p>
<p>State the nature (capital or revenue) of the following expenditure are which are incurred by Harikishore &amp; Co. during the year ending 30<sup>th</sup> June, 1997.</p>
<p>i)         Rs.350 was spent on repairing a  second hand machine which was purchased on 8<sup>th</sup> July, 1996 and Rs. 200 was paid on carriage and freight in connection with its acquisition.</p>
<p>ii)       A sum of Rs.500 was paid as compensation to two employees who were retrenched.</p>
<p>iii)    Rs.150 was paid in connection with carriage on goods purchased.</p>
<p>iv)      Rs.20,000 customs duty is paid on import of a machinery for modernization of the factory production during the current year  and Rs.6,000 is paid on import duty for purchase of raw materials.</p>
<p>v)        Rs.18,000 interest had accrued during the year on term loan obtained and utilized for the construction of factory building and purchase of machineries; however, the production has not commenced till the last date of the accounting year.</p>
<p>&nbsp;</p>
<p>Illustration: 7</p>
<p>State the reasons whether the following items relating to Sitalpur Sugal Mill Ltd. Are capital are revenue.</p>
<p>i)         A truck costing Rs.1,00,000 and standing in the books at Rs.60,000 was sold for Rs. 70,000</p>
<p>ii)       Rs.50,000 received from issue of shares including Rs.10,000 by way of premium.</p>
<p>iii)    Purchased agricultural land for the mill for Rs.60,000. Rs. 500 also paid for land revenue.</p>
<p>iv)      Rs.5,000 paid as contribution to PWD for improving roads of sugar producing area.</p>
<p>v)        Rs.40,000 paid for excise duty on sugar manufactured.</p>
<p>vi)      Rs.70,000 spent for constructing railway siding.</p>
<p>&nbsp;</p>
<p>Illustration: 8</p>
<p>State with reasons whether the following are Capital Expenditure or Revenue expenditure:</p>
<p>i)         Expenses incurred in connection with obtaining a license for starting the factory were Rs.10,000</p>
<p>ii)       Rs.1,000 paid for removal of stock to a new site.</p>
<p>iii)    Rings and Pistons of an engine were changed at a cost of Rs.5,000 to get full efficiency.</p>
<p>iv)      Rs.2,000 spent as lawyer’s fee to defend a suit claiming that the firm’s factory site belonged to the plaintiff. The suit was not successful.</p>
<p>v)        Rs.10,000 were spent on advertising the introduction of a new product in the market, the benefit of which will be effective during four years.</p>
<p>vi)      A factory shed was constructed at a cost of Rs.1,00,000. A sum of Rs.5,000 had been incurred for the construction of the temporary huts for strong building materials.</p>
<p>&nbsp;</p>
<p>Illustration: 9</p>
<p>State clearly how you would deal with the following in the books of Theatrical Company:</p>
<p>i)         The redecoration expenses Rs.6,000</p>
<p>ii)       The installation of a new wine bar for Rs.10,000</p>
<p>iii)    The building of an extension of the club dressing room for Rs.15,000</p>
<p>iv)      The purchase of wines and spirits Rs.2,000</p>
<p>v)        The purchase of V.C.R and T.V. for the use in the club lounge for Rs.15,000.</p>
<p>&nbsp;</p>
<h2>Bad debts, Provision for Band and Doubtful Debts</h2>
<p align="center">Index</p>
<p align="center"> </p>
<ol>
<li>Introduction</li>
<li>Methods</li>
<li>Provision for Discount on Debtors</li>
<li>Reserve for discount on creditors</li>
<li>Recovery of Bad debts</li>
</ol>
<p>&nbsp;</p>
<ol>
<li>introduction:</li>
</ol>
<p><em>Bad debts is an amount owing from a debtor which is not expected to be received.</em> Though bad debts is a loss to the business, it is treated as an operating expense of doing business, since it is inevitable to any business that extends credit to its customers.</p>
<p>&nbsp;</p>
<p>Generally accepted accounting principles (also the matching concept) require that revenue must be matched against related expenses for a specific accounting period. If the dues from the customers cannot be collected, these logically become expenses and should be matched against the sales of the accounting period that recognizes this revenue. <em> It can be argued that the transfer of bad debts to the Profit &amp; Loss Account should be made in the year in which the sale took place as only such a treatment will conform to the matching concept.</em></p>
<p>&nbsp;</p>
<ol>
<li>Methods:</li>
</ol>
<p>First Method</p>
<p>Under this method, a Bad debts Account is opened and all bad debts are written off to it. A provision for Doubtful debts Account is also opened in the very first year. All bad debts are adjusted against this Provision for Doubtful Debts Account in the subsequent years. However, the first year’s bad debts is charged to Profit &amp; Loss Account directly.</p>
<p>&nbsp;</p>
<p>Journal entries in the first year.</p>
<p>1)       <em>When a provision is created for the first time.</em></p>
<p>Profit &amp; Loss Account                                             Dr.</p>
<div>
<p>            To Provision for Bad and Doubtful Debts Account</p>
</div>
<p>2)       <em>For bad debts after Trial Balance </em></p>
<p>Bad debts Account                                                    Dr.</p>
<div>
<p>            To Sundry Debtors Account</p>
</div>
<p>3)       <em>For writing off bad debts in the Profit &amp; Loss Account </em></p>
<p>Profit &amp; Loss Account                                             Dr.</p>
<div>
<p>            To Bad Debs Account (Trial Balance figure and bad debts after Trial Balance)</p>
</div>
<p>&nbsp;</p>
<p>Journal Entries in the second and subsequent years.</p>
<p>&nbsp;</p>
<p>1)       <em>For bad debts after Trial Balance</em></p>
<p>Bad debts Account                                                                Dr.</p>
<div>
<p>            To Sundry Debtors Account</p>
</div>
<p>2)       <em>For writing off bad debts against provision account </em></p>
<p>Provision for Bad and Doubtful Debts Account   Dr.</p>
<div>
<p>To Bad debts Account (bad debt during the year and after the Trial Balance)   </p>
</div>
<p>3)       <em>For creating necessary provision at the year end</em></p>
<p>Profit &amp; Loss Account                                                        Dr.</p>
<div>
<p>           To Provision for Bad and Doubtful debts Account</p>
</div>
<p>&nbsp;</p>
<p>In the second and any subsequent year, we may consider out provision to be too large or too small. The above entry is passed to increase the provision. Conversely, to reduce the provision, we must reserve the entry.</p>
<p>&nbsp;</p>
<p align="center">The amount of provision to be created is calculated as under</p>
<p>&nbsp;</p>
<p>Closing Provision required<sup>*</sup>                                                                   ****</p>
<p>Add: Bad debts written off (total)                                                          <span style="text-decoration:underline;">****</span></p>
<p>                                                                                                                  ****</p>
<p>Less: Provision for bad and doubtful debts at the beginning   <span style="text-decoration:underline;">****</span></p>
<p>Amount to be charged to Profit &amp; Loss Account                                <span style="text-decoration:underline;">****</span></p>
<p>&nbsp;</p>
<p><sup>*</sup> Provision is to be calculated on the balance of sundry debtors after adjusting bad debts (after Trial Balance)</p>
<p>&nbsp;</p>
<p>Illustration: 1</p>
<p>The outstanding debtors of X at the end of his first year’s trading on 31.12.1997 amounted to Rs.76,800. A review of the debtors list on the same date revealed that there was a long over due of Rs.1,500 from a debtor, the collection of which was considered doubtful.</p>
<p>You are required to show the relevant Journal entries and ledger accounts in the books of X in the following circumstances: (i) If he decides a to write off the balance due from the debtor as a bad debt; and (ii) if he decides to make a provision of Rs.1,500 for the debt.</p>
<p>&nbsp;</p>
<p>illustration: 2</p>
<p>Mr. X, a trader, had incurred a loss of Rs.3,000 as bad debt during the year 1996, and then decided to create a Provision for Bad and Doubtful debts at 5% on good debtors amounting to Rs.50,000 on 31<sup>st</sup> December, 1996. During the year ended 31<sup>st</sup> December,1997 the bad debts loss was Rs.2,000. On 31<sup>st</sup> December, 1997, his good debtors amounted to Rs.65,000 and decided to maintain the Provision for Bad and doubtful debts at 4%. Pass the necessary Journal entries in the books of Mr. X for the year 1996 and 1997.</p>
<p>&nbsp;</p>
<p>Illustration: 3</p>
<p>The Balance Sheet of A as on 31-12-1995 included the following items:</p>
<p>      Sundry Debtors                                                                      Rs. 98,000</p>
<p>      Less: Provision for bad debts                                              Rs. <span style="text-decoration:underline;">  2,450</span>                  95,555</p>
<p>&nbsp;</p>
<p>At the end of the following financial years, the gross amount of debtors (before deducting a provision) were as under:</p>
<p>As on 31.12.1996 – Rs.94,000; As on 31.12.1997 – Rs. 1,02,000</p>
<p>On each of these years there was a provision for bad debts calculated on the same percentage basis as on 31.12.1995.</p>
<p>The actual amount of bad debts written off from Debtors Accounts over those period were.</p>
<p>For the year ended 31.12.1996 – Rs. 2,600; for the year ended 31.12.1997 – Rs.2,300.</p>
<p><em>You are required to prepare Bad debts Account and Provision for bad debts Account for the years 1996 and 1997.</em></p>
<p>&nbsp;</p>
<p>Illustration: 4</p>
<p>Mr. X started business on 1.1.1995. Following is the information provide for the year ended 31<sup>st</sup> December.</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="252">
<p align="center">year</p>
</td>
<td valign="top" width="105">
<p align="center">1995</p>
</td>
<td valign="top" width="111">
<p align="center">1996</p>
</td>
<td valign="top" width="111">
<p align="center">1997</p>
</td>
</tr>
<tr>
<td valign="top" width="252">Credit sales</td>
<td valign="top" width="105">
<p align="right">50,000</p>
</td>
<td valign="top" width="111">
<p align="right">70,000</p>
</td>
<td valign="top" width="111">
<p align="right">1,00,000</p>
</td>
</tr>
<tr>
<td valign="top" width="252">Received from Debtors</td>
<td valign="top" width="105">
<p align="right">30,000</p>
</td>
<td valign="top" width="111">
<p align="right">50,000</p>
</td>
<td valign="top" width="111">
<p align="right">50,000</p>
</td>
</tr>
<tr>
<td valign="top" width="252">Discount allowed</td>
<td valign="top" width="105">
<p align="right">5,000</p>
</td>
<td valign="top" width="111">
<p align="right">7,000</p>
</td>
<td valign="top" width="111">
<p align="right">6,000</p>
</td>
</tr>
<tr>
<td valign="top" width="252">Returns inward</td>
<td valign="top" width="105">
<p align="right">3,000</p>
</td>
<td valign="top" width="111">
<p align="right">2,000</p>
</td>
<td valign="top" width="111">
<p align="right">23,000</p>
</td>
</tr>
<tr>
<td valign="top" width="252">Bad debts</td>
<td valign="top" width="105">
<p align="right">2,000</p>
</td>
<td valign="top" width="111">
<p align="right">6,000</p>
</td>
<td valign="top" width="111">
<p align="right">1,000</p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Provision is to be created for doubtful debts @10% on closing debtors. <em>You are required to prepare Sundry Debtors Account, bad debts Account and Provision for Bad debts Account for the years 1995 to 1997.</em></p>
<p>&nbsp;</p>
<p>Illustration: 5</p>
<p>A trader had incurred a loss of Rs.2,500 as bad debt during the year 1995 and then decided to create a provision for bad and doubtful debts at 5% on the good debtors amounting to Rs.75,000 on 31<sup>st</sup> December, 1995.</p>
<p>&nbsp;</p>
<p>During the year ended 31<sup>st</sup> December, 1996 his debtors worth Rs.1,500 failed to pay their dues. On 31<sup>st</sup> December, 1996, his good debtors amounted to Rs.40,000 and he decided to maintain the provision for bad and doubtful debts at 4% on debtors. During 1997 his bad debts amounted to Rs.3,000. He decided to increase the Provision for Bad and Doubtful debts to 5% on good debtors, which amounted to Rs.80,000 on 31<sup>st</sup> December, 1997.</p>
<p>&nbsp;</p>
<p><em>Pass necessary Journal entries and show the Bad debts Account, Provision for bad and doubtful debts Account and also appropriate entries in the Profit &amp; Loss Account and Balance Sheet of 1995, 1996 and 1997.</em></p>
<p><em> </em></p>
<p>Second Method</p>
<p>Under this method, a Bad debts Account is opened and all bad debts are written off to it. At the end of the each year, Bad debts Account is closed by transferring to Profit &amp; Loss Account. In the first year, a provision is created by debiting the Profit &amp; Loss Account and it is carried to the next period. The amount of provision needed at the end of each subsequent year is established and necessary adjustment made to the balance on the Provision Account.</p>
<p>Journal entries in the first year</p>
<p>1)       <em>For the bad debts of the period for which no entry has been made</em></p>
<p>Bad Debts Account                          Dr.</p>
<div>
<p>           To Sundry Debtors Account</p>
</div>
<p>2)       <em>For writing off bad debts in the Profit &amp; Loss Account </em></p>
<p>Profit &amp; Loss Account                                Dr.</p>
<div>
<p>           To Bad Debts Account</p>
</div>
<p>3)       <em>When provision is created for the first time</em></p>
<p>Profit &amp; Loss Account                                Dr.</p>
<div>
<p>           To Provision for Bad and Doubtful Debts Account</p>
</div>
<p>&nbsp;</p>
<p><em>The total charge to the Profit &amp; Loss Account for the first year is thus the sum of the bad debts written off and the amount transferred to the Provision for bad and doubtful debts Account.</em></p>
<p>&nbsp;</p>
<p>Journal entries in the second and subsequent year</p>
<p>&nbsp;</p>
<p>1)       <em>For the bad debts of the period for which no entry has been made</em></p>
<p>Bad debts Account                                        Dr.</p>
<div>
<p>            To Sundry Debtors Account</p>
</div>
<p>2)       <em>For writing off bad debts in the Profit &amp; Loss Account </em></p>
<p>Profit &amp; Loss Account                                Dr.</p>
<div>
<p>           To Bad debts Account</p>
</div>
<p>3)       <em>For creating provision at the year end</em></p>
<p>a)        (Closing provision &gt; opening provision)</p>
<p>Profit &amp; Loss Account                         Dr.</p>
<p>    To Provision for Bad and Doubtful debts Account</p>
<p>&nbsp;</p>
<p>b)        (closing provision &lt; opening provision)</p>
<p>Provision for Bad and Doubtful Debts Account        Dr.</p>
<p>    To Profit &amp; Loss Account</p>
<p>&nbsp;</p>
<p>Illustration: 6</p>
<p>Mr. X, a trader, had incurred a loss of Rs.3,000 as bad debt during the year 1996, and then decided to create a Provision for Bad and Doubtful debts at 5% on good debtors amounting to Rs.50,000 on 31<sup>st</sup> December, 1996. During the year ended 31<sup>st</sup> December,1997 the bad debts loss was Rs.2,000. On 31<sup>st</sup> December, 1997, his good debtors amounted to Rs.65,000 and decided to maintain the Provision for Bad and doubtful debts at 4%. Pass the necessary Journal entries in the books of Mr. X for the year 1996 and 1997.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>You are given the following balances on 1<sup>st</sup> January, 1996 : Debtors – Rs.10,000; Provision for doubtful debts Rs.400. You ascertain the following information:</p>
<p>Sales for the year 1996 (all on credit) : Rs.1,00,000; Sales returns for the year 1996 – Rs. 1,000; collection from debtors during 1996 – Rs. 90,000; Bad debt written off during 1996 – Rs. 500; discount allowed during 1996 – Rs.400.</p>
<p>At the end of 1996 the provision for doubtful debts is required to be 5% of debtors, after making a specific provision for a debt of Rs.200 from a customer who has been declared bankrupt.</p>
<p>Sales for the year 1997 (90% on credit) – Rs.1,00,000; sales returns for the year 1997 (90% relating to credit customers) – Rs. 2,000; collection from debtors during 1997 – Rs.95,000; debtors balances settled by contra against creditors balances during 1997 – Rs.3,000; bad debts written off during 1997 (including 50% of the debt due from the customer who had gone bankrupt), other 50% having been received in cash during 1997 – Rs.1,500; discount allowed during 1997 – Rs. 500. at the end of 1997, the provision for doubtful debts is still required to be 5% of debtors. <em>You are required to write up the Sundry debtors Account and the Provision for Doubtful debts Account for the year 1996 and 1997.</em></p>
<p>&nbsp;</p>
<ol>
<li>Provision for Discount of debtors</li>
</ol>
<p>A separate ‘Provision for Discount on Debtors Account’ is opened, which is very similar to provision for bad and doubtful debts Account. The only difference is that provision for discount is calculated on the debtor’s balance after deducting the Provision for Bad and Doubtful debts. Like provision for Bad and doubtful debts it is also shown in the Balance Sheet as a deduction from Sundry Debtors.</p>
<p>&nbsp;</p>
<p>Accounting entries in the first year</p>
<p>1)       <em>When discount is allowed to debtors </em></p>
<p>Discount allowed Account                          Dr.</p>
<div>
<p>           To sundry Debtors Account</p>
</div>
<p>2)       <em>For closing the discount allowed account against Profit &amp; Loss Account </em></p>
<p>Profit &amp; Loss Account                                            Dr.</p>
<div>
<p>           To Discount allowed Account</p>
</div>
<p>3)       <em>When provision is created for the first time</em></p>
<p>Profit &amp; Loss Account                                             Dr.</p>
<p>            To Provision for Discount on Debtors Account <sup>*</sup></p>
<p>&nbsp;</p>
<p><sup>*</sup>This figure will be calculated by applying a percentage on Sundry debtors after adjusting bad debts (after Trial Balance) and Provision for Bad and Doubtful debts (new).</p>
<p>&nbsp;</p>
<p>Accounting entries in the second and subsequent years</p>
<p>1)       <em>When discount is allowed</em></p>
<p>Discount allowed Account                          Dr.</p>
<div>
<p>           To Sundry debtors Account</p>
</div>
<p>2)       <em>At the end of the accounting year the discount is closed by passing the following entry:</em></p>
<p>Provision for Discount on Debtors Account          Dr.</p>
<div>
<p>            To discount allowed Account</p>
</div>
<p>3)       <em>The balance left in the Provision for Discount on Debtors account at the end of a period is adjusted with the provision required to be made for next financial year and accounting entry to be passed according to situation.</em></p>
<p>i)         If the required provision is more than the balance left:</p>
<p>Profit &amp; Loss Account                                     Dr.</p>
<p>    To Provision for Discount on Debtor’s account <sup>*</sup></p>
<p>&nbsp;</p>
<p>ii)       If the required provision is less than the balance left:</p>
<p>Provision for Discount on Debtors account Dr.</p>
<p>    To Profit &amp; Loss Account</p>
<p><sup>*</sup> This figure will be calculated as follows:</p>
<p>Closing provision required                                                      *****</p>
<p>Add: Discount allowed during the period                               <span style="text-decoration:underline;">*****</span></p>
<p>                                                                                                    *****</p>
<p>Less: Opening provision                                                          <span style="text-decoration:underline;">*****</span></p>
<p>Amount to be provided                                                 <span style="text-decoration:underline;">*****</span></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>The sundry debtors at 31.12.1997 were Rs.10,000. A provision for bad debts @4% was made and also a provision for discount on debtors @5% was required. The discount allowed during the year amounted to Rs.400. The business was commenced on 1.1.1997. Pass Journal entries and prepare Discount allowed Account, Provision for Bad debts account and Provision for discount on Debtors Account. Also, show how they appear in the Profit &amp; Loss Account and in the Balance Sheet.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Following are the balances taken from the Trial Balance of a trader as on 31.12.1997.</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="394">&nbsp;</td>
<td valign="top" width="114">Dr. (Rs.)</td>
<td valign="top" width="87">cr. (Rs.)</td>
</tr>
<tr>
<td valign="top" width="394">Sundry Debtors</td>
<td valign="top" width="114">1,00,000</td>
<td valign="top" width="87">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="394">Bad debts</td>
<td valign="top" width="114">7,000</td>
<td valign="top" width="87">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="394">Discount allowed</td>
<td valign="top" width="114">3,000</td>
<td valign="top" width="87">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="394">Provision for Bad debts</td>
<td valign="top" width="114">&nbsp;</td>
<td valign="top" width="87">12,000</td>
</tr>
<tr>
<td valign="top" width="394">Provision for discount on debtors</td>
<td valign="top" width="114">&nbsp;</td>
<td valign="top" width="87">6,000</td>
</tr>
</tbody>
</table>
<p>  You are required to prepare Bad debts Account, Discount allowed Account, provision for bad debts Account and provision for discount on Debtors Account. Also, show how they appear in the Profit &amp; Loss Account and in Balance Sheet, after considering the following:</p>
<p>Ò       Further bad debts and discount allowed are Rs.3,000 and Rs.2,000 respectively.</p>
<p>Ò       Provision for bad debts and provision for discount on debtors to be created @10% and 5% respectively.</p>
<p>&nbsp;</p>
<ol start="4">
<li>Reserve for discount on creditors</li>
</ol>
<p>If the firm is to allow cash discount to customers for early payments, it is quite possible that the firm may receive discount by making early payment which can be treated as income in the Profit &amp; Loss Account. Such discount will be received in the next year but should be taken into account in current year’s account because it related to creditors of current year. Generally accepted accounting principles (also the concept of conservatism), state that we should provide a loss only when we apprehend that, but should never take a profit unit it is actually made. <em>It is seldom found in actual practice that a reserve has been created for discount to be received by making prompt payment to creditors. (except in examiniation problems)</em></p>
<p><em> </em></p>
<p>Journal entries for Reserve for Discount on creditors in the first year</p>
<p>1)       <em>When discount is received from the creditors</em></p>
<p>Sundry Creditors Account                                       Dr.</p>
<div>
<p>           To Discount received Account </p>
</div>
<p>2)       <em>For closing the discount received to Profit &amp; Loss Account</em></p>
<p>Discount received Account                          Dr.</p>
<div>
<p>            To Profit &amp; Loss Account</p>
</div>
<p>3)       <em>When a reserve is created for the first time</em></p>
<p>Reserve for Discount on creditors account            Dr.</p>
<div>
<p>            To Profit &amp; Loss Account</p>
</div>
<p>     </p>
<p>Journal entries in the Second year and subsequent years</p>
<p>&nbsp;</p>
<p>1)       <em>When discount is received from the creditors</em></p>
<p>Sundry creditors account                                          Dr.</p>
<div>
<p>            To Discount received Account </p>
</div>
<p>2)       <em>At the end of the accounting year, the discount received account is closed by transferring it to the Reserve for Discount on Creditors account as under:</em></p>
<p>Discount Received Account                                     Dr.</p>
<div>
<p>            To Reserve for Discount on Creditors Account</p>
</div>
<p>3)       <em>For creating a reserve for the next year</em></p>
<p>Reserve for Discount on Creditors Account         Dr.</p>
<div>
<p>           To Profit &amp; Loss Account <sup>*</sup></p>
</div>
<p>&nbsp;</p>
<p><sup>*</sup> This is calculated as under:</p>
<p>&nbsp;</p>
<p>Closing reserve required                                                                        *****</p>
<p>Add: Discount received during the year                                                <span style="text-decoration:underline;">*****</span></p>
<p>                                                                                                                  *****</p>
<p>Less: Opening balance of Reserve                                                        <span style="text-decoration:underline;">*****</span></p>
<p>Amount to be credited to Profit &amp; Loss Account                                <span style="text-decoration:underline;">*****</span></p>
<p>&nbsp;</p>
<ol start="5">
<li>Recovery of Bad debts</li>
</ol>
<p>When the seller apprehends any loss due to bad debt, he immediately writes it off by debiting Bad debt Account and crediting the Sundry Debtors Account. In case of bad debts, the seller takes the initiative for closing the account of the customer and he does it immediately. After writing off any bad debt, if any amount is received from that customer in respect of that old debt, it is called recovery of bad debt. Occasionally, sundry debtors that have been charged off as bad debts are unexpectedly collected (generally in a subsequent accounting period). When any bad debt is recovered, the accounting entries are as follows:</p>
<p>&nbsp;</p>
<p>1)       <em>When the bad debts is recovered</em></p>
<p>Bank Account                                                                 Dr.</p>
<div>
<p>     To bad debt Recovery Account</p>
</div>
<p>2)       <em>For closing bad debt recovery</em></p>
<p>a)        If the seller is maintaining a Provision for Bad and Doubtful debts Account and adjusting the bad debt against such provision, the bad debt recovery should be closed by transferring it to the Provision for Bad debts Account.</p>
<p>&nbsp;</p>
<p>Bad Debt Recovery Account                                 Dr.</p>
<p>          To Provision for Bad and Doubtful Debts Account</p>
<p>&nbsp;</p>
<p>b)        In all other cases, it should be transferred to Profit &amp; Loss Account</p>
<p>Bad debt Recovery Account                                  Dr.</p>
<p>          To Profit &amp; Loss Account</p>
<p>&nbsp;</p>
<p>Treatment of Bad Debt Recovery in the Books of the Buyer</p>
<p>1)       If the account of the seller (in the buyer’s book) has not been closed</p>
<p>Seller account                                                          Dr.</p>
<div>
<p>           To Bank Account</p>
</div>
<p>2)       If the seller’s account has been closed</p>
<p>Goodwill Account <sup>*</sup>                                                 Dr.</p>
<div>
<p>           To Bank Account </p>
</div>
<p><sup>*</sup> The amount is paid for maintaining the goodwill of the business.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Coalman Ltd. Had : (a) Sundry Debtors worth Rs.68,000, Rs.48,000 and Rs. 92,000; and (b) Sundry Creditors worth Rs.38,000, Rs. 45,000 and Rs.55,000 as on 31<sup>st</sup> December, 1995, 1996 and 1997 respectively.</p>
<p>Show from the following data the provision for bad and doubtful debts Account, provision for discount on Debtors account and Reserve for Discount on creditors Account at 5%, 2% and 2% respectively, for the years 1995, 1996 and 1997.</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="168">During the year</td>
<td valign="top" width="168">Bad debts written off</td>
<td valign="top" width="168">Discount allowed</td>
<td valign="top" width="169">Discount received</td>
</tr>
<tr>
<td valign="top" width="168">1995</td>
<td valign="top" width="168">3,000</td>
<td valign="top" width="168">1,000</td>
<td valign="top" width="169">700</td>
</tr>
<tr>
<td valign="top" width="168">1996</td>
<td valign="top" width="168">1,800</td>
<td valign="top" width="168">500</td>
<td valign="top" width="169">980</td>
</tr>
<tr>
<td valign="top" width="168">1997</td>
<td valign="top" width="168">2,900</td>
<td valign="top" width="168">1,200</td>
<td valign="top" width="169">620</td>
</tr>
</tbody>
</table>
<p>All the provisions / reserves were created for the first time on 31.12.1995 and maintained accordingly in the following years.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>On January 1, 1997 the provision for Bad and Doubtful Debts Account of a concern showed a balance of Rs.60,000 and the Debtors amounted to Rs.15,00,000. Out of those, during 1997, Debtors amounting to Rs.10,75,000 paid in full, but the following debts proved bad or doubtful: A (Rs.20,000) – bad to the full extent; B (Rs.40,000) – insolvent, estate expected to pay 50 paise in the rupee; C (Rs.12,000) – realized 33.1/3% in full settlement.</p>
<p>The remaining debts were considered somewhat doubtful on December 31. The following further debts became due during 1997 but outstanding on December 31:</p>
<p>D (Rs. 20,000) – expected to prove totally bad; E (Rs.80,000) – expected to prove 5% bad; F (Rs.6,40,000) – expected to prove 4% bad; G (Rs. 4,00,000) – expected to prove bad to some extent; H (Rs. 12,60,000) – expected to prove wholly good.</p>
<p>It was decided to write off actual debts and to make reserve of 5%  on debts of unknown doubtful nature. Draw up the Provision for Bad and Doubtful debts Account and show the balance of the Account as at December 31, 1997.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>A trader maintained provision for Doubtful Debts @5%; a Provision for discount @2% on Debtors; and Reserve for Discount @2% on creditors, which on 1<sup>st</sup> January, 1996 stood at Rs.1,500, Rs.500 and Rs.400 respectively. His balances on 31.12.1996 and on 31.12.97 were : (all figures in Rupees)</p>
<p>                                                                                                      31.12.96                     31.12.97</p>
<p>Bad debts written off                                                                     1,800                             300</p>
<p>Discount allowed                                                                              600                             200</p>
<p>Sundry debtors                                                                             20,000                           6,000</p>
<p>Discount received                                                                            300                                50</p>
<p>Sundry creditors                                                                          15,000                        10,000</p>
<p><em>Show necessary accounts in the ledger.</em></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>Depreciation</h3>
<p align="center"> </p>
<p align="center">Index</p>
<p align="center"> </p>
<ol>
<li>Introduction</li>
<li>Factors in the measurement of Depreciation</li>
<li> </li>
<li> </li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ol>
<li>introduction</li>
</ol>
<p>Depreciation is an attempt to spread the cost of a long – lived asset, as an expense to the Profit &amp; Loss Account, over its useful economic life.</p>
<p>Indian Accounting Standard – 6 states that</p>
<p>‘Depreciation is a measure of the wearing out, consumption or other loss of value of a depreciable asset arising from use, effluxion of time or obsolescence through technology and market changes. Depreciation is allocated so as to charge a fair proportion of the depreciable amount in each accounting period during the expected useful life of the asset. Depreciation includes the amortization of assets whose useful life is pre-determined.</p>
<p>&nbsp;</p>
<ol>
<li>Factors in the measurement of Depreciation</li>
</ol>
<p>1)       Cost of asset</p>
<p>The cost an asset is the basis for all subsequent accounting for that asset. Generally the cost of an asset means its acquisition cost, which is the sum of all costs incurred in acquiring the asset, and all other incidental costs involved in bringing the asset into working condition.</p>
<p>&nbsp;</p>
<p>2)       Residual or Scrap value of asset</p>
<p>This is the estimated value of a fixed asset at the end of its economic life. It is the amount which is expected to be received when the asset is sold after being removed from service. It is often assumed to be zero (except for academic examinations) as the scrap value of an asset is very difficult to estimate at the time of acquisition, for it is a matter of many imponderables and uncertainties.</p>
<p>&nbsp;</p>
<p>3)       Useful life to asset</p>
<p>The basic objective of estimating the useful life f an asset is to allocate the net cost of the asset of its useful life by means of Depreciation. The useful life of an asset is its service life which can be defined as the number of accounting periods during which it will be useful to the business.</p>
<p>&nbsp;</p>
<p>Important Terms / Expressions regarding Depreciation</p>
<p>The important Accounting terms / expressions regarding Depreciation:</p>
<p>a)        The entire process of allocating the cost of a fixed asset over its useful life is called Depreciation.</p>
<p>b)        The allocated cost for one accounting period, which is matched against revenue, is referred to as Depreciation expenses.</p>
<p>c)        The total allocated cost already charged as expense in different accounting period is called is accumulated Depreciation.</p>
<p>d)        The portion of the cost yet to be allocated is known as the written down value (W.D.V.) or net book value (N.B.V.)</p>
<p>&nbsp;</p>
<p>Illustration: 1</p>
<p>ITC Ltd. Purchased a new motor car for its sales manager and the invoice contained the following information :</p>
<p>Open Astra                                                                                                           Rs. 7,20,000</p>
<p>Road licence Rs.1,000; Petrol Rs.100; Delivery Rs.500;</p>
<p>Number plates Rs.300; Alarm system Rs.2,200                                              Rs. <span style="text-decoration:underline;">     4,100</span></p>
<p>                                                                                                                              Rs. 7,24,100</p>
<p>Advance booking                                                                                                 Rs. <span style="text-decoration:underline;">   24,000</span></p>
<p>Amount due                                                                                                          Rs. <span style="text-decoration:underline;">7,00,100</span></p>
<p>&nbsp;</p>
<p>It is estimated that the new car will have a useful life of 10 years and will have a residual value of Rs.1,00,000. Calculate the total cost and the total amount to be depreciated.</p>
<p>&nbsp;</p>
<p>Illustration: 2</p>
<p>In the year 1996, X Ltd, bought a new fixed asset and made the following payments in relation to it.</p>
<p>Cost as per supplier’s list                                               Rs.1,20,000</p>
<p>Less: Agreed discount                                                    Rs.<span style="text-decoration:underline;">   10,000 </span>                          Rs.1,10,000</p>
<p>&nbsp;</p>
<p>Delivery charges Rs.1,000; Erection charges Rs.2,000; Maintenance charges Rs. 3,000; Additional component to increase capacity Rs.4,000; Replacement parts Rs.2,500.</p>
<p>&nbsp;</p>
<p>State and justify the cost figure which should be used as the basis for Depreciation.</p>
<p>&nbsp;</p>
<p>Illustration: 3</p>
<p>On 1.1.1992, X Ltd. Purchased a plant at a cost of Rs.1,80,000. Additionally, installation costs totaled Rs.20,000. During 1994, major repairs costing Rs.31,500 had been carried out on this plant and in order to increase the capacity of the plant, a new motor had been fitted in December 1994 at a cost of Rs.22,000. A further overhauling cost of Rs.13,500 had been carried out during 1995. <em>You are required to calculate the total amount to be considered for calculating Depreciation throughout its economic life.</em></p>
<p>&nbsp;</p>
<ol>
<li>Methods of Depreciation</li>
</ol>
<p>There are several methods of Depreciation, i.e., for computing the expense to be allocated to each period. In deciding on the best Depreciation method, the choice would depend upon the pattern of expected benefits obtainable in each period from its use.</p>
<p>&nbsp;</p>
<p>1)       Straight Line / Equal Instalment Method</p>
<p>This is the most popular method because of its simplicity and consistency. It requires allocation of an equal amount to each period. A fixed amount of the original cost is charged as Depreciation every year. Thus, the asset is written down in value each year by the same amount.</p>
<p>                                               Cost of the asset – Residual Value</p>
<p>Annual Depreciation =</p>
<p>                                               Estimated Economic Life</p>
<p>&nbsp;</p>
<p>Methods of recording Depreciation</p>
<p>i)         When no provision for Depreciation Account is maintained</p>
<p>Under this method, Depreciation is directly charged to an asset Account by debiting Depreciation Account and crediting the Asset Account. At the end of the accounting period, Depreciation Account is closed by transferring it to the Profit &amp; Loss Account. In the Balance Sheet, the asset appears at its written down value (cost less Depreciation provided to date). Here, actual cost of an asset and the total amount of Depreciation that has been provided (to – date) cannot be ascertained form the Balance Sheet.</p>
<p>&nbsp;</p>
<p>Journal entries:</p>
<p>a)        Depreciation Account                          Dr.</p>
<p>To Asset Account</p>
<p>&nbsp;</p>
<p>b)        Profit &amp; Loss Account                         Dr.</p>
<p>To Depreciation Account</p>
<p>&nbsp;</p>
<p>ii)       When provision for Depreciation Account is maintained</p>
<p>Under this method, (in contrast to the above), Depreciation is not directly charged to the Asset Account.</p>
<p>The Depreciation for the period is debited to Depreciation Account and credited to ‘Accumulated Depreciation Account’ or ‘Provision for Depreciation Account’. As in the previous method, Depreciation Account is closed by transferring it to the Profit &amp; Loss Account. In the Balance Sheet, asset appears at its original cost and the accumulated Depreciation is shown as a deduction from the Asset Account. Here, from the Balance Sheet, the original cost of the asset and the total Depreciation to-date that has been charged on that asset can be easily ascertained. As the year passes, the balance of the accumulated Depreciation goes on increasing since constant credit is given to this account in each accounting year. After the expiry of the useful life, these two accounts are closed by debiting Accumulated Depreciation Account and crediting Asset Account – any balance in Asset account is transferred to the Profit &amp; Loss Account.</p>
<p>&nbsp;</p>
<p>Journal entries:</p>
<p>a)        Depreciation Account                                                              Dr.</p>
<p>To Accumulated Depreciation Account</p>
<p>&nbsp;</p>
<p>b)        Profit &amp; Loss Account                                                             Dr.</p>
<p>To Depreciation account</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>B. Brown purchased a machine by cheque for Rs.90,000 on 1<sup>st</sup> January, 1995. Its probable working life was estimated at 10 years and its probable value at the end of that time at Rs.10,000. It was decided to write off  Depreciation by equal annual instalments. You are required to pass necessary Journal entries for first two years and show necessary accounts and the Balance Sheet.</p>
<p>a)        When no provision for Depreciation Account is maintained</p>
<p>b)        When provision for Depreciation account is maintained</p>
<p>&nbsp;</p>
<p>It was decided to close books each year on December 31<sup>st</sup>.</p>
<p>&nbsp;</p>
<p>2)       Diminishing balance method</p>
<p>Where the straight line method assumes that the net cost of an asset should be allocated to successive periods in uniform amounts, the diminishing balance method assumes that the rate of allocation should be constant through</p>
<p>time.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Thompson Bros. Purchased machinery by cheque for Rs.1,00,000 on 1<sup>st</sup> January 1995. The estimated scrap value of the machinery is Rs.20,000. At the end of each year, Depreciation is provided at the rate of 10% per annum by the diminishing balance method. Show Machinery Account and Balance Sheet for the first two financial years which is ending on December, 31<sup>st</sup> every year.</p>
<p>(a)   when no provision for Depreciation account is maintained</p>
<p>(b)  When provision for Depreciation account is maintained.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Distinction between straight line method and diminishing balance method</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="40">No.</td>
<td valign="top" width="262">Straight line method</td>
<td valign="top" width="47">No.</td>
<td valign="top" width="269">Diminishing Balance Method</td>
</tr>
<tr>
<td valign="top" width="40">1.</td>
<td valign="top" width="262">Affixed amount of Depreciation is charged.</td>
<td valign="top" width="47">1.</td>
<td valign="top" width="269">A fixed rate of Depreciation is charged.</td>
</tr>
<tr>
<td valign="top" width="40">2.</td>
<td valign="top" width="262">The rate of Depreciation is the reciprocal of the life of the asset.</td>
<td valign="top" width="47">2.</td>
<td valign="top" width="269">The rate overdraft Depreciation is ascertained by applying a formula.</td>
</tr>
<tr>
<td valign="top" width="40">3.</td>
<td valign="top" width="262">The asset may or may not have scrap value.</td>
<td valign="top" width="47">3.</td>
<td valign="top" width="269">The asset must have a significant scrap value.</td>
</tr>
<tr>
<td valign="top" width="40">4.</td>
<td valign="top" width="262">The amount of Depreciation per year is the same.</td>
<td valign="top" width="47">4.</td>
<td valign="top" width="269">The amount overdraft Depreciation goes on reducing.</td>
</tr>
<tr>
<td valign="top" width="40">5.</td>
<td valign="top" width="262">In the first year, the Depreciation is charged on the cost of the asset, less scrap value, if any.</td>
<td valign="top" width="47">5.</td>
<td valign="top" width="269">In the first year, the Depreciation is charged on the cost of the asset.</td>
</tr>
<tr>
<td valign="top" width="40">6.</td>
<td valign="top" width="262">At the end of its life, the book value of the asset becomes zero.</td>
<td valign="top" width="47">6.</td>
<td valign="top" width="269">The book value of the asset never reduces to zero.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Profit and Loss on Disposal of Fixed Assets</p>
<p>If the asset is sold at a price which is more than its written down value, it produces a profit. On the contrary, when the asset is sold at a price which is les its written down value, it is a case of loss on sale of an asset.</p>
<p>&nbsp;</p>
<p>The Journal entries for disposal or sale of asset will depend upon the method of recording Depreciation.</p>
<p>1)       When no provision for Depreciation  account is maintained.</p>
<p>When  the asset appears the Balance Sheet at its written down value, on disposal, the written down value of such assets (at the beginning of the year of disposal) is transferred to “Asset Disposal Account’ and profit and loss on sale of assets ar ascertained with the help of that Account. The detailed entries are given below:</p>
<p><em>a)        </em><em>For transferring to Asset disposal Account</em></p>
<p>Assets Disposal Account                                 Dr. (W.D.V. of the asset at the</p>
<div>
<p>    To asset account                                                beginning of the year of disposal)<em> </em></p>
</div>
<p><em>b)        </em><em>For charging Depreciation of current year on disposed asset</em></p>
<p>Depreciation Account                                      Dr.</p>
<div>
<p>                To assets disposal account<em></em></p>
</div>
<p><em>c)         </em><em>For sale proceeds</em></p>
<p>Bank Account                                                    Dr.</p>
<div>
<p>    To Assets Disposal account <em></em></p>
</div>
<p><em>d)        </em><em>If the credit side of the  asset disposal Account is greater than the debit side, there is profit on disposal and it is transferred to Profit &amp; Loss Account </em></p>
<p>Assets Disposal Account                                 Dr.</p>
<div>
<p>    To Profit &amp; Loss Account <em></em></p>
</div>
<p><em>e)        </em><em>If the debit side of the asset disposal Account is greater than the credit side, there is loss on disposal and it is transferred to Profit &amp; Loss Account.</em></p>
<p>Profit &amp; Loss Account                                     Dr.</p>
<div>
<p>    To Asset Disposal Account <em></em></p>
</div>
<p>&nbsp;</p>
<p>Alternatively, all adjustments regarding disposal of asset can be done in the asset Account itself without opening assets disposal account separately. In such a situation, the entries will be as follows:</p>
<p>a)        <em>For current year’s Depreciation on disposed asset</em></p>
<p>Depreciation Account                                              Dr.</p>
<div>
<p>            To Asset Account</p>
</div>
<p>b)        <em>For sale proceeds</em></p>
<p>Bank Account                                                           Dr.</p>
<div>
<p>           To Asset Account</p>
</div>
<p>c)        <em>For profit on sale</em></p>
<p>Asset Account                                                          Dr.</p>
<div>
<p>           To Profit &amp; Loss Account</p>
</div>
<p>d)        <em>For loss on sale</em></p>
<p>Profit &amp; Loss Account                                            Dr.</p>
<div>
<p>           To Asset Account</p>
</div>
<p>&nbsp;</p>
<p>For calculating profit or loss on sale, the following points should be remembered:</p>
<p>i)         If the sale proceeds is greater than the written down value on the date of disposal, the surplus represents profit.</p>
<p>ii)       If the sale proceeds is less than the written down value on the date of disposal, the deficit represents loss.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Mr. Vaid of Calcutta purchased the required machine on 1.4.1994 for Rs.65,000. He engaged Kabul to erect the units, who charged Rs.5,000 and agreed to wait a month for his payment.</p>
<p>The machinery was depreciated at 10% p.a. on the Fixed instalment method – and accounting year being April – March.</p>
<p>On 1.10.1996, a single unit which cost Rs.10,000 originally was sold for a cash price of Rs.7,000. On the same date, a new machine costing Rs.10,000 (paid for by cheque) was installed.</p>
<p>Write out the Machinery Account for the years 1994-95, 1995-96, 1996-97 and Machinery Disposal Account.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Bajaj and Co. close their accounts on 31<sup>st</sup> March, every year. They purchased the machineries as follows:</p>
<p>a)        Purchased the machineries costing Rs.1,20,000 on 1.7.1993.</p>
<p>b)        On 1.1.1994, some machineries were purchased costing Rs.1,20,000</p>
<p>c)        On 1.10.1994, again purchased some machinery costing Rs.20,000.</p>
<p>d)        On 1.1.1995 purchased a new machinery for Rs.60,000</p>
<p>e)        One machinery costing Rs.40,000 which was purchased on 1.7.1993, was sold for Rs.12,000 on 1.4.1995.</p>
<p>f)         They charged Depreciation @33.33% on the written down value method.</p>
<p>g)        They have the practice to charge Depreciation for the full year even if the machinery is used for a part of the year.</p>
<p><em>Prepare Machinery Account in the books of Bajaj &amp; Co. for the three years – 1993-94, 1994-95, 1995-96.</em></p>
<p><em> </em></p>
<p>Illustration:</p>
<p>Kalyani industries depreciates its machinery at 10% p.a. on straight line basis. On 1<sup>st</sup> April, 1996 the balance in Machinery Account was Rs.8,50,000 (original cost Rs.12,00,000). On 1<sup>st</sup> July, 1996 a new machine was purchased for Rs.25,000. on 31<sup>st</sup> December, 1996 and ole machine having written down value of Rs.40,000 on 1.4.1996 (original cost Rs.60,000) was sold for Rs.30,000. show the Machinery Account for the year ended on 31<sup>st</sup> March, 1997.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>On 1<sup>st</sup> January, 1993, machinery was purchased by X for Rs.50,000. On 1<sup>st</sup> July, 1994, additions were made to extent of Rs.10,00. On 1<sup>st</sup> April, 1995, further additions were made to the extent of Rs.6,400. On 30<sup>th</sup> June, 1996, machinery, original value of which was Rs.8,000 on 1<sup>st</sup> January, 1993, was sold for Rs.6,000. Depreciation is charged @10% p.a. on original cost.</p>
<p><em>Show Machinery Account for the years from 1993 to 1996 in the books of X. X closes his books on 31<sup>st</sup> December.</em></p>
<p>&nbsp;</p>
<p>2)       When provision for Depreciation Account is maintained.</p>
<p>&nbsp;</p>
<p>If the asset account is maintained at cost price, on disposal, the original cost of such asset is transferred to Asset Disposal Account and Accumulated Depreciation on such asset is also transferred to this Account. The entries are as follows:</p>
<p>a)        <em>For transferring to Assets disposal Account</em></p>
<p>Asset Disposal Account                                          Dr.       (Original cost)</p>
<div>
<p>           To asset Account</p>
</div>
<p>b)        <em>For transferring accumulated Depreciation on disposed asset</em></p>
<p>Accumulated Depreciation account                       Dr.</p>
<div>
<p>           To Assets Disposal Account</p>
</div>
<p>c)        <em>For charging current year’s Depreciation on disposed asset</em></p>
<p>Depreciation Account                                             Dr.</p>
<div>
<p>           To assets disposal Account</p>
</div>
<p>d)        <em>For sale proceeds</em></p>
<p>Bank Account                                                           Dr.</p>
<div>
<p>           To Asset Disposal Account</p>
</div>
<p>e)        <em>For profit</em></p>
<p>Assets Disposal account                                         Dr.</p>
<div>
<p>           To Profit &amp; Loss Account</p>
</div>
<p>f)         <em>For loss</em></p>
<p>Profit &amp; Loss Account                                            Dr.</p>
<div>
<p>           To Assets Disposal Account</p>
</div>
<p>Illustration:</p>
<p>Goutham &amp; Co., whose books are closed on 31.12.1994, purchased a machine for Rs.1,50,000on 1<sup>st</sup> January, 1994. Additional machinery was acquired for Rs.50,000 on 1<sup>st</sup> July 1994. Certain machinery, which was purchased for Rs.50,000 on 1<sup>st</sup> July, 1994 was sold for Rs.30,000 on 30<sup>th</sup> June 1996. prepare machinery Account and Accumulated Depreciation Account for all the years up to  the year ending 31<sup>st</sup> December, 1996 into account Depreciation @10% p.a. on straight line method. And also show Machinery disposal Account.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>You have been given the task, by one of the partners of the firm of Chartered Accountants for which you work, of assisting in the preparation of a trend statement for a client.</p>
<p>The client’s business has been in existence for four years. Figures for the three previous years are known but those for the fourth year need to be calculated. Unfortunately, the supporting workings for the previous years’ figures cannot be found and the client’s own ledger accounts and working are not available.</p>
<p>One item in particular, Plant is causing difficulty and the following figures have been given to you. </p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td rowspan="2" valign="top" width="132">Particulars</td>
<td colspan="4" valign="top" width="517">12 months ended on 31<sup>st</sup> March</td>
</tr>
<tr>
<td valign="top" width="131">1993</td>
<td valign="top" width="129">1994</td>
<td valign="top" width="129">1995</td>
<td valign="top" width="129">1996</td>
</tr>
<tr>
<td valign="top" width="132">a) Plant at cost (Rs.)</td>
<td valign="top" width="131">4,00,000</td>
<td valign="top" width="129">4,00,000</td>
<td valign="top" width="129">4,50,000</td>
<td valign="top" width="129">?</td>
</tr>
<tr>
<td valign="top" width="132">b) Accumulated Depreciation (Rs.)</td>
<td valign="top" width="131">(80,000)</td>
<td valign="top" width="129">(1,44,000)</td>
<td valign="top" width="129">(1,83,600)</td>
<td valign="top" width="129">?</td>
</tr>
<tr>
<td valign="top" width="132">c) Net (written down Value) (Rs.)</td>
<td valign="top" width="131">3,20,000</td>
<td valign="top" width="129">2,56,000</td>
<td valign="top" width="129">2,66,400</td>
<td valign="top" width="129">?</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>The only other information available is that disposal have been taken place at the beginning of the financial years concerned.</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="131">Particulars</td>
<td valign="top" width="129">Date of Disposal</td>
<td valign="top" width="131">Date of Original Acquisition</td>
<td valign="top" width="129">Original cost</td>
<td valign="top" width="130">Sales Proceeds</td>
</tr>
<tr>
<td valign="top" width="131">&nbsp;</td>
<td colspan="2" valign="top" width="261">12 months ended on 31<sup>st</sup> March</td>
<td valign="top" width="129">Rs.</td>
<td valign="top" width="130">Rs.</td>
</tr>
<tr>
<td valign="top" width="131">First disposal</td>
<td valign="top" width="129">1995</td>
<td valign="top" width="131">1993</td>
<td valign="top" width="129">75,000</td>
<td valign="top" width="130">40,000</td>
</tr>
<tr>
<td valign="top" width="131">Second disposal</td>
<td valign="top" width="129">1996</td>
<td valign="top" width="131">1993</td>
<td valign="top" width="129">1,50,000</td>
<td valign="top" width="130">1,05,000</td>
</tr>
</tbody>
</table>
<p>Plant sold was replaced on the same day by new plant. The cost of the plant which replaced the first disposal is not known but the replacement for the second disposal is known to have cost of Rs.2,50,000.</p>
<p>Required:</p>
<p>a)        Identify the methods of providing for Depreciation on plant employed by the client, stating how you have arrived at your conclusion.</p>
<p>b)        Reconstruct a working schedule to support the figures shown at line (B) for each of the years ended 31<sup>st</sup> March; 1993, 1994 and 1995. Extend your workings to cover for they year ended 31<sup>st</sup> March, 1996.</p>
<p>c)        Produce the figures that should be included in the blank spaces on the trend statement at lines. (A), (B) and (C) for the year ended 31<sup>st</sup> March, 1996.</p>
<p>d)        Calculate profit or loss arising on each of two disposals.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>A factory possessing different plant and machinery, Depreciation on which is provided under ‘straight line’ method at the rate of 10% p.a. A full year’s Depreciation is provided at the end of each year on all plant not already completely written off or sold, including any plant purchased during the year. Any profit or loss which may result form sales is transferred to Profit &amp; Loss Account at the end of the year. Accounts are prepared annually to 31<sup>st</sup> December.</p>
<p>The balance standing on the Plant and Machinery Account at 31<sup>st</sup> December, 1994 after writing off Depreciation for that year was Rs.19,515 and subsidiary records showed that the cost of plant then on hand was made – up as follows:</p>
<p>&nbsp;</p>
<p>Items bought: in 1984 (or earlier) Rs.5,800; in 1985 Rs.3,100; in 1986 Rs.1,700; and in 1987 (or later) Rs.25,200.</p>
<p>&nbsp;</p>
<p>During 1995 a new plant was bought at a cost of Rs.2,950 and one machine which had cost Rs.550 in 1983 was sold as scrap for Rs.35. During 1996 there were additions, costing Rs.1,800 and  a machine which had cost Rs.700 in 1992 was sold for Rs.350.</p>
<p><em>You are required to write – up Plant and Machinery Account and Plant Disposal Account for 1995 and 1996.</em></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>The machinery register of ABC Ltd. On 1.1.1996 contained the following items:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="112">Machines</td>
<td valign="top" width="112">A</td>
<td valign="top" width="112">B</td>
<td valign="top" width="112">C</td>
<td valign="top" width="112">D</td>
<td valign="top" width="112">E</td>
</tr>
<tr>
<td valign="top" width="112">Cost (Rs.)</td>
<td valign="top" width="112">10,000</td>
<td valign="top" width="112">12,000</td>
<td valign="top" width="112">15,000</td>
<td valign="top" width="112">16,000</td>
<td valign="top" width="112">20,000</td>
</tr>
<tr>
<td valign="top" width="112">Year of purchase</td>
<td valign="top" width="112">1985</td>
<td valign="top" width="112">1989</td>
<td valign="top" width="112">1991</td>
<td valign="top" width="112">1994</td>
<td valign="top" width="112">1995</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Depreciation policies are as follows:</p>
<p>Machines A, and B on straight line basis assuming zero scrap value, over 10 years. Machine C on reducing balance basis at 20% p.a. assuming scrap value of Rs.1,000. Machines D and E on straight line basis assuming scrap value equal to 10% of the original cost, over 5 years. All machines receive a full year’s Depreciation in the year of purchase.</p>
<p>Relevant transactions during the year  to 31.12.1996 are as follows:</p>
<p>a)        Machine B is taken on part exchange by the supplier of machines F. the invoice for machine F reads as follows:</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="325">&nbsp;</td>
<td valign="top" width="76">
<p align="center">Rs.</p>
</td>
<td valign="top" width="68">
<p align="center">Rs.</p>
</td>
</tr>
<tr>
<td valign="top" width="325">New machines – list price</p>
<p>Less: Trade discount</td>
<td valign="top" width="76">
<p align="right">25,000</p>
<p align="right">  1,000</p>
</td>
<td valign="top" width="68">
<p align="right"> </p>
<p align="right">24,000</p>
</td>
</tr>
<tr>
<td valign="top" width="325">Allowance on your old machine</td>
<td valign="top" width="76">
<p align="right"> </p>
</td>
<td valign="top" width="68">
<p align="right">2,000</p>
</td>
</tr>
<tr>
<td valign="top" width="325">&nbsp;</td>
<td valign="top" width="76">
<p align="right"> </p>
</td>
<td valign="top" width="68">
<p align="right">22,000</p>
</td>
</tr>
<tr>
<td valign="top" width="325">Add: Delivery of new machine</p>
<p>Collection of old machine</td>
<td valign="top" width="76">
<p align="right">1,500</p>
<p align="right">1,000</p>
</td>
<td valign="top" width="68">
<p align="right"> </p>
<p align="right">2,500</p>
</td>
</tr>
<tr>
<td valign="top" width="325">Total due</td>
<td valign="top" width="76">
<p align="right"> </p>
</td>
<td valign="top" width="68">
<p align="right">24,500</p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>b)        The motor in machine E is discovered to be inadequate. By agreement, it is replaced by a more powerful motor. The new motor costs Rs.6,000 as compared to Rs.4,000 for the original motor. The old adequate motor is taken back by the supplier and full credit of the original Rs.4,000 is given against the Rs.6,000 cost of new motor. This change is not expected to increase the life of the machine and it is agreed to treat this as a correction of the original cost.</p>
<p>The Depreciation policy for the new machine F is the same for the Machines D and E.</p>
<p><em>You are required to prepare a table showing for each machine : Cost, Depreciation to date and net Balance Sheet figure, and the Profit &amp; Loss Account entries for the year 1996.</em></p>
<p>&nbsp;</p>
<p>Exchange of used asset with new asset</p>
<p>When a new fixed asset is acquired in exchange for another old one (already used and depreciated) of the same kind or other, the business is to pay only the difference, i.e., the difference between the cost of the new asset and the value of the old asset granted by the seller. The value of old asset is known as ‘trade-in-allowance’ which becomes a part of the cost of the new asset. It is quite possible that the written down value and the trade-in-allowance of the asset may differ. If the trade in  allowance is <em>less</em> than the written down value, it is a loss. On the contrary, if it is <em>more </em>than the written down value, it is a gain to the business.</p>
<p>&nbsp;</p>
<p>Journal entries:</p>
<p>a)        <em>Ascertain the written down value of the old asset and pass the following entry:</em></p>
<p>Asset disposal account                                 Dr.       [written down value]</p>
<div>
<p>            To Asset account</p>
</div>
<p>b)        <em>Ascertain the value of new asset (which is the sum total of trade – in – allowance and cash payment to the seller) and pass the following entry:</em></p>
<p>Asset account                                                Dr.</p>
<div>
<p>            To Vendor Account</p>
</div>
<p>c)        <em>For settlement of account with the vendor pass the following entry:</em></p>
<p>Vendor account                                             Dr.</p>
<p>            To Bank Account                                           [cash payment]</p>
<div>
<p>            To Assets Disposal account                         [Trade-in-allowance]</p>
</div>
<p>d)        <em>Ascertain the amount of current year’s Depreciation on old asset and pass the following entry:</em></p>
<p>Depreciation Account                                   Dr.</p>
<div>
<p>            To Assets disposal account</p>
</div>
<div>
<p>e)        Charge Depreciation on new asset in the usual manner.</p>
<p>f)         Balance of assets disposal Account should be transferred to Profit &amp; Loss Account to close that account.</p>
</div>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>On 1.1.1993, X Purchased a roasting machine for Rs.60,000 and grinding machine for Rs.40,000. On 1.1.1994, he purchased one oil expeller for Rs.1,00,000. On 1.1.1995, the roasting machine got out of order and a new roaster was purchased costing Rs.1,20,000, after surrendering the old one and paying cash of Rs.90,000. On 1.1.1996, the oil expeller purchased on 1.1.1994 was destroyed by fire and the insurance company paid Rs.60,000 only. Show machinery Account for 1993, 1994, 1995 and 1996, charging Depreciation @10% p.a. on the W.D.V. method. Also show Machinery disposal Account and Accidental Loss Account.</p>
<p>&nbsp;</p>
<ol>
<li>Change of Method of Depreciation</li>
</ol>
<p>The change in the method of Depreciation may be effected <em>(i) without retrospective effect; and (ii) with retrospective effect</em></p>
<p><em> </em></p>
<p>i)         Without retrospective effect: Under this method Depreciation already record in prior years would not be adjusted. The balance of W.D.V. is written off over the remaining useful life by adopting the new method commencing from the year in which change is effected.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>A businessman bought for motor vehicles costing Rs.1,20,000 each on 1<sup>st</sup> May, 1993. He expected to fetch a scrap value of 25% of the cost price of the vehicles after ten years. He Depreciated the vehicles under the fixed instalment method upto 31<sup>st</sup> December, 1995.</p>
<p>With effect form 1<sup>st</sup> January, 1996, he decided to introduce the diminishing balance method of Depreciation @20%  p.a. instead of the fixed instalment method after he had sold one of the vehicles at Rs.70,000 on 31<sup>st</sup> December, 1995.</p>
<p><em>Prepare Motor Vehicles Account for the years 1993, 1994, 1995 and 1996; the accounting year being January to December, without giving any retrospective effect.</em></p>
<p>&nbsp;</p>
<p>illustration:</p>
<p>a second – hand machine was purchased on 1.1.1991 for Rs.4,00,000. Overhauling and installation expenses for the same machine amounted to Rs.1,00,000. Another machine was purchased for Rs.2,00,000 on 1.7.1991.</p>
<p>&nbsp;</p>
<p>on 1.7.1993, the machine installed on 1.1.1991 was sold for Rs.2,50,000. Dismantling charges for the machine sold on 1.7.1993 were Rs.10,000. On the same date, another machine was purchased for Rs.8,00,000 and was commissioned on 30.9.1993. The company has adopted the calendar year as its financial year. Under the existing practice, the company provides Depreciation at 10% p.a. on the original cost. In 1994, it has been decided that Depreciation will be charged on the diminishing balance method @15% p.a. The change is not be made with retrospective effect.</p>
<p><em>Show Plant account from 1991 to 1995. also show Plant Disposal account. </em></p>
<p>&nbsp;</p>
<p>ii)       With retrospective effect:</p>
<p> In this case Depreciation already recorded in prior years will be adjusted. The W.D.V. on the date of change is to be adjusted for under – Depreciation or over – Depreciation. The following steps should be taken for such adjustment:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="78">Step 1</td>
<td valign="top" width="537">Calculate total Depreciation from the date of retrospective effect to the date of change by adopting the <em>new method</em> of Depreciation.</td>
</tr>
<tr>
<td valign="top" width="78">Step 2</td>
<td valign="top" width="537">Ascertain total Depreciation under the existing method upto the date of change.</td>
</tr>
<tr>
<td valign="top" width="78">Step 3</td>
<td valign="top" width="537">Pass the following entry:</p>
<p>a)        <em>If total Depreciation of step 1 is greater than that of step 2</em></p>
<p>Profit &amp; Loss Adjustment Account Dr.</p>
<p>       To Asset Account</p>
<p>b)        <em>If the total Depreciation of step 1 is less than that of step 2</em></p>
<p>Asset Account                Dr.</p>
<p>          To Profit &amp; Loss Adjustment Account</td>
</tr>
<tr>
<td valign="top" width="78">Step 4</td>
<td valign="top" width="537">Charge Depreciation from the date of change by adopting the new method.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>A company purchased machinery for Rs.20,000 on 1<sup>st</sup> January, 1993 and followed the diminishing balance method of depreciating the value @15%. At the end of 1994, it was decided to follow the fixed installment system of depreciating the machine at Rs.3,000 per year from the very beginning and necessary amount of unabsorbed Depreciation of 1993 to 1995 to be adjusted in 1996. <em>show the Machinery Account for the period 1993 to 1996.</em></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Messers Mill and Wright commences business on 1<sup>st</sup> January, 1992, when they purchased plant and equipment for Rs.7,00,000. They adopted a policy: (i) Charging Depreciation at 15% per annum on diminishing balance basis: and (ii) charging full years Depreciation on additions. Over the years, their purchases of plant have been</p>
<p>1.8.1993                                                                                                                                                                             Rs. 1,50,000</p>
<p>30.9.1996                                                                                                                                                                         Rs. 2,00,000</p>
<p>&nbsp;</p>
<p>On 1.1.1996 it was decided to change the method and rate of Depreciation to 10% on straight line basis with retrospective effect from 1.1.1992, the adjustment being made in the accounts for the year ending 31<sup>st</sup> December, 1996. Calculate the difference in Depreciation to be adjusted in the Plant and equipment. Account on 1.1.1996 and show the ledger Account for the year 1996.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Better and Best Enterprises depreciates its machinery @10% p.a. on reducing balance. On 1.1.1996, the balance in Machinery Account was Rs.97,200.</p>
<p>During the year 1996, a machine purchased on 1.1.1994 for Rs. 8,000 was sold for Rs.4,500 on 1.7.1996. A new machine was bought on the same date for Rs.15,800.</p>
<p>On 1<sup>st</sup> January, 1996, the concern changed the method of Depreciation from reducing balance method to straight line method with retrospective effect from 1994 with no change in the rate.</p>
<p><em>Show the Machinery Account for the year ending 31<sup>st</sup> December, 1996, and also the Machinery Disposal Account. Working should form part of your answer.</em></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>On 1.1.1994, a new plant was purchased by Mrs. Kalyani Basu for Rs.1,00,000 and a further sum of Rs.5,000 was spent on its installation. On 1.6.1995, another plant was acquired for Rs.65,000.</p>
<p>On 2.10.1996, the first plant was totally destroyed and the amount of Rs.2,500 only was realized by selling the scrap. It was not insured.</p>
<p>On 20.10.1996, a second hand plant was purchased for Rs.75,000 and a further sum of Rs.7,500 was spent on repairs and Rs.2,500 on its erection it came into use on 15.11.1996. Depreciation has been provided at 10% on the original cost annually on 31<sup>st</sup> December. It was the practice to provide Depreciation for full year on all acquisitions made at any time during  any year and to ignore Depreciation on any item sold during the year. The accounts are closed annually on 31<sup>st</sup> December. In December 1996, it was decided to change the method of Depreciation and to follow the rate of 15% on diminishing balance method with retrospective effect in respect of  the existing  items of plant and to make necessary adjustments on 31.12.1996.</p>
<p><em>Show Plant Account, Plant Disposal Account and Provision for Depreciation Account for 3 years.</em></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>On 1<sup>st</sup> April, 1993, Zenith Chemical Ltd., acquired a new plant A fro Rs.2,00,000 and a further sum of Rs.10,000 was spent on its installation. On 1<sup>st</sup> October, 1994 another plant B was purchased for Rs.2,50,000.</p>
<p>In an accident, on 31<sup>st</sup> December, 1995, the plant A was destroyed. The scrap was sold for Rs.20,000. On 15<sup>th</sup> January, 1996, a used plant C was purchased for Rs. 3,00,000 and a further sum of Rs.50,000 was spent on its repairs. The company had been providing for Depreciation at 10% on straight line basis. It was the practice to provide Depreciation for the full year on all acquisitions made at any time during the year and to ignore Depreciation on any items sold or disposed of during the year. None of the assets was insured. The accounts are closed annually on 31<sup>st</sup> March. It has now been decided to provide Depreciation @20% under the diminishing balance method with retrospective effect in respect of existing items of plant and to make the necessary adjustment entries on 1<sup>st</sup> April, 1997.</p>
<p><em>Required: (a) Determine the additional Depreciation, if any, to be provided on account of the change in the method of Depreciation; (b) Prepare the Plant Account and Accumulated Depreciation Account for all the years upto the financial year ending 31<sup>st</sup> March, 1997.</em></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>The Plant and Machinery Account of a company had a debit balance of Rs.1,47,390 on 1<sup>st</sup> January, 1997. The company was incorporated in 1994 and has been following the practice of charging full year’s Depreciation every year on the diminishing balance system @15%. In 1997, it was, however, decided to change the method from reducing system to the straight line with retrospective effect from 1994 and to give effect of the change while preparing the final accounts for the year ended 31<sup>st</sup> December, 1997, the rate of Depreciation remaining the same as before.</p>
<p>In 1997, new machineries were purchased at a cost of Rs.50,000. All the other machineries were acquired in 1994.</p>
<p><em>Show the Plant and Machinery Account from 1994 to 1997.</em></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>3)       Sinking Fund Method or Depreciation Fund Method</p>
<p>Journal entries</p>
<p>A)      At the end of the first year</p>
<p>i)         <em>For setting aside the required amount</em></p>
<p>Depreciation Account                                                  Dr.</p>
<div>
<p>    To Sinking Fund Account</p>
</div>
<p>ii)       <em>For transferring Depreciation to Profit &amp; Loss Account </em></p>
<p>Profit &amp; Loss Account                                                 Dr.</p>
<div>
<p>    To Depreciation Account</p>
</div>
<p>iii)    <em>For investing the amount</em></p>
<p>Sinking Fund Investment Account                               Dr.</p>
<div>
<p>    To Bank Account </p>
</div>
<p>&nbsp;</p>
<p>B)      Second and subsequent years</p>
<p>i)         <em>For interest on investment</em></p>
<p>a)        Bank Account                                             Dr.</p>
<p>To Interest on Sinking Fund Investment Account </p>
<p>&nbsp;</p>
<p>b)       Interest on Sinking Fund Investment Account                 Dr.</p>
<div>
<p>To Sinking Fund Account</p>
</div>
<p>ii)       <em>For setting aside the amount</em></p>
<p>Depreciation Account                                      Dr.</p>
<div>
<p>    To Sinking Fund Account</p>
</div>
<p>iii)    <em>For transferring Depreciation to Profit &amp; Loss Account </em></p>
<p>Profit &amp; Loss Account                                     Dr.</p>
<div>
<p>                To Depreciation Account</p>
</div>
<p>iv)      <em>For investing (amount of Depreciation plus interest)</em></p>
<p>Sinking Fund Investment Account                   Dr.</p>
<div>
<p>    To bank Account</p>
</div>
<p>&nbsp;</p>
<p>C)      Last Year</p>
<p>i)         <em>For interest on investment</em></p>
<div>
<p>a)        Bank Account                                             Dr.</p>
<p>                To Interest on Sinking Fund Investment Account</p>
<p>b)       Interest on Sinking Fund Investment Account         Dr.</p>
<p>               To Sinking Fund Account</p>
</div>
<p>ii)       <em>For setting aside the amount</em></p>
<p>Depreciation Account                                      Dr.</p>
<p>    To Sinking Fund Account</p>
<div>
<p>In the last year, the amount of Depreciation and interest are not re-invested. Instead, all investments are sold</p>
</div>
<p>iii)    <em>For sale of investment</em></p>
<p>Bank Account                                                    Dr.</p>
<div>
<p>    To Sinking Fund Investment Account</p>
</div>
<p>iv)      <em>For transferring Profit &amp; Loss on sale investment</em></p>
<p>a)        For Profit</p>
<p>Sinking Fund Investment Account            Dr.</p>
<p>         To Sinking Fund Account</p>
<p>b)       For Loss</p>
<p>Sinking Fund Account                               Dr.</p>
<div>
<p>         To Sinking Fund Investment Account</p>
</div>
<p>v)        <em>For sale of scrap</em></p>
<p>Bank Account                                                    Dr.</p>
<div>
<p>    To Asset Account</p>
</div>
<p>vi)      <em>For closing Sinking Fund Account </em></p>
<p>Sinking Fund Account                          Dr.</p>
<div>
<p>    To Asset Account</p>
</div>
<p>vii)   <em>For closing Asset Account </em></p>
<div>
<p>If there is any balance in the asset Account, it is transferred to Profit &amp; Loss Account.</p>
</div>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>On 1<sup>st</sup> July, 1993, Wise Ltd purchased a machine for Rs.1,10,000 and spent Rs.6,000 on its installation. The expected life of the machine is 4 years at the end of which the estimated scarp value will be Rs.16,000. Desiring to replace the machine on the expiry of its life, the company establishes a sinking fund. Investments are expected to realize 5% interest. On  30<sup>th</sup> June, 1997, the machine was sold off as scrap for Rs.18,000 and the investments were realized at 5% less than the book value. On 1<sup>st</sup> July, 1997, a new machine is installed at a cost of Rs.1,25,000. Sinking Fund tables show that Re.0.2320 invested each year will produce re.1 at the end of 4 years at 5%.</p>
<p><em>Show the necessary ledger Accounts in the books of Wise Ltd  for all the years.</em></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>4)       Insurance Policy Method</p>
<p>Journal entries:</p>
<p>a)        <em>For yearly Depreciation</em></p>
<p>Depreciation Account                                      Dr.       [Insurance Premium]</p>
<div>
<p>    To Depreciation Reserve Fund Account <em> </em></p>
</div>
<p>b)        <em>For transferring Depreciation to Profit &amp; Loss Account</em></p>
<p>Profit &amp; Loss Account                                     Dr.</p>
<div>
<p>    To Depreciation Account</p>
</div>
<p>c)        <em>For payment of yearly premium</em></p>
<p>Depreciation Insurance Policy account          Dr.</p>
<div>
<p>    To Bank Account</p>
<p>[<em>no entry will be passed in respect of interest which will be earned]</em></p>
</div>
<p>d)        <em>For realization of insurance policy</em></p>
<p>Bank Account                                                    Dr.</p>
<div>
<p>    To Depreciation Insurance Policy Account</p>
</div>
<p>e)        <em>If there is any balance in the Depreciation Balance Insurance Policy Account, it should be transferred to Depreciation Reserve Account. Assuming that the realized amount of policy is greater than the total premia paid, the following entry will be passed:</em></p>
<p>Depreciation Insurance Policy Account         Dr.</p>
<div>
<p>    To Depreciation Reserve Fund Account</p>
</div>
<p>f)         <em>For sale of asset ( when the asset becomes worthless)</em></p>
<p>i)         Bank Account                                 Dr.</p>
<p>To Asset Account</p>
<p>ii)      Depreciation Reserve Fund Account       Dr.</p>
<div>
<p>        To Asset Account</p>
</div>
<div>
<p>g)        <em>If there is any balance lying in the Asset Account, it should be transferred to Profit &amp; Loss Account to close the asset Account.</em></p>
</div>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>A company purchased a machinery for Rs.50,000 on 1.1.1993 and incurred Rs.10,000 towards freight, insurance, carriage inwards and installation charges. It was estimated that the machinery will have a scrap value of Rs.5,000 at the end of its useful life of 4 years. It was decided  to take out an insurance policy to provide necessary funds for the replacement of asset at the end of its useful life. The annual insurance premium for the policy on 1<sup>st</sup> April every year was Rs.13,000. The scrap value at the end of the 4<sup>th</sup> year realized Rs.5,200. Prepare Depreciation Reserve Fund Account, Depreciation Insurance Policy Account.</p>
<p>&nbsp;</p>
<p>Distinction between Depreciation Fund Method and Insurance Policy Method</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="46">
<p align="center">No.</p>
</td>
<td valign="top" width="269">
<p align="center">Depreciation Fund Method</p>
</td>
<td valign="top" width="47">
<p align="center">No.</p>
</td>
<td valign="top" width="278">
<p align="center">Insurance Policy Method</p>
</td>
</tr>
<tr>
<td valign="top" width="46">1.</td>
<td valign="top" width="269">Investments are made outside the business regularly in securities equal to the amount necessary for the replacement of an asset at the end of its economic life.</td>
<td valign="top" width="47">1.</td>
<td valign="top" width="278">An insurance policy is taken equal to the amount necessary for the replacement of an asset at the end of its estimated economic life.</td>
</tr>
<tr>
<td valign="top" width="46">2.</td>
<td valign="top" width="269">Funds are invested at the  end of each accounting year.</td>
<td valign="top" width="47">2.</td>
<td valign="top" width="278">Premium is paid for the first time when the asset is acquired and thereafter at regular intervals.</td>
</tr>
<tr>
<td valign="top" width="46">3.</td>
<td valign="top" width="269">Entries are passed for the amount of interest earned during the period and reinvestment of those interests.</td>
<td valign="top" width="47">3.</td>
<td valign="top" width="278">No entry is passed in respect of interest that accrues at the end of the accounting period.</td>
</tr>
<tr>
<td valign="top" width="46">4.</td>
<td valign="top" width="269">This method does not cover the risk of damage or destruction of the asset during its economic life.</td>
<td valign="top" width="47">4.</td>
<td valign="top" width="278">Any loss to the asset during its life is well insured.</td>
</tr>
<tr>
<td valign="top" width="46">5.</td>
<td valign="top" width="269">There may be a loss or gain when the securities are realized.</td>
<td valign="top" width="47">5.</td>
<td valign="top" width="278">A fixed amount is received after the expiry of a specified period.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>5)       Sum – of – the – years’ – Digits  method</p>
<p>Number of years life remaining</p>
<p>Depreciation  =                                                                     x         (Cost  &#8211; Salvage Value)</p>
<p>                                    Sum of years’ digits</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>If the cost of a machine is Rs.5,000 and scrap value after 5 years is Rs.100. calculate Depreciation under sum of years’ digit method.</p>
<p>&nbsp;</p>
<p>6)       Annuity method</p>
<p>Journal entries:</p>
<p>a)        Asset Account                            Dr.</p>
<p>To Interest Account</p>
<p>b)        Depreciation Account               Dr.</p>
<p>To Asset Account</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>P Ltd. Took a lease on 1<sup>st</sup> January, 1993, costing Rs.1,00,000 for a period of 5 years. The company decided to amortise the lease by the annuity method, interest at the rate of 5%p.a. being charged. If annuity of Re.1 for 5 years at 5% is 0.230975, Show lease Account for the whole period.</p>
<p>&nbsp;</p>
<p>Distinction between Depreciation Fund Method and Annuity Method</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="46">No.</td>
<td valign="top" width="253">
<p align="center">Depreciation Fund Method</p>
</td>
<td valign="top" width="40">No.</td>
<td valign="top" width="292">
<p align="center">Annuity method</p>
</td>
</tr>
<tr>
<td valign="top" width="46">1.</td>
<td valign="top" width="253">This method considers the generation of funds for replacement of an asset.</td>
<td valign="top" width="40">1.</td>
<td valign="top" width="292">This method considers the time value of money and opportunity cost of capital locked up in the asset.</td>
</tr>
<tr>
<td valign="top" width="46">2.</td>
<td valign="top" width="253">An amount equal to the Depreciation provides is invested outside the business.</td>
<td valign="top" width="40">2.</td>
<td valign="top" width="292">No investments are made outside the business.</td>
</tr>
<tr>
<td valign="top" width="46">3.</td>
<td valign="top" width="253">Entries are passed for actual receipts of interests at periodic intervals.</td>
<td valign="top" width="40">3.</td>
<td valign="top" width="292">Adjustment entries are made for notional interests.</td>
</tr>
<tr>
<td valign="top" width="46">4.</td>
<td valign="top" width="253">All the calculations are made with the help of a sinking fund table.</td>
<td valign="top" width="40">4.</td>
<td valign="top" width="292">Calculations are made with the help of an annuity table.</td>
</tr>
<tr>
<td valign="top" width="46">5.</td>
<td valign="top" width="253">The amount of interest in any year depends on the funds accumulated which increased year after year.</td>
<td valign="top" width="40">5.</td>
<td valign="top" width="292">The amount of interest depends on the written down value of the asset which decreases year after year.</td>
</tr>
<tr>
<td valign="top" width="46">6.</td>
<td valign="top" width="253">The net charge to the Profit &amp; Loss Account every year is the difference between the allocated cost and the interest.</td>
<td valign="top" width="40">6.</td>
<td valign="top" width="292">The net charge to the Profit &amp; Loss Account is the aggregate of the allocated cost and the interest.</td>
</tr>
<tr>
<td valign="top" width="46">7.</td>
<td valign="top" width="253">The carrying value of the asset is the same year after year.</td>
<td valign="top" width="40">7.</td>
<td valign="top" width="292">The carrying value of the asset decreases as the years pass.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>7)       Revaluation Method</p>
<p>Illustration:</p>
<p>A company manufacturers loose tools for its own use. At the end of each year, Depreciation is charged on revaluation method. Form the following particulars, show the Loose Tools Account:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="191">Year ended 31.12.1993:</td>
<td valign="top" width="411">Loose Tools Manufacturer Rs.5,000 (revalued on 31.12.1993 Rs. 4,100)</td>
</tr>
<tr>
<td valign="top" width="191">Year ended 31.12.1994:</td>
<td valign="top" width="411">Loose tools manufacturer Rs.2,700 (revalued on 31.12.1994 Rs. 5,700)</td>
</tr>
<tr>
<td valign="top" width="191">Year ended 31.12.1995:</td>
<td valign="top" width="411">Loose tools manufacturer Rs.1,000 (revalued on 31.12.1995 Rs.6,000)</td>
</tr>
<tr>
<td valign="top" width="191">Year ended 31.12.1996:</td>
<td valign="top" width="411">Loose tools manufacturer Rs. 1,500 (revalued on 31.12.1996 Rs.5,100)</td>
</tr>
</tbody>
</table>
<p>The value as on 31.12.1996 after considering the sale of old tools at the book value of Rs.1,200 (as on 31.12.1996) for Rs.950.</p>
<p>&nbsp;</p>
<p>8)       Depletion Method</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Bharat collieries Ltd. Acquired a lease right for 25 years of a mine on January 1<sup>st</sup>, 1992 on a lumpsum payment of Rs.5,00,000. Estimated coal deposit was 25,00,000 tonnes, 80% of which, it is expected, could be raised within the lease period. The company decided to depreciate the lease under the depletion method. The annual raising were: 1992 – 40,000 tonnnes; 1993 – 60,000 tonnes; 1994 – 1,00,000 tonnes; 1995 to 1997 – 2,00,000 tonnes each year.</p>
<p>Show lease Account from 1<sup>st</sup> January 1992 to 31<sup>st</sup> December, 1997.</p>
<p>&nbsp;</p>
<p>9)       Machine Hour Rate method</p>
<p>&nbsp;</p>
<p>Cost of the Machine – Scrap Value</p>
<p>Machine Hour Rate =          </p>
<p>                                                Effective Working Hours</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Computer ‘Meteor -500’ is estimated to have effective life of 20,000 hours. The cost of the computer Rs.60,000. IF the computer has worked for 2,000 hours in 1996 and 3,000 hours in 1997, what will be the Depreciation at the end of each year? You are required to show the computer Account for 1996 and 1997.</p>
<p>&nbsp;</p>
<p>10)   Depreciation and Repairs Fund Method</p>
<p>Journal entries:</p>
<p>a)        <em>For setting aside the required sum</em></p>
<p>Profit &amp; Loss Account                                                 Dr.</p>
<div>
<p>    To Depreciation and Repairs Fund Account</p>
</div>
<p>b)        <em>For actual repairs and renewals </em></p>
<p>Repairs and Renewals Account                                   Dr.</p>
<div>
<p>    To cash Account</p>
</div>
<p>c)        <em>For closing the Repairing and Renewals Account</em></p>
<div>
<p>Depreciation and Repairs Fund Account                    Dr.</p>
<p>    To Repairing and Renewals Account </p>
</div>
<p>d)        <em>For closing Depreciation and Repairs Fund Account (at the end of the life of the asset)</em></p>
<p>Depreciation and Repairs Fund Account                    Dr.</p>
<div>
<p>    To Asset Account</p>
</div>
<p>e)        <em>For closing asset account </em></p>
<div>
<p>Any balance of the Asset Account will be transferred to Profit &amp; Loss Account and it will close this account.</p>
</div>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>A combined provision for Depreciation and repairs and renewals was made every year at 15% of the original cost of a machine purchased at Rs.50,000. The provision for Depreciation and Maintenance Account that was opened for the purpose was, therefore, debited with the actual costs of repairs and renewals which were as stated below:</p>
<p>1<sup>st</sup> year – Rs. 1,500; 2<sup>nd</sup> year – Rs.1,600; 3<sup>rd</sup> year – Rs.2,100; 4<sup>th</sup> year – Rs.3,000; 5<sup>th</sup> year – Rs.4,200.</p>
<p>At the end of the fifth year, the machine was sold out at Rs.20,000 after utilizing a few of its minor parts valued at Rs.4,000, in installing in its place a new machine purchased at Rs.75,000. The resulting loss in the disposal of the old machine was debited to revenue. Write up ‘Provision for Depreciation and Maintenance Account’ for the five years and the Old and the New Machine Accounts at the end.</p>
<p>&nbsp;</p>
<h4>Rectification of Errors</h4>
<p align="center"> </p>
<p align="center">Index</p>
<p align="center"> </p>
<ol>
<li>Introduction</li>
</ol>
<p>Errors are unintentional misstatement or omission of amounts or disclosures in financial statements. They include mistakes in gathering or processing accounting data from which financial statements are prepared.</p>
<p>&nbsp;</p>
<ol>
<li>Types of errors</li>
</ol>
<p>The kinds of errors that usually occur in the books of account. There errors can broadly be divided into two classes –</p>
<p>1)       Errors of omission and</p>
<p>2)       Errors of commission</p>
<p>&nbsp;</p>
<p>1)      Errors of omission</p>
<p>Errors of omission are errors resulting from the complete failure to enter a transaction in the books. Such errors creep in as a result of some act of omission on the part of the person responsible for the maintenance of the books of account. These errors can further be classified into: (a) complete error; and (b) Partial error.</p>
<p>&nbsp;</p>
<p>a)         Complete error:</p>
<p>When any particular transaction has not at all been entered in the Journal or a book of original entry, it cannot be posted into the ledger, and a ‘complete error of omission’ will occur. A complete error will affect both the debit and the credit side of the entry and it will not hamper the agreement of the Trial Balance. Instances of complete errors are:</p>
<p>i)           A receipt of Rs.1,000 from Ravi is omitted from being entered in the Cash Book.</p>
<p>ii)         Goods sold to Ramesh on credit for Rs.500 has not been entered in the ‘sales day book’.</p>
<p>&nbsp;</p>
<p>b)        Partial Error:</p>
<p>If a transaction has been journalized or recorded in a subsidiary book but has not been posted in both the Ledger Accounts. It will be an error of partial omission and it will not hamper the agreement of the Trial Balance. For example, discount allowed to a customer has not been debited to ‘Discount allowed Account’ in the General Ledger and has also not been credited to Customer Account in the Customer Ledger.</p>
<p>&nbsp;</p>
<p>2)      Errors of commission:</p>
<p>These errors are the result of some positive act of commission on the part of the person responsible for the maintenance of the books of account. For example, if wrong accounts are entered either in the Journal or in the Ledger, or when the totals are wrongly made, or when the posting is done to wrong accounts, errors of commission are occurred. Errors of commission may further be classified into:</p>
<p>a)        Errors of Principle:</p>
<p>These errors arise because of an incorrect application of the principles of accounting, and failure to differentiate between capital and revenue expenditure. Their existence are not usually disclosed by the Trial Balance. Instances of errors of principle are:</p>
<p>i)         Wages paid for the installation of machinery debited to wages Account. Here, Machinery Account should be debited in place of wages Account.</p>
<p>ii)       A purchase of furniture passed through the purchases Day Book. Here, furniture Account should be debited in place of Purchase Account.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>b)        Compensating error:</p>
<p>These are a group of errors, the total effect of which are not reflected in the Trial Balance. These errors are of a neutralizing nature. One error is compensated by the other error or errors of an opposite nature. For example, an extra debit in Salary Account for Rs.100 may be compensated by an extra credit of Rs.100 in Sales Account.</p>
<p>Neither the original error nor the compensating error will thus be detected by a failure to balance, since on error conceals another error. The point to note is that there is no connection between an error and its compensating error other than the coincidence that they are equal and opposite in amount.</p>
<p>&nbsp;</p>
<p>c)        Errors of posting:</p>
<p>If a transaction has been journalized or recorded in a subsidiary book but has been posted wrongly in the Ledger Account, it is an error of posting. The following are examples of errors of posting:</p>
<p>a)        Goods sold to Ram on credit for Rs.210 have been posted in Ram Account as Rs.21.</p>
<p>b)        Goods purchased from Robin for Rs.300 have been posted to Rahim Account.</p>
<p>&nbsp;</p>
<p>d)        Errors of Casting:</p>
<p>Casting is an accounting term for addition. These errors may occur due to short casting or excess casting in any subsidiary book or in any account in the Ledger. These errors are reflected in the Trial Balance unless it is compensated by other error.</p>
<p>&nbsp;</p>
<p>1)     Rectification of errors before the preparation of the Trial Balance</p>
<p>a)        One – sided errors:</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Purchases day book was cast Rs.1,500 in place of Rs.2,000. It means purchases account has been debited Rs.500 short. Therefore, to rectify the purchases Account should be debited further by Rs.500.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Sales Day Book was cast Rs.2,000 in place of Rs.1,800. It means Sales Account has received excess credit for Rs.200. Therefore, to rectify, the sales Account should be debited by Rs.200.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Return Outward Book was cast Rs.1,000 in place of Rs. 1,600. It means that Return Outward Account has been credited Rs.600 short. Therefore, to rectify, the Return Outward Account is to be credited further with Rs.600.</p>
<p>&nbsp;</p>
<p>b)        Two – sided errors: for rectification of these types of errors, the following steps should be taken:</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="68">Step 1</td>
<td valign="top" width="490">Write down in the rough sheet the correct entry necessary for recording the transaction.</td>
</tr>
<tr>
<td valign="top" width="68">Step 2</td>
<td valign="top" width="490">Write down in the rough sheet in entry that has actually been passed.</td>
</tr>
<tr>
<td valign="top" width="68">Step 3</td>
<td valign="top" width="490">Pass in the Journal, the required entry to arrive at the correct entry of step 1 and to cancel the entry of step 2.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>A purchase of Rs.1,000 from Rahim entered in the Day book as Rs.100.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>A cash sales of Rs.600 has completely been omitted to be recorded in the books.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Rs.500 received from B.Sen entered as Rs.300 in the Cash Book</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>The following errors have been detected before the preparation of the final Trial Balance. You are required to pass the Journal entries, where necessary, or if no journal entry is required.  State how they will be corrected.</p>
<p>(1) the sales day books has been undercast by Rs.800; (2) The total of the discount column on the debit side of the cash book was cast short by Rs.50; (3) Repairs to building charged to building Account Rs.500; (4) Goods worth Rs.645 sold to Zishan Ali, but the latter’s Account was credited with Rs.654; (5) wages paid for installation of the machinery debited to wages Account Rs.1,000.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Pass rectification entries for the following transactions:</p>
<p>a)        A builder’s bill for Rs.4,600 for the erection of a small shed was debited to Repairs Account.</p>
<p>b)        Repairs to plant amounting to Rs.900 had been charged to Plant and Machinery Account.</p>
<p>c)        Wages paid to the firm’s workmen for making certain additions to machinery amounting to Rs.340 were debited to wages Account.</p>
<p>d)        A cheque for Rs.750 received from S Desai was credited to the Account of R Ram.</p>
<p>e)        Goods to the value of Rs.700 returned by X were included in closing stock, but no entry was made in the books.</p>
<p>f)         Goods costing Rs.2,000 were purchased for various members of the staff and the cost was included in purchases. A similar amount was deducted from the salaries of the staff members concerned and the net payments to them debited to Salaries Account.</p>
<p>g)        A bill of exchange (received from Hari) for Rs.3,000 had been returned by the  Bank, with whom it had been discounted, as dishonoured and had been credited to Bank Account and debited to Bills Receivable Account.</p>
<p>h)        Goods sold to Z for Rs.475 have been wrongly entered in the Sales Book as Rs. 745.</p>
<p>&nbsp;</p>
<p>2)     Rectification of errors after the preparation of Trial Balance but before the preparation of Final Accounts</p>
<p>a)        One sided error:</p>
<p>Most of the one – sided errors will be rectified by passing a Journal entry via Suspense Account.</p>
<p>Suspense Account:</p>
<p>A Suspense Account is a ledger Account in which entries are made on a temporary basis when the correct account cannot be immediately identified. This may be so because further information has to become available or while preparing the accounts, the accountant is unsure of how to proceed with it. It is opened in the following cases : (i) to balance a disagreed Trial Balance; (ii) to post doubtful items; and (iii) to record incomplete transactions.</p>
<p>&nbsp;</p>
<p>i)         To balance a disagreed Trial Balance</p>
<p>Sometimes, a Trial Balance does not tally despite all efforts; but one cannot wait indefinitely a accounts must be closed at the end of a financial year. In such a case, the amount of difference is entered in the lighter column against Suspense Account. <em>The point to note is that no double entry will be possible.</em> Later, when the mistakes are detected, the rectifying entries are passed.</p>
<p><em> </em></p>
<p>ii)      To post doubtful items</p>
<p>Sometimes, an item cannot be posted to the correct account for one reason or another. For instance, you may receive a remittance of Rs.1,500 but you may not know who has sent it.</p>
<p>&nbsp;</p>
<p>iii)    To record incomplete transactions</p>
<p>Sometimes a Suspense Account is opened to record a balance that has not yet been finalized because a particular deal has not been concluded. For example, an advance of Rs.10,000 received from X for the goods to be delivered in the future, subject to availability. A suspense Account can include many transactions of this nature, without involving any error.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Goods worth Rs.1,000 were sold to Mr. R Sharma on credit. This was entered in the Sales Day Book, but was not posted into R Sharma Account.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Cash paid to Ram Rs.400 was posted to the credit of his account as Rs.440 from Cash Book.</p>
<p>&nbsp;</p>
<p>b)        Two sided error: For rectification of two – sided errors, the following steps should be taken:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="84">Step 1</td>
<td valign="top" width="474">Write down in the rough sheet the correct entry necessary for recording the transaction.</td>
</tr>
<tr>
<td valign="top" width="84">Step 2</td>
<td valign="top" width="474">Write down in the rough sheet the entry that has actually been passed.</td>
</tr>
<tr>
<td valign="top" width="84">Step 3</td>
<td valign="top" width="474">Pass in the Journal, the required entry to arrive at the correct entry of step 1 and to cancel the entry of step 2.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Purchase of stationary for Rs.400 has been recorded in the Cash Book as Rs.40.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Sale of old furniture has been credited to Sales Account for Rs.200</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>a)        An experienced book keeper has drawn up a Trial Balance for the year ended 30<sup>th</sup> June, 1997:</p>
<p>&nbsp;</p>
<table width="591" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="370">Heads of Accounts</td>
<td valign="top" width="111">
<p align="center">Rs.</p>
</td>
<td valign="top" width="111">
<p align="center">Rs.</p>
</td>
</tr>
<tr>
<td valign="top" width="370">Provision for Doubtful debts</td>
<td valign="top" width="111">
<p align="right">200</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">Bank overdraft</td>
<td valign="top" width="111">
<p align="right">1,654</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">Capital</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
<td valign="top" width="111">
<p align="right">4,591</p>
</td>
</tr>
<tr>
<td valign="top" width="370">Creditors</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
<td valign="top" width="111">
<p align="right">1.637</p>
</td>
</tr>
<tr>
<td valign="top" width="370">Debtors</td>
<td valign="top" width="111">
<p align="right">2,983</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">Discount received</td>
<td valign="top" width="111">
<p align="right">252</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">Discount allowed</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
<td valign="top" width="111">
<p align="right">733</p>
</td>
</tr>
<tr>
<td valign="top" width="370">Drawings</td>
<td valign="top" width="111">
<p align="right">1,200</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">Office furniture</td>
<td valign="top" width="111">
<p align="right">2,155</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">General expenses</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
<td valign="top" width="111">
<p align="right">829</p>
</td>
</tr>
<tr>
<td valign="top" width="370">Purchases</td>
<td valign="top" width="111">
<p align="right">10,923</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">Returns inward</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
<td valign="top" width="111">
<p align="right">330</p>
</td>
</tr>
<tr>
<td valign="top" width="370">Rent &amp; Rates</td>
<td valign="top" width="111">
<p align="right">314</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">Salaries</td>
<td valign="top" width="111">
<p align="right">2,520</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">Sales</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
<td valign="top" width="111">
<p align="right">16,882</p>
</td>
</tr>
<tr>
<td valign="top" width="370">Stock</td>
<td valign="top" width="111">
<p align="right">2,418</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">Provision for Depreciation on furniture</td>
<td valign="top" width="111">
<p align="right">364</p>
</td>
<td valign="top" width="111">
<p align="right"> </p>
</td>
</tr>
<tr>
<td valign="top" width="370">Total</td>
<td valign="top" width="111">
<p align="right">24,983</p>
</td>
<td valign="top" width="111">
<p align="right">25,002</p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Required: (a) Draw up a ‘Corrected’ Trial Balance, debiting any residual errors to a Suspense Account</p>
<p>(b) Further investigation of the Suspense Account, ascertained in (a) above reveals the following errors:</p>
<p>&nbsp;</p>
<p>i)         Good bought from J Jones amounting to Rs.13 had been posted to this Account as Rs.33.</p>
<p>ii)       Furniture which had cost Rs.173 had been debited to the general expenses Account.</p>
<p>iii)    An invoice from suppliers Ltd., for Rs.370 had been omitted from  the purchases Account, but credited to Suppliers Ltd., Account.</p>
<p>iv)      Sales on credit to A Hope Ltd. For Rs.450 had been posted to the Sales Account, but not to A Hope Ltd. Account.</p>
<p>v)        The balance on the capital Account had been incorrectly brought forward in the ledger, and should have been Rs.4,291</p>
<p>vi)      An amount of Rs.86 received from A.  Blunt, a debtor, in settlement of his account had been treated as a cash  sale.</p>
<p>vii)   Discount allowed has been undertotalled by Rs.35</p>
<p>&nbsp;</p>
<p>Required: Prepare Journal entries correcting each of the above errors and write up the Suspense Account.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Pass necessary Journal entries to rectify the following errors:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="337">1) Sales day book under cast by Rs.500</td>
<td valign="top" width="337">7) purchases returns day book undercast by Rs.500</td>
</tr>
<tr>
<td valign="top" width="337">2) Sales day book overcast by Rs.1,000</td>
<td valign="top" width="337">8) purchases returns day book overcast by Rs.1,000</td>
</tr>
<tr>
<td valign="top" width="337">3) Sales returns day book undercast by Rs.600</td>
<td valign="top" width="337">9) bills receivable book undercast by Rs.500</td>
</tr>
<tr>
<td valign="top" width="337">4) sales returns day book overcast by Rs.1,600</td>
<td valign="top" width="337">10) Bills Payable book undercast by Rs.1,000</td>
</tr>
<tr>
<td valign="top" width="337">5) Purchases day book undercast by Rs.500</td>
<td valign="top" width="337">11) Bills receivable book overcast by Rs.600</td>
</tr>
<tr>
<td valign="top" width="337">6) Purchases day book overcasy by Rs.1,500</td>
<td valign="top" width="337">12) Bills Payable book overcast by Rs.500</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>The Trial Balance of Shri Govind shows a difference of Rs.500, the credit side being in excess. The difference is subsequently found due to the following mistakes:</p>
<p>a)        The purchase of an office table costing Rs.2,000 had been passed through the Purchases Day Book.</p>
<p>b)        A motor car had been purchased for Rs.3,400. Cash had been correctly credited but the Motor Car Account had been debited with Rs.3,140 only.</p>
<p>c)        Interest on deposits received Rs.60 had been debited in cash Account, but had not been credited to the interest Account.</p>
<p>d)        The balance in the account of Mr. Rahim Rs.100 had been written off as bad but no other account had been debited.</p>
<p>e)        A debit balance of Rs.200 on the personal account of Mr. John (correctly shown in the ledger) had been omitted when extracting a Trial Balance.</p>
<p><em>Give the necessary Journal entries and show the Suspense Account.</em></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Ganesh drew a Trial Balance of his operations for the year ended 31.03.1992. There was a difference in the Trial Balance which he closed with a suspense Account. On a scrutiny by the auditors, the following errors were found:</p>
<p>i)         Purchases day book for the month of April, 1991 was undercast by Rs.1,000</p>
<p>ii)       Sales day book of October, 1991 was overcast by Rs.10,000</p>
<p>iii)    A furniture purchased for Rs.8,100 was entered in the Furniture Account as Rs.810.</p>
<p>iv)      A bill for Rs.10,000 drawn by Ganesh was not entered in the Bills Receivable book.</p>
<p>v)        A machinery purchased for Rs.10,000 was entered in the purchases day book.</p>
<p>&nbsp;</p>
<p><em>Pass necessary Journal entries to rectify the same and ascertain the difference in the Trial Balance that was shown under the Suspense Account in respect of the above items.</em></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>In taking out a Trial Balance, a book – keeper finds that debit total exceeds the credit total by Rs.352. The amount is placed to the credit of a newly opened Suspense Account. Subsequently, the following mistakes were discovered.</p>
<p> You are required to pass the necessary entries for rectifying the mistakes and show the suspense Account.</p>
<p>i)         Sales day book was overcast by Rs.100</p>
<p>ii)       A sale of Rs.50 to Shri Ram was wrongly debited to Sri Krishna</p>
<p>iii)    General expenses Rs.18 was posted as Rs.80</p>
<p>iv)      Cash received from shri Govind was debited to his account Rs.150</p>
<p>v)        While carrying forward the total of one page of the purchase day book to the next, the amount of Rs.1,235 was entered as Rs.1,325.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>rectify the following errors by way of Journal Entries and work out their effect on the Profit and Loss account of the  concern:</p>
<p>1)     returns inwards Book for December was short totaled by Rs.100</p>
<p>2)     rs.5,810 being cash paid to Hira chand was debited to Ram Chand as Rs.5,010.</p>
<p>3)     Rs.1,500 worth of furniture purchased on credit was debited to Purchases account</p>
<p>4)     a Purchase made for Rs.500 was posted to the Purchases account as rs. 50</p>
<p>5)     wages paid for the erection of machinery amounting to Rs.700 was debited to Purchase account</p>
<p>6)     goods purchased for proprietor’s use for Rs.1,000 was debited to Purchases account</p>
<p>7)     a sum of rs.1,000 written off from machinery has not been posted to Depreciation account.</p>
<p>8)     Rs.100 received from Raghu has been debited to Sunder.</p>
<p>9)     Rs.1,150 received from Radhey Mohan was debited to his account.</p>
<p>10)purchase returns worth Rs.980 to Shri Hari Kishan were not recorded in the books.</p>
<p>&nbsp;</p>
<p>illustration:</p>
<p>the Trial Balance extracted from a set of books of X showed difference which was placed in a Suspense Account. subsequently, the following mistakes were detected:</p>
<p>                     i)            a cheque for Rs.1,000 received from B was dishonoured and retruned by the bank had been credited to the Bank account and debited to Sundry Creditors account.</p>
<p>                   ii)            several items of furniture sold for rs.5,000 had been entered in the Sales Day book.</p>
<p>                iii)            goods purchased from Z for Rs. 310 had been  posted to the debit of his account as Rs. 130.</p>
<p>                  iv)            Rs.1,200 for goods sold on credit to A had been omitted to be entered in his account.</p>
<p>&nbsp;</p>
<p>show the necessary entries in the journal properly ruled and with suitable narrations to rectify these errors and also indicate the amount of the difference in the Trial Balance.</p>
<p>&nbsp;</p>
<p>illustration:</p>
<p>the difference in Trial Balance is kept in Suspense Account. before preparing the final accounts, the following errors were detected:</p>
<p>a)      purchase for rs.540 was written in Sales Day Book, but was posted to the correct side of Party’s account.</p>
<p>b)     salary account total Rs.12,600 on page 32 was carried over to the next page as Rs.1,260 on the wrong side.</p>
<p>c)     interest on overdraft Rs.650 was not posted to the Ledger from the Cash Book.</p>
<p>d)     Rs.600 collected from a party in respect of the old dues from his which had been written off as bad two years ago, was credited to the Party’s account.</p>
<p>show rectification entries and suspense account. state to what extent the Profit and Loss account would have been affected if the above errors had not been detected and corrected.</p>
<p><em> </em></p>
<p>Illustration:</p>
<p>You are presented with Trial Balance of Saxena  as on 30.6.97, showing the credit is in excess by Rs.415, which has been carried to Suspense Account. On close scrutiny of the books, the following errors are revealed:</p>
<p>a)      A cheque of Rs.3,456 received from Sankar, after allowing him a discount of Rs.46 was endorsed to Sharma in full settlement for Rs.3,500. The cheque was finally dishonoured but no entires were passed in the books.</p>
<p>b)     Goods valued Rs.230 retruned by Swaminathan were entered in the Purchases Book and posted there from to Sarika’a account for rs. 320.</p>
<p>c)     Bad debts amounting to Rs.505 written – off during the year in the Sales Ledger but were not recorded in the General Ledger.</p>
<p>d)     Bill for Rs.750 received from Surekha for repairs to machinery was entered in the inward invoice book as Rs.650</p>
<p>e)     Goods worth Rs.1,234 purchased from Sharaf on 29.6.97 had been entered in the Purchase Day Book and credited to him but were not delivered till 5<sup>th</sup> July, 1997, stock being taken on 30.6.97. The title of the goods was, however, passed on 29.6.97.</p>
<p>f)      Rs.79 paid for freight on machinery was debited to Frieght Account as Rs.97.</p>
<p><em>You are required to pass the necessary journal entries for correcting the above errors.</em></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>The bookkeeper of a firm having been unable to agree the Trial Balance, raised a Suspense Account, in which he entered the amount by which he was out of balance. The following errors were discovered:</p>
<p>a)      The addition of the analysis column in the tabular purchases journal posted to Goods Purchased for resale account was found to be Rs.150 short, though the addition of the total column was correct.</p>
<p>b)     Goods bought from a supplier amounting to Rs.77 had been posted to the credit of his account at Rs.770.</p>
<p>c)     A dishonoured bill of exchange receivable for Rs.1,600 returned by the firm’s bank had been credited to the Bank account and debited to the Bills Receivable account. A cheque was received later from the customer for Rs.1,600 and duly paid.</p>
<p>d)     An item of Rs.80 entered in the Sales Returns Book had been posted to the debit of the customers who returned the goods.</p>
<p>e)     Sundry items of plant sold amounting to Rs.3,000 had been entered in Sales Day Book, the total of which book had been posted to the credit of sales account.</p>
<p>f)      An account of Rs.800 owing by a customer, had been omitted from the list of Sundry Debtors.</p>
<p>g)     Discount amounting to Rs.30 allowed to a customer, had been duly entered in his account, but not posted to the discount account.</p>
<p>h)     An amount of Rs.100, being rates treated as paid in advance in the previous year, had not been brought forward as a balance on the rates account.</p>
<p>&nbsp;</p>
<p>You are required to: (i) Pass necessary Journal entries; (ii) Show the Suspense account.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>Prosperity &amp; Co. has produced  a Trial Balance as on March 31, 1997 which does not balance, the difference of Rs.1,760 being transferred to the Suspense Account. On Examination of Company’s Book discloses the following Errors:</p>
<p>a)      The Sales Day book has been undercast by Rs.800 and posted to the Debtors Control account accordingly.</p>
<p>b)     Goods received from XYZ Limited on March 31, 1997 costing Rs.9,690 have been included in stock but the invoice has not been received.</p>
<p>c)     Sales Account in the General Ledger has been credited with a credit note for Rs.950 being trade – in – allowance given on a company van. This amount had already been taken into account when dealing with the replacement in the motor van account.</p>
<p>d)     An invoice from Joseph &amp; Co. , amounting Rs.4,450 for goods purchased has been omitted from the Purchases Day Book and posted direct to Purchases Account in the General Ledger and Joseph &amp; Co. Account in the suppliers’ ledger but has not been included in the suppliers’ ledger control account in the Trial Balance.</p>
<p>e)     Discount allowed for the month of March amounting to Rs.1,740 has not been posted to Discount allowed account in the General Ledger.</p>
<p>f)      A cheque for Rs.1,920 received from Jolly Limited, a debtor, has been posted directly to the Sales account in the General Ledger.</p>
<p>&nbsp;</p>
<p>You are required: (i) to give the journal entries, where necessary, to correct these errors, or if no journal entry is required, state how they will be corrected; (ii) to prepare a statement showing the effect the corrections would have on the company’s profit for  the year, and (iii) to prepare Suspense account.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>How would you rectify the following errors discovered after the preparation of the Trial Balance:</p>
<p>a)      A cheque for Rs.12,500 received as insurance claim for loss of goods in transit at the time of import was deposited by the proprietor into his Private Bank Account. The full value of the invoice was passed through the Purchases Book.</p>
<p>b)     A purchase of Rs.500 from A &amp; Co. , on the last date of the year was taken into stock, but the invoice was not passed through the Purchase Book.</p>
<p>c)     Sale of goods on approval amounting to Rs.300 was included in Sales account, out of which good to the value of Rs.125 were returned. No record of the return was made in the books, though the returned goods were included in the stock at their cost of Rs.100.</p>
<p>d)     A typewriter which stood in the books at Rs.2,000 was sold for Rs.1,250 in part exchange of a new typewriter costing Rs.6,250 and net invoice of Rs.5,000 was passed through the purchase book.</p>
<p>e)     Four percent G.P. Notes of the face value of Rs.5,000 purchased through Lakhotia at 96% ex-dividend, brokerage Rs.25. Accrued interest to date of purchase was Rs.130. The total payment of Rs.4,955 stands debited in the books in the name of the broker Lakhotia.</p>
<p>&nbsp;</p>
<p>3)     rectification of errors after preparation of Final Accounts</p>
<p>&nbsp;</p>
<p><em>when errors are detected after preparation of Final accounts, the following points should be kept in mind:</em></p>
<p><em>1)     </em><em>all the Nominal Accounts have been closed, after transferring to Trading Account, or Profit and Loss account.</em></p>
<p><em>2)     </em><em>The Suspense Account, if any, had been carried forward to the next period. It should appear in the Balance Sheet under current assets if it has a debit balance and under current liabilities if it has a credit balance.</em></p>
<p><em>3)     </em><em>Real and Personal accounts have also been carried forward to the next period.</em></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>The books of account of A Co. Ltd. For the year ending 31<sup>st</sup> December, 1996 were closed with a difference in books carried forward. The following errors were detected in 1997:</p>
<p>&nbsp;</p>
<p><em>a)     </em>Returns outwards book was undercast by Rs.150.<em></em></p>
<p><em>b)     </em>Rs.1,500 being the total of the discount column on the credit side of the cash book was posted in General Ledger.<em></em></p>
<p><em>c)      </em>Rs.6,000 being the cost of purchase of office furniture was entered in the purchase account.<em></em></p>
<p><em>d)     </em>A credit sale of Rs.760 was wrongly posted as Rs.670 to the customer’s account in the Sales Ledger.<em></em></p>
<p><em>e)      </em>Closing stock was overstated by Rs.9,000 being casting error in the schedule of inventory.<em></em></p>
<p>&nbsp;</p>
<h1>Pass rectification entries, prepare suspense account and find out the effect of corrections on 1996 profit.</h1>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>There was a difference in Trial Balance of Mr. S Basu, a trader, on 31.12.1992 and the different in the books was carried to a Suspense Account and the books were closed. Subsequently, on going through the books, the following errors were located:</p>
<p>a)      Rs.2,296 paid for repairs to motor car, was debited to Motor Car, Account as Rs.696.</p>
<p>b)      A sale of Rs.1,400 to J Das entered in the sales book as Rs.2,120.</p>
<p>c)      A cash discount of Rs.800 received was entered in the cash book but was not posted in the ledger.</p>
<p>d)      Rs.400 being purchase returns posted to the debit of purchases account.</p>
<p>e)      The purchase of a machine on 1.1.1992 for Rs.24,000 was entered in the purchases book.</p>
<p>f)        While carrying forward total of one page in N Das’s Account, the amount of Rs.1,000 was written on the credit side instead of the debit side.</p>
<p>g)      A cheque of Rs.6,192 received from S Das (after allowing a discount of Rs.92) was endorsed to P. Ghosh in full settlement for Rs.7,000. The cheque was finally dishonoured but no entry is passed in the books.</p>
<p>Give journal entries to rectify the above errors and prepare Suspense account.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>A book keeper while preparing his Trial Balance finds that the debit exceeds by Rs.7,250. For preparing Final Accounts he places the difference to a Suspense account. In the next year, the following mistakes were discovered:</p>
<p>a)      A sale of Rs.4,000 has been passed through the Purchases Day Book. The entry in customer’s account has been correctly recorded.</p>
<p>b)     Goods worth Rs.2,500 taken away by the proprietor for his use has been debited to Repairs account.</p>
<p>c)     A bill receivable for Rs.1,300 received from Krishna has been dishonoured on maturity but no entry passed.</p>
<p>d)     Salary of Rs.650 paid to a clerk has been debited to his personal account.</p>
<p>e)     A purchase of Rs.750 from Raghubir has been debited to his account. Purchases account has been correctly debited.</p>
<p>f)      A sum of Rs.2,250 written off as depreciation on furniture has not been debited to Depreciation account.</p>
<p>Draft the journal entries for rectifying the above mistakes and prepare suspense account.</p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>The following Balance Sheet was prepared by a invoice on 31.12.1994:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="204">
<p align="center">Liabilities</p>
</td>
<td valign="top" width="79">
<p align="center">Rs.</p>
</td>
<td valign="top" width="237">
<p align="center">Assets</p>
</td>
<td valign="top" width="79">
<p align="center">Rs.</p>
</td>
</tr>
<tr>
<td valign="top" width="204">Capital</p>
<p>Net Profit during the year</p>
<p>Loan</p>
<p>Creditors</p>
<p>Suspense account</td>
<td valign="top" width="79">
<p align="right">98,500</p>
<p align="right">45,700</p>
<p align="right">50,000</p>
<p align="right">22,150</p>
<p align="right">2,110</p>
<p align="right">2,18,460</p>
</td>
<td valign="top" width="237">Furniture &amp; other fixed assets</p>
<p>Stock</p>
<p>Debtors</p>
<p>Fixed deposits</p>
<p>Bank</p>
<p>Drawings</p>
<p>&nbsp;</td>
<td valign="top" width="79">
<p align="right">59,500</p>
<p align="right">61,000</p>
<p align="right">38,190</p>
<p align="right">25,750</p>
<p align="right">19,820</p>
<p align="right">14,200</p>
<p align="right">2,18,460</p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>On close scrutiny, the following errors were discovered:</p>
<p>a)      Closing stock was overvalued by Rs.4,000</p>
<p>b)     A sale of Rs.2,300 was recovered in sales Day Book a Rs.3,200, though it was rightly posted in Sales account.</p>
<p>c)     The total of one page of purchases Day Book was carried forward as Rs.3,800 instead of Rs.8,300</p>
<p>d)     Outstanding telephone bill of Rs.510 was not recorded in the books.</p>
<p>e)     A collection of Rs.2,000 from a customer was posted in the Creditors account.</p>
<p>f)      Rent for one month Rs.2,500 was recorded in the books as rent of the residential house of the proprietor.</p>
<p>g)     Some old furnitures were purchased at Rs.2,000 for resale. But they were recorded in the books as fixed assets and depreciation was charged @10%.</p>
<p>h)     A fixed deposit of Rs.5,000 was matured and Rs.7,500 was realized. But the entire amount was credited to Fixed Deposit Account.</p>
<p><em>Show the necessary journal entries to rectify the errors, prepare a Profit and Loss adjustment account and a Balance sheet after rectification.</em></p>
<p><em> </em></p>
<p>Illustration:</p>
<p>After completing a draft Profit and Loss  account for the year ended April, 30, 1997 of ABC Ltd, the following balances remained and a Suspense account entry was required for the difference which had arisen: (all figures in Rupees)</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="362">Fixed assets at cost</td>
<td valign="top" width="65">60,000</td>
<td valign="top" width="79">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="362">Provision for Depreciation</td>
<td valign="top" width="65">&nbsp;</td>
<td valign="top" width="79">31,000</td>
</tr>
<tr>
<td valign="top" width="362">Ordinary share capital</td>
<td valign="top" width="65">&nbsp;</td>
<td valign="top" width="79">35,000</td>
</tr>
<tr>
<td valign="top" width="362">Retained earnings</td>
<td valign="top" width="65">&nbsp;</td>
<td valign="top" width="79">12,300</td>
</tr>
<tr>
<td valign="top" width="362">Stock in trade, at cost</td>
<td valign="top" width="65">14,000</td>
<td valign="top" width="79">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="362">Sales ledger control account</td>
<td valign="top" width="65">9,600</td>
<td valign="top" width="79">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="362">Purchases ledger control account</td>
<td valign="top" width="65">&nbsp;</td>
<td valign="top" width="79">6,500</td>
</tr>
<tr>
<td valign="top" width="362">Balance at Bank</td>
<td valign="top" width="65">1,640</td>
<td valign="top" width="79">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="362">Suspense account (Difference on balance)</td>
<td valign="top" width="65">&nbsp;</td>
<td valign="top" width="79">440</td>
</tr>
<tr>
<td valign="top" width="362">&nbsp;</td>
<td valign="top" width="65">85,240</td>
<td valign="top" width="79">85.240</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>After investigation: the following discoveries were made:</p>
<p>                    i)            A rent payment of Rs.350 in March, 1997 had been debited in the sales Ledger control account.</p>
<p>                   ii)            Although instructed to do so, the accounts clerk had not set a debt due from B Bell of Rs.1,560 in the sales ledger control account against an amount due to B Bell in the purchase ledger control account.</p>
<p>                 iii)            Discounts allowed of Rs.500 during the year ended 30 April, 1997 had not been recorded in the company’s accounts.</p>
<p>                 iv)            No entry had been made for the refund of Rs.2,620 made by cheque to L. Green in March, 1997, in respect of defective goods returned to the company. [<em>note: the correct entries had been made previously for the return of the goods to ABC Limited]</em></p>
<p>                  v)            The purchases day book for February, 1997 had been under cast by Rs.300.</p>
<p>                 vi)            A payment of Rs.1,000 to K. Bloom in January, 1997 for cash purchases had debited in the purchases Ledger control accounts. [Note: The company does not maintain a credit account with K.Bloom]</p>
<p>               vii)            No entries had been made in the company’s books for cash sales of Rs.2,450 on April 30, 1997 and banked on that date.</p>
<p>              viii)            No entries had been made in the company’s books for the bank charges of Rs.910 debited in the company’s bank account in December, 1996.</p>
<p>                 ix)            The company’s cash book (bank debit column) had been overcast by Rs.1,900 in March, 1997</p>
<p>                  x)            A cheque payment of Rs.8,640 for new fixtures and fittings in April, 1997 had not been recorded in the company’s books.</p>
<p>                 xi)            A payment by cheque for rs.1,460 in June 1996 for stationary had not been posted to the appropriate nominal account.</p>
<p>&nbsp;</p>
<p><em>You are required to prepare: (a) Journal entries to reflect the above; (b) The suspense account, clearing the balance and ; (c) A corrected Balance sheet.</em></p>
<p>&nbsp;</p>
<p>Illustration:</p>
<p>The first draft of the final accounts of Torkard Traders disclosed a net profit of Rs.41,004 and a capital employed of Rs.3,52,600 before providing for the manager’s efficiency bonus, but including Rs.8,928 (credit balance) for errors held in suspense.</p>
<p>H Huthwaithe, the manager, receives a basic salary plus an annual bonus of Rs.300 for every complete percentage point by which the net profit to capital employed percentage exceeds 10%. In this context, net profit is before charging the manager’s bonus, and capital employed is defined as fixed assets plus working capital . the bonus calculation is not carried out until the figure have been audited. During the course of audit, it was discovered that:</p>
<p>a)      Discounts allowed Rs.536, had been credited to Discount Received Account.</p>
<p>b)     The sale for cash, of some disused fixtures and fittings which had been completely written off in a previous year, had been credited to Fixtures and Fittings Rs.470</p>
<p>c)     An amount of Rs.380 owed by M &amp; Co. for goods supplied had been settled in contra against an amount of Rs.850 owing to M &amp; Co., but ledger entries had not yet been made.</p>
<p>d)     A glass Canboy  containing chemicals, which was kept in the warehouse, had sprung a leak. The resultant seepage had caused irreparable damage to stock valued at Rs.800 but no account has yet been taken of this fact.</p>
<p>e)     Due to an oversight, credit sales for the last three days of the accounting year, amounting to Rs.1,575 have been completely omitted from the Sales Day Book.</p>
<p>f)      In the Purchase Day Book, a subtotal of Rs.27, 183.54 had been carried forward as  Rs.37,183.54. Creditors however, have been correctly posted.</p>
<p>g)     A credit sale invoice of Rs.978 had been entered in the sales Day Book as Rs.789.</p>
<p>h)     A credit note from a supplier for Rs.21 in respect of faulty goods, had not been posted.</p>
<p>i)       The proprietor of Torkard Traders sometimes, for his convenience, abstracts cash from the till for personal purposes. During the year, this has amounted to Rs.86. The Bookkeeper states that he has ‘reduced cash sales so that the cash book balances.</p>
<p><em>Required: (i) Necessary journal entries to rectify the errors; (ii) Recalculate the net profit and capital employed figures after the above errors have been corrected; (iii) Calculate the manager’s bonus; and (iv) Open the suspense account and post the eliminating entries.</em></p>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/know-about-accounts/'>Know About Accounts</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1278/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1278&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/09/24/know-about-accounts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>
	</item>
		<item>
		<title>Know about Ethical Issues in Software Engineering</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/09/24/know-about-ethical-issues-in-software-engineering/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/09/24/know-about-ethical-issues-in-software-engineering/#comments</comments>
		<pubDate>Sat, 24 Sep 2011 14:04:39 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[know about Ethical Issues in Software Engineering]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1276</guid>
		<description><![CDATA[Ethical Issues in Software Engineering &#8230;Written by meher. Every person sets some goals to be achieved in life, both personal goals and professional goals. One has to work towards achieving these goals. Achieving these goals is important, so is the means and ways to achieve them. Is it OK to take bribe to get rich? Is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1276&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="text-align:center;"><a title="Permanent link to Ethical Issues in Software Engineering" href="http://sailjamehra.wordpress.com/2009/03/21/ethical-issues-in-software-engineering/" rel="bookmark">Ethical Issues in Software Engineering</a></h2>
<h4 style="text-align:right;"><span style="color:#0000ff;">&#8230;Written by meher</span>.</h4>
<p>Every person sets some goals to be achieved in life, both personal goals and professional goals. One has to work towards achieving these goals. Achieving these goals is important, so is the means and ways to achieve them. Is it OK to take bribe to get rich? Is it OK to suppress the fact that the software you developed still has bugs just to ensure that the deadline given by the manager is met? Ethical issues come into picture and the individual has to decide what to do depending on what one’s conscience says.</p>
<div>
<div>
<p>As software has become the lifeline of many systems, the software professional needs to be aware of the ethical issues connected with the software engineering and it is the manager’s responsibility to bring this awareness to all the team members. We will discuss the ethical issues and the code of ethics for software professionals.</p>
<p><strong>Human Ethics</strong></p>
<p>Every human being has certain responsibilities towards the society and the surrounding environment. As good citizens of the world, we all have to contribute our might to make the world a better place to live in. As human beings, we have to follow certain principles to achieve this. Our responsibilities include doing good for the society and following the rules and regulations set by the government for one’s country’s growth, prosperity and security. While doing so, one may encounter conflicts—as to what is ‘good’ and what is ‘bad’. We hear a number of episodes wherein individuals fight rules and regulations—it is such people, who create history and also contribute to the growth of the profession. As an example, one may feel that the regulations framed by governments are not correct (for instance the regulation that encryption software cannot be exported). If one has a strong conviction that it is not correct, one can fight against it. Ethical issues are highly subjective and one has to be guided by one’s conscience.</p>
<p><strong>Professional Ethics</strong></p>
<p>A professional, doctor or engineer or chartered accountant, has further obligations to the society because professionals play a greater role in designing the future for the rest of the society. Every professional has to adhere to a ‘code of ethics’—the guidelines to be followed while discharging one’s duties as a professional.</p>
<p>The code of ethics framed by IEEE, the largest professional body of electrical and electronics engineers, can be found at the web site www.ieee.org</p>
<p><strong>Ethical Issues in Software Engineering</strong></p>
<p>With the influence of computers on all walks of life and the role of software in all the systems, software professionals have the power to do good or bad to the society. As responsible human beings and as professionals, we need to use the knowledge and skills for the benefit of the society. Every software professional has to follow a code of ethics keeping in view the importance of quality software development and the ill effects of</p>
</div>
<p>&nbsp;</p>
<div>
<p>defective software. The quality of software will affect the society and human life—the impact of defective software in such systems as medical equipment, transportation systems, nuclear plants, banking etc., are not difficult to imagine.</p>
<p>&nbsp;</p>
<p>IEEE Computer Society and Association for Computing Machinery (ACM), two major professional bodies jointly established a task force to frame software engineering code of ethics and professional practice. According to this code, every software professional has obligations to</p>
<p>(a)         Society</p>
<p>(b)        Self</p>
<p>(c)         Profession</p>
<p>(d)        Product</p>
<p>(e)         Employer</p>
<p>(f)            Client</p>
<p>(g)         Colleagues</p>
<p>These obligations have to be fulfilled by every person as</p>
<p>(a)       a human being</p>
<p>(b)      a professional</p>
<p>(c)       a software engineering professional</p>
<p>While discharging one’s duties, sometimes there may be a conflict between the obligations to different entities. Consider the following examples:</p>
</div>
<p>&nbsp;</p>
<p> At the place of work, you may be constrained to violate copyright laws. What would<br />
you do?</p>
<p>(a)         The employer (or the manager to whom you report) insists on violating intellectual<br />
property rights by asking you to use software developed by someone else. Would you<br />
accept to do it or not?</p>
<p>(b)        The employer insists on delivering software to the client in spite of the fact that there<br />
are some known defects. You insist on informing the client about the defects, your<br />
employer says no. What stand do you take? If the software is to be used in the<br />
intensive care unit of a hospital, would you accept?</p>
<p>(c)         A colleague of yours is passing the confidential information of your organization to<br />
an outsider. Will you be silent or inform your superiors?</p>
<p>The answers to these questions (and many more such questions which we encounter during our careers) depend on whether we promote our self-interest or accept what the manager/employer says; or as professionals with ethical values, use our judgment to do what we think is RIGHT—irrespective of the consequences.</p>
<p><strong>Code of Ethics for Software Engineers</strong></p>
<p>Ethical issues have no boolean (yes/no) answer. One has to use one’s own judgment and do what one feels is right. Many professional bodies formulated code of ethics, a set of guidelines, which can be used by professionals to make judgments.</p>
<p>The Code of Ethics and Professional Practice framed by the IEEE Computer Society and Association for Computing Machinery (ACM) joint task force, is available at</p>
<p>www.computer.org/certification/ethics.htm or</p>
<p>Software Engineering Code of Ethics and Professional Practice, IEEE Computer, Vol. 32, No. 10, October 1999.</p>
<p><strong>Ethical Issues: Right versus Wrong</strong></p>
<p>While pursuing a career in software engineering, we all encounter situations in which there may not be right/wrong answer for a particular question. In such cases, one should always use one’s own judgment to decide what is right and what is wrong, but that judgment should be based on realistic reasoning and with adequate background information. For instance, there are professionals who feel that working in defense organizations particularly in projects for destroying mankind is wrong; but many of those who work on such projects are proud of their contributions for the defense of their countries. These are two different viewpoints—it is not correct to say that one is right and the other is wrong. One has to decide for oneself.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The broad guidelines as given in the code of ethics are to ensure that no damage is done to human life and society at large for the sake of personal advancement. Every software professional’s main objective must be to improve the quality of life.</p>
<p>Everywhere, money, power and fame drive human beings. To achieve their personal goals, the ethics are set aside resulting in corruption, crime and unhealthy social life. Professionals who have a great role to play to make the world a better place to live, need to follow the code of ethics. As software becomes the lifeline of many critical systems, the software professionals have a great responsibility so that the society respects the software profession. It is not enough to have technical competence, one has to have social consciousness and contribute to improve the quality of life through ethical behavior.</p>
</div>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/know-about-ethical-issues-in-software-engineering/'>know about Ethical Issues in Software Engineering</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1276/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1276&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/09/24/know-about-ethical-issues-in-software-engineering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>
	</item>
		<item>
		<title>How the Training Process in Software Project</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/09/20/how-the-training-process-in-software-project/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/09/20/how-the-training-process-in-software-project/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 14:41:42 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[How the Training Process in Software Project]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1270</guid>
		<description><![CDATA[The Training Process ..Writeen by Meher. &#160; The success of a project is solely dependent on creating a team that can perform with dedication, quality consciousness and time consciousness. If the project manager is capable of creating such a team, half the battle is won. It is said that the software projects are never managed adequately. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1270&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="text-align:center;"><a title="Permanent link to The Training Process" href="http://sailjamehra.wordpress.com/2009/03/21/the-training-process/" rel="bookmark">The Training Process</a></h2>
<h4 style="text-align:right;">..<span style="color:#0000ff;">Writeen by Meher.</span></h4>
<p>&nbsp;</p>
<div>
<div>
<p>The success of a project is solely dependent on creating a team that can perform with dedication, quality consciousness and time consciousness. If the project manager is capable of creating such a team, half the battle is won.</p>
<p>It is said that the software projects are never managed adequately. True. It is extremely difficult to manage each and every aspect of the project-for example to review each and every line of code written by all the programmers. So, the manager has to inculcate the quality consciousness in the individual engineers and programmers so that each and every activity is of high quality.</p>
<p>The project manager has to select the right persons for the job, give the necessary orientation on the tools and application domain, educate them on the software development life cycle and quality standards and create the right atmosphere so that the team members will give their best. The project manager has to act as a mentor and motivator, as a counselor and of course sometimes as a boss as well. The foremost priority is to be given to training the team members on all aspects of the project.</p>
<p>We will discuss the various aspects on the training to be imparted to the team members; and how the information can be shared among the employees through Enterprise Information Infrastructure.</p>
<p><strong>Orientation Program</strong></p>
<p>After formation of the project team and before starting the development work, the project team has to undergo an orientation program which includes the following topics:</p>
<p>•         Rules and regulations of the organization</p>
<p>•         Client details and scope of the project</p>
<p>•         Communication skills</p>
<p>•         Teamwork</p>
<p>•         Software development tools</p>
<p>•         Application domain</p>
<p>•         Software engineering principles</p>
<p>•         Quality standards</p>
<p>•         Ethical issues</p>
<p>If the entire team is selected afresh, rather than deploying people from other divisions/groups of the organization, this orientation is a must. We will briefly discuss these aspects in the following sections.</p>
<p><strong>Rules and Regulations of the Organization</strong></p>
<p>New employees have to be informed of the various rules and regulations of the organization. These include timings, leave rules, travel rules, details of salary and perks,</p>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div>
<p>transfer rules etc. The employees also need to be informed of the various facilities that are available such as library/digital library facilities, information that can be shared over the Intranet of the organization, Internet access facilities etc.</p>
<p>The project manager also has to share the vision and the overall objectives of the organization. Periodic updating of the progress of the organization also is very helpful to make the employees develop affinity towards the organization.</p>
<p><strong>Client Details and Scope of the Project</strong></p>
<p>The team members should be informed the details of the client. Particularly if the client is from another country with another cultural background, the team members should be trained on cross-cultural relations so that cultural differences do not come in the way of good business relation. The etiquette to be followed in face-to-face meetings, at dinner parties and even in e-mail communication and telephone conversations differ from culture to culture or country to country. The team members must be trained on these finer aspects.</p>
<p>The project team also must be apprised of the scope of the project. The project manager can keep the agreement with the client confidential, but the team should be informed of the technical aspects—scope of work, deliverables, time frame, documentation to be supplied, quality processes to be followed etc.</p>
<p><strong>Communication Skills</strong></p>
<p>Effective communication is crucial for the success of any project. Software is divided into modules and each module is divided into units, and each unit is given to an individual; and if there is no interaction, the software can never be integrated and made to work. The project manager has to make the hierarchy of the project team very clear and also inform the members the authorities and responsibilities of each individual. The reviews that will be conducted during the execution of the project, as mentioned in the project plan document, should be informed to all the team members.</p>
<p>Peer reviews: The project manager has to cultivate the habit of the team members sitting together and reviewing the development periodically. Many informal reviews (over a cup of coffee in the canteen) would also do great wonders.</p>
<p>In addition, formal review meetings need to be conducted periodically, say once in a fortnight and all the issues have to be discussed openly. All the important issues discussed and decisions arrived at have to be recorded and communicated to the project manager.</p>
<p>The peer reviews are required to review specifications, design, source code, test plan, test reports and the acceptance test plan and results.</p>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div>
<p>Communication with the manager: The manager has to create an open atmosphere so that the members can freely express their opinions. At the beginning of the project itself, the manager has to make it clear that free and frank opinions need to be given. Many software project fiascoes would have been avoided if this simple thing is followed.</p>
<p>This free communication would bring out the possible risk factors. For instance, one team member may say, during the course of the project, that the time frame is not sufficient. If that member is bulldozed to keep his mouth shut, the issue is not resolved. The manager has to listen to his argument and see the possible impact of what has been said. May be it is an uncalled for fear, or may be it is due to an unforeseen fact. Risk assessment greatly improves through this open communication process.</p>
<p>Communication with other groups: The development team has to interact with other groups such as <strong>QA, </strong>test group, process group etc. These group meetings also have to be planned and open discussions should be held. The important issues discussed and decisions made have to be recorded.</p>
<p>Communication with the client: The manager has to make it clear the exact interfaces with the client—who will do the formal communication. If the client talks to a team member who does not have the global picture of the entire project, the client may get a wrong impression about the status of the project. If the client talks to the team members directly, the team members have to be advised that they should only tell about the module on which he/she has the total knowledge but does not pass a loose remark. The project manager also has to inform the client the names of the persons who will act as interface to the development team.</p>
<p>Written communications: Many times, the changes in specifications or design etc. are done through oral discussions. Particularly, in off-shore execution models, there is a great risk of this kind of change in specifications through telephone. It may happen that the manager forgets some of them and the client says T told you’. Any such changes discussed orally, should be followed up by written communication—if not through paper, at least by email. A bit of bureaucracy is better than relying on the memory of human beings!</p>
<p><strong>Teamwork</strong></p>
<p>Team effort is essential in software development projects. To recruit persons who can work as team members is the first important step. During the recruitment process, the interviewer has to look for past experience on projects which have team size of at least 5. People who did projects all alone need to be probed into their personality traits, some people do admit that they are not good team players. Depending on the project requirement, such people need to be eliminated unless there is a plan to develop single person armies for some specific projects.</p>
<p>All the engineers need to be given an orientation on the teamwork—to respect others’ opinions, to work together in spite of personal differences, to be honest in admitting a</p>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div>
<p>mistake, to be truthful in revealing the defects still in the code or design and so on. The engineers also need to be trained on the ethical issues as related to the colleagues.</p>
<p>The manager also needs to be impartial. Showing partiality towards one person in the team leads to discontent and lack of team spirit.</p>
<p>The manager’s responsibility is to curb politics that arises out of personal rivalries. Many projects get delayed or fail because of lack of cooperation amongst the team members, that too for petty silly personal reasons. The manager has to identify the root cause and the person responsible for the politics and take stern action. Otherwise, project is doomed.</p>
<p><strong>Software Development Tools</strong></p>
<p>The project manager, during the planning stage, has to identify the skills required for the project on hand. These skills include:</p>
<p>•         Operating system(s)</p>
<p>•         Programming language(s)</p>
<p>•         Database management system(s)</p>
<p>•         CASE tools</p>
<p>•         Any specific application software packages</p>
<p>•         Hardware platforms (such as DSP, micro-controllers etc.)</p>
<p>After identifying the skills required, the manager has to identify the people who have the requisite knowledge. It may not be possible to get people who are well versed in all the tools. One way of solving this problem is to have a team in which these skills are available or to give an orientation program whereby people can be trained on the specific tools.</p>
<p><strong>Domain Knowledge</strong></p>
<p>In addition to knowledge of the programming languages and other development tools, the team members should have sound domain knowledge. It is not difficult to gain knowledge in general business practices and procedures such as inventory management, purchase and sales procedures etc., but for domains such as telecommunications, data communications, computer telephony integration, artificial intelligence applications etc., specialized knowledge is required. If the project is very highly specialized, domain experts must be recruited for the project team. Even then, the team members need to be given the necessary orientation on the domain so that the developers understand the jargon of the domain expert.</p>
<p>Even in major organizations, the training in application domain is not given enough thrust and the developers are pushed into the job directly resulting in delay in the project execution. The developers may be very good at coding, but unless they understand the intricacies of the application, they will not be able to do a good job.</p>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div>
<p><strong>Software Engineering Principles</strong></p>
<p>Most of the software engineers consider software development as coding. The project manager knows better! It is not enough if the project manager is process-oriented, each and every team member must appreciate the need and importance of the process of software development. Hence all the members must be trained on the basic software engineering principles, which include</p>
<p>•         Software development life cycle models</p>
<p>•         Software execution models</p>
<p>•         Requirements specifications</p>
<p>•         Design principles</p>
<p>•         Implementation issues</p>
<p>•         Testing methodologies</p>
<p>•         Maintenance and configuration management</p>
<p>•         Software metrics</p>
<p>•         Basic project management principles</p>
<p><strong>Quality Standards</strong></p>
<p>Every organization must base its development process on international quality standards/guidelines. ISO 9000 and CMM are the two standards which have been recognized internationally. If the organization has already obtained certification, it is mandatory to train each and every employee on the quality standards and process definitions. Even otherwise, the project manager has to train the team members on the quality processes to be followed for the specific project. The project manager also has to invite the team members to actively contribute for the process improvement.</p>
<p>In small organizations, training the team members on Personal Software Process (PSP) would be very beneficial.</p>
<p><strong>Ethical Issues in Software Engineering</strong></p>
<p>Sometimes the progress of the project is jeopardized because of lack of ethical values in the development engineers. Some major problems are</p>
<p>•         Due to ignorance or due to vested interest, some engineers may leak the commercial<br />
information of the project to the competitors. Particularly engineers without any<br />
practical experience may do such a thing out of ignorance. To avoid problems arising<br />
out of such behavior, the project manager has to brief the team members about the<br />
confidentiality issues.</p>
<p>•         In the case of product development, the engineers have to maintain confidentiality as<br />
regards the technical aspects of the project as well. Revealing the product information<br />
to the outsiders may result in a competitor developing the same or similar product.</p>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div>
<p><strong>Enterprise Infrastructure</strong></p>
<p>For dissemination of information to all the employees, no additional infrastructure is required other than the infrastructure available for development viz., a Local Area Network (LAN). All the employees’ workstations/PCs have to be connected over the LAN for easy access to the information stored on the servers.</p>
<p>The LAN has to be configured as an Intranet using the necessary hardware and software viz., a web server, a mail server, firewall software along with the browser software on each node.</p>
<p><strong>Enterprise Information</strong></p>
<p>The Intranet has to be used for dissemination of information to all the employees. The information can be divided under the following headings:</p>
<p>•         Company profile:  Information about the organization, history, client list,<br />
profile of the promoters and stakeholders, projects executed, employees<br />
details, divisions and products etc.</p>
<p>•         Staff rules: Employee benefits, leave rules, promotion policies, salary and<br />
perks policies, continuing education programs offered, appraisal system etc.</p>
<p>•  Product   documentation:   Details   of   the   products   developed   in   the<br />
organization, and the details of each product such as specifications, project<br />
plan, design document, test plan, test reports, postmortem analysis report etc.</p>
<p>•         Process   documentation:   Quality   policy,   formats   for   project   proposal,<br />
feasibility  analysis  report,   SRS   document,   design   document,   test  plan,<br />
configuration management plan, test report, postmortem analysis report, user<br />
manual etc.</p>
<p>•         Forms: Forms to be used for making requests for changes in process such as<br />
engineering change note, engineering change request, process change request,<br />
process change note etc. Leave form, appraisal form can also be submitted<br />
electronically over the Intranet.</p>
<p>•         E-learning: The internal training program material containing the lecture<br />
material, study material, e-books (books in electronic form), sample codes in<br />
different programming languages, reusable code etc.</p>
<p><strong>Enterprise Information Distribution</strong></p>
<p>The information mentioned above can be organized as a simple web document (“Body of Knowledge”) and kept on the server. The typical home page of the Intranet for software development organizations is shown in Fig. 1. This essentially involves writing simple HTML code and providing the necessary links to various documents.</p>
</div>
<p>&nbsp;</p>
<div>
<p>&nbsp;</p>
<p>Accessing this information is very simple. One has to get on to the home page and click on the required links to obtain the required information. Of course, a web master has to continuously update the material for providing up-to-date information to all the employees.</p>
<p>Distribution of information using this approach has many advantages.</p>
<p>&gt;       Whenever a new employee joins the organization, lot of time has to be spent by<br />
senior personnel explaining about the organization policies, rules and regulations,<br />
products and divisions, and also taking around the library (the brick and mortar<br />
library) and informing about the various manuals and documents available for<br />
reference. Using the Intranet, this information is readily available literally, at<br />
one’s fingertips. So, all the effort required in giving the necessary orientation is<br />
saved.   Also,   since   organization-wide   information   is   available   to   all   the<br />
employees, the employee can get necessary information about other divisions, for<br />
instance, when he/she is looking out for a change of division.</p>
<p>&gt;       During the course of one’s work, employees may like to refer the documentation<br />
of the past projects, to get a design idea or to get a hint on an implementation<br />
approach. As the product/project information is readily available, the employee<br />
can refer to it easily without the need to make inquires as to who were the<br />
responsible persons that worked on the projects.</p>
</div>
<p> During the execution of a project, every employee needs to refer to the process<br />
documents. Because the process documents are continuously updated, if paper<br />
documents are used, it is extremely difficult to know whether the document on<br />
hand is the latest one or not. Over the Intranet, the latest process documents can<br />
be kept and the employee is always sure that he/she is looking at the latest<br />
version.</p>
<p>&gt;      When the employee has to make a suggestion on a process change, or obtain<br />
information about the status of a proposed change, he need not run around, it is<br />
just available on the desktop. Similarly, one can make requests for engineering<br />
changes on the present work products to one’s project manager very easily.</p>
<p>&gt;      In most organizations, ‘reinventing the wheel’ is very common. Different groups<br />
work on same or similar problem and develop code independently. Lot of time<br />
and effort can be saved if reusable components/snippets of code are kept on the<br />
Intranet to be accessed by all. Each component should have the necessary<br />
information on the functionality, inputs, outputs etc. along with the author of the<br />
code and the project for which the code was developed. This software component<br />
repository would reduce the development time drastically.</p>
<p>&gt;      Continuing education programs are required to keep all the employees well<br />
informed about the latest developments in technology and processes. To achieve<br />
this, web-based learning is very cost-effective and the Intranet can be effectively<br />
used. The complete course material (lecture material and study material) can be<br />
kept on the Intranet for self-paced learning by the employees. This module can<br />
also contain an objective testing software so that the employees can do self-<br />
assessment on a particular topic which they learned using the on-line course<br />
material.</p>
<p>&gt;      In addition to the above, lot of ‘tips’ can be shared by the employees across the<br />
organization—when the engineers go for on-site development work in Austria<br />
where to find good Indian restaurants, or which discotheque is the best in Jakarta<br />
and so on.</p>
<p>&gt;      The latest ‘news’ can be easily given to all the employees using the ‘news’ facility<br />
on the Intranet which can be updated regularly by the web master. Through this,<br />
authentic news can be shared with the employees, and the employees need not<br />
depend on the rumors that float around, particularly in large organizations.</p>
<p>To share information is of utmost importance in an organization as it increases the productivity of the employees tremendously. The Intranet provides an excellent platform for sharing the information as it facilitates easy storage, retrieval and updating of information. The project manager has to use this ‘Enterprise Information Infrastructure’ effectively for dissemination of information and also to inform of the new happenings within the organization.</p>
<p>To summarize, if the project manager designs an effective training program and provides an enterprise information infrastructure to share the information and knowledge, and then puts the engineers on the job, he/she can play golf! In most projects, there would be no training and hence the project manager struggles along with all the team members; and as the project deadline approaches, everyone spends sleepless nights.</p>
</div>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/how-the-training-process-in-software-project/'>How the Training Process in Software Project</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1270/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1270&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/09/20/how-the-training-process-in-software-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>
	</item>
		<item>
		<title>Must know the Software Project Management</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/09/18/must-know-the-software-project-management/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/09/18/must-know-the-software-project-management/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 03:25:16 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[Must know the Software Project Management]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1266</guid>
		<description><![CDATA[Basic things that Project Managers must know for the success of IT Project  …..Sri. RaviVarma Thumati (Miracle Software Systems Team Lead · Vishakhapatnam, Andhra Pradesh, India IBM India Pvt Ltd Bangalore, India.) What are activities to be considered while deciding the software project time lines? TIME ACCOUNTING The early part of a project is also a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1266&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="text-align:center;"><a title="Permanent link to Basic things that Project Managers must know for the success of IT Project" href="http://rthumati.wordpress.com/2009/03/16/basic-things-that-project-managers-must-know-for-the-success-of-it-project/" rel="bookmark">Basic things that Project Managers must know for the success of IT Project</a></h2>
<h3 style="text-align:center;"><span style="color:#0000ff;"> …..Sri. RaviVarma Thumati (</span><a href="http://www.facebook.com/pages/Miracle-Software-Systems/114617525216339">Miracle Software Systems</a></h3>
<div style="text-align:right;">Team Lead · Vishakhapatnam, Andhra Pradesh, India</div>
<div>
<div style="text-align:right;"><a href="http://www.facebook.com/pages/IBM-India-Pvt-Ltd/107647785933226">IBM India Pvt Ltd</a></div>
<div style="text-align:right;">Bangalore, India.)</div>
</div>
<h3>What are activities to be considered while deciding the software project time lines?</h3>
<p><strong>TIME ACCOUNTING</strong><br />
The early part of a project is also a good time to begin detailed time accounting, that is, keeping track of how project personnel spend their time. Time accounting is a critical component of project visibility and control on the current project and lays the foundation for more accurate estimates and planning on future projects.</p>
<p>Tune-accounting data enables you to compare estimated time to actual time with the goal of improving future estimates. You can use the breakdown of time spent on activities from one project to help plan future projects. your project can use following the time-accounting categories to decide the time lines.</p>
<ul>
<li>Time-Accounting Category Activity</li>
<li>Management</li>
<li>Administration</li>
<li>Process development</li>
<li>Requirements development</li>
<li>User-interface prototyping</li>
<li>Architecture</li>
<li>Plan</li>
<li>Track progress/status</li>
<li>Report progress/status</li>
<li>Manage project team activities</li>
<li>Manage customer/end-user relations</li>
<li>Manage change</li>
<li>Downtime</li>
<li>Lab setup</li>
<li>Create development process</li>
<li>Review development process</li>
<li>Rework development process</li>
<li>Educate customer or team members about development process</li>
<li>Create User Manual/Requirements</li>
<li>Specification</li>
<li>Review User Manual/Requirements</li>
<li>Specification</li>
<li>Rework User Manual/Requirements</li>
<li>Specification</li>
<li>Report defects detected during requirements development</li>
<li>Create User Interface Prototype</li>
<li>Review User Interface Prototype</li>
<li>Rework User Interface Prototype</li>
<li>Report defects detected during prototyping</li>
<li>Create architecture</li>
<li>Review architecture</li>
<li>Rework architecture</li>
<li>Report defects detected during architecture</li>
<li>Preliminary Planning</li>
<li>Time-Accounting Category Activity</li>
<li>Detailed design</li>
<li>Implementation</li>
<li>Component acquisition</li>
<li>Integration</li>
<li>System testing</li>
<li>Software release</li>
<li>Metrics</li>
<li>Create detailed design</li>
<li>Review detailed design</li>
<li>Rework detailed design</li>
<li>Report defects detected during detailed design</li>
<li>Create implementation</li>
<li>Review implementation</li>
<li>Rework implementation</li>
<li>Report defects detected during implementation</li>
<li>Investigate/acquire components</li>
<li>Manage component acquisition</li>
<li>Test/review acquired components</li>
<li>Maintain acquired components</li>
<li>Report defects in acquired components</li>
<li>Automate build</li>
<li>Maintain build</li>
<li>Test build</li>
<li>Distribute build</li>
<li>Plan system testing</li>
<li>Create manual for system testing</li>
<li>Create automated system test</li>
<li>Run manual system test</li>
<li>Run automated system test</li>
<li>Report defects detected during system test</li>
<li>Prepare and support alpha, beta, or staged release</li>
<li>Prepare and support final release</li>
<li>Collect measurement data</li>
<li>Analyze measurement data</li>
</ul>
<h2><a title="Permanent link to Effective Project Management" href="http://rthumati.wordpress.com/2009/03/16/effective-project-management/" rel="bookmark">Effective Project Management</a></h2>
<div>
<h4>What are the factors to be considered before resolving a proposed change in project?</h4>
<p>Project team should consider the following factors when it decides how to resolve a proposed change:</p>
<ul>
<li>What is the expected benefit of the change?</li>
<li>How would the change affect the project’s cost?</li>
<li>How would the change affect the project’s schedule?</li>
<li>How would the change affect the software’s quality?</li>
<li>How would the change affect the project’s resource allocation?</li>
<li>Would it add work to people already on the project’s critical path?</li>
<li>Can the change be deferred to a later stage of the project or a later version of the software?</li>
<li>Is the project at a point when making the change would risk destabilizing the software?</li>
</ul>
<p>&nbsp;</p>
<h4>What are the actions can be taken to resolve risks in the software project?</h4>
<p>Following actions can be taken by the project team to resolve a risk in IT Project:</p>
<p><strong>Research</strong><br />
The risk is not yet fully understood. Its impact or likelihood of occurrence may be unclear or the context in which it may occur could seem unreasonable. Further research by members of the project team is warranted.</p>
<p><strong>Accept </strong><br />
The risk is unavoidable and must be accepted as-is. This category of risks become extremely important to a project since they cannot be resolved but still represent a threat to completion. Anticipation therefore become the key to dealing with this category of risk.</p>
<p><strong>Reduce</strong><br />
The risk as it stands is unacceptable. The project team must act to reduce the risk and to establish contingency plans should the risk occur. The risk will have to reviewed in future to define the threat it poses.</p>
<p><strong>Eliminate</strong><br />
The risk is unacceptable under any circumstances and must be eliminated as a possibility. The project team must put in place processes and procedures not only to ensure the immediate threat is eliminated but that it does not re-occur in the future.</p>
<h4>What is the purpose of a project Plan?</h4>
<p>The purpose of a <strong>project plan</strong> is to maintain control of a project. As a complicated process, a project always threatens to exceed the limit of your control. Some people are better than others at controlling complex problems, but all of us reach our limits at some stage. To maintain control you need help in the form of tools and your best tool is your plan. The project plan controls the project by:</p>
<ul>
<li>Breaking a complex process down into a number of simpler components</li>
<li>Providing visibility for obscure or ambiguous tasks in the project</li>
<li>Providing a single point of reference for everyone</li>
<li>Enforcing scrutiny of the sequence and nature of events</li>
<li>Providing a baseline against which execution of the project can be compared</li>
<li>Anticipating likely events and providing pre-planned means of avoiding them</li>
</ul>
<p>A project plan must be as accurate, complete and as specific as possible. How accurate, complete and specific of course depends upon how much time and resources you have.</p>
<p>&nbsp;</p>
<h4>How does a project team plan a project so that it can deliver software on a budget?</h4>
<p>Here are some of the specific <strong>features of a well-planned project</strong>:</p>
<p><strong>A Software Development Plan:</strong> This plan maps a course for the project. Committing the plan to writing allows the project’s stakeholders to refer to the plan throughout the project.</p>
<p><strong>Project estimates: </strong>Project estimates provide a foundation for project plans. A careful estimate leads to scoping the project appropriately, which in turn leads to budgeting, staffing, and scheduling the project appropriately. A shoddy estimate can undercut the project in all these respects, making it difficult to complete the project successfully and impossible to complete it efficiently.</p>
<p><strong>Revised estimates: </strong>Revised estimates created at the end of each major phase of the project allow for mid-course corrections and help to keep the project on solid footing.</p>
<p><strong>A Quality Assurance Plan: </strong>A Quality Assurance Plan that includes both technical reviews and testing assures that the project will not succumb to a costly and defect-ridden test, debug, and correction cycle.</p>
<p><strong>A Staged Delivery Plan:</strong> A Staged Delivery Plan defines the order in which the software will be constructed. It ensures that the software solution is developed to both maximize the value to the customer at each stage and minimize the risks to the project. In addition to the explicit planning activities I just listed, several of a software projects other major activities are also planning activities, though they aren’t usually thought of that way.<br />
<strong>Requirements development:</strong> Requirements development identifies in detail the problem that the project team is trying to solve. It amounts to planning to solve the right problem.</p>
<p><strong>Architecture:</strong> Architecture is a high-level specification for the way in which the problem will be solved. It is a plan to build the right solution to the problem.<br />
<strong>Detailed design:</strong> Detailed design is a comprehensive plan of what the project is going to build. It is a plan to build the right solution in the right way.</p>
<h2><a title="Permanent link to Software Project Team" href="http://rthumati.wordpress.com/2009/03/16/software-project-team/" rel="bookmark">Software Project Team</a></h2>
<p>Posted by Ravi Varma Thumati on March 16, 2009</p>
<div>
<h1>Explain the organization of software project team.</h1>
<p><strong>Software Project Team Organization</strong></p>
<p>A <strong>project team</strong>, no matter what size, needs to differentiate among the various roles played by team members. On small projects, several roles may be performed by one person.</p>
<p><strong>Project manager</strong></p>
<p>The project manager is responsible for orchestrating the detailed technical work of the project, including development, quality assurance, and user documentation. The project manager is responsible for developing the project’s software development plan and is usually the development team’s link to upper management.</p>
<p><strong>Product manager</strong></p>
<p>The product manager is responsible for integrating project work at the business level. On commercial software products, this work includes marketing, product packaging, end-user documentation, end-user support, and the software itself. On in-house projects, this work includes working with groups that will use the system to define the software, setting up training and user support, and planning for cut over to the new system.</p>
<p><strong>Architect</strong><br />
The architect is responsible for the conceptual integrity of the software at the design and implementation level.</p>
<p><strong>User-interface designer</strong></p>
<p>The user-interface designer is responsible for the conceptual integrity of the software at the level visible to the user. On in-house projects, this role can be played by someone from end-user support, user documentation, development, or product management. On commercial products, it should be performed by a user-interface specialist.</p>
<p><strong>End-user liaison</strong></p>
<p>The end-user liaison is responsible for interacting with end users throughout the project walking them through the prototype, demonstrating new releases, eliciting user feedback, and so on. This role can be performed by a developer, product manager, or someone from end-user support.</p>
<p><strong>Development Lead</strong></p>
<p>The development lead is the mid-point in the path between being a developer and being the solutions architect. They are still rooted in the reality of the code and the capabilities of the developers they have working on the project. They were once developers themselves and instead of spending all day every day coding their own tasks they now lead and mentor developers as the developers have problems that they don’t understand.</p>
<p><strong>Developers</strong><br />
Developers are responsible for the detailed design and implementation of the software. Developers are responsible for making the software work.<br />
<strong>QA/Testers</strong><br />
The quality assurance personnel plan and manage test activities, create detailed test plans, and perform tests. They are responsible for finding all the ways to make the software break. If the project is large enough, these people may have their own QA lead or manager.</p>
<p><strong>Tool smith</strong></p>
<p>The tool smith is responsible for developing build scripts, maintaining the source-code control system, developing specialized utilities needed by the project, and so on. Build coordinator. The build coordinator is responsible for maintaining and running the daily build (discussed in Chapter 14) and for notifying developers when their source code breaks the build.</p>
<p><strong>Risk officer</strong></p>
<p>The risk officer is assigned to watch for emerging risks,<br />
<strong>End-user documentation specialists</strong></p>
<p>These specialists are responsible for generating help files, printed documentation, and other instructional materials that end users will use.</p>
<p>&nbsp;</p>
<h1>What are Stakeholders?</h1>
<p><strong>Stakeholders</strong> are an integral part of a project. They are the end-users or clients, the people from whom requirements will be drawn, the people who will influence the design and, ultimately, the people who will reap the benefits of your completed project.</p>
<p>It is extremely important to involve stakeholders in all phases of your project for two reasons. Firstly, experience shows that their involvement in the project significantly increases your chances of success by building in a self-correcting feedback loop. Secondly, involving them in your project builds confidence in your product and will greatly ease its acceptance in your target audience.</p>
<p>There are different types of stakeholders and each type should be handled differently:</p>
<p><strong>Executive:</strong> Executive stakeholders are the guys who pay the bills. Typically they are managers or directors who are involved with commercial objectives for the project. They should restrict themselves to commercial considerations and be actively discouraged from being involved in technical design, their experience and skills are vastly different to that of ‘typical’ end-users.</p>
<p><strong>End-user:</strong> These are the guys that are going to use your product.</p>
<p><strong>Expert:</strong> Sometimes you need input from experts in other fields. People like graphic designers, support reps, sales or lawyers and accountants.</p>
<p>&nbsp;</p>
</div>
</div>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/must-know-the-software-project-management/'>Must know the Software Project Management</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1266/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1266&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/09/18/must-know-the-software-project-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>
	</item>
		<item>
		<title>know about What Is Cancer?</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/09/10/know-about-what-is-cancer/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/09/10/know-about-what-is-cancer/#comments</comments>
		<pubDate>Sat, 10 Sep 2011 13:16:42 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[know about what is cancer]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1249</guid>
		<description><![CDATA[What Is Cancer? Cancer is term that encompasses a complex group of more than 100 different types of cancerous diseases. Cancer can affect just about every organ in the human body. Many people are surprised to learn that cancer can affect parts of the body like eyes and the heart. Each type of cancer is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1249&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="text-align:center;" align="left"><span style="text-decoration:underline;"><strong>What Is Cancer? </strong></span></h2>
<p style="text-align:center;" align="left">Cancer is term that encompasses a complex group of more than 100 different <a href="http://cancer.about.com/od/cancerlistaz/u/cancertypes.htm">types of cancerous diseases</a>. Cancer can affect just about every organ in the human body. Many people are surprised to learn that cancer can affect parts of the body like eyes and the heart.</p>
<p>Each type of cancer is unique with its own causes, symptoms, and methods of treatment. Like with all groups of disease, some types of cancer are more common than others. <a href="http://cancer.about.com/od/cancerlistaz/u/cancertypes.htm">A-Z Index of Types of Cancer</a></p>
<p align="left"><strong>How Does Cancer Develop?</strong></p>
<p align="left">The organs in our body are made up of cells. Cells divide and multiply as the body needs them. When these cells continue multiplying when the body doesn&#8217;t need them, the result is a mass or growth, also called a tumor.</p>
<p>These growths are considered either benign or malignant. Benign is considered non-cancerous and malignant is cancerous. Benign tumors rarely are life threatening and do not spread to other parts of the body. They can often be removed.</p>
<p align="left">Malignant tumors, however, often invade nearby tissue and organs, spreading the disease.</p>
<p align="left"><strong>How Does Cancer Spread to Other Parts of the Body?</strong></p>
<p align="left">The cells within <a href="http://cancer.about.com/od/newlydiagnosed/f/benignmalignant.htm">malignant</a> tumors have the ability to invade neighboring tissues and organs, thus spreading the disease. It is also possible for cancerous cells to break free from the tumor site and enter the bloodstream, spreading the disease to other organs. This process of spreading is called metastasis.</p>
<p>When cancer has metastasized and has affected other areas of the body, the disease is still referred to the organ of origination. For example, if <a href="http://cancer.about.com/od/cervicalcancer/a/whatiscervical.htm">cervical cancer</a> spreads to the lungs, it is still called cervical cancer, not <a href="http://cancer.about.com/od/lungcancer/a/typeslungcancer.htm">lung cancer</a>.</p>
<p>Although most cancers develop and spread this way &#8212; via an organ &#8211; blood cancer like <a href="http://cancer.about.com/od/leukemia/a/whatisleukemia.htm">leukemia</a> do not. They affect the blood and the organs that form blood and then invade nearby tissues.</p>
<h2 style="text-align:left;" align="left"><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/cellularlogo.jpg"><img class="aligncenter size-full wp-image-1251" title="CellularLogo" src="http://meherchilakalapudi.files.wordpress.com/2011/09/cellularlogo.jpg" alt="" width="138" height="138" /></a> </h2>
<p style="text-align:left;" align="left"><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/demo07logo.jpg"><img class="aligncenter size-full wp-image-1253" title="Demo07Logo" src="http://meherchilakalapudi.files.wordpress.com/2011/09/demo07logo.jpg" alt="" width="260" height="138" /></a><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/digestivelogo.jpg"><img class="aligncenter size-full wp-image-1254" title="DigestiveLogo" src="http://meherchilakalapudi.files.wordpress.com/2011/09/digestivelogo.jpg" alt="" width="138" height="138" /></a><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/circulatorylogo.jpg"><img class="aligncenter size-full wp-image-1252" title="CirculatoryLogo" src="http://meherchilakalapudi.files.wordpress.com/2011/09/circulatorylogo.jpg" alt="" width="138" height="138" /></a></p>
<p align="left"><em>About.com Health&#8217;s Disease and Condition content is reviewed by our <a href="http://www.about.com/health/review.htm">Medical Review Board</a> </em></p>
<p align="left"><strong>See More About:</strong></p>
<ul>
<li><a href="http://cancer.about.com/lr/types_of_cancer/50007/1/">types of cancer</a></li>
<li><a href="http://cancer.about.com/lr/fatigue/50007/2/">fatigue</a></li>
<li><a href="http://cancer.about.com/lr/anemia/50007/3/">anemia</a></li>
<li><a href="http://cancer.about.com/lr/brain_tumors/50007/4/">brain tumors</a></li>
</ul>
<div>
<p align="left"><strong>Sponsored Links</strong></p>
</div>
<p><a title="Homeopathic cancer support From England New Zealand" href="http://googleads.g.doubleclick.net/aclk?sa=l&amp;ai=BXIaMxY7pSpCjA5TI6QP9zdnVCez4nrIB4KX_nwzAjbcBwKWsAhABGAEgm9GoBigJOABQyZ3GigRg5frjg5gOsgEQY2FuY2VyLmFib3V0LmNvbcgBAdoBNmh0dHA6Ly9jYW5jZXIuYWJvdXQuY29tL29kL2NhdXNlcy9hL3N5bXB0b21zY2FuY2VyLmh0bakCZiSfyl6xVj6oAwG4AwHoA60D6AP9AfUDAAQAhPUDAABAAA&amp;num=1&amp;sig=AGiWqtyyns3PPaz9J9kUv6KP_OzwNaBR1g&amp;client=ca-about-health_js&amp;adurl=http://www.drshangloo.com/products.php%3Fact%3Dview_product%26prod_cat_id%3D4" target="_blank"><strong>Cancer</strong>Homeopathic cancer support From England New Zealandwww.drshangloo.com</a></p>
<p><a title="Unusual article with crazy tips to help you burn abdominal fat." href="http://googleads.g.doubleclick.net/aclk?sa=l&amp;ai=BCDhmxY7pSpCjA5TI6QP9zdnVCfvNq2mH2Y7aEMCNtwGgjQYQAhgCIJvRqAYoCTgAUJST0NMDYOX644OYDqAB5erG_gOyARBjYW5jZXIuYWJvdXQuY29tyAEB2gE2aHR0cDovL2NhbmNlci5hYm91dC5jb20vb2QvY2F1c2VzL2Evc3ltcHRvbXNjYW5jZXIuaHRtgAIBqAMBuAMB6AOtA-gD_QH1AwAEAIT1AwAAQAA&amp;num=2&amp;sig=AGiWqtxw79KUlkyGrbKlso3ouNonOwcLMA&amp;client=ca-about-health_js&amp;adurl=http://m231g.mikegeary1.hop.clickbank.net/%3Ftid%3Dggtxt" target="_blank"><strong>5 Tips for a Flat Belly:</strong>Unusual article with crazy tips to help you burn abdominal fat.www.TruthAboutAbs.com</a></p>
<p><a title="Latest Advances for Glioblastoma Multiforme - Yours Free." href="http://googleads.g.doubleclick.net/aclk?sa=l&amp;ai=BkazJxY7pSpCjA5TI6QP9zdnVCdaXmQa0l_nmDdCN-rgDoP4KEAMYAyCb0agGKAk4AFCnhqqF-P____8BYOX644OYDqABss-7_wOyARBjYW5jZXIuYWJvdXQuY29tyAEB2gE2aHR0cDovL2NhbmNlci5hYm91dC5jb20vb2QvY2F1c2VzL2Evc3ltcHRvbXNjYW5jZXIuaHRtgAIBqAMBuAMB6AOtA-gD_QH1AwAEAIT1AwAAQAA&amp;num=3&amp;sig=AGiWqty5qvVenNoi8gZYMBHFmbUcbnPlqA&amp;client=ca-about-health_js&amp;adurl=http://www.glioblastoma-info.com/guide_detail.asp%3Fgid%3DOC009%26a%3Da%26assoc%3DGoogle%26keyword%3Dglioblastoma" target="_blank"><strong>Glioblastoma Multiforme</strong>Latest Advances for Glioblastoma Multiforme &#8211; Yours Free.www.glioblastoma-info.com</a></p>
<p><a href="mN(9);"><strong>Cancer Ads</strong></a></p>
<p align="left"><a href="http://cancer.about.com/z/js/o.htm?k=symptoms%20of%20breast%20cancer&amp;d=Symptoms%20of%20Breast%20Cancer&amp;r=http%3A//cancer.about.com/od/causes/a/symptomscancer.htm" target="_top">Symptoms of Breast Cancer</a> <a href="http://cancer.about.com/z/js/o.htm?k=causes%20of%20colon%20cancer&amp;d=Causes%20of%20Colon%20Cancer&amp;r=http%3A//cancer.about.com/od/causes/a/symptomscancer.htm" target="_top">Causes of Colon Cancer</a> <a href="http://cancer.about.com/z/js/o.htm?k=cancer%20pictures&amp;d=Cancer%20Pictures&amp;r=http%3A//cancer.about.com/od/causes/a/symptomscancer.htm" target="_top">Cancer Pictures</a> <a href="http://cancer.about.com/z/js/o.htm?k=liver%20cancer&amp;d=Liver%20Cancer&amp;r=http%3A//cancer.about.com/od/causes/a/symptomscancer.htm" target="_top">Liver Cancer</a> <a href="http://cancer.about.com/z/js/o.htm?k=tumor%20symptoms&amp;d=Tumor%20Symptoms&amp;r=http%3A//cancer.about.com/od/causes/a/symptomscancer.htm" target="_top">Tumor Symptoms</a></p>
<p align="left">Cancer is a broad term that encompasses over one hundred <a href="http://cancer.about.com/od/cancerlistaz/u/cancertypes.htm">different types of cancer</a>. Although each type has its own set of characteristics, there are some cancer symptoms that occur in many types of cancer.</p>
<p align="left">It is important to note that some types of cancer do not present any symptoms until they are in advanced stages. This is why cancer screening and risk assessment are vital for cancer prevention and early detection.</p>
<p align="left"><strong>Symptoms of Cancer</strong></p>
<p align="left">A broad spectrum of non-specific cancer symptoms may include:</p>
<ul>
<li><strong>Persistent Fatigue:</strong> Fatigue is one of the most commonly experienced cancer symptoms. It is usually more common when the cancer is advanced, but still occurs in the early stages of some cancers. Anemia is commonly the culprit &#8212; a condition that is associated with many types of cancer, especially types affecting the bowel. Fatigue is a symptom of both malignant and non-malignant conditions and should be evaluated by a physician.</li>
<li><strong>Unintentional Weight Loss:</strong> While it may be a welcome surprise to lose weight without trying, it can be a red flag for many illnesses, including cancer. Losing 10 pounds or more unintentionally definitely warrants a visit to the doctor. This type of weight loss can occur with or without loss of appetite. Remember, weight loss can be a symptom of cancer, but is also a symptom of many other illnesses, too.</li>
<li><strong>Pain</strong>Typically, pain is not an early symptom of cancer, except in some cancer types like those that spread to the bone. Pain generally occurs when cancer spreads and begins to affect other organs and nerves.Lower pack pain is cancer symptom that is associated with <a href="http://cancer.about.com/od/ovariancancer/a/ovarian_ca.htm">ovarian cancer</a> and <a href="http://cancer.about.com/od/coloncancer/a/colon_overview.htm">colon cancer</a>. Shoulder pain can also be a symptom of <a href="http://lungcancer.about.com/">lung cancer</a>. Pain in the form of headaches can be associated with brain tumors (malignant and benign).
<p>Stomach pains can be related to types of cancer, like stomach cancer, pancreatic cancer, and many others. Stomach pain can be a very vague symptom because so many illnesses can cause stomach pain.</li>
<li><strong>Fever:</strong> A fever is a very non-specific symptom of many mild to severe conditions, including cancer. In relation to cancer, a fever that is persistent or one that comes and goes frequently can signal stress on the immune system. Fevers are commonly associated with types of cancer that affects the blood, like <a href="http://cancer.about.com/od/leukemia/a/leukemia_hub.htm">leukemia</a> and <a href="http://cancer.about.com/od/lymphoma/a/lymphoma_over.htm">lymphoma</a>, but are also common in people whose cancer has spread.</li>
<li><strong>Bowel Changes:</strong> If you experience constipation, diarrhea, blood in the stools, gas, thinner stools, or just a general overall change in bowel habits, see your doctor. These symptoms are most commonly associated with <a href="http://coloncancer.about.com/">colon cancer</a>, but are also related to other cancer types.</li>
<li><strong>Chronic Cough:</strong> A persistent, new cough or a cough that won&#8217;t go away or becomes worse needs to be evaluated by a doctor. Blood and/or mucus may accompany the cough and can be caused many conditions. In relation to cancer, a chronic cough with blood or mucus can be symptom of <a href="http://lungcancer.about.com/">lung cancer</a>.</li>
</ul>
<p align="left">Keep in mind that these are very general, vague symptoms of cancer. If you have one or two of these symptoms, it is not a red flag for cancer but more an indication to your doctor to run certain medical tests. The symptoms listed above are experienced by most people with cancer at various stages of their disease, but are also linked to many other non-cancerous conditions. For more specific cancer symptoms, see below for symptom information about several types of cancer. You may also get a better understanding of what your symptoms may mean by using the <a href="http://symptomchecker.about.com/">About.com Symptom Checker</a>, an interactive health education tool.</p>
<p align="left"><strong>Specific Symptoms of Different Types of Cancer</strong></p>
<p align="left"> </p>
<p><strong>Treatment of Cancer</strong>This list of common cancer types includes cancers that are diagnosed with the greatest frequency in the United States. Cancer incidence statistics from the American Cancer Society<a href="http://www.cancer.gov/cancertopics/commoncancers#1"><sup>1</sup></a> and other resources were used to create the list. To qualify as a common cancer, the estimated annual incidence for 2009 had to be 35,000 cases or more.</p>
<p>The most common type of cancer on the list is nonmelanoma skin cancer, with more than 1,000,000 new cases expected in the United States in 2009. Nonmelanoma skin cancers represent about half of all cancers diagnosed in this country.</p>
<p>The cancer on the list with the lowest incidence is thyroid cancer. The estimated number of new cases of thyroid cancer for 2009 is 37,200.</p>
<p>Because colon and rectal cancers are often referred to as &#8220;colorectal cancers,&#8221; these two cancer types are combined for the list. For 2009, the estimated number of new cases of colon cancer and rectal cancer are 106,100 and 40,870, respectively, adding to a total of 146,970 new cases of colorectal cancer.</p>
<p>Kidney cancers can be divided into two major groups, renal parenchyma cancers and renal pelvis cancers. Approximately 85 percent of kidney cancers develop in the renal parenchyma,<a href="http://www.cancer.gov/cancertopics/commoncancers#2"><sup>2</sup></a> and nearly all of these cancers are renal cell cancers. The estimated number of new cases of renal cell cancer for 2009 is 49,096.</p>
<p>Leukemia as a cancer type includes acute lymphoblastic (or lymphoid) leukemia, chronic lymphocytic leukemia, acute myeloid leukemia, chronic myelogenous (or myeloid) leukemia, and other forms of leukemia. It is estimated that more than 44,790 new cases of leukemia will be diagnosed in the United States in 2009, with chronic lymphocytic leukemia being the most common type (approximately 15,490 new cases).</p>
<p>The following table gives the estimated numbers of new cases and deaths for each common cancer type:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top"><strong>Cancer Type</strong></td>
<td valign="top"><strong>Estimated New Cases</strong></td>
<td valign="top"><strong>Estimated Deaths</strong></td>
</tr>
<tr>
<td valign="top">Bladder</td>
<td valign="top">70,980</td>
<td valign="top">14,330</td>
</tr>
<tr>
<td valign="top">Breast (Female &#8211; Male)</td>
<td valign="top">192,370 &#8211; 1,910</td>
<td valign="top">40,170 &#8211; 440</td>
</tr>
<tr>
<td valign="top">Colon and Rectal (Combined)</td>
<td valign="top">146,970</td>
<td valign="top">49,920</td>
</tr>
<tr>
<td valign="top">Endometrial</td>
<td valign="top">42,160</td>
<td valign="top">7,780</td>
</tr>
<tr>
<td valign="top">Kidney (Renal Cell) Cancer</td>
<td valign="top">49,096</td>
<td valign="top">11,033</td>
</tr>
<tr>
<td valign="top">Leukemia (All)</td>
<td valign="top">44,790</td>
<td valign="top">21,870</td>
</tr>
<tr>
<td valign="top">Lung (Including Bronchus)</td>
<td valign="top">219,440</td>
<td valign="top">159,390</td>
</tr>
<tr>
<td valign="top">Melanoma</td>
<td valign="top">68,720</td>
<td valign="top">8,650</td>
</tr>
<tr>
<td valign="top">Non-Hodgkin Lymphoma</td>
<td valign="top">65,980</td>
<td valign="top">19,500</td>
</tr>
<tr>
<td valign="top">Pancreatic</td>
<td valign="top">42,470</td>
<td valign="top">35,240</td>
</tr>
<tr>
<td valign="top">Prostate</td>
<td valign="top">192,280</td>
<td valign="top">27,360</td>
</tr>
<tr>
<td valign="top">Skin (Nonmelanoma)</td>
<td valign="top">&gt;1,000,000</td>
<td valign="top">&lt;1,000</td>
</tr>
<tr>
<td valign="top">Thyroid</td>
<td valign="top">37,200</td>
<td valign="top">1,630</td>
</tr>
</tbody>
</table>
<p align="left"><strong>Cancer Prevention</strong></p>
<p align="left">Most people don&#8217;t realize that cancer is preventable in many cases. Learning what causes cancer and what the risk factors are is the first step in cancer prevention. Many cancer risk factors can be avoided, thus reducing the likelihood of developing cancer. Of course, some cancer risks like genetics cannot be avoided.</p>
<p>Smoking is the most significant cancer risk factor that we can reduce. It is responsible for not only lung cancer, but many other types of cancer. One of the best ways to prevent cancer is to quit smoking or never start. As soon as you quit, and it&#8217;s never too late, your body reaps the benefits of being tobacco-free</p>
<p>This list of common cancer types includes cancers that are diagnosed with the greatest frequency in the United States. Cancer incidence statistics from the American Cancer Society<a href="http://www.cancer.gov/cancertopics/commoncancers#1"><sup>1</sup></a> and other resources were used to create the list. To qualify as a common cancer, the estimated annual incidence for 2009 had to be 35,000 cases or more.</p>
<p>The most common type of cancer on the list is nonmelanoma skin cancer, with more than 1,000,000 new cases expected in the United States in 2009. Nonmelanoma skin cancers represent about half of all cancers diagnosed in this country.</p>
<p>The cancer on the list with the lowest incidence is thyroid cancer. The estimated number of new cases of thyroid cancer for 2009 is 37,200.</p>
<p>Because colon and rectal cancers are often referred to as &#8220;colorectal cancers,&#8221; these two cancer types are combined for the list. For 2009, the estimated number of new cases of colon cancer and rectal cancer are 106,100 and 40,870, respectively, adding to a total of 146,970 new cases of colorectal cancer.</p>
<p>Kidney cancers can be divided into two major groups, renal parenchyma cancers and renal pelvis cancers. Approximately 85 percent of kidney cancers develop in the renal parenchyma,<a href="http://www.cancer.gov/cancertopics/commoncancers#2"><sup>2</sup></a> and nearly all of these cancers are renal cell cancers. The estimated number of new cases of renal cell cancer for 2009 is 49,096.</p>
<p>Leukemia as a cancer type includes acute lymphoblastic (or lymphoid) leukemia, chronic lymphocytic leukemia, acute myeloid leukemia, chronic myelogenous (or myeloid) leukemia, and other forms of leukemia. It is estimated that more than 44,790 new cases of leukemia will be diagnosed in the United States in 2009, with chronic lymphocytic leukemia being the most common type (approximately 15,490 new cases).</p>
<p>The following table gives the estimated numbers of new cases and deaths for each common cancer type:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top"><strong>Cancer Type</strong></td>
<td valign="top"><strong>Estimated New Cases</strong></td>
<td valign="top"><strong>Estimated Deaths</strong></td>
</tr>
<tr>
<td valign="top">Bladder</td>
<td valign="top">70,980</td>
<td valign="top">14,330</td>
</tr>
<tr>
<td valign="top">Breast (Female &#8211; Male)</td>
<td valign="top">192,370 &#8211; 1,910</td>
<td valign="top">40,170 &#8211; 440</td>
</tr>
<tr>
<td valign="top">Colon and Rectal (Combined)</td>
<td valign="top">146,970</td>
<td valign="top">49,920</td>
</tr>
<tr>
<td valign="top">Endometrial</td>
<td valign="top">42,160</td>
<td valign="top">7,780</td>
</tr>
<tr>
<td valign="top">Kidney (Renal Cell) Cancer</td>
<td valign="top">49,096</td>
<td valign="top">11,033</td>
</tr>
<tr>
<td valign="top">Leukemia (All)</td>
<td valign="top">44,790</td>
<td valign="top">21,870</td>
</tr>
<tr>
<td valign="top">Lung (Including Bronchus)</td>
<td valign="top">219,440</td>
<td valign="top">159,390</td>
</tr>
<tr>
<td valign="top">Melanoma</td>
<td valign="top">68,720</td>
<td valign="top">8,650</td>
</tr>
<tr>
<td valign="top">Non-Hodgkin Lymphoma</td>
<td valign="top">65,980</td>
<td valign="top">19,500</td>
</tr>
<tr>
<td valign="top">Pancreatic</td>
<td valign="top">42,470</td>
<td valign="top">35,240</td>
</tr>
<tr>
<td valign="top">Prostate</td>
<td valign="top">192,280</td>
<td valign="top">27,360</td>
</tr>
<tr>
<td valign="top">Skin (Nonmelanoma)</td>
<td valign="top">&gt;1,000,000</td>
<td valign="top">&lt;1,000</td>
</tr>
<tr>
<td valign="top">Thyroid</td>
<td valign="top">37,200</td>
<td valign="top">1,630</td>
</tr>
</tbody>
</table>
<p><strong>References</strong></p>
<p><strong>                                     Cancer</strong> (medical term: <a title="Malignancy" href="http://en.wikipedia.org/wiki/Malignancy">malignant</a> <a title="Neoplasm" href="http://en.wikipedia.org/wiki/Neoplasm">neoplasm</a>) is a class of <a title="Disease" href="http://en.wikipedia.org/wiki/Disease">diseases</a> in which a group of <a title="Cell (biology)" href="http://en.wikipedia.org/wiki/Cell_(biology)">cells</a> display <em>uncontrolled growth</em> (<a title="Cell division" href="http://en.wikipedia.org/wiki/Cell_division">division</a> beyond the normal limits), <em>invasion</em> (intrusion on and destruction of adjacent tissues), and sometimes <em><a title="Metastasis" href="http://en.wikipedia.org/wiki/Metastasis">metastasis</a></em> (spread to other locations in the body via lymph or blood). These three malignant properties of cancers differentiate them from <a title="Benign tumor" href="http://en.wikipedia.org/wiki/Benign_tumor">benign tumors</a>, which are self-limited, and do not invade or metastasize. Most cancers form a <a title="Tumor" href="http://en.wikipedia.org/wiki/Tumor">tumor</a> but some, like <a title="Leukemia" href="http://en.wikipedia.org/wiki/Leukemia">leukemia</a>, do not. The branch of medicine concerned with the study, diagnosis, treatment, and prevention of cancer is <a title="Oncology" href="http://en.wikipedia.org/wiki/Oncology">oncology</a>.</p>
<p>Cancer may affect people at all ages, even <a title="Fetus" href="http://en.wikipedia.org/wiki/Fetus">fetuses</a>, but the risk for most varieties increases with age.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Cancer_Research_UK-0">[1]</a></sup> Cancer causes about 13% of <a title="Causes of death" href="http://en.wikipedia.org/wiki/Causes_of_death">all human deaths</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-WHO-1">[2]</a></sup> According to the <a title="American Cancer Society" href="http://en.wikipedia.org/wiki/American_Cancer_Society">American Cancer Society</a>, 7.6 million people died from cancer in the world during 2007.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-American_Cancer_Society-2">[3]</a></sup> Cancers can affect all animals.</p>
<p>Nearly all cancers are caused by abnormalities in the <a title="Genome" href="http://en.wikipedia.org/wiki/Genome">genetic material</a> of the <a title="Malignant transformation" href="http://en.wikipedia.org/wiki/Malignant_transformation">transformed</a> cells.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Kinz-3">[4]</a></sup> These abnormalities may be due to the effects of <a title="Carcinogens" href="http://en.wikipedia.org/wiki/Carcinogens">carcinogens</a>, such as <a title="Tobacco smoke" href="http://en.wikipedia.org/wiki/Tobacco_smoke">tobacco smoke</a>, <a title="Electromagnetic radiation" href="http://en.wikipedia.org/wiki/Electromagnetic_radiation">radiation</a>, <a title="Chemicals" href="http://en.wikipedia.org/wiki/Chemicals">chemicals</a>, or <a title="Pathogen" href="http://en.wikipedia.org/wiki/Pathogen">infectious agents</a>. Other cancer-promoting genetic abnormalities may be randomly acquired through errors in <a title="DNA replication" href="http://en.wikipedia.org/wiki/DNA_replication">DNA replication</a>, or are <a title="Genetic disorder" href="http://en.wikipedia.org/wiki/Genetic_disorder">inherited</a>, and thus present in all cells from birth. The <a title="Heritability" href="http://en.wikipedia.org/wiki/Heritability">heritability</a> of cancers is usually affected by complex interactions between carcinogens and the host&#8217;s <a title="Genome" href="http://en.wikipedia.org/wiki/Genome">genome</a>. New aspects of the genetics of cancer pathogenesis, such as <a title="DNA methylation" href="http://en.wikipedia.org/wiki/DNA_methylation">DNA methylation</a>, and <a title="MicroRNAs" href="http://en.wikipedia.org/wiki/MicroRNAs">microRNAs</a> are increasingly recognized as important.</p>
<p>Genetic abnormalities found in cancer typically affect two general classes of genes. Cancer-promoting <em><a title="Oncogene" href="http://en.wikipedia.org/wiki/Oncogene">oncogenes</a></em> are typically activated in cancer cells, giving those cells new properties, such as hyperactive growth and division, protection against <a title="Programmed cell death" href="http://en.wikipedia.org/wiki/Programmed_cell_death">programmed cell death</a>, loss of respect for normal tissue boundaries, and the ability to become established in diverse tissue environments. <em><a title="Tumor suppressor gene" href="http://en.wikipedia.org/wiki/Tumor_suppressor_gene">Tumor suppressor genes</a></em> are then inactivated in cancer cells, resulting in the loss of normal functions in those cells, such as accurate DNA replication, control over the <a title="Cell cycle" href="http://en.wikipedia.org/wiki/Cell_cycle">cell cycle</a>, orientation and adhesion within tissues, and interaction with protective cells of the <a title="Immune system" href="http://en.wikipedia.org/wiki/Immune_system">immune system</a>.</p>
<p>Diagnosis usually requires the <a title="Histology" href="http://en.wikipedia.org/wiki/Histology">histologic</a> examination of a tissue <a title="Biopsy" href="http://en.wikipedia.org/wiki/Biopsy">biopsy</a> specimen by a <a title="Anatomical pathology" href="http://en.wikipedia.org/wiki/Anatomical_pathology">pathologist</a>, although the initial indication of malignancy can be symptoms or <a title="Radiographic" href="http://en.wikipedia.org/wiki/Radiographic">radiographic</a> imaging abnormalities. Most cancers can be treated and some cured, depending on the specific type, location, and <a title="Cancer staging" href="http://en.wikipedia.org/wiki/Cancer_staging">stage</a>. Once diagnosed, cancer is usually treated with a combination of <a title="Surgery" href="http://en.wikipedia.org/wiki/Surgery">surgery</a>, <a title="Chemotherapy" href="http://en.wikipedia.org/wiki/Chemotherapy">chemotherapy</a> and <a title="Radiation therapy" href="http://en.wikipedia.org/wiki/Radiation_therapy">radiotherapy</a>. As research develops, treatments are becoming more specific for different varieties of cancer. There has been significant progress in the development of <a title="Targeted therapy" href="http://en.wikipedia.org/wiki/Targeted_therapy">targeted therapy</a> drugs that act specifically on detectable molecular abnormalities in certain tumors, and which minimize damage to normal cells. The prognosis of cancer patients is most influenced by the type of cancer, as well as the <a title="Cancer staging" href="http://en.wikipedia.org/wiki/Cancer_staging">stage</a>, or extent of the disease. In addition, <a title="Histology" href="http://en.wikipedia.org/wiki/Histology">histologic</a> <a title="Grading (tumors)" href="http://en.wikipedia.org/wiki/Grading_(tumors)">grading</a> and the presence of specific molecular markers can also be useful in establishing prognosis, as well as in determining individual treatments.</p>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td>
<ul>
<li> </li>
</ul>
</td>
</tr>
</tbody>
</table>
<h2>Glossary</h2>
<p><em>Further information: <a title="List of oncology-related terms" href="http://en.wikipedia.org/wiki/List_of_oncology-related_terms">List of oncology-related terms</a></em></p>
<p>The following closely related terms may be used to designate abnormal growths:</p>
<ul>
<li><strong><a title="Tumor" href="http://en.wikipedia.org/wiki/Tumor">Tumor</a> or tumour:</strong> originally, it meant any abnormal swelling, lump or mass. In current English, however, the word tumor has become synonymous with neoplasm, specifically solid neoplasm. Note that some neoplasms, such as <a title="Leukemia" href="http://en.wikipedia.org/wiki/Leukemia">leukemia</a>, do not form tumors.</li>
<li><strong><a title="Neoplasia" href="http://en.wikipedia.org/wiki/Neoplasia">Neoplasm</a>:</strong> the scientific term to describe an abnormal proliferation of genetically altered cells. Neoplasms can be benign or malignant:</li>
<ul>
<li><strong>Malignant neoplasm</strong> or <strong>malignant tumor</strong>: synonymous with <strong>cancer</strong>.</li>
<li><strong>Benign neoplasm</strong> or <strong><a title="Benign tumor" href="http://en.wikipedia.org/wiki/Benign_tumor">benign tumor</a></strong>: a tumor (solid neoplasm) that stops growing by itself, does not invade other tissues and does not form metastases.</li>
</ul>
<li><strong>Invasive</strong> tumor is another synonym of <strong>cancer</strong>. The name refers to invasion of surrounding tissues.</li>
<li><strong>Pre-malignancy</strong>, <strong>pre-cancer</strong> or <strong>non-invasive</strong> tumor: A neoplasm that is not invasive but has the potential to progress to cancer (become invasive) if left untreated. These lesions are, in order of increasing potential for cancer, <a title="Atypia" href="http://en.wikipedia.org/wiki/Atypia">atypia</a>, <a title="Dysplasia" href="http://en.wikipedia.org/wiki/Dysplasia">dysplasia</a> and <a title="Carcinoma in situ" href="http://en.wikipedia.org/wiki/Carcinoma_in_situ">carcinoma in situ</a>.</li>
</ul>
<p>The following terms can be used to describe a cancer:</p>
<ul>
<li><strong>Screening</strong>: a test done on healthy people to detect tumors before they become apparent. A <a title="Mammogram" href="http://en.wikipedia.org/wiki/Mammogram">mammogram</a> is a screening test.</li>
<li><strong>Diagnosis</strong>: the confirmation of the cancerous nature of a lump. This usually requires a <a title="Biopsy" href="http://en.wikipedia.org/wiki/Biopsy">biopsy</a> or removal of the tumor by <a title="Surgery" href="http://en.wikipedia.org/wiki/Surgery">surgery</a>, followed by examination by a <a title="Surgical pathology" href="http://en.wikipedia.org/wiki/Surgical_pathology">pathologist</a>.</li>
<li><strong>Surgical excision</strong>: the removal of a tumor by a <a title="Surgery" href="http://en.wikipedia.org/wiki/Surgery">surgeon</a>.</li>
<ul>
<li><strong>Surgical margins</strong>: the evaluation by a <a title="Surgical pathology" href="http://en.wikipedia.org/wiki/Surgical_pathology">pathologist</a> of the edges of the tissue removed by the surgeon to determine if the tumor was removed completely (&#8220;negative margins&#8221;) or if tumor was left behind (&#8220;positive margins&#8221;).</li>
</ul>
<li><strong>Grade</strong>: a number (usually on a scale of 3) established by a <a title="Surgical pathology" href="http://en.wikipedia.org/wiki/Surgical_pathology">pathologist</a> to describe the degree of resemblance of the tumor to the surrounding benign tissue.</li>
<li><strong>Stage</strong>: a number (usually on a scale of 4) established by the <a title="Oncology" href="http://en.wikipedia.org/wiki/Oncology">oncologist</a> to describe the degree of invasion of the body by the tumor.</li>
<li><strong>Recurrence</strong>: new tumors that appear at the site of the original tumor after surgery.</li>
<li><strong>Metastasis</strong>: new tumors that appear far from the original tumor.</li>
<li><strong>Median survival time</strong>: a period of time, often measured in months or years, over which 50% of the cancer patients are expected to be alive. <sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-4">[5]</a></sup></li>
<li><strong>Transformation:</strong> the concept that a low-grade tumor transforms to a high-grade tumor over time. Example: <a title="Richter's transformation" href="http://en.wikipedia.org/wiki/Richter%27s_transformation">Richter&#8217;s transformation</a>.</li>
<li><strong>Chemotherapy</strong>: treatment with drugs.</li>
<li><strong>Radiation therapy</strong>: treatment with radiations.</li>
<li><strong>Adjuvant</strong> therapy: treatment, either chemotherapy or radiation therapy, given after surgery to kill the remaining cancer cells.</li>
<li><strong>Prognosis</strong>: the probability of cure after the therapy. It is usually expressed as a probability of <a title="Cancer survivor" href="http://en.wikipedia.org/wiki/Cancer_survivor">survival</a> five years after diagnosis. Alternatively, it can be expressed as the number of years when 50% of the patients are still alive. Both numbers are derived from statistics accumulated with hundreds of similar patients to give a <a title="Kaplan-Meier estimator" href="http://en.wikipedia.org/wiki/Kaplan-Meier_estimator">Kaplan-Meier curve</a>.</li>
<li><strong>Cure</strong>: A cancer patient is &#8220;cured&#8221; if 95% of treated patients live a certain period of time after the date of their diagnosis of cancer. For example in the case of Hodgkin&#8217;s disease this period of time is 10 years, whereas for Burkitt&#8217;s lymphoma this period would be 1 year. <sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-5">[6]</a></sup> The phrase &#8220;cure&#8221; used in oncology is based upon the statistical concept of a median survival time and disease-free median survival time. <sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-6">[7]</a></sup></li>
</ul>
<h2>Classification</h2>
<p><em>Further information: <a title="List of cancer types" href="http://en.wikipedia.org/wiki/List_of_cancer_types">List of cancer types</a></em></p>
<p>A large invasive <a title="Mammary ductal carcinoma" href="http://en.wikipedia.org/wiki/Mammary_ductal_carcinoma">ductal carcinoma</a> in a <a title="Mastectomy" href="http://en.wikipedia.org/wiki/Mastectomy">mastectomy</a> specimen.</p>
<p>Cancers are classified by the <a title="List of distinct cell types in the adult human body" href="http://en.wikipedia.org/wiki/List_of_distinct_cell_types_in_the_adult_human_body">type of cell</a> that resembles the tumor and, therefore, the tissue presumed to be the origin of the tumor. These are the histology and the location, respectively. Examples of general categories include:</p>
<ul>
<li><strong><a title="Carcinoma" href="http://en.wikipedia.org/wiki/Carcinoma">Carcinoma</a>:</strong> Malignant tumors derived from <a title="Epithelium" href="http://en.wikipedia.org/wiki/Epithelium">epithelial</a> cells. This group represents the most common cancers, including the common forms of <a title="Breast cancer" href="http://en.wikipedia.org/wiki/Breast_cancer">breast</a>, <a title="Prostate cancer" href="http://en.wikipedia.org/wiki/Prostate_cancer">prostate</a>, <a title="Lung cancer" href="http://en.wikipedia.org/wiki/Lung_cancer">lung</a> and <a title="Colorectal cancer" href="http://en.wikipedia.org/wiki/Colorectal_cancer">colon cancer</a>.</li>
<li><strong><a title="Sarcoma" href="http://en.wikipedia.org/wiki/Sarcoma">Sarcoma</a>:</strong> Malignant tumors derived from <a title="Connective tissue" href="http://en.wikipedia.org/wiki/Connective_tissue">connective tissue</a>, or <a title="Mesenchyme" href="http://en.wikipedia.org/wiki/Mesenchyme">mesenchymal</a> cells.</li>
<li><strong><a title="Lymphoma" href="http://en.wikipedia.org/wiki/Lymphoma">Lymphoma</a></strong> and <strong><a title="Leukemia" href="http://en.wikipedia.org/wiki/Leukemia">leukemia</a>:</strong> Malignancies derived from hematopoietic (<a title="Blood" href="http://en.wikipedia.org/wiki/Blood">blood</a>-forming) cells</li>
<li><strong><a title="Germ cell tumor" href="http://en.wikipedia.org/wiki/Germ_cell_tumor">Germ cell tumor</a>:</strong> Tumors derived from <a title="Totipotent" href="http://en.wikipedia.org/wiki/Totipotent">totipotent</a> cells. In adults most often found in the <a title="Testicle" href="http://en.wikipedia.org/wiki/Testicle">testicle</a> and <a title="Ovary" href="http://en.wikipedia.org/wiki/Ovary">ovary</a>; in fetuses, babies, and young children most often found on the body midline, particularly at the tip of the tailbone; in horses most often found at the poll (base of the skull).</li>
<li><strong>Blastic tumor or <a title="Blastoma" href="http://en.wikipedia.org/wiki/Blastoma">blastoma</a>:</strong> A tumor (usually malignant) which resembles an immature or embryonic tissue. Many of these tumors are most common in children.</li>
</ul>
<p>Malignant tumors (cancers) are usually named using <strong>-carcinoma</strong>, <strong>-sarcoma</strong> or <strong>-blastoma</strong> as a suffix, with the Latin or Greek word for the organ of origin as the root. For instance, a cancer of the liver is called <em><a title="Hepatocarcinoma" href="http://en.wikipedia.org/wiki/Hepatocarcinoma">hepatocarcinoma</a></em>; a cancer of the fat cells is called <em>liposarcoma</em>. For common cancers, the English organ name is used. For instance, the most common type of <a title="Breast cancer" href="http://en.wikipedia.org/wiki/Breast_cancer">breast cancer</a> is called <em>ductal carcinoma of the breast</em> or <em>mammary ductal carcinoma</em>. Here, the adjective <em>ductal</em> refers to the appearance of the cancer under the microscope, resembling normal breast ducts.</p>
<p><a title="Benign tumor" href="http://en.wikipedia.org/wiki/Benign_tumor">Benign tumors</a> (which are not cancers) are named using <strong>-oma</strong> as a suffix with the organ name as the root. For instance, a benign tumor of the smooth muscle of the uterus is called <em>leiomyoma</em> (the common name of this frequent tumor is <em>fibroid</em>). Unfortunately, some cancers also use the <strong>-oma</strong> suffix, examples being <a title="Melanoma" href="http://en.wikipedia.org/wiki/Melanoma">melanoma</a> and <a title="Seminoma" href="http://en.wikipedia.org/wiki/Seminoma">seminoma</a>.</p>
<h2>Signs and symptoms</h2>
<p>Symptoms of cancer metastasis depend on the location of the tumor.</p>
<p>Roughly, cancer symptoms can be divided into three groups:</p>
<ul>
<li><em>Local symptoms</em>: unusual lumps or swelling (<em><a title="Tumor" href="http://en.wikipedia.org/wiki/Tumor">tumor</a></em>), <a title="Hemorrhage" href="http://en.wikipedia.org/wiki/Hemorrhage">hemorrhage</a> (bleeding), <a title="Pain" href="http://en.wikipedia.org/wiki/Pain">pain</a> and/or <a title="Ulcer (dermatology)" href="http://en.wikipedia.org/wiki/Ulcer_(dermatology)">ulceration</a>. Compression of surrounding tissues may cause symptoms such as <a title="Jaundice" href="http://en.wikipedia.org/wiki/Jaundice">jaundice</a> (yellowing the eyes and skin).</li>
<li><em><a title="Symptoms of metastasis" href="http://en.wikipedia.org/wiki/Symptoms_of_metastasis">Symptoms of metastasis</a> (spreading)</em>: enlarged <a title="Lymph node" href="http://en.wikipedia.org/wiki/Lymph_node">lymph nodes</a>, <a title="Cough" href="http://en.wikipedia.org/wiki/Cough">cough</a> and <a title="Hemoptysis" href="http://en.wikipedia.org/wiki/Hemoptysis">hemoptysis</a>, <a title="Hepatomegaly" href="http://en.wikipedia.org/wiki/Hepatomegaly">hepatomegaly</a> (enlarged <a title="Liver" href="http://en.wikipedia.org/wiki/Liver">liver</a>), bone pain, <a title="Fracture" href="http://en.wikipedia.org/wiki/Fracture">fracture</a> of affected bones and <a title="Neurology" href="http://en.wikipedia.org/wiki/Neurology">neurological</a> symptoms. Although advanced cancer may cause <a title="Pain" href="http://en.wikipedia.org/wiki/Pain">pain</a>, it is often not the first symptom.</li>
<li><em>Systemic symptoms</em>: <a title="Weight loss" href="http://en.wikipedia.org/wiki/Weight_loss">weight loss</a>, <a title="Anorexia (symptom)" href="http://en.wikipedia.org/wiki/Anorexia_(symptom)">poor appetite</a>, <a title="Fatigue (medical)" href="http://en.wikipedia.org/wiki/Fatigue_(medical)">fatigue</a> and <a title="Cachexia" href="http://en.wikipedia.org/wiki/Cachexia">cachexia</a> (<a title="Wasting" href="http://en.wikipedia.org/wiki/Wasting">wasting</a>), excessive <a title="Sweating" href="http://en.wikipedia.org/wiki/Sweating">sweating</a> (<a title="Sleep hyperhidrosis" href="http://en.wikipedia.org/wiki/Sleep_hyperhidrosis">night sweats</a>), <a title="Anemia" href="http://en.wikipedia.org/wiki/Anemia">anemia</a> and specific <a title="Paraneoplastic phenomenon" href="http://en.wikipedia.org/wiki/Paraneoplastic_phenomenon">paraneoplastic phenomena</a>, i.e. specific conditions that are due to an active cancer, such as <a title="Thrombosis" href="http://en.wikipedia.org/wiki/Thrombosis">thrombosis</a> or hormonal changes.</li>
</ul>
<p>Every symptom in the above list can be caused by a variety of conditions (a list of which is referred to as the <a title="Differential diagnosis" href="http://en.wikipedia.org/wiki/Differential_diagnosis">differential diagnosis</a>). Cancer may be a common or uncommon cause of each item.</p>
<h2>Causes</h2>
<p><em>Main article: <a title="Carcinogenesis" href="http://en.wikipedia.org/wiki/Carcinogenesis">Carcinogenesis</a></em></p>
<p>Cancer is a diverse class of diseases which differ widely in their causes and biology. Any organism, even <a title="Plants" href="http://en.wikipedia.org/wiki/Plants">plants</a>, can acquire cancer. Nearly all known cancers arise gradually, as errors build up in the cancer cell and its progeny (see <a title="Cancer" href="http://en.wikipedia.org/wiki/Cancer#Mechanisms">mechanisms</a> section for common types of errors).</p>
<p>Anything which replicates (our cells) will <a title="Probability" href="http://en.wikipedia.org/wiki/Probability">probabilistically</a> suffer from errors (mutations). Unless <a title="Error correction" href="http://en.wikipedia.org/wiki/Error_correction">error correction</a> and prevention is properly carried out, the errors will survive, and might be passed along to <a title="Cell division" href="http://en.wikipedia.org/wiki/Cell_division">daughter cells</a>. Normally, the body safeguards against cancer via numerous methods, such as: <a title="Apoptosis" href="http://en.wikipedia.org/wiki/Apoptosis">apoptosis</a>, helper molecules (some DNA polymerases), possibly <a title="Senescence" href="http://en.wikipedia.org/wiki/Senescence">senescence</a>, etc. However these error-correction methods often fail in small ways, especially in environments that make errors more likely to arise and propagate. For example, such environments can include the presence of disruptive substances called <a title="Carcinogens" href="http://en.wikipedia.org/wiki/Carcinogens">carcinogens</a>, or periodic injury (physical, heat, etc.), or environments that cells did not evolve to withstand, such as <a title="Hypoxia" href="http://en.wikipedia.org/wiki/Hypoxia">hypoxia</a><sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-7">[8]</a></sup> (see subsections). Cancer is thus a <em>progressive</em> disease, and these progressive errors slowly accumulate until a cell begins to act contrary to its function in the animal.</p>
<p>The errors which cause cancer are often <em>self-amplifying</em>, eventually compounding at an exponential rate. For example:</p>
<ul>
<li>A mutation in the error-correcting machinery of a cell might cause that cell and its children to accumulate errors more rapidly</li>
<li>A mutation in signaling (<a title="Endocrine" href="http://en.wikipedia.org/wiki/Endocrine">endocrine</a>) machinery of the cell can send error-causing signals to nearby cells</li>
<li>A mutation might cause cells to become <a title="Neoplastic" href="http://en.wikipedia.org/wiki/Neoplastic">neoplastic</a>, causing them to migrate and disrupt more healthy cells</li>
<li>A mutation may cause the cell to become immortal (see <a title="Telomeres" href="http://en.wikipedia.org/wiki/Telomeres">telomeres</a>), causing them to disrupt healthy cells forever</li>
</ul>
<p>Thus cancer often explodes in something akin to a <a title="Chain reaction" href="http://en.wikipedia.org/wiki/Chain_reaction">chain reaction</a> caused by a few errors, which compound into more severe errors. Errors which produce more errors are effectively the root cause of cancer, and also the reason that cancer is so hard to treat: even if there were 10,000,000,000 cancerous cells and one killed all but 10 of those cells, those cells (and other error-prone precancerous cells) could still self-replicate or send error-causing signals to other cells, starting the process over again. This rebellion-like scenario is an undesirable <a title="Survival of the fittest" href="http://en.wikipedia.org/wiki/Survival_of_the_fittest">survival of the fittest</a>, where the driving forces of <a title="Evolution" href="http://en.wikipedia.org/wiki/Evolution">evolution</a> itself work against the body&#8217;s design and enforcement of order. In fact, once cancer has begun to develop, this same force continues to drive the progression of cancer towards more invasive stages, and is called <a title="Cancer" href="http://en.wikipedia.org/wiki/Cancer#Clonal_evolution">clonal evolution</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-8">[9]</a></sup></p>
<p><a title="Cancer research" href="http://en.wikipedia.org/wiki/Cancer_research">Research about cancer</a> causes often falls into the following categories:</p>
<ul>
<li>Agents (e.g. viruses) and events (e.g. mutations) which cause or facilitate genetic changes in cells destined to become cancer.</li>
<li>The precise nature of the genetic damage, and the genes which are affected by it.</li>
<li>The consequences of those genetic changes on the biology of the cell, both in generating the defining properties of a cancer cell, and in facilitating additional genetic events which lead to further progression of the cancer.</li>
</ul>
<h3>Mutation: chemical carcinogens</h3>
<p><em>Further information: <a title="Carcinogen" href="http://en.wikipedia.org/wiki/Carcinogen">Carcinogen</a></em></p>
<p>Cancer pathogenesis is traceable back to <a title="DNA mutations" href="http://en.wikipedia.org/wiki/DNA_mutations">DNA mutations</a> that impact cell growth and metastasis. Substances that cause <a title="DNA mutations" href="http://en.wikipedia.org/wiki/DNA_mutations">DNA mutations</a> are known as mutagens, and mutagens that cause cancers are known as carcinogens. Particular substances have been linked to specific types of cancer. <a title="Tobacco smoking" href="http://en.wikipedia.org/wiki/Tobacco_smoking">Tobacco smoking</a> is associated with many forms of cancer,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Sasco-9">[10]</a></sup> and causes 90% of <a title="Lung cancer" href="http://en.wikipedia.org/wiki/Lung_cancer">lung cancer</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-10">[11]</a></sup> Prolonged exposure to <a title="Asbestos" href="http://en.wikipedia.org/wiki/Asbestos">asbestos</a> fibers is associated with <a title="Mesothelioma" href="http://en.wikipedia.org/wiki/Mesothelioma">mesothelioma</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-11">[12]</a></sup></p>
<p>Many <a title="Mutagen" href="http://en.wikipedia.org/wiki/Mutagen">mutagens</a> are also <a title="Carcinogen" href="http://en.wikipedia.org/wiki/Carcinogen">carcinogens</a>, but some carcinogens are not mutagens. <a title="Alcohol" href="http://en.wikipedia.org/wiki/Alcohol">Alcohol</a> is an example of a chemical carcinogen that is not a mutagen.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-12">[13]</a></sup> Such chemicals may promote cancers through stimulating the rate of cell division. Faster rates of replication leaves less time for repair enzymes to repair damaged DNA during <a title="DNA replication" href="http://en.wikipedia.org/wiki/DNA_replication">DNA replication</a>, increasing the likelihood of a mutation.</p>
<p>The incidence of lung cancer is highly correlated with smoking. Source:NIH.</p>
<p>Decades of research has demonstrated the link between <a title="Tobacco" href="http://en.wikipedia.org/wiki/Tobacco">tobacco</a> use and cancer in the lung, larynx, head, neck, stomach, bladder, kidney, oesophagus and pancreas.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-13">[14]</a></sup> Tobacco smoke contains over fifty known carcinogens, including <a title="Nitrosamine" href="http://en.wikipedia.org/wiki/Nitrosamine">nitrosamines</a> and <a title="Polycyclic aromatic hydrocarbon" href="http://en.wikipedia.org/wiki/Polycyclic_aromatic_hydrocarbon">polycyclic aromatic hydrocarbons</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Kuper-14">[15]</a></sup> Tobacco is responsible for about one in three of all cancer deaths in the developed world,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Sasco-9">[10]</a></sup> and about one in five worldwide.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Kuper-14">[15]</a></sup> Indeed, <a title="Lung cancer" href="http://en.wikipedia.org/wiki/Lung_cancer">lung cancer</a> death rates in the United States have mirrored <a title="Tobacco smoking" href="http://en.wikipedia.org/wiki/Tobacco_smoking">smoking</a> patterns, with increases in smoking followed by dramatic increases in lung cancer death rates and, more recently, decreases in smoking followed by decreases in lung cancer death rates in men. However, the numbers of smokers worldwide is still rising, leading to what some organizations have described as the <em>tobacco epidemic</em>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-15">[16]</a></sup></p>
<h3>Mutation: ionizing radiation</h3>
<p>Sources of <a title="Ionizing radiation" href="http://en.wikipedia.org/wiki/Ionizing_radiation">ionizing radiation</a>, such as <a title="Radon" href="http://en.wikipedia.org/wiki/Radon">radon</a> gas, can cause cancer. Prolonged exposure to <a title="Ultraviolet radiation" href="http://en.wikipedia.org/wiki/Ultraviolet_radiation">ultraviolet radiation</a> from the <a title="Sun" href="http://en.wikipedia.org/wiki/Sun">sun</a> can lead to <a title="Melanoma" href="http://en.wikipedia.org/wiki/Melanoma">melanoma</a> and other skin malignancies.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-16">[17]</a></sup></p>
<p>Non-ionizing radio frequency radiation from <a title="Mobile phone" href="http://en.wikipedia.org/wiki/Mobile_phone">mobile phones</a> and other similar <a title="Radio frequency" href="http://en.wikipedia.org/wiki/Radio_frequency">RF</a> sources has also been proposed as a cause of cancer, but there is currently little established evidence of such a link.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-17">[18]</a></sup></p>
<h3>Viral or bacterial infection</h3>
<p>Some cancers can be caused by <a title="Infection" href="http://en.wikipedia.org/wiki/Infection">infection</a> with <a title="Pathogen" href="http://en.wikipedia.org/wiki/Pathogen">pathogens</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-18">[19]</a></sup> Many cancers originate from a <a title="Virus" href="http://en.wikipedia.org/wiki/Virus">viral</a> infection; this is especially true in animals such as <a title="Bird" href="http://en.wikipedia.org/wiki/Bird">birds</a>, but also in <a title="Human" href="http://en.wikipedia.org/wiki/Human">humans</a>, as viruses are responsible for 15% of human cancers worldwide. The main viruses associated with human cancers are <a title="Human papillomavirus" href="http://en.wikipedia.org/wiki/Human_papillomavirus">human papillomavirus</a>, <a title="Hepatitis B" href="http://en.wikipedia.org/wiki/Hepatitis_B">hepatitis B</a> and <a title="Hepatitis C" href="http://en.wikipedia.org/wiki/Hepatitis_C">hepatitis C</a> virus, <a title="Epstein-Barr virus" href="http://en.wikipedia.org/wiki/Epstein-Barr_virus">Epstein-Barr virus</a>, and <a title="Human T-lymphotropic virus" href="http://en.wikipedia.org/wiki/Human_T-lymphotropic_virus">human T-lymphotropic virus</a>. Experimental and epidemiological data imply a causative role for viruses and they appear to be the second most important risk factor for cancer development in humans, exceeded only by tobacco usage.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-zur_Hausen-viruses-19">[20]</a></sup> The mode of virally-induced tumors can be divided into two, <em>acutely-transforming</em> or <em>slowly-transforming</em>. In acutely transforming viruses, the virus carries an overactive oncogene called viral-oncogene (v-onc), and the infected cell is transformed as soon as v-onc is expressed. In contrast, in slowly-transforming viruses, the virus genome is inserts near a proto-oncogene in the host genome. The viral <a title="Promoter" href="http://en.wikipedia.org/wiki/Promoter">promoter</a> or other transcription regulation elements then cause overexpression of that proto-oncogene. This induces uncontrolled cell division. Because the site of insertion is not specific to proto-oncogenes and the chance of insertion near any proto-oncogene is low, slowly-transforming viruses will cause tumors much longer after infection than the acutely-transforming viruses.</p>
<p>Hepatitis viruses, including <a title="Hepatitis B" href="http://en.wikipedia.org/wiki/Hepatitis_B">hepatitis B</a> and <a title="Hepatitis C" href="http://en.wikipedia.org/wiki/Hepatitis_C">hepatitis C</a>, can induce a chronic viral infection that leads to <a title="Hepatocellular carcinoma" href="http://en.wikipedia.org/wiki/Hepatocellular_carcinoma">liver cancer</a> in 0.47% of <a title="Hepatitis B" href="http://en.wikipedia.org/wiki/Hepatitis_B">hepatitis B</a> patients per year (especially in Asia, less so in North America), and in 1.4% of <a title="Hepatitis C" href="http://en.wikipedia.org/wiki/Hepatitis_C">hepatitis C</a> carriers per year. Liver cirrhosis, whether from chronic viral hepatitis infection or alcoholism, is associated with the development of <a title="Hepatocellular carcinoma" href="http://en.wikipedia.org/wiki/Hepatocellular_carcinoma">liver cancer</a>, and the combination of cirrhosis and viral hepatitis presents the highest risk of <a title="Hepatocellular carcinoma" href="http://en.wikipedia.org/wiki/Hepatocellular_carcinoma">liver cancer</a> development. Worldwide, <a title="Hepatocellular carcinoma" href="http://en.wikipedia.org/wiki/Hepatocellular_carcinoma">liver cancer</a> is one of the most common, and most deadly, cancers due to a huge burden of <a title="Viral hepatitis" href="http://en.wikipedia.org/wiki/Viral_hepatitis">viral hepatitis</a> transmission and disease.</p>
<p>Advances in cancer research have made a vaccine designed to prevent cancer available. In 2006, the <a title="U.S. Food and Drug Administration" href="http://en.wikipedia.org/wiki/U.S._Food_and_Drug_Administration">U.S. Food and Drug Administration</a> approved a <a title="Human papilloma virus" href="http://en.wikipedia.org/wiki/Human_papilloma_virus">human papilloma virus</a> vaccine, called <a title="Gardasil" href="http://en.wikipedia.org/wiki/Gardasil">Gardasil</a>. The vaccine protects against four HPV types, which together cause 70% of cervical cancers and 90% of genital warts. In March 2007, the US <a title="Centers for Disease Control and Prevention" href="http://en.wikipedia.org/wiki/Centers_for_Disease_Control_and_Prevention">Centers for Disease Control and Prevention</a> (CDC) <a title="Advisory Committee on Immunization Practices" href="http://en.wikipedia.org/wiki/Advisory_Committee_on_Immunization_Practices">Advisory Committee on Immunization Practices</a> (ACIP) officially recommended that females aged 11–12 receive the vaccine, and indicated that females as young as age 9 and as old as age 26 are also candidates for immunization.</p>
<p>In addition to viruses, researchers have noted a connection between <a title="Cancer bacteria" href="http://en.wikipedia.org/wiki/Cancer_bacteria">bacteria and certain cancers</a>. The most prominent example is the link between chronic infection of the wall of the stomach with <em><a title="Helicobacter pylori" href="http://en.wikipedia.org/wiki/Helicobacter_pylori">Helicobacter pylori</a></em> and <a title="Gastric cancer" href="http://en.wikipedia.org/wiki/Gastric_cancer">gastric cancer</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-20">[21]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-21">[22]</a></sup> Although only a minority of those infected with <em>Helicobacter</em> go on to develop cancer, since this pathogen is quite common it is probably responsible for the majority of these cancers.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-22">[23]</a></sup></p>
<h3>Hormonal imbalances</h3>
<p>Some hormones can act in a similar manner to non-mutagenic carcinogens in that they may stimulate excessive cell growth. A well-established example is the role of <a title="Estrogen" href="http://en.wikipedia.org/wiki/Estrogen">hyperestrogenic</a> states in promoting <a title="Endometrial cancer" href="http://en.wikipedia.org/wiki/Endometrial_cancer">endometrial cancer</a>.</p>
<h3>Immune system dysfunction</h3>
<p><a title="HIV" href="http://en.wikipedia.org/wiki/HIV">HIV</a> is associated with a number of malignancies, including <a title="Kaposi's sarcoma" href="http://en.wikipedia.org/wiki/Kaposi%27s_sarcoma">Kaposi&#8217;s sarcoma</a>, <a title="Non-Hodgkin's lymphoma" href="http://en.wikipedia.org/wiki/Non-Hodgkin%27s_lymphoma">non-Hodgkin&#8217;s lymphoma</a>, and <a title="HPV" href="http://en.wikipedia.org/wiki/HPV">HPV</a>-associated malignancies such as <a title="Anal cancer" href="http://en.wikipedia.org/wiki/Anal_cancer">anal cancer</a> and <a title="Cervical cancer" href="http://en.wikipedia.org/wiki/Cervical_cancer">cervical cancer</a>. <a title="AIDS" href="http://en.wikipedia.org/wiki/AIDS">AIDS</a>-defining illnesses have long included these diagnoses. The increased incidence of malignancies in HIV patients points to the breakdown of immune surveillance as a possible etiology of cancer.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-23">[24]</a></sup> Certain other immune deficiency states (e.g. <a title="Common variable immunodeficiency" href="http://en.wikipedia.org/wiki/Common_variable_immunodeficiency">common variable immunodeficiency</a> and <a title="IgA deficiency" href="http://en.wikipedia.org/wiki/IgA_deficiency">IgA deficiency</a>) are also associated with increased risk of malignancy.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-24">[25]</a></sup></p>
<h3>Heredity</h3>
<p>Most forms of cancer are <em>sporadic</em>, meaning that there is no inherited cause of the cancer. There are, however, a number of recognised <a title="Syndrome" href="http://en.wikipedia.org/wiki/Syndrome">syndromes</a> where there is an inherited predisposition to cancer, often due to a defect in a gene that <a title="Tumor suppressor" href="http://en.wikipedia.org/wiki/Tumor_suppressor">protects against tumor formation</a>. Famous examples are:</p>
<ul>
<li>certain inherited mutations in the genes <em><a title="BRCA1" href="http://en.wikipedia.org/wiki/BRCA1">BRCA1</a></em> and <em><a title="Lung cancer" href="http://en.wikipedia.org/wiki/Lung_cancer#Non-small_cell_lung_carcinoma_.28NSCLC.29">BRCA2</a></em> are associated with an elevated risk of <a title="Breast cancer" href="http://en.wikipedia.org/wiki/Breast_cancer">breast cancer</a> and <a title="Ovarian cancer" href="http://en.wikipedia.org/wiki/Ovarian_cancer">ovarian cancer</a></li>
<li>tumors of various endocrine organs in <a title="Multiple endocrine neoplasia" href="http://en.wikipedia.org/wiki/Multiple_endocrine_neoplasia">multiple endocrine neoplasia</a> (MEN types 1, 2a, 2b)</li>
<li><a title="Li-Fraumeni syndrome" href="http://en.wikipedia.org/wiki/Li-Fraumeni_syndrome">Li-Fraumeni syndrome</a> (various tumors such as <a title="Osteosarcoma" href="http://en.wikipedia.org/wiki/Osteosarcoma">osteosarcoma</a>, breast cancer, <a title="Soft tissue sarcoma" href="http://en.wikipedia.org/wiki/Soft_tissue_sarcoma">soft tissue sarcoma</a>, <a title="Brain tumor" href="http://en.wikipedia.org/wiki/Brain_tumor">brain tumors</a>) due to mutations of <a title="P53" href="http://en.wikipedia.org/wiki/P53">p53</a></li>
<li><a title="Turcot syndrome" href="http://en.wikipedia.org/wiki/Turcot_syndrome">Turcot syndrome</a> (<a title="Brain tumor" href="http://en.wikipedia.org/wiki/Brain_tumor">brain tumors</a> and colonic polyposis)</li>
<li><a title="Familial adenomatous polyposis" href="http://en.wikipedia.org/wiki/Familial_adenomatous_polyposis">Familial adenomatous polyposis</a> an inherited mutation of the <em>APC</em> gene that leads to early onset of <a title="Colon carcinoma" href="http://en.wikipedia.org/wiki/Colon_carcinoma">colon carcinoma</a>.</li>
<li><a title="Hereditary nonpolyposis colorectal cancer" href="http://en.wikipedia.org/wiki/Hereditary_nonpolyposis_colorectal_cancer">Hereditary nonpolyposis colorectal cancer</a> (HNPCC, also known as Lynch syndrome) can include familial cases of <a title="Colorectal cancer" href="http://en.wikipedia.org/wiki/Colorectal_cancer">colon cancer</a>, uterine cancer, <a title="Gastric cancer" href="http://en.wikipedia.org/wiki/Gastric_cancer">gastric cancer</a>, and <a title="Ovarian cancer" href="http://en.wikipedia.org/wiki/Ovarian_cancer">ovarian cancer</a>, without a preponderance of <a title="Polyp (medicine)" href="http://en.wikipedia.org/wiki/Polyp_(medicine)">colon polyps</a>.</li>
<li><a title="Retinoblastoma" href="http://en.wikipedia.org/wiki/Retinoblastoma">Retinoblastoma</a>, when occurring in young children, is due to a hereditary mutation in the retinoblastoma gene.</li>
<li><a title="Down syndrome" href="http://en.wikipedia.org/wiki/Down_syndrome">Down syndrome</a> patients, who have an extra <a title="Chromosome 21" href="http://en.wikipedia.org/wiki/Chromosome_21">chromosome 21</a>, are known to develop malignancies such as <a title="Leukemia" href="http://en.wikipedia.org/wiki/Leukemia">leukemia</a> and <a title="Testicular cancer" href="http://en.wikipedia.org/wiki/Testicular_cancer">testicular cancer</a>, though the reasons for this difference are not well understood.</li>
</ul>
<h3>Other causes</h3>
<p>Excepting the rare transmissions that occur with pregnancies and only a marginal few organ donors, cancer is generally not a transmissible disease. The main reason for this is tissue graft rejection caused by <a title="Major histocompatibility complex" href="http://en.wikipedia.org/wiki/Major_histocompatibility_complex">MHC</a> <a title="Histocompatibility" href="http://en.wikipedia.org/wiki/Histocompatibility">incompatibility</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Tolar-25">[26]</a></sup> In humans and other vertebrates, the immune system uses MHC antigens to differentiate between &#8220;self&#8221; and &#8220;non-self&#8221; cells because these antigens are different from person to person. When non-self antigens are encountered, the immune system reacts against the appropriate cell. Such reactions may protect against tumour cell engraftment by eliminating implanted cells. In the United States, approximately 3,500 pregnant women have a malignancy annually, and transplacental transmission of <a title="Acute leukaemia" href="http://en.wikipedia.org/wiki/Acute_leukaemia">acute leukaemia</a>, <a title="Lymphoma" href="http://en.wikipedia.org/wiki/Lymphoma">lymphoma</a>, <a title="Melanoma" href="http://en.wikipedia.org/wiki/Melanoma">melanoma</a> and <a title="Carcinoma" href="http://en.wikipedia.org/wiki/Carcinoma">carcinoma</a> from mother to fetus has been observed.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Tolar-25">[26]</a></sup> The development of donor-derived tumors from organ transplants is exceedingly rare. The main cause of organ transplant associated tumors seems to be malignant melanoma, that was undetected at the time of organ harvest<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-26">[27]</a></sup>, though other cases exist<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-27">[28]</a></sup>. In fact, cancer from one organism will usually grow in another organism of that species, as long as they share the same <a title="Histocompatibility" href="http://en.wikipedia.org/wiki/Histocompatibility">histocompatibility</a> genes<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-28">[29]</a></sup>, proven using mice; however this would never happen in a real-world setting except as described above.</p>
<p>In non-humans, a few types of cancer have been found to be caused by transmission of the tumor cells themselves. This phenomenon is seen in dogs with <a title="Sticker's sarcoma" href="http://en.wikipedia.org/wiki/Sticker%27s_sarcoma">Sticker&#8217;s sarcoma</a>, also known as canine transmissible venereal tumor,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-29">[30]</a></sup> as well as <a title="Devil facial tumour disease" href="http://en.wikipedia.org/wiki/Devil_facial_tumour_disease">Devil facial tumour disease</a> in <a title="Tasmanian Devil" href="http://en.wikipedia.org/wiki/Tasmanian_Devil">Tasmanian devils</a>.</p>
<h2>Mechanism</h2>
<p>Cancers are caused by a series of mutations. Each mutation alters the behavior of the cell somewhat.</p>
<p>Cancer is fundamentally a disease of regulation of tissue growth. In order for a normal cell to <a title="Malignant transformation" href="http://en.wikipedia.org/wiki/Malignant_transformation">transform</a> into a cancer cell, <a title="Genes" href="http://en.wikipedia.org/wiki/Genes">genes</a> which regulate cell growth and differentiation must be altered.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-30">[31]</a></sup> Genetic changes can occur at many levels, from gain or loss of entire chromosomes to a mutation affecting a <a title="Single nucleotide polymorphism" href="http://en.wikipedia.org/wiki/Single_nucleotide_polymorphism">single DNA nucleotide</a>. There are two broad categories of genes which are affected by these changes. <a title="Oncogene" href="http://en.wikipedia.org/wiki/Oncogene">Oncogenes</a> may be normal genes which are expressed at inappropriately high levels, or altered genes which have novel properties. In either case, expression of these genes promotes the malignant phenotype of cancer cells. <a title="Tumor suppressor gene" href="http://en.wikipedia.org/wiki/Tumor_suppressor_gene">Tumor suppressor genes</a> are genes which inhibit cell division, survival, or other properties of cancer cells. Tumor suppressor genes are often disabled by cancer-promoting genetic changes. Typically, changes in many genes are required to transform a normal cell into a cancer cell.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-31">[32]</a></sup></p>
<p>There is a diverse classification scheme for the various genomic changes which may contribute to the generation of cancer cells. Most of these changes are <a title="Mutation" href="http://en.wikipedia.org/wiki/Mutation">mutations</a>, or changes in the <a title="Nucleotide" href="http://en.wikipedia.org/wiki/Nucleotide">nucleotide</a> sequence of genomic DNA. <a title="Aneuploidy" href="http://en.wikipedia.org/wiki/Aneuploidy">Aneuploidy</a>, the presence of an abnormal number of chromosomes, is one genomic change which is not a mutation, and may involve either gain or loss of one or more <a title="Chromosomes" href="http://en.wikipedia.org/wiki/Chromosomes">chromosomes</a> through errors in <a title="Mitosis" href="http://en.wikipedia.org/wiki/Mitosis">mitosis</a>.</p>
<p>Large-scale mutations involve the deletion or gain of a portion of a chromosome. <a title="Gene amplification" href="http://en.wikipedia.org/wiki/Gene_amplification">Genomic amplification</a> occurs when a cell gains many copies (often 20 or more) of a small chromosomal locus, usually containing one or more oncogenes and adjacent genetic material. <a title="Chromosomal translocation" href="http://en.wikipedia.org/wiki/Chromosomal_translocation">Translocation</a> occurs when two separate chromosomal regions become abnormally fused, often at a characteristic location. A well-known example of this is the <a title="Philadelphia chromosome" href="http://en.wikipedia.org/wiki/Philadelphia_chromosome">Philadelphia chromosome</a>, or translocation of chromosomes 9 and 22, which occurs in <a title="Chronic myelogenous leukemia" href="http://en.wikipedia.org/wiki/Chronic_myelogenous_leukemia">chronic myelogenous leukemia</a>, and results in production of the <a title="BCR gene" href="http://en.wikipedia.org/wiki/BCR_gene">BCR</a>-<a title="Abl gene" href="http://en.wikipedia.org/wiki/Abl_gene">abl</a> <a title="Fusion protein" href="http://en.wikipedia.org/wiki/Fusion_protein">fusion protein</a>, an oncogenic <a title="Tyrosine kinase" href="http://en.wikipedia.org/wiki/Tyrosine_kinase">tyrosine kinase</a>.</p>
<p>Small-scale mutations include point mutations, deletions, and insertions, which may occur in the <a title="Promoter" href="http://en.wikipedia.org/wiki/Promoter">promoter</a> of a gene and affect its <a title="Gene expression" href="http://en.wikipedia.org/wiki/Gene_expression">expression</a>, or may occur in the gene&#8217;s <a title="Coding sequence" href="http://en.wikipedia.org/wiki/Coding_sequence">coding sequence</a> and alter the function or stability of its <a title="Protein" href="http://en.wikipedia.org/wiki/Protein">protein</a> product. Disruption of a single gene may also result from <a title="Provirus" href="http://en.wikipedia.org/wiki/Provirus">integration of genomic material</a> from a <a title="DNA virus" href="http://en.wikipedia.org/wiki/DNA_virus">DNA virus</a> or <a title="Retrovirus" href="http://en.wikipedia.org/wiki/Retrovirus">retrovirus</a>, and such an event may also result in the expression of viral oncogenes in the affected cell and its descendants.</p>
<h3>Epigenetics</h3>
<p><a title="Epigenetic" href="http://en.wikipedia.org/wiki/Epigenetic">Epigenetics</a> is the study of the regulation of gene expression through chemical, non-mutational changes in DNA structure. The theory of <a title="Epigenetics" href="http://en.wikipedia.org/wiki/Epigenetics">epigenetics</a> in cancer pathogenesis is that non-mutational changes to DNA can lead to alterations in gene expression. Normally, <a title="Oncogenes" href="http://en.wikipedia.org/wiki/Oncogenes">oncogenes</a> are silent, for example, because of <a title="DNA methylation" href="http://en.wikipedia.org/wiki/DNA_methylation">DNA methylation</a>. Loss of that methylation can induce the aberrant expression of <a title="Oncogenes" href="http://en.wikipedia.org/wiki/Oncogenes">oncogenes</a>, leading to cancer pathogenesis. Known mechanisms of epigenetic change include <a title="DNA methylation" href="http://en.wikipedia.org/wiki/DNA_methylation">DNA methylation</a>, and methylation or acetylation of <a title="Histone" href="http://en.wikipedia.org/wiki/Histone">histone</a> proteins bound to chromosomal DNA at specific locations. Classes of medications, known as <a title="HDAC inhibitors" href="http://en.wikipedia.org/wiki/HDAC_inhibitors">HDAC inhibitors</a> and <a title="DNA methyltransferase" href="http://en.wikipedia.org/wiki/DNA_methyltransferase">DNA methyltransferase</a> inhibitors, can re-regulate the epigenetic signaling in the cancer cell.</p>
<h3>Oncogenes</h3>
<p><a title="Oncogene" href="http://en.wikipedia.org/wiki/Oncogene">Oncogenes</a> promote cell growth through a variety of ways. Many can produce <a title="Hormone" href="http://en.wikipedia.org/wiki/Hormone">hormones</a>, a &#8220;chemical messenger&#8221; between cells which encourage <a title="Mitosis" href="http://en.wikipedia.org/wiki/Mitosis">mitosis</a>, the effect of which depends on the <a title="Signal transduction" href="http://en.wikipedia.org/wiki/Signal_transduction">signal transduction</a> of the receiving tissue or cells. In other words, when a hormone receptor on a recipient cell is stimulated, the signal is conducted from the surface of the cell to the <a title="Cell nucleus" href="http://en.wikipedia.org/wiki/Cell_nucleus">cell nucleus</a> to effect some change in gene transcription regulation at the nuclear level. Some oncogenes are part of the signal transduction system itself, or the signal <a title="Receptor (biochemistry)" href="http://en.wikipedia.org/wiki/Receptor_(biochemistry)">receptors</a> in cells and tissues themselves, thus controlling the sensitivity to such hormones. Oncogenes often produce <a title="Mitogen" href="http://en.wikipedia.org/wiki/Mitogen">mitogens</a>, or are involved in <a title="Transcription (genetics)" href="http://en.wikipedia.org/wiki/Transcription_(genetics)">transcription</a> of DNA in <a title="Protein biosynthesis" href="http://en.wikipedia.org/wiki/Protein_biosynthesis">protein synthesis</a>, which creates the <a title="Protein" href="http://en.wikipedia.org/wiki/Protein">proteins</a> and <a title="Enzyme" href="http://en.wikipedia.org/wiki/Enzyme">enzymes</a> responsible for producing the products and <a title="Biochemistry" href="http://en.wikipedia.org/wiki/Biochemistry">biochemicals</a> cells use and interact with.</p>
<p>Mutations in proto-oncogenes, which are the normally quiescent counterparts of <a title="Oncogenes" href="http://en.wikipedia.org/wiki/Oncogenes">oncogenes</a>, can modify their <a title="Gene expression" href="http://en.wikipedia.org/wiki/Gene_expression">expression</a> and function, increasing the amount or activity of the product protein. When this happens, the proto-oncogenes become <a title="Oncogene" href="http://en.wikipedia.org/wiki/Oncogene">oncogenes</a>, and this transition upsets the normal balance of <a title="Cell cycle" href="http://en.wikipedia.org/wiki/Cell_cycle">cell cycle</a> regulation in the cell, making uncontrolled growth possible. The chance of cancer cannot be reduced by removing proto-oncogenes from the <a title="Genome" href="http://en.wikipedia.org/wiki/Genome">genome</a>, even if this were possible, as they are critical for growth, repair and <a title="Homeostasis" href="http://en.wikipedia.org/wiki/Homeostasis">homeostasis</a> of the organism. It is only when they become mutated that the signals for growth become excessive.</p>
<p>One of the first <a title="Oncogenes" href="http://en.wikipedia.org/wiki/Oncogenes">oncogenes</a> to be defined in cancer research is the <a title="Ras oncogene" href="http://en.wikipedia.org/wiki/Ras_oncogene">ras oncogene</a>. Mutations in the Ras family of <a title="Proto-oncogene" href="http://en.wikipedia.org/wiki/Proto-oncogene">proto-oncogenes</a> (comprising H-Ras, N-Ras and K-Ras) are very common, being found in 20% to 30% of all human tumours.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-32">[33]</a></sup> Ras was originally identified in the Harvey sarcoma virus genome, and researchers were surprised that not only was this gene present in the human genome but that, when ligated to a stimulating control element, could induce cancers in cell line cultures.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid6283358-33">[34]</a></sup></p>
<h3>Tumor suppressor genes</h3>
<p>Many tumor suppressor genes effect signal transduction pathways which regulate <a title="Apoptosis" href="http://en.wikipedia.org/wiki/Apoptosis">apoptosis</a>, also known as &#8220;programmed cell death&#8221;.</p>
<p><a title="Tumor suppressor gene" href="http://en.wikipedia.org/wiki/Tumor_suppressor_gene">Tumor suppressor genes</a> code for anti-proliferation signals and proteins that suppress mitosis and cell growth. Generally, tumor suppressors are <a title="Transcription factor" href="http://en.wikipedia.org/wiki/Transcription_factor">transcription factors</a> that are activated by cellular <a title="Stress (medicine)" href="http://en.wikipedia.org/wiki/Stress_(medicine)">stress</a> or DNA damage. Often DNA damage will cause the presence of free-floating genetic material as well as other signs, and will trigger enzymes and pathways which lead to the activation of <a title="Tumor suppressor genes" href="http://en.wikipedia.org/wiki/Tumor_suppressor_genes">tumor suppressor genes</a>. The functions of such genes is to arrest the progression of the cell cycle in order to carry out DNA repair, preventing mutations from being passed on to daughter cells. The <a title="P53" href="http://en.wikipedia.org/wiki/P53">p53</a> protein, one of the most important studied tumor suppressor genes, is a transcription factor activated by many cellular stressors including <a title="Hypoxia (medical)" href="http://en.wikipedia.org/wiki/Hypoxia_(medical)">hypoxia</a> and <a title="Ultraviolet radiation" href="http://en.wikipedia.org/wiki/Ultraviolet_radiation">ultraviolet radiation</a> damage.</p>
<p>Despite nearly half of all cancers possibly involving alterations in p53, its tumor suppressor function is poorly understood. p53 clearly has two functions: one a nuclear role as a transcription factor, and the other a cytoplasmic role in regulating the cell cycle, cell division, and apoptosis.</p>
<p>The <a title="Warburg hypothesis" href="http://en.wikipedia.org/wiki/Warburg_hypothesis">Warburg hypothesis</a> is the preferential use of glycolysis for energy to sustain cancer growth. p53 has been shown to regulate the shift from the respiratory to the glycolytic pathway.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Mantoba-Warburg-34">[35]</a></sup></p>
<p>However, a mutation can damage the tumor suppressor gene itself, or the signal pathway which activates it, &#8220;switching it off&#8221;. The invariable consequence of this is that DNA repair is hindered or inhibited: DNA damage accumulates without repair, inevitably leading to cancer.</p>
<p>Mutations of tumor suppressor genes that occur in <a title="Germline" href="http://en.wikipedia.org/wiki/Germline">germline</a> cells are passed along to <a title="Offspring" href="http://en.wikipedia.org/wiki/Offspring">offspring</a>, and increase the likelihood for cancer diagnoses in subsequent generations. Members of these families have increased incidence and decreased latency of multiple tumors. The tumor types are typical for each type of tumor suppressor gene mutation, with some mutations causing particular cancers, and other mutations causing others. The mode of inheritance of mutant tumor suppressors is that an affected member inherits a defective copy from one parent, and a normal copy from the other. For instance, individuals who inherit one mutant <em><a title="P53" href="http://en.wikipedia.org/wiki/P53">p53</a></em> allele (and are therefore <a title="Heterozygote" href="http://en.wikipedia.org/wiki/Heterozygote">heterozygous</a> for mutated <em>p53</em>) can develop <a title="Melanomas" href="http://en.wikipedia.org/wiki/Melanomas">melanomas</a> and <a title="Pancreatic cancer" href="http://en.wikipedia.org/wiki/Pancreatic_cancer">pancreatic cancer</a>, known as <a title="Li-Fraumeni syndrome" href="http://en.wikipedia.org/wiki/Li-Fraumeni_syndrome">Li-Fraumeni syndrome</a>. Other inherited tumor suppressor gene syndromes include <em><a title="Retinoblastoma protein" href="http://en.wikipedia.org/wiki/Retinoblastoma_protein">Rb</a></em> mutations, linked to <a title="Retinoblastoma" href="http://en.wikipedia.org/wiki/Retinoblastoma">retinoblastoma</a>, and <em><a title="Familial adenomatous polyposis" href="http://en.wikipedia.org/wiki/Familial_adenomatous_polyposis#Pathophysiology">APC</a></em> gene mutations, linked to <a title="Familial adenomatous polyposis" href="http://en.wikipedia.org/wiki/Familial_adenomatous_polyposis">adenopolyposis colon cancer</a>. Adenopolyposis colon cancer is associated with thousands of polyps in colon while young, leading to <a title="Colorectal cancer" href="http://en.wikipedia.org/wiki/Colorectal_cancer">colon cancer</a> at a relatively early age. Finally, inherited mutations in <em><a title="BRCA1" href="http://en.wikipedia.org/wiki/BRCA1">BRCA1</a></em> and <em><a title="BRCA2" href="http://en.wikipedia.org/wiki/BRCA2">BRCA2</a></em> lead to early onset of <a title="Breast cancer" href="http://en.wikipedia.org/wiki/Breast_cancer">breast cancer</a>.</p>
<p>Development of cancer was proposed in 1971 to depend on at least two mutational events. In what became known as the <a title="Alfred G. Knudson" href="http://en.wikipedia.org/wiki/Alfred_G._Knudson">Knudson</a> <a title="Knudson hypothesis" href="http://en.wikipedia.org/wiki/Knudson_hypothesis">two-hit hypothesis</a>, an inherited, germ-line mutation in a <a title="Tumor suppressor gene" href="http://en.wikipedia.org/wiki/Tumor_suppressor_gene">tumor suppressor gene</a> would only cause cancer if another mutation event occurred later in the organism&#8217;s life, inactivating the other <a title="Allele" href="http://en.wikipedia.org/wiki/Allele">allele</a> of that <a title="Tumor suppressor gene" href="http://en.wikipedia.org/wiki/Tumor_suppressor_gene">tumor suppressor gene</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-35">[36]</a></sup></p>
<p>Usually, oncogenes are <a title="Dominant gene" href="http://en.wikipedia.org/wiki/Dominant_gene">dominant</a>, as they contain <a title="Gain-of-function mutation" href="http://en.wikipedia.org/wiki/Gain-of-function_mutation">gain-of-function mutations</a>, while mutated tumor suppressors are <a title="Recessive gene" href="http://en.wikipedia.org/wiki/Recessive_gene">recessive</a>, as they contain <a title="Loss-of-function mutation" href="http://en.wikipedia.org/wiki/Loss-of-function_mutation">loss-of-function mutations</a>. Each cell has two copies of the same gene, one from each parent, and under most cases gain of function mutations in just one copy of a particular proto-oncogene is enough to make that gene a true oncogene. On the other hand, loss of function mutations need to happen in both copies of a tumor suppressor gene to render that gene completely non-functional. However, cases exist in which one mutated copy of a <a title="Tumor suppressor gene" href="http://en.wikipedia.org/wiki/Tumor_suppressor_gene">tumor suppressor gene</a> can render the other, <a title="Wild-type" href="http://en.wikipedia.org/wiki/Wild-type">wild-type</a> copy non-functional. This phenomenon is called the <em>dominant negative effect</em> and is observed in many p53 mutations.</p>
<p>Knudson’s two hit model has recently been challenged by several investigators. Inactivation of one allele of some tumor suppressor genes is sufficient to cause tumors. This phenomenon is called <a title="Haploinsufficiency" href="http://en.wikipedia.org/wiki/Haploinsufficiency">haploinsufficiency</a> and has been demonstrated by a number of experimental approaches. Tumors caused by <a title="Haploinsufficiency" href="http://en.wikipedia.org/wiki/Haploinsufficiency">haploinsufficiency</a> usually have a later age of onset when compared with those by a two hit process.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Fodde-Haploinsufficiency-36">[37]</a></sup></p>
<h3>Cancer cell biology</h3>
<p>Tissue can be organized in a continuous spectrum from normal to cancer.</p>
<p>Often, the multiple genetic changes which result in cancer may take many years to accumulate. During this time, the biological behavior of the pre-malignant cells slowly change from the properties of normal cells to cancer-like properties. Pre-malignant tissue can have a distinctive appearance under the <a title="Microscope" href="http://en.wikipedia.org/wiki/Microscope">microscope</a>. Among the distinguishing traits are an increased number of dividing cells, variation in <a title="Cell nucleus" href="http://en.wikipedia.org/wiki/Cell_nucleus">nuclear</a> size and shape, variation in cell size and shape, loss of specialized cell features, and loss of normal tissue organization. <a title="Dysplasia" href="http://en.wikipedia.org/wiki/Dysplasia">Dysplasia</a> is an abnormal type of excessive cell proliferation characterized by loss of normal tissue arrangement and cell structure in pre-malignant cells. These early neoplastic changes must be distinguished from hyperplasia, a reversible increase in cell division caused by an external stimulus, such as a hormonal imbalance or chronic irritation.</p>
<p>The most severe cases of dysplasia are referred to as &#8220;<a title="Carcinoma in situ" href="http://en.wikipedia.org/wiki/Carcinoma_in_situ">carcinoma in situ</a>.&#8221; In Latin, the term &#8220;in situ&#8221; means &#8220;in place&#8221;, so carcinoma in situ refers to an uncontrolled growth of cells that remains in the original location and has not shown invasion into other tissues. Nevertheless, carcinoma in situ may develop into an invasive malignancy and is usually removed surgically, if possible.</p>
<h4>Clonal evolution</h4>
<p><em>Main article: <a title="Somatic evolution in cancer" href="http://en.wikipedia.org/wiki/Somatic_evolution_in_cancer">Somatic evolution in cancer</a></em></p>
<p>Just like a population of animals undergoes <a title="Evolution" href="http://en.wikipedia.org/wiki/Evolution">evolution</a>, an unchecked population of cells also can undergo evolution. This undesirable process is called <a title="Somatic evolution in cancer" href="http://en.wikipedia.org/wiki/Somatic_evolution_in_cancer">somatic evolution</a>, and is how cancer arises and becomes more malignant. <sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-37">[38]</a></sup></p>
<p>Most changes in cellular metabolism that allow cells to grow in a disorderly fashion lead to cell death. However once cancer begins, cancer cells undergo a process of <a title="Natural selection" href="http://en.wikipedia.org/wiki/Natural_selection">natural selection</a>: the few cells with new genetic changes that enhance their survival or reproduction continue to multiply, and soon come to dominate the growing tumor, as cells with less favorable genetic change are out-competed.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-38">[39]</a></sup> This is exactly how pathogens such as <a title="MRSA" href="http://en.wikipedia.org/wiki/MRSA">MRSA</a> can become <a title="Antibiotic resistance" href="http://en.wikipedia.org/wiki/Antibiotic_resistance">antibiotic-resistant</a> (or how <a title="HIV" href="http://en.wikipedia.org/wiki/HIV">HIV</a> can become <a title="Drug resistance" href="http://en.wikipedia.org/wiki/Drug_resistance">drug-resistant</a>), and the same reason why crop blights and pests can become <a title="Pesticide resistance" href="http://en.wikipedia.org/wiki/Pesticide_resistance">pesticide-resistant</a>. This evolution is why cancer recurrences will have cells which have acquired <a title="Somatic evolution in cancer" href="http://en.wikipedia.org/wiki/Somatic_evolution_in_cancer#Somatic_evolution_in_therapeutic_resistance">cancer-drug resistance</a> (or in some cases, resistance to radiation from <a title="Radiotherapy" href="http://en.wikipedia.org/wiki/Radiotherapy">radiotherapy</a>).</p>
<h4>Biological properties of cancer cells</h4>
<p>When normal cells are damaged beyond repair, they are eliminated by <a title="Apoptosis" href="http://en.wikipedia.org/wiki/Apoptosis">apoptosis</a> (A). Cancer cells avoid apoptosis and continue to multiply in an unregulated manner (B).</p>
<p>In a 2000 article by Hanahan and <a title="Robert Weinberg" href="http://en.wikipedia.org/wiki/Robert_Weinberg">Weinberg</a>, the biological properties of malignant tumor cells were summarized as follows:<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid10647931-39">[40]</a></sup></p>
<ul>
<li>Acquisition of self-sufficiency in <a title="Growth factor" href="http://en.wikipedia.org/wiki/Growth_factor">growth signals</a>, leading to unchecked growth.</li>
<li>Loss of sensitivity to anti-growth signals, also leading to unchecked growth.</li>
<li>Loss of capacity for <a title="Apoptosis" href="http://en.wikipedia.org/wiki/Apoptosis">apoptosis</a>, in order to allow growth despite genetic errors and external anti-growth signals.</li>
<li>Loss of capacity for <a title="Senescence" href="http://en.wikipedia.org/wiki/Senescence">senescence</a>, leading to limitless replicative potential (immortality)</li>
<li>Acquisition of sustained <a title="Angiogenesis" href="http://en.wikipedia.org/wiki/Angiogenesis">angiogenesis</a>, allowing the tumor to grow beyond the limitations of passive nutrient diffusion.</li>
<li>Acquisition of ability to invade neighbouring <a title="Biological tissue" href="http://en.wikipedia.org/wiki/Biological_tissue">tissues</a>, the defining property of invasive carcinoma.</li>
<li>Acquisition of ability to build <a title="Metastasis" href="http://en.wikipedia.org/wiki/Metastasis">metastases</a> at distant sites, the classical property of malignant tumors (carcinomas or others).</li>
</ul>
<p>The completion of these multiple steps would be a very rare event without :</p>
<ul>
<li>Loss of capacity to repair genetic errors, leading to an increased <a title="Mutation" href="http://en.wikipedia.org/wiki/Mutation">mutation</a> rate (genomic instability), thus accelerating all the other changes.</li>
</ul>
<p>These biological changes are classical in <a title="Carcinoma" href="http://en.wikipedia.org/wiki/Carcinoma">carcinomas</a>; other malignant tumors may not need all to achieve them all. For example, tissue invasion and displacement to distant sites are normal properties of <a title="Leukocytes" href="http://en.wikipedia.org/wiki/Leukocytes">leukocytes</a>; these steps are not needed in the development of <a title="Leukemia" href="http://en.wikipedia.org/wiki/Leukemia">leukemia</a>. The different steps do not necessarily represent individual mutations. For example, inactivation of a single gene, coding for the <a title="P53" href="http://en.wikipedia.org/wiki/P53">p53</a> protein, will cause genomic instability, evasion of apoptosis and increased angiogenesis. Not all the cancer cells are dividing. Rather, a subset of the cells in a tumor, called <a title="Cancer stem cell" href="http://en.wikipedia.org/wiki/Cancer_stem_cell">cancer stem cells</a>, replicate themselves and generate differentiated cells.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-40">[41]</a></sup></p>
<h2>Prevention</h2>
<p>Cancer prevention is defined as active measures to decrease the incidence of cancer. This can be accomplished by avoiding <a title="Carcinogen" href="http://en.wikipedia.org/wiki/Carcinogen">carcinogens</a> or altering their <a title="Metabolism" href="http://en.wikipedia.org/wiki/Metabolism">metabolism</a>, pursuing a lifestyle or diet that modifies cancer-causing factors and/or medical intervention (<a title="Chemoprevention" href="http://en.wikipedia.org/wiki/Chemoprevention">chemoprevention</a>, treatment of pre-malignant lesions). The <a title="Epidemiology" href="http://en.wikipedia.org/wiki/Epidemiology">epidemiological</a> concept of &#8220;prevention&#8221; is usually defined as either <a title="Primary prevention" href="http://en.wikipedia.org/wiki/Primary_prevention">primary prevention</a>, for people who have not been diagnosed with a particular disease, or <a title="Secondary prevention" href="http://en.wikipedia.org/wiki/Secondary_prevention">secondary prevention</a>, aimed at reducing recurrence or complications of a previously diagnosed illness.</p>
<h3>Modifiable (&#8220;lifestyle&#8221;) risk factors</h3>
<p><em>See also: <a title="Alcohol and cancer" href="http://en.wikipedia.org/wiki/Alcohol_and_cancer">Alcohol and cancer</a></em></p>
<p>A <a title="Squamous cell carcinoma" href="http://en.wikipedia.org/wiki/Squamous_cell_carcinoma">squamous cell carcinoma</a> (the whitish tumor) near the <a title="Bronchi" href="http://en.wikipedia.org/wiki/Bronchi">bronchi</a> in a lung specimen.</p>
<p>The vast majority of cancer risk factors are environmental or lifestyle-related in nature, leading to the claim that cancer is a largely preventable disease.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Danaei-41">[42]</a></sup> Examples of modifiable cancer risk factors include <a title="Alcoholic beverage" href="http://en.wikipedia.org/wiki/Alcoholic_beverage">alcohol</a> consumption (associated with increased risk of oral, esophageal, breast, and other cancers), smoking (although 20% of women with lung cancer have never smoked, versus 10% of men<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-42">[43]</a></sup>), physical inactivity (associated with increased risk of colon, breast, and possibly other cancers), and being <a title="Overweight" href="http://en.wikipedia.org/wiki/Overweight">overweight</a> / <a title="Obese" href="http://en.wikipedia.org/wiki/Obese">obese</a> (associated with colon, breast, endometrial, and possibly other cancers). Based on epidemiologic evidence, it is now thought that avoiding excessive alcohol consumption may contribute to reductions in risk of certain cancers; however, compared with tobacco exposure, the magnitude of effect is modest or small and the strength of evidence is often weaker. Other lifestyle and environmental factors known to affect cancer risk (either beneficially or detrimentally) include certain sexually transmitted diseases (such as those conveyed by the <a title="Human papillomavirus" href="http://en.wikipedia.org/wiki/Human_papillomavirus">human papillomavirus</a>), the use of exogenous hormones, exposure to <a title="Ionizing radiation" href="http://en.wikipedia.org/wiki/Ionizing_radiation">ionizing radiation</a> and <a title="Ultraviolet" href="http://en.wikipedia.org/wiki/Ultraviolet">ultraviolet</a> radiation, and certain occupational and chemical exposures.</p>
<p>Every year, at least 200,000 people die worldwide from cancer related to their workplace.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-WHO_occup-43">[44]</a></sup> Millions of workers run the risk of developing cancers such as <a title="Lung cancer" href="http://en.wikipedia.org/wiki/Lung_cancer">lung cancer</a> and <a title="Mesothelioma" href="http://en.wikipedia.org/wiki/Mesothelioma">mesothelioma</a> from inhaling asbestos fibers and tobacco smoke, or <a title="Leukemia" href="http://en.wikipedia.org/wiki/Leukemia">leukemia</a> from exposure to <a title="Benzene" href="http://en.wikipedia.org/wiki/Benzene">benzene</a> at their workplaces.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-WHO_occup-43">[44]</a></sup> Currently, most cancer deaths caused by occupational risk factors occur in the developed world.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-WHO_occup-43">[44]</a></sup> It is estimated that approximately 20,000 cancer deaths and 40,000 new cases of cancer each year in the U.S. are attributable to occupation.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-44">[45]</a></sup></p>
<h3>Diet</h3>
<p><em>Main article: <a title="Diet and cancer" href="http://en.wikipedia.org/wiki/Diet_and_cancer">Diet and cancer</a></em></p>
<p>The consensus on diet and cancer is that <a title="Obesity" href="http://en.wikipedia.org/wiki/Obesity">obesity</a> increases the risk of developing cancer. Particular dietary practices often explain differences in cancer incidence in different countries (e.g. <a title="Gastric cancer" href="http://en.wikipedia.org/wiki/Gastric_cancer">gastric cancer</a> is more common in Japan, while <a title="Colorectal cancer" href="http://en.wikipedia.org/wiki/Colorectal_cancer">colon cancer</a> is more common in the United States. In this example the preceding consideration of <a title="Haplogroups" href="http://en.wikipedia.org/wiki/Haplogroups">Haplogroups</a> are excluded). Studies have shown that immigrants develop the risk of their new country, often within one generation, suggesting a substantial link between diet and cancer.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-45">[46]</a></sup> Whether reducing obesity in a population also reduces cancer incidence is unknown.</p>
<p>Despite frequent reports of particular substances (including foods) having a beneficial or detrimental effect on cancer risk, few of these have an established link to cancer. These reports are often based on studies in cultured cell media or animals. Public health recommendations cannot be made on the basis of these studies until they have been validated in an observational (or occasionally a prospective interventional) trial in humans.</p>
<p>An invasive <a title="Colorectal carcinoma" href="http://en.wikipedia.org/wiki/Colorectal_carcinoma">colorectal carcinoma</a> (top center) in a <a title="Colectomy" href="http://en.wikipedia.org/wiki/Colectomy">colectomy</a> specimen.</p>
<p>Proposed dietary interventions for primary cancer risk reduction generally gain support from epidemiological association studies. Examples of such studies include reports that reduced meat consumption is associated with decreased risk of colon cancer,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid9663397-46">[47]</a></sup> and reports that consumption of coffee is associated with a reduced risk of liver cancer.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid17484871-47">[48]</a></sup> Studies have linked consumption of grilled meat to an increased risk of <a title="Stomach cancer" href="http://en.wikipedia.org/wiki/Stomach_cancer">stomach cancer</a>,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid9096659-48">[49]</a></sup> <a title="Colorectal cancer" href="http://en.wikipedia.org/wiki/Colorectal_cancer">colon cancer</a>,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid16140978-49">[50]</a></sup> <a title="Breast cancer" href="http://en.wikipedia.org/wiki/Breast_cancer">breast cancer</a>,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid17435448-50">[51]</a></sup> and <a title="Pancreatic cancer" href="http://en.wikipedia.org/wiki/Pancreatic_cancer">pancreatic cancer</a>,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid16172241-51">[52]</a></sup> a phenomenon which could be due to the presence of carcinogens such as <a title="Benzopyrene" href="http://en.wikipedia.org/wiki/Benzopyrene">benzopyrene</a> in foods cooked at high temperatures.</p>
<p>A 2005 <a title="Secondary prevention" href="http://en.wikipedia.org/wiki/Secondary_prevention">secondary prevention</a> study showed that consumption of a plant-based diet and lifestyle changes resulted in a reduction in cancer markers in a group of men with prostate cancer who were using no conventional treatments at the time.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Ornish-52">[53]</a></sup> These results were amplified by a 2006 study in which over 2,400 women were studied, half randomly assigned to a normal diet, the other half assigned to a diet containing less than 20% calories from fat. The women on the low fat diet were found to have a markedly lower risk of breast cancer recurrence, in the interim report of December, 2006.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-53">[54]</a></sup></p>
<p>Recent studies have also demonstrated potential links between some forms of cancer and high consumption of refined sugars and other simple carbohydrates.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-54">[55]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-55">[56]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-56">[57]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-57">[58]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-58">[59]</a></sup> Although the degree of correlation and the degree of causality is still debated,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-59">[60]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-60">[61]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-61">[62]</a></sup> some organizations have in fact begun to recommend reducing intake of refined sugars and starches as part of their cancer prevention regimens.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-62">[63]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-63">[64]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-64">[65]</a></sup></p>
<p>In November 2007, the <a title="American Institute for Cancer Research" href="http://en.wikipedia.org/wiki/American_Institute_for_Cancer_Research">American Institute for Cancer Research</a> (AICR), in conjunction with the <a title="World Cancer Research Fund" href="http://en.wikipedia.org/wiki/World_Cancer_Research_Fund">World Cancer Research Fund</a> (WCRF), published <em><a title="Food, Nutrition, Physical Activity and the Prevention of Cancer: a Global Perspective" href="http://en.wikipedia.org/wiki/Food,_Nutrition,_Physical_Activity_and_the_Prevention_of_Cancer:_a_Global_Perspective">Food, Nutrition, Physical Activity and the Prevention of Cancer: a Global Perspective</a></em>, &#8220;the most current and comprehensive analysis of the literature on diet, physical activity and cancer&#8221;.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-65">[66]</a></sup> The WCRF/AICR Expert Report lists 10 recommendations that people can follow to help reduce their risk of developing cancer, including the following dietary guidelines: (1) reducing intake of foods and drinks that promote weight gain, namely energy-dense foods and sugary drinks, (2) eating mostly foods of plant origin, (3) limiting intake of red meat and avoiding processed meat, (4) limiting consumption of alcoholic beverages, and (5) reducing intake of salt and avoiding mouldy cereals (grains) or pulses (legumes).<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-66">[67]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-67">[68]</a></sup></p>
<p>Some mushrooms offer an anti-cancer effect, which is thought to be linked to their ability to up-regulate the immune system. Some mushrooms known for this effect include, <a title="Reishi" href="http://en.wikipedia.org/wiki/Reishi">Reishi</a>,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid16351502-68">[69]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid18951965-69">[70]</a></sup> <em><a title="Agaricus blazei" href="http://en.wikipedia.org/wiki/Agaricus_blazei">Agaricus blazei</a></em>, <a href="http://www3.interscience.wiley.com/cgi-bin/fulltext/121398729/PDFSTART?CRETRY=1&amp;SRETRY=0">[1]</a>, <a title="Maitake" href="http://en.wikipedia.org/wiki/Maitake">Maitake</a>,<a href="http://www.ncbi.nlm.nih.gov/pubmed/12126464">[2]</a> and <em><a title="Trametes versicolor" href="http://en.wikipedia.org/wiki/Trametes_versicolor">Trametes versicolor</a></em><a href="http://www.ncbi.nlm.nih.gov/pubmed/7606203">[3]</a>. Research suggests the compounds in <a title="Medicinal mushrooms" href="http://en.wikipedia.org/wiki/Medicinal_mushrooms">medicinal mushrooms</a> most responsible for up-regulating the immune system and providing an anti-cancer effect, are a diverse collection of <a title="Polysaccharide" href="http://en.wikipedia.org/wiki/Polysaccharide">polysaccharide</a> compounds, particularly <a title="Beta-glucans" href="http://en.wikipedia.org/wiki/Beta-glucans">beta-glucans</a>. Beta-glucans are known as &#8220;biological response modifiers&#8221;, and their ability to activate the immune system is well documented. Specifically, beta-glucans stimulate the <a title="Innate immune system" href="http://en.wikipedia.org/wiki/Innate_immune_system">innate</a> branch of the immune system. Research has shown beta-glucans have the ability to stimulate <a title="Macrophage" href="http://en.wikipedia.org/wiki/Macrophage">macrophage</a>, <a title="NK cells" href="http://en.wikipedia.org/wiki/NK_cells">NK cells</a>, <a title="T cells" href="http://en.wikipedia.org/wiki/T_cells">T cells</a>, and immune system <a title="Cytokines" href="http://en.wikipedia.org/wiki/Cytokines">cytokines</a>. The mechanisms in which beta-glucans stimulate the immune system is only partially understood. One mechanism in which beta-glucans are able to activate the immune system, is by interacting with the <a title="Complement Receptor 3" href="http://en.wikipedia.org/wiki/Complement_Receptor_3">Macrophage-1 antigen</a> (<a title="CD18" href="http://en.wikipedia.org/wiki/CD18">CD18</a>) <a title="Cell receptor" href="http://en.wikipedia.org/wiki/Cell_receptor">receptor</a> on immune cells.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid15084502-70">[71]</a></sup></p>
<h3>Vitamins</h3>
<p>The idea that cancer can be prevented through vitamin supplementation stems from early observations correlating human disease with vitamin deficiency, such as <a title="Pernicious anemia" href="http://en.wikipedia.org/wiki/Pernicious_anemia">pernicious anemia</a> with <a title="Vitamin B12" href="http://en.wikipedia.org/wiki/Vitamin_B12">vitamin B12</a> deficiency, and <a title="Scurvy" href="http://en.wikipedia.org/wiki/Scurvy">scurvy</a> with <a title="Vitamin C" href="http://en.wikipedia.org/wiki/Vitamin_C">Vitamin C</a> deficiency. This has largely not been proven to be the case with cancer, and vitamin supplementation is largely not proving effective in preventing cancer. The cancer-fighting components of food are also proving to be more numerous and varied than previously understood, so patients are increasingly being advised to consume fresh, unprocessed fruits and vegetables for maximal health benefits.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-71">[72]</a></sup></p>
<p><a title="Epidemiology" href="http://en.wikipedia.org/wiki/Epidemiology">Epidemiological studies</a> have shown that low <a title="Vitamin D" href="http://en.wikipedia.org/wiki/Vitamin_D">vitamin D</a> status is correlated to increased cancer risk.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-72">[73]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-73">[74]</a></sup> However, the results of such studies need to be treated with caution, as they cannot show whether a correlation between two factors means that one causes the other (<em>i.e.</em> <a title="Correlation does not imply causation" href="http://en.wikipedia.org/wiki/Correlation_does_not_imply_causation">correlation does not imply causation</a>).<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-74">[75]</a></sup> The possibility that Vitamin D might protect against cancer has been contrasted with the risk of malignancy from sun exposure. Since exposure to the sun enhances natural human production of vitamin D, some cancer researchers have argued that the potential deleterious malignant effects of sun exposure are far outweighed by the cancer-preventing effects of extra vitamin D synthesis in sun-exposed skin. In 2002, Dr. William B. Grant claimed that 23,800 premature cancer deaths occur in the US annually due to insufficient UVB exposure (apparently via vitamin D deficiency).<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-75">[76]</a></sup> This is higher than 8,800 deaths occurred from melanoma or squamous cell carcinoma, so the overall effect of sun exposure might be beneficial. Another research group<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-76">[77]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-77">[78]</a></sup> estimates that 50,000–63,000 individuals in the United States and 19,000 &#8211; 25,000 in the UK die prematurely from cancer annually due to insufficient vitamin D.</p>
<p>The case of <a title="Beta-carotene" href="http://en.wikipedia.org/wiki/Beta-carotene">beta-carotene</a> provides an example of the importance of <a title="Clinical trial" href="http://en.wikipedia.org/wiki/Clinical_trial">randomized clinical trials</a>. <a title="Epidemiology" href="http://en.wikipedia.org/wiki/Epidemiology">Epidemiologists</a> studying both diet and serum levels observed that high levels of <a title="Beta-carotene" href="http://en.wikipedia.org/wiki/Beta-carotene">beta-carotene</a>, a precursor to <a title="Vitamin A" href="http://en.wikipedia.org/wiki/Vitamin_A">vitamin A</a>, were associated with a protective effect, reducing the risk of cancer. This effect was particularly strong in <a title="Lung cancer" href="http://en.wikipedia.org/wiki/Lung_cancer">lung cancer</a>. This <a title="Hypothesis" href="http://en.wikipedia.org/wiki/Hypothesis">hypothesis</a> led to a series of large randomized <a title="Clinical trials" href="http://en.wikipedia.org/wiki/Clinical_trials">clinical trials</a> conducted in both <a title="Finland" href="http://en.wikipedia.org/wiki/Finland">Finland</a> and the United States (CARET study) during the 1980s and 1990s. This study provided about 80,000 smokers or former smokers with daily supplements of beta-carotene or <a title="Placebo" href="http://en.wikipedia.org/wiki/Placebo">placebos</a>. Contrary to expectation, these tests found no benefit of <a title="Beta-carotene" href="http://en.wikipedia.org/wiki/Beta-carotene">beta-carotene</a> supplementation in reducing lung cancer incidence and mortality. In fact, the risk of lung cancer was slightly, but not significantly, <em>increased</em> by beta-carotene, leading to an early termination of the study.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-78">[79]</a></sup></p>
<p>Results reported in the <a title="Journal of the American Medical Association" href="http://en.wikipedia.org/wiki/Journal_of_the_American_Medical_Association">Journal of the American Medical Association</a> (JAMA) in 2007 indicate that folic acid supplementation is not effective in preventing colon cancer, and folate consumers may be more likely to form colon polyps.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-79">[80]</a></sup></p>
<h3>Chemoprevention</h3>
<p>The concept that medications could be used to prevent cancer is an attractive one, and many high-quality clinical trials support the use of such chemoprevention in defined circumstances.</p>
<p>Daily use of <a title="Tamoxifen" href="http://en.wikipedia.org/wiki/Tamoxifen">tamoxifen</a>, a <a title="Selective estrogen receptor modulator" href="http://en.wikipedia.org/wiki/Selective_estrogen_receptor_modulator">selective estrogen receptor modulator</a> (SERM), typically for 5 years, has been demonstrated to reduce the risk of developing <a title="Breast cancer" href="http://en.wikipedia.org/wiki/Breast_cancer">breast cancer</a> in high-risk women by about 50%. A recent study reported that the <a title="Selective estrogen receptor modulator" href="http://en.wikipedia.org/wiki/Selective_estrogen_receptor_modulator">selective estrogen receptor modulator</a> <a title="Raloxifene" href="http://en.wikipedia.org/wiki/Raloxifene">raloxifene</a> has similar benefits to <a title="Tamoxifen" href="http://en.wikipedia.org/wiki/Tamoxifen">tamoxifen</a> in preventing breast cancer in high-risk women, with a more favorable side effect profile.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-STAR-P2-80">[81]</a></sup></p>
<p><a title="Raloxifene" href="http://en.wikipedia.org/wiki/Raloxifene">Raloxifene</a> is a SERM like <a title="Tamoxifen" href="http://en.wikipedia.org/wiki/Tamoxifen">tamoxifen</a>; it has been shown (in the STAR trial) to reduce the risk of breast cancer in high-risk women equally as well as tamoxifen. In this trial, which studied almost 20,000 women, <a title="Raloxifene" href="http://en.wikipedia.org/wiki/Raloxifene">raloxifene</a> had fewer side effects than <a title="Tamoxifen" href="http://en.wikipedia.org/wiki/Tamoxifen">tamoxifen</a>, though it did permit more <a title="Ductal carcinoma" href="http://en.wikipedia.org/wiki/Ductal_carcinoma">DCIS</a> to form.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-STAR-P2-80">[81]</a></sup></p>
<p><a title="Finasteride" href="http://en.wikipedia.org/wiki/Finasteride">Finasteride</a>, a <a title="5-alpha-reductase inhibitor" href="http://en.wikipedia.org/wiki/5-alpha-reductase_inhibitor">5-alpha-reductase inhibitor</a>, has been shown to lower the risk of prostate cancer, though it seems to mostly prevent low-grade tumors.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-81">[82]</a></sup> The effect of <a title="COX-2 selective inhibitor" href="http://en.wikipedia.org/wiki/COX-2_selective_inhibitor">COX-2 inhibitors</a> such as <a title="Rofecoxib" href="http://en.wikipedia.org/wiki/Rofecoxib">rofecoxib</a> and <a title="Celecoxib" href="http://en.wikipedia.org/wiki/Celecoxib">celecoxib</a> upon the risk of colon polyps have been studied in <a title="Familial adenomatous polyposis" href="http://en.wikipedia.org/wiki/Familial_adenomatous_polyposis">familial adenomatous polyposis</a> patients<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-82">[83]</a></sup> and in the general population.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-83">[84]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-84">[85]</a></sup> In both groups, there were significant reductions in <a title="Colon polyp" href="http://en.wikipedia.org/wiki/Colon_polyp">colon polyp</a> <a title="Incidence (epidemiology)" href="http://en.wikipedia.org/wiki/Incidence_(epidemiology)">incidence</a>, but this came at the price of increased cardiovascular toxicity.</p>
<h3>Genetic testing</h3>
<p><a title="Genetic testing" href="http://en.wikipedia.org/wiki/Genetic_testing">Genetic testing</a> for high-risk individuals is already available for certain cancer-related genetic mutations. Carriers of genetic mutations that increase risk for cancer incidence can undergo enhanced surveillance, chemoprevention, or risk-reducing surgery. Early identification of inherited genetic risk for cancer, along with cancer-preventing interventions such as surgery or enhanced surveillance, can be lifesaving for high-risk individuals.</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="center"><strong>Gene</strong><strong></strong></p>
</td>
<td>
<p align="center"><strong>Cancer types</strong><strong></strong></p>
</td>
<td>
<p align="center"><strong>Availability</strong><strong></strong></p>
</td>
</tr>
<tr>
<td><a title="BRCA1" href="http://en.wikipedia.org/wiki/BRCA1">BRCA1</a>, <a title="BRCA2" href="http://en.wikipedia.org/wiki/BRCA2">BRCA2</a></td>
<td>Breast, ovarian, pancreatic</td>
<td>Commercially available for clinical specimens</td>
</tr>
<tr>
<td><a title="MLH1" href="http://en.wikipedia.org/wiki/MLH1">MLH1</a>, <a title="MSH2" href="http://en.wikipedia.org/wiki/MSH2">MSH2</a>, <a title="MSH6" href="http://en.wikipedia.org/wiki/MSH6">MSH6</a>, <a title="PMS1" href="http://en.wikipedia.org/wiki/PMS1">PMS1</a>, <a title="PMS2" href="http://en.wikipedia.org/wiki/PMS2">PMS2</a></td>
<td>Colon, uterine, small bowel, stomach, urinary tract</td>
<td>Commercially available for clinical specimens</td>
</tr>
</tbody>
</table>
<h3>Vaccination</h3>
<p>Prophylactic <a title="Vaccine" href="http://en.wikipedia.org/wiki/Vaccine">vaccines</a> have been developed to prevent infection by oncogenic infectious agents such as viruses, and therapeutic vaccines are in development to stimulate an immune response against cancer-specific <a title="Epitope" href="http://en.wikipedia.org/wiki/Epitope">epitopes</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-vacc_facts_nci-85">[86]</a></sup></p>
<p>As reported above, a preventive <a title="Human papillomavirus vaccine" href="http://en.wikipedia.org/wiki/Human_papillomavirus_vaccine">human papillomavirus vaccine</a> exists that targets certain sexually transmitted strains of <a title="Human papillomavirus" href="http://en.wikipedia.org/wiki/Human_papillomavirus">human papillomavirus</a> that are associated with the development of <a title="Cervical cancer" href="http://en.wikipedia.org/wiki/Cervical_cancer">cervical cancer</a> and <a title="Genital warts" href="http://en.wikipedia.org/wiki/Genital_warts">genital warts</a>. The only two HPV vaccines on the market as of October 2007 are <a title="Gardasil" href="http://en.wikipedia.org/wiki/Gardasil">Gardasil</a> and <a title="Cervarix" href="http://en.wikipedia.org/wiki/Cervarix">Cervarix</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-vacc_facts_nci-85">[86]</a></sup> There is also a <a title="Hepatitis B vaccine" href="http://en.wikipedia.org/wiki/Hepatitis_B_vaccine">hepatitis B vaccine</a>, which prevents infection with the hepatitis B virus, an infectious agent that can cause liver cancer.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-vacc_facts_nci-85">[86]</a></sup> A canine melanoma vaccine has also been developed.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Liao-86">[87]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-87">[88]</a></sup></p>
<h3>Screening</h3>
<p><em>Main article: <a title="Cancer screening" href="http://en.wikipedia.org/wiki/Cancer_screening">Cancer screening</a></em></p>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="center"> </p>
</td>
<td width="100%">This article <strong>does not <a title="Wikipedia:Citing sources" href="http://en.wikipedia.org/wiki/Wikipedia:Citing_sources">cite</a> any <a title="Wikipedia:Verifiability" href="http://en.wikipedia.org/wiki/Wikipedia:Verifiability">references or sources</a></strong>. Please help <a href="http://en.wikipedia.org/w/index.php?title=Cancer&amp;action=edit">improve this article</a> by adding citations to <a title="Wikipedia:Reliable sources" href="http://en.wikipedia.org/wiki/Wikipedia:Reliable_sources">reliable sources</a>. Unsourced material may be <a title="Template:Citation needed" href="http://en.wikipedia.org/wiki/Template:Citation_needed">challenged</a> and <a title="Wikipedia:Verifiability" href="http://en.wikipedia.org/wiki/Wikipedia:Verifiability#Burden_of_evidence">removed</a>. <em>(May 2009)</em></td>
</tr>
</tbody>
</table>
<p>Cancer <a title="Screening (medicine)" href="http://en.wikipedia.org/wiki/Screening_(medicine)">screening</a> is an attempt to detect unsuspected cancers in an asymptomatic population. Screening tests suitable for large numbers of healthy people must be relatively affordable, safe, noninvasive procedures with acceptably low rates of <a title="Type I and type II errors" href="http://en.wikipedia.org/wiki/Type_I_and_type_II_errors">false positive</a> results. If signs of cancer are detected, more definitive and invasive follow up tests are performed to confirm the diagnosis.</p>
<p>Screening for cancer can lead to earlier diagnosis in specific cases. Early diagnosis may lead to extended life, but may also falsely prolong the lead time to death through <a title="Lead time bias" href="http://en.wikipedia.org/wiki/Lead_time_bias">lead time bias</a> or <a title="Length time bias" href="http://en.wikipedia.org/wiki/Length_time_bias">length time bias</a>.</p>
<p>A number of different screening tests have been developed for different malignancies. Breast cancer screening can be done by <a title="Breast self-examination" href="http://en.wikipedia.org/wiki/Breast_self-examination">breast self-examination</a>, though this approach was discredited by a 2005 study in over 300,000 <a title="People's Republic of China" href="http://en.wikipedia.org/wiki/People%27s_Republic_of_China">Chinese</a> women. Screening for breast cancer with <a title="Mammogram" href="http://en.wikipedia.org/wiki/Mammogram">mammograms</a> has been shown to reduce the average stage of diagnosis of breast cancer in a population. Stage of diagnosis in a country has been shown to decrease within ten years of introduction of mammographic screening programs. Colorectal cancer can be detected through <a title="Fecal occult blood test" href="http://en.wikipedia.org/wiki/Fecal_occult_blood_test">fecal occult blood testing</a> and <a title="Colonoscopy" href="http://en.wikipedia.org/wiki/Colonoscopy">colonoscopy</a>, which reduces both colon cancer incidence and mortality, presumably through the detection and removal of pre-malignant polyps. Similarly, cervical cytology testing (using the <a title="Pap smear" href="http://en.wikipedia.org/wiki/Pap_smear">Pap smear</a>) leads to the identification and excision of precancerous lesions. Over time, such testing has been followed by a dramatic reduction of <a title="Cervical cancer" href="http://en.wikipedia.org/wiki/Cervical_cancer">cervical cancer</a> incidence and mortality. <a title="Testicular self-examination" href="http://en.wikipedia.org/wiki/Testicular_self-examination">Testicular self-examination</a> is recommended for men beginning at the age of 15 years to detect <a title="Testicular cancer" href="http://en.wikipedia.org/wiki/Testicular_cancer">testicular cancer</a>. Prostate cancer can be screened using a <a title="Digital rectal exam" href="http://en.wikipedia.org/wiki/Digital_rectal_exam">digital rectal exam</a> along with <a title="Prostate specific antigen" href="http://en.wikipedia.org/wiki/Prostate_specific_antigen">prostate specific antigen</a> (PSA) blood testing, though some authorities (such as the <a title="US Preventive Services Task Force" href="http://en.wikipedia.org/wiki/US_Preventive_Services_Task_Force">US Preventive Services Task Force</a>) recommend against routinely screening all men.</p>
<p>Screening for cancer is controversial in cases when it is not yet known if the test actually saves lives. The controversy arises when it is not clear if the benefits of screening outweigh the risks of follow-up diagnostic tests and cancer treatments. For example: when screening for <a title="Prostate cancer" href="http://en.wikipedia.org/wiki/Prostate_cancer">prostate cancer</a>, the <a title="Prostate specific antigen" href="http://en.wikipedia.org/wiki/Prostate_specific_antigen">PSA</a> test may detect small cancers that would never become life threatening, but once detected will lead to treatment. This situation, called overdiagnosis, puts men at risk for complications from unnecessary treatment such as surgery or radiation. Follow up procedures used to diagnose prostate cancer (<a title="Prostate biopsy" href="http://en.wikipedia.org/wiki/Prostate_biopsy">prostate biopsy</a>) may cause side effects, including bleeding and infection. Prostate cancer treatment may cause <a title="Urinary incontinence" href="http://en.wikipedia.org/wiki/Urinary_incontinence">incontinence</a> (inability to control urine flow) and <a title="Erectile dysfunction" href="http://en.wikipedia.org/wiki/Erectile_dysfunction">erectile dysfunction</a> (erections inadequate for intercourse). Similarly, for <a title="Breast cancer" href="http://en.wikipedia.org/wiki/Breast_cancer">breast cancer</a>, there have recently been criticisms that breast screening programs in some countries cause more problems than they solve. This is because screening of women in the general population will result in a large number of women with false positive results which require extensive follow-up investigations to exclude cancer, leading to having a high number-to-treat (or number-to-screen) to prevent or catch a single case of breast cancer early.</p>
<p>Cervical cancer screening via the <a title="Pap smear" href="http://en.wikipedia.org/wiki/Pap_smear">Pap smear</a> has the best cost-benefit profile of all the forms of cancer screening from a public health perspective as, being largely caused by a virus, it has clear risk factors (sexual contact), and the natural progression of cervical cancer is that it normally spreads slowly over a number of years therefore giving more time for the screening program to catch it early. Moreover, the test itself is easy to perform and relatively cheap.</p>
<p>For these reasons, it is important that the benefits and risks of diagnostic procedures and treatment be taken into account when considering whether to undertake cancer screening.</p>
<p>Use of <a title="Medical imaging" href="http://en.wikipedia.org/wiki/Medical_imaging">medical imaging</a> to search for cancer in people without clear symptoms is similarly marred with problems. There is a significant risk of detection of what has been recently called an <em><a title="Incidentaloma" href="http://en.wikipedia.org/wiki/Incidentaloma">incidentaloma</a></em> &#8211; a benign lesion that may be interpreted as a malignancy and be subjected to potentially dangerous investigations. Recent studies of <a title="CT scan" href="http://en.wikipedia.org/wiki/CT_scan">CT scan</a>-based screening for <a title="Lung cancer" href="http://en.wikipedia.org/wiki/Lung_cancer">lung cancer</a> in smokers have had equivocal results, and systematic screening is not recommended as of July 2007. <a title="Randomized clinical trials" href="http://en.wikipedia.org/wiki/Randomized_clinical_trials">Randomized clinical trials</a> of plain-film <a title="Chest X-rays" href="http://en.wikipedia.org/wiki/Chest_X-rays">chest X-rays</a> to screen for lung cancer in smokers have shown no benefit for this approach.</p>
<p><a title="Canine cancer detection" href="http://en.wikipedia.org/wiki/Canine_cancer_detection">Canine cancer detection</a> has shown promise, but is still in the early stages of research.</p>
<h2>Diagnosis</h2>
<p>Most cancers are initially recognized either because signs or symptoms appear or through screening. Neither of these lead to a definitive diagnosis, which usually requires the opinion of a <a title="Anatomical pathology" href="http://en.wikipedia.org/wiki/Anatomical_pathology">pathologist</a>, a type of physician (medical doctor) who specializes in the diagnosis of cancer and other diseases.</p>
<h3>Investigation</h3>
<p>Chest x-ray showing lung cancer in the left lung.</p>
<p>People with suspected cancer are investigated with <a title="Medical test" href="http://en.wikipedia.org/wiki/Medical_test">medical tests</a>. These commonly include <a title="Blood test" href="http://en.wikipedia.org/wiki/Blood_test">blood tests</a>, <a title="X-ray" href="http://en.wikipedia.org/wiki/X-ray">X-rays</a>, <a title="CT scan" href="http://en.wikipedia.org/wiki/CT_scan">CT scans</a> and <a title="Endoscopy" href="http://en.wikipedia.org/wiki/Endoscopy">endoscopy</a>.</p>
<h3>Biopsy</h3>
<p>A cancer may be suspected for a variety of reasons, but the definitive diagnosis of most malignancies must be confirmed by <a title="Histology" href="http://en.wikipedia.org/wiki/Histology">histological</a> examination of the cancerous cells by a <a title="Anatomical pathology" href="http://en.wikipedia.org/wiki/Anatomical_pathology">pathologist</a>. Tissue can be obtained from a <a title="Biopsy" href="http://en.wikipedia.org/wiki/Biopsy">biopsy</a> or <a title="Surgery" href="http://en.wikipedia.org/wiki/Surgery">surgery</a>. Many biopsies (such as those of the skin, breast or liver) can be done in a doctor&#8217;s office. Biopsies of other organs are performed under <a title="Anesthesia" href="http://en.wikipedia.org/wiki/Anesthesia">anesthesia</a> and require <a title="Surgery" href="http://en.wikipedia.org/wiki/Surgery">surgery</a> in an <a title="Operating room" href="http://en.wikipedia.org/wiki/Operating_room">operating room</a>.</p>
<p>The tissue <a title="Medical diagnosis" href="http://en.wikipedia.org/wiki/Medical_diagnosis">diagnosis</a> given by the pathologist indicates the type of cell that is proliferating, its <a title="Histological grade" href="http://en.wikipedia.org/wiki/Histological_grade">histological grade</a>, genetic abnormalities, and other features of the tumor. Together, this information is useful to evaluate the <a title="Prognosis" href="http://en.wikipedia.org/wiki/Prognosis">prognosis</a> of the patient and to choose the best treatment. <a title="Cytogenetics" href="http://en.wikipedia.org/wiki/Cytogenetics">Cytogenetics</a> and <a title="Immunohistochemistry" href="http://en.wikipedia.org/wiki/Immunohistochemistry">immunohistochemistry</a> are other types of testing that the pathologist may perform on the tissue specimen. These tests may provide information about the molecular changes (such as <a title="Mutation" href="http://en.wikipedia.org/wiki/Mutation">mutations</a>, <a title="Fusion gene" href="http://en.wikipedia.org/wiki/Fusion_gene">fusion genes</a>, and numerical <a title="Chromosome" href="http://en.wikipedia.org/wiki/Chromosome">chromosome</a> changes) that has happened in the cancer cells, and may thus also indicate the future behavior of the cancer (prognosis) and best treatment.</p>
<h2>Treatment</h2>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="center"> </p>
</td>
<td width="100%">It has been suggested that this section be <a title="Wikipedia:Splitting" href="http://en.wikipedia.org/wiki/Wikipedia:Splitting">split</a> into a new article titled <em><a title="Cancer treatment" href="http://en.wikipedia.org/wiki/Cancer_treatment">Cancer treatment</a></em>. (<a title="Talk:Cancer" href="http://en.wikipedia.org/wiki/Talk:Cancer#Propose_split_out_section_Cancer_treatment_to_New_article">Discuss</a>)</td>
</tr>
</tbody>
</table>
<p>Cancer can be treated by <a title="Surgery" href="http://en.wikipedia.org/wiki/Surgery">surgery</a>, <a title="Chemotherapy" href="http://en.wikipedia.org/wiki/Chemotherapy">chemotherapy</a>, <a title="Radiation therapy" href="http://en.wikipedia.org/wiki/Radiation_therapy">radiation therapy</a>, <a title="Immunotherapy" href="http://en.wikipedia.org/wiki/Immunotherapy">immunotherapy</a>, <a title="Monoclonal antibody therapy" href="http://en.wikipedia.org/wiki/Monoclonal_antibody_therapy">monoclonal antibody therapy</a> or other methods. The choice of therapy depends upon the location and grade of the tumor and the <a title="Cancer staging" href="http://en.wikipedia.org/wiki/Cancer_staging">stage</a> of the disease, as well as the general state of the patient (<a title="Performance status" href="http://en.wikipedia.org/wiki/Performance_status">performance status</a>). A number of <a title="Experimental cancer treatment" href="http://en.wikipedia.org/wiki/Experimental_cancer_treatment">experimental cancer treatments</a> are also under development.</p>
<p>Complete removal of the cancer without damage to the rest of the body is the goal of treatment. Sometimes this can be accomplished by surgery, but the propensity of cancers to invade adjacent tissue or to spread to distant sites by microscopic metastasis often limits its effectiveness. The effectiveness of chemotherapy is often limited by toxicity to other tissues in the body. Radiation can also cause damage to normal tissue.</p>
<p>Because &#8220;cancer&#8221; refers to a class of diseases,<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-WhatIsCancerNCI-88">[89]</a><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-89">[90]</a></sup> it is unlikely that there will ever be a single &#8220;<a title="Cure for cancer" href="http://en.wikipedia.org/wiki/Cure_for_cancer">cure for cancer</a>&#8221; any more than there will be a single treatment for all <a title="Infectious disease" href="http://en.wikipedia.org/wiki/Infectious_disease">infectious diseases</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-90">[91]</a></sup> <a title="Angiogenesis inhibitors" href="http://en.wikipedia.org/wiki/Angiogenesis_inhibitors">Angiogenesis inhibitors</a> were once thought to have potential as a &#8220;<a title="Silver bullet" href="http://en.wikipedia.org/wiki/Silver_bullet">silver bullet</a>&#8221; treatment applicable to many types of cancer, but this has not been the case in practice.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-91">[92]</a></sup></p>
<h3>Surgery</h3>
<p>In theory, non-<a title="Hematological" href="http://en.wikipedia.org/wiki/Hematological">hematological</a> cancers can be cured if entirely removed by <a title="Surgery" href="http://en.wikipedia.org/wiki/Surgery">surgery</a>,<sup>[<em><a title="Wikipedia:Citation needed" href="http://en.wikipedia.org/wiki/Wikipedia:Citation_needed">citation needed</a></em>]</sup> but this is not always possible. When the cancer has <a title="Metastasis" href="http://en.wikipedia.org/wiki/Metastasis">metastasized</a> to other sites in the body prior to surgery, complete surgical excision is usually impossible. In the <a title="William Stewart Halsted" href="http://en.wikipedia.org/wiki/William_Stewart_Halsted">Halstedian</a> model of cancer progression, tumors grow locally, then spread to the lymph nodes, then to the rest of the body. This has given rise to the popularity of local-only treatments such as surgery for small cancers. Even small localized tumors are increasingly recognized as possessing metastatic potential.</p>
<p>Examples of surgical procedures for cancer include <a title="Mastectomy" href="http://en.wikipedia.org/wiki/Mastectomy">mastectomy</a> for breast cancer and <a title="Prostatectomy" href="http://en.wikipedia.org/wiki/Prostatectomy">prostatectomy</a> for prostate cancer. The goal of the surgery can be either the removal of only the tumor, or the entire organ. A single cancer cell is invisible to the naked eye but can regrow into a new tumor, a process called recurrence. For this reason, the <a title="Anatomical pathology" href="http://en.wikipedia.org/wiki/Anatomical_pathology">pathologist</a> will examine the surgical specimen to determine if a margin of healthy tissue is present, thus decreasing the chance that microscopic cancer cells are left in the patient.</p>
<p>In addition to removal of the primary tumor, surgery is often necessary for <a title="Cancer staging" href="http://en.wikipedia.org/wiki/Cancer_staging">staging</a>, e.g. determining the extent of the disease and whether it has <a title="Metastasis" href="http://en.wikipedia.org/wiki/Metastasis">metastasized</a> to regional <a title="Lymph node" href="http://en.wikipedia.org/wiki/Lymph_node">lymph nodes</a>. Staging is a major determinant of <a title="Prognosis" href="http://en.wikipedia.org/wiki/Prognosis">prognosis</a> and of the need for <a title="Adjuvant therapy" href="http://en.wikipedia.org/wiki/Adjuvant_therapy">adjuvant therapy</a>.</p>
<p>Occasionally, surgery is necessary to control symptoms, such as <a title="Spinal cord compression" href="http://en.wikipedia.org/wiki/Spinal_cord_compression">spinal cord compression</a> or <a title="Bowel obstruction" href="http://en.wikipedia.org/wiki/Bowel_obstruction">bowel obstruction</a>. This is referred to as <a title="Palliative treatment" href="http://en.wikipedia.org/wiki/Palliative_treatment">palliative treatment</a>.</p>
<h3>Radiation therapy</h3>
<p><em>Main article: <a title="Radiation therapy" href="http://en.wikipedia.org/wiki/Radiation_therapy">Radiation therapy</a></em></p>
<p><a title="Radiation therapy" href="http://en.wikipedia.org/wiki/Radiation_therapy">Radiation therapy</a> (also called radiotherapy, X-ray therapy, or irradiation) is the use of ionizing radiation to kill cancer cells and shrink tumors. Radiation therapy can be administered externally via <a title="External beam radiotherapy" href="http://en.wikipedia.org/wiki/External_beam_radiotherapy">external beam radiotherapy</a> (EBRT) or internally via <a title="Brachytherapy" href="http://en.wikipedia.org/wiki/Brachytherapy">brachytherapy</a>. The effects of radiation therapy are localised and confined to the region being treated. Radiation therapy injures or destroys cells in the area being treated (the &#8220;target tissue&#8221;) by damaging their genetic material, making it impossible for these cells to continue to grow and divide. Although radiation damages both cancer cells and normal cells, most normal cells can recover from the effects of radiation and function properly. The goal of radiation therapy is to damage as many cancer cells as possible, while limiting harm to nearby healthy tissue. Hence, it is given in many fractions, allowing healthy tissue to recover between fractions.</p>
<p>Radiation therapy may be used to treat almost every type of solid tumor, including cancers of the brain, breast, cervix, larynx, lung, pancreas, prostate, skin, stomach, uterus, or soft tissue sarcomas. Radiation is also used to treat leukemia and lymphoma. Radiation dose to each site depends on a number of factors, including the radiosensitivity of each cancer type and whether there are tissues and organs nearby that may be damaged by radiation. Thus, as with every form of treatment, radiation therapy is not without its side effects.</p>
<h3>Chemotherapy</h3>
<p><em>Main article: <a title="Chemotherapy" href="http://en.wikipedia.org/wiki/Chemotherapy">Chemotherapy</a></em></p>
<p><a title="Chemotherapy" href="http://en.wikipedia.org/wiki/Chemotherapy">Chemotherapy</a> is the treatment of cancer with <a title="Medication" href="http://en.wikipedia.org/wiki/Medication">drugs</a> (&#8220;anticancer drugs&#8221;) that can destroy cancer cells. In current usage, the term &#8220;chemotherapy&#8221; usually refers to <em>cytotoxic</em> drugs which affect rapidly dividing cells in general, in contrast with <em>targeted therapy</em> (see below). Chemotherapy drugs interfere with cell division in various possible ways, e.g. with the duplication of <a title="DNA" href="http://en.wikipedia.org/wiki/DNA">DNA</a> or the separation of newly formed <a title="Chromosome" href="http://en.wikipedia.org/wiki/Chromosome">chromosomes</a>. Most forms of chemotherapy target all rapidly dividing cells and are not specific to cancer cells, although some degree of specificity may come from the inability of many cancer cells to repair <a title="DNA damage" href="http://en.wikipedia.org/wiki/DNA_damage">DNA damage</a>, while normal cells generally can. Hence, chemotherapy has the potential to harm healthy tissue, especially those tissues that have a high replacement rate (e.g. intestinal lining). These cells usually repair themselves after chemotherapy.</p>
<p>Because some drugs work better together than alone, two or more drugs are often given at the same time. This is called &#8220;combination chemotherapy&#8221;; most chemotherapy regimens are given in a combination.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-takimoto-92">[93]</a></sup></p>
<p>The treatment of some <a title="Leukaemia" href="http://en.wikipedia.org/wiki/Leukaemia">leukaemias</a> and <a title="Lymphoma" href="http://en.wikipedia.org/wiki/Lymphoma">lymphomas</a> requires the use of high-dose chemotherapy, and <a title="Total body irradiation" href="http://en.wikipedia.org/wiki/Total_body_irradiation">total body irradiation</a> (TBI). This treatment ablates the bone marrow, and hence the body&#8217;s ability to recover and repopulate the blood. For this reason, bone marrow, or peripheral blood stem cell harvesting is carried out before the ablative part of the therapy, to enable &#8220;rescue&#8221; after the treatment has been given. This is known as autologous <a title="Stem cell transplantation" href="http://en.wikipedia.org/wiki/Stem_cell_transplantation">stem cell transplantation</a>. Alternatively, <a title="Hematopoietic stem cells" href="http://en.wikipedia.org/wiki/Hematopoietic_stem_cells">hematopoietic stem cells</a> may be transplanted from a matched unrelated donor (MUD).</p>
<h3>Targeted therapies</h3>
<p><em>Main article: <a title="Targeted therapy" href="http://en.wikipedia.org/wiki/Targeted_therapy">Targeted therapy</a></em></p>
<p>Targeted therapy, which first became available in the late 1990s, has had a significant impact in the treatment of some types of cancer, and is currently a very active research area. This constitutes the use of agents specific for the deregulated proteins of cancer cells. <a title="Small molecule" href="http://en.wikipedia.org/wiki/Small_molecule">Small molecule</a> targeted therapy drugs are generally inhibitors of <a title="Enzyme" href="http://en.wikipedia.org/wiki/Enzyme">enzymatic</a> domains on mutated, overexpressed, or otherwise critical proteins within the cancer cell. Prominent examples are the tyrosine kinase inhibitors <a title="Imatinib" href="http://en.wikipedia.org/wiki/Imatinib">imatinib</a> (Gleevec/Glivec) and <a title="Gefitinib" href="http://en.wikipedia.org/wiki/Gefitinib">gefitinib</a> (Iressa).</p>
<p><a title="Monoclonal antibody therapy" href="http://en.wikipedia.org/wiki/Monoclonal_antibody_therapy">Monoclonal antibody therapy</a> is another strategy in which the therapeutic agent is an <a title="Antibody" href="http://en.wikipedia.org/wiki/Antibody">antibody</a> which specifically binds to a protein on the surface of the cancer cells. Examples include the anti-<a title="HER2/neu" href="http://en.wikipedia.org/wiki/HER2/neu">HER2/neu</a> antibody <a title="Trastuzumab" href="http://en.wikipedia.org/wiki/Trastuzumab">trastuzumab</a> (Herceptin) used in breast cancer, and the anti-CD20 antibody <a title="Rituximab" href="http://en.wikipedia.org/wiki/Rituximab">rituximab</a>, used in a variety of <a title="B-cell" href="http://en.wikipedia.org/wiki/B-cell">B-cell</a> malignancies.</p>
<p><a title="Targeted therapy" href="http://en.wikipedia.org/wiki/Targeted_therapy">Targeted therapy</a> can also involve small <a title="Peptide" href="http://en.wikipedia.org/wiki/Peptide">peptides</a> as &#8220;homing devices&#8221; which can bind to cell surface receptors or affected <a title="Extracellular matrix" href="http://en.wikipedia.org/wiki/Extracellular_matrix">extracellular matrix</a> surrounding the tumor. Radionuclides which are attached to these peptides (e.g. RGDs) eventually kill the cancer cell if the nuclide decays in the vicinity of the cell. Especially oligo- or multimers of these binding motifs are of great interest, since this can lead to enhanced tumor specificity and avidity.</p>
<p><a title="Photodynamic therapy" href="http://en.wikipedia.org/wiki/Photodynamic_therapy">Photodynamic therapy</a> (PDT) is a ternary treatment for cancer involving a photosensitizer, tissue oxygen, and light (often using <a title="Lasers" href="http://en.wikipedia.org/wiki/Lasers">lasers</a>). PDT can be used as treatment for <a title="Basal cell carcinoma" href="http://en.wikipedia.org/wiki/Basal_cell_carcinoma">basal cell carcinoma</a> (BCC) or <a title="Lung cancer" href="http://en.wikipedia.org/wiki/Lung_cancer">lung cancer</a>; PDT can also be useful in removing traces of malignant tissue after surgical removal of large tumors.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-93">[94]</a></sup></p>
<h3>Immunotherapy</h3>
<p>A renal cell carcinoma (lower left) in a <a title="Kidney" href="http://en.wikipedia.org/wiki/Kidney">kidney</a> specimen.</p>
<p><em>Main article: <a title="Cancer immunotherapy" href="http://en.wikipedia.org/wiki/Cancer_immunotherapy">Cancer immunotherapy</a></em></p>
<p>Cancer immunotherapy refers to a diverse set of therapeutic strategies designed to induce the patient&#8217;s own <a title="Immune system" href="http://en.wikipedia.org/wiki/Immune_system">immune system</a> to fight the tumor. Contemporary methods for generating an immune response against tumours include intravesical <a title="Bacillus Calmette-Guérin" href="http://en.wikipedia.org/wiki/Bacillus_Calmette-Gu%C3%A9rin">BCG</a> immunotherapy for superficial bladder cancer, and use of <a title="Interferon" href="http://en.wikipedia.org/wiki/Interferon">interferons</a> and other <a title="Cytokine" href="http://en.wikipedia.org/wiki/Cytokine">cytokines</a> to induce an immune response in <a title="Renal cell carcinoma" href="http://en.wikipedia.org/wiki/Renal_cell_carcinoma">renal cell carcinoma</a> and <a title="Melanoma" href="http://en.wikipedia.org/wiki/Melanoma">melanoma</a> patients. <a title="Vaccine" href="http://en.wikipedia.org/wiki/Vaccine">Vaccines</a> to generate specific <a title="Immune response" href="http://en.wikipedia.org/wiki/Immune_response">immune responses</a> are the subject of intensive research for a number of tumours, notably <a title="Malignant melanoma" href="http://en.wikipedia.org/wiki/Malignant_melanoma">malignant melanoma</a> and <a title="Renal cell carcinoma" href="http://en.wikipedia.org/wiki/Renal_cell_carcinoma">renal cell carcinoma</a>. <a title="Sipuleucel-T" href="http://en.wikipedia.org/wiki/Sipuleucel-T">Sipuleucel-T</a> is a vaccine-like strategy in late clinical trials for <a title="Prostate cancer" href="http://en.wikipedia.org/wiki/Prostate_cancer">prostate cancer</a> in which <a title="Dendritic cell" href="http://en.wikipedia.org/wiki/Dendritic_cell">dendritic cells</a> from the patient are loaded with <a title="Prostatic acid phosphatase" href="http://en.wikipedia.org/wiki/Prostatic_acid_phosphatase">prostatic acid phosphatase</a> peptides to induce a specific immune response against prostate-derived cells.</p>
<p>Allogeneic <a title="Hematopoietic stem cell transplantation" href="http://en.wikipedia.org/wiki/Hematopoietic_stem_cell_transplantation">hematopoietic stem cell transplantation</a> (&#8220;bone marrow transplantation&#8221; from a genetically non-identical donor) can be considered a form of immunotherapy, since the donor&#8217;s immune cells will often attack the tumor in a phenomenon known as <a title="Hematopoietic stem cell transplantation" href="http://en.wikipedia.org/wiki/Hematopoietic_stem_cell_transplantation#Side_effects_and_complications">graft-versus-tumor effect</a>. For this reason, allogeneic HSCT leads to a higher cure rate than autologous transplantation for several cancer types, although the side effects are also more severe.</p>
<h3>Hormonal therapy</h3>
<p><em>Main article: <a title="Hormonal therapy (oncology)" href="http://en.wikipedia.org/wiki/Hormonal_therapy_(oncology)">Hormonal therapy (oncology)</a></em></p>
<p>The growth of some cancers can be inhibited by providing or blocking certain hormones. Common examples of hormone-sensitive tumors include certain types of breast and prostate cancers. Removing or blocking <a title="Estrogen" href="http://en.wikipedia.org/wiki/Estrogen">estrogen</a> or <a title="Testosterone" href="http://en.wikipedia.org/wiki/Testosterone">testosterone</a> is often an important additional treatment. In certain cancers, administration of hormone agonists, such as <a title="Progestogen" href="http://en.wikipedia.org/wiki/Progestogen">progestogens</a> may be therapeutically beneficial.</p>
<h3>Angiogenesis inhibitors</h3>
<p><em>Main article: <a title="Angiogenesis inhibitor" href="http://en.wikipedia.org/wiki/Angiogenesis_inhibitor">Angiogenesis inhibitor</a></em></p>
<p>Angiogenesis inhibitors prevent the extensive growth of blood vessels (<a title="Angiogenesis" href="http://en.wikipedia.org/wiki/Angiogenesis">angiogenesis</a>) that tumors require to survive. Some, such as <a title="Bevacizumab" href="http://en.wikipedia.org/wiki/Bevacizumab">bevacizumab</a>, have been approved and are in clinical use. One of the main problems with anti-angiogenesis drugs is that many factors stimulate blood vessel growth in cells normal or cancerous. Anti-angiogenesis drugs only target one factor, so the other factors continue to stimulate blood vessel growth. Other problems include <a title="Route of administration" href="http://en.wikipedia.org/wiki/Route_of_administration">route of administration</a>, maintenance of stability and activity and targeting at the tumor vasculature.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-94">[95]</a></sup></p>
<h3>Symptom control</h3>
<p>Although the control of the symptoms of cancer is not typically thought of as a treatment directed at the cancer, it is an important determinant of the <a title="Quality of life" href="http://en.wikipedia.org/wiki/Quality_of_life">quality of life</a> of cancer patients, and plays an important role in the decision whether the patient is able to undergo other treatments. Although doctors generally have the therapeutic skills to reduce pain, nausea, vomiting, diarrhea, hemorrhage and other common problems in cancer patients, the multidisciplinary specialty of <a title="Palliative care" href="http://en.wikipedia.org/wiki/Palliative_care">palliative care</a> has arisen specifically in response to the symptom control needs of this group of patients. This is an especially important aspect of care for those patients whose disease is not a good candidate for other forms of treatment. As most treatments for cancer involve significantly unpleasant side effects, a patient with little realistic hope of a cure may choose to seek palliative care only, eschewing more radical therapies in exchange for a prolonged period of normal living.</p>
<p><a title="Analgesia" href="http://en.wikipedia.org/wiki/Analgesia">Pain medication</a>, such as <a title="Morphine" href="http://en.wikipedia.org/wiki/Morphine">morphine</a> and <a title="Oxycodone" href="http://en.wikipedia.org/wiki/Oxycodone">oxycodone</a>, and <a title="Antiemetic" href="http://en.wikipedia.org/wiki/Antiemetic">antiemetics</a>, drugs to suppress nausea and vomiting, are very commonly used in patients with cancer-related symptoms. Improved <a title="Antiemetics" href="http://en.wikipedia.org/wiki/Antiemetics">antiemetics</a> such as <a title="Ondansetron" href="http://en.wikipedia.org/wiki/Ondansetron">ondansetron</a> and analogues, as well as <a title="Aprepitant" href="http://en.wikipedia.org/wiki/Aprepitant">aprepitant</a> have made aggressive treatments much more feasible in cancer patients.</p>
<p><a title="Chronic pain" href="http://en.wikipedia.org/wiki/Chronic_pain">Chronic pain</a> due to cancer is almost always associated with continuing tissue damage due to the disease process or the treatment (i.e. surgery, radiation, chemotherapy). Although there is always a role for environmental factors and affective disturbances in the genesis of pain behaviors, these are not usually the predominant etiologic factors in patients with cancer pain. Furthermore, many patients with severe pain associated with cancer are nearing the end of their lives and <a title="Palliative" href="http://en.wikipedia.org/wiki/Palliative">palliative</a> therapies are required. Issues such as social stigma of using <a title="Opioids" href="http://en.wikipedia.org/wiki/Opioids">opioids</a>, work and functional status, and health care consumption are not likely to be important in the overall case management. Hence, the typical strategy for cancer pain management is to get the patient as comfortable as possible using opioids and other medications, surgery, and physical measures. Doctors have been reluctant to prescribe narcotics for pain in terminal cancer patients, for fear of contributing to addiction or suppressing respiratory function. The <a title="Palliative care" href="http://en.wikipedia.org/wiki/Palliative_care">palliative care</a> movement, a more recent offshoot of the <a title="Hospice" href="http://en.wikipedia.org/wiki/Hospice">hospice</a> movement, has engendered more widespread support for preemptive pain treatment for cancer patients.</p>
<p><a title="Fatigue (medical)" href="http://en.wikipedia.org/wiki/Fatigue_(medical)">Fatigue</a> is a very common problem for cancer patients, and has only recently become important enough for oncologists to suggest treatment, even though it plays a significant role in many patients&#8217; quality of life.</p>
<h3>Treatment trials</h3>
<p><em>Main article: <a title="Experimental cancer treatment" href="http://en.wikipedia.org/wiki/Experimental_cancer_treatment">Experimental cancer treatment</a></em></p>
<p><a title="Clinical trial" href="http://en.wikipedia.org/wiki/Clinical_trial">Clinical trials</a>, also called research studies, test new treatments in people with cancer. The goal of this research is to find better ways to treat cancer and help cancer patients. Clinical trials test many types of treatment such as new drugs, new approaches to surgery or radiation therapy, new combinations of treatments, or new methods such as <a title="Gene therapy" href="http://en.wikipedia.org/wiki/Gene_therapy">gene therapy</a>.</p>
<p>A clinical trial is one of the final stages of a long and careful cancer research process. The search for new treatments begins in the laboratory, where scientists first develop and test new ideas. If an approach seems promising, the next step may be testing a treatment in animals to see how it affects cancer in a living being and whether it has harmful effects. Of course, treatments that work well in the lab or in animals do not always work well in people. Studies are done with cancer patients to find out whether promising treatments are safe and effective.</p>
<p>Patients who take part may be helped personally by the treatment they receive. They get up-to-date care from cancer experts, and they receive either a new treatment being tested or the best available standard treatment for their cancer. At the same time, new treatments also may have unknown risks, but if a new treatment proves effective or more effective than standard treatment, study patients who receive it may be among the first to benefit. There is no guarantee that a new treatment being tested or a standard treatment will produce good results. In children with cancer, a survey of trials found that those enrolled in trials were on average not more likely to do better or worse than those on standard treatment; this confirms that success or failure of an experimental treatment cannot be predicted.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-95">[96]</a></sup></p>
<h3>Complementary and alternative</h3>
<p><em>Main article: <a title="Unproven cancer therapy" href="http://en.wikipedia.org/wiki/Unproven_cancer_therapy">Unproven cancer therapy</a></em></p>
<p><a title="Alternative medicine" href="http://en.wikipedia.org/wiki/Alternative_medicine">Complementary and alternative medicine</a> (CAM) treatments are the diverse group of medical and health care systems, practices, and products that are not part of conventional medicine.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-mnalt-96">[97]</a></sup> &#8220;Complementary medicine&#8221; refers to methods and substances used along with conventional medicine, while &#8220;alternative medicine&#8221; refers to compounds used instead of conventional medicine.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-97">[98]</a></sup> CAM use is common among people with cancer; a 2000 study found that 69% of cancer patients had used at least one CAM therapy as part of their cancer treatment.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Richardson2000-98">[99]</a></sup> Most complementary and alternative medicines for cancer have not been rigorously studied or tested. Some alternative treatments which have been investigated and shown to be ineffective continue to be marketed and promoted.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-pmid15061600-99">[100]</a></sup></p>
<h3>In pregnancy</h3>
<p>The incidence of concurrent cancer during <a title="Pregnancy" href="http://en.wikipedia.org/wiki/Pregnancy">pregnancy</a> has risen due to the increasing age of pregnant mothers<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-curado-100">[101]</a></sup> and due to the incidental discovery of maternal tumors during prenatal ultrasound examinations.</p>
<p>Cancer treatment needs to be selected to do least harm to both the woman and her embryo/fetus. In some cases a <a title="Therapeutic abortion" href="http://en.wikipedia.org/wiki/Therapeutic_abortion">therapeutic abortion</a> may be recommended.</p>
<p>Radiation therapy is generally out of the question, and chemotherapy always poses the risk of miscarriage and congenital malformations.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-curado-100">[101]</a></sup> Little is known about the effects of medications on the child.</p>
<p>Even if a drug has been tested as not crossing the placenta to reach the child, some cancer forms can harm the placenta and make the drug pass over it anyway.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-curado-100">[101]</a></sup> Some forms of skin cancer may even metastasize to the child&#8217;s body.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-curado-100">[101]</a></sup></p>
<p>Diagnosis is also made more difficult, since <a title="Computed tomography" href="http://en.wikipedia.org/wiki/Computed_tomography">computed tomography</a> is infeasible because of its high radiation dose. Still, <a title="Magnetic resonance imaging" href="http://en.wikipedia.org/wiki/Magnetic_resonance_imaging">magnetic resonance imaging</a> works normally.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-curado-100">[101]</a></sup> However, <a title="Contrast medium" href="http://en.wikipedia.org/wiki/Contrast_medium">contrast media</a> cannot be used, since they cross the placenta.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-curado-100">[101]</a></sup></p>
<p>As a consequence of the difficulties to properly diagnose and treat cancer during pregnancy, the alternative methods are either to perform a <a title="Cesarean section" href="http://en.wikipedia.org/wiki/Cesarean_section">Cesarean section</a> when the child is viable in order to begin a more aggressive cancer treatment, or, if the cancer is malignant enough that the mother is unlikely to be able to wait that long, to perform an abortion in order to treat the cancer.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-curado-100">[101]</a></sup></p>
<h3>In utero</h3>
<p>Fetal tumors are sometimes diagnosed while still in utero. <a title="Teratoma" href="http://en.wikipedia.org/wiki/Teratoma">Teratoma</a> is the most common type of fetal tumor, and usually is benign.</p>
<h3>Ultrasound energy</h3>
<p><a title="Ultrasound energy" href="http://en.wikipedia.org/wiki/Ultrasound_energy">Ultrasound energy</a> is being studied as a form of therapy.</p>
<h2>Prognosis</h2>
<p>Cancer has a reputation for being a deadly disease. While this certainly applies to certain particular types, the truths behind the historical connotations of cancer are increasingly being overturned by advances in medical care. Some types of cancer have a prognosis that is substantially better than nonmalignant diseases such as <a title="Heart failure" href="http://en.wikipedia.org/wiki/Heart_failure">heart failure</a> and <a title="Stroke" href="http://en.wikipedia.org/wiki/Stroke">stroke</a>.</p>
<p>Progressive and disseminated malignant disease has a substantial impact on a cancer patient&#8217;s quality of life, and many cancer treatments (such as <a title="Chemotherapy" href="http://en.wikipedia.org/wiki/Chemotherapy">chemotherapy</a>) may have severe side-effects. In the advanced stages of cancer, many patients need extensive care, affecting family members and friends. <a title="Palliative care" href="http://en.wikipedia.org/wiki/Palliative_care">Palliative care</a> solutions may include permanent or &#8220;respite&#8221; hospice nursing.</p>
<h3>Emotional impact</h3>
<p>Many local organizations offer a variety of practical and support services to people with cancer. Support can take the form of <a title="Cancer support group" href="http://en.wikipedia.org/wiki/Cancer_support_group">support groups</a>, <a title="Counseling" href="http://en.wikipedia.org/wiki/Counseling">counseling</a>, advice, financial assistance, transportation to and from treatment, films or information about cancer. Neighborhood organizations, local health care providers, or area hospitals may have resources or services available.</p>
<p>Counseling can provide emotional support to cancer patients and help them better understand their illness. Different types of counseling include individual, group, family, peer counseling, bereavement, patient-to-patient, and sexuality.</p>
<p>Many governmental and charitable organizations have been established to help patients cope with cancer. These organizations are often involved in cancer prevention, cancer treatment, and cancer research.</p>
<h2>Epidemiology</h2>
<p><em>Main article: <a title="Epidemiology of cancer" href="http://en.wikipedia.org/wiki/Epidemiology_of_cancer">Epidemiology of cancer</a></em></p>
<p>Cancer is responsible for about 25% of all deaths in the U.S., and is a major <a title="Public health" href="http://en.wikipedia.org/wiki/Public_health">public health</a> problem in many parts of the world. In the U.S., <a title="Lung cancer" href="http://en.wikipedia.org/wiki/Lung_cancer">lung cancer</a> causes about 30% of cancer deaths but only about 15% of new cancer cases; the most commonly occurring cancer in men is <a title="Prostate cancer" href="http://en.wikipedia.org/wiki/Prostate_cancer">prostate cancer</a> (about 25% of new cases) and in women is <a title="Breast cancer" href="http://en.wikipedia.org/wiki/Breast_cancer">breast cancer</a> (also about 25%). Cancer can also occur in young children and adolescents, but it is rare (about 150 cases per million in the U.S.), with <a title="Leukemia" href="http://en.wikipedia.org/wiki/Leukemia">leukemia</a> being the most common.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-101">[102]</a></sup> In the first year of life the <a title="Incidence (epidemiology)" href="http://en.wikipedia.org/wiki/Incidence_(epidemiology)">incidence</a> is about 230 cases per million in the U.S., with the most common being <a title="Neuroblastoma" href="http://en.wikipedia.org/wiki/Neuroblastoma">neuroblastoma</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-102">[103]</a></sup></p>
<p>Over a third of cancer deaths worldwide are due to potentially modifiable risk factors, which are headed by <a title="Tobacco smoking" href="http://en.wikipedia.org/wiki/Tobacco_smoking">tobacco smoking</a>, <a title="Alcoholic beverage" href="http://en.wikipedia.org/wiki/Alcoholic_beverage">alcohol</a> use, and diets low in <a title="Fruit" href="http://en.wikipedia.org/wiki/Fruit">fruit</a> and <a title="Vegetables" href="http://en.wikipedia.org/wiki/Vegetables">vegetables</a>. In developed countries <a title="Overweight" href="http://en.wikipedia.org/wiki/Overweight">overweight</a> and <a title="Obesity" href="http://en.wikipedia.org/wiki/Obesity">obesity</a> is also a leading cause of cancer, and in low-and-middle-income countries sexual transmission of <a title="Human papillomavirus" href="http://en.wikipedia.org/wiki/Human_papillomavirus">human papillomavirus</a> is a leading risk factor for <a title="Cervical cancer" href="http://en.wikipedia.org/wiki/Cervical_cancer">cervical cancer</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Danaei-41">[42]</a></sup></p>
<h2>History</h2>
<p>Typical macroscopic appearance of cancer. This invasive <a title="Ductal carcinoma" href="http://en.wikipedia.org/wiki/Ductal_carcinoma">ductal carcinoma</a> of the breast (pale area at the center) shows an oval tumor surrounded by spikes of whitish scar tissue in the surrounding yellow fatty tissue. The silhouette vaguely resembles a crab.</p>
<p>Today, the Greek term <a title="Carcinoma" href="http://en.wikipedia.org/wiki/Carcinoma">carcinoma</a> is the medical term for a malignant tumor derived from <a title="Epithelium" href="http://en.wikipedia.org/wiki/Epithelium">epithelial</a> cells. It is <a title="Aulus Cornelius Celsus" href="http://en.wikipedia.org/wiki/Aulus_Cornelius_Celsus">Celsus</a> who translated <em>carcinos</em> into the <a title="Latin" href="http://en.wikipedia.org/wiki/Latin">Latin</a> <em>cancer</em>, also meaning crab. <a title="Galen" href="http://en.wikipedia.org/wiki/Galen">Galen</a> used &#8220;<em>oncos</em>&#8221; to describe <em>all</em> tumours, the root for the modern word <a title="Oncology" href="http://en.wikipedia.org/wiki/Oncology">oncology</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Galen-103">[104]</a></sup></p>
<p><a title="Hippocrates" href="http://en.wikipedia.org/wiki/Hippocrates">Hippocrates</a> described several kinds of cancers. He called benign tumours <em>oncos</em>, <a title="Greek language" href="http://en.wikipedia.org/wiki/Greek_language">Greek</a> for swelling, and malignant tumours <em>carcinos</em>, Greek for <a title="Crab" href="http://en.wikipedia.org/wiki/Crab">crab</a> or <a title="Crayfish" href="http://en.wikipedia.org/wiki/Crayfish">crayfish</a>. This name comes from the appearance of the cut surface of a solid malignant tumour, with &#8220;the veins stretched on all sides as the animal the crab has its feet, whence it derives its name&#8221;<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-104">[105]</a></sup> (see picture). He later added the suffix <em>-oma</em>, Greek for swelling, giving the name <em>carcinoma</em>. Since it was against Greek tradition to open the body, Hippocrates only described and made drawings of outwardly visible tumors on the skin, nose, and breasts. Treatment was based on the <a title="Humorism" href="http://en.wikipedia.org/wiki/Humorism">humor theory</a> of four bodily fluids (black and yellow bile, blood, and phlegm). According to the patient&#8217;s humor, treatment consisted of diet, blood-letting, and/or laxatives. Through the centuries it was discovered that cancer could occur anywhere in the body, but humor-theory based treatment remained popular until the 19th century with the discovery of <a title="Cell (biology)" href="http://en.wikipedia.org/wiki/Cell_(biology)">cells</a>.</p>
<p>The oldest known description and <a title="Surgery" href="http://en.wikipedia.org/wiki/Surgery">surgical</a> treatment of cancer was discovered in <a title="Egypt" href="http://en.wikipedia.org/wiki/Egypt">Egypt</a> and dates back to approximately 1600 B.C. The <a title="Papyrus" href="http://en.wikipedia.org/wiki/Papyrus">Papyrus</a> describes 8 cases of ulcers of the breast that were treated by cauterization, with a tool called &#8220;the fire drill.&#8221; The writing says about the disease, &#8220;There is no treatment.&#8221;<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-CancerOrgHistory-105">[106]</a></sup></p>
<p>Another very early <a title="Surgery" href="http://en.wikipedia.org/wiki/Surgery">surgical</a> treatment for cancer was described in the 1020s by <a title="Avicenna" href="http://en.wikipedia.org/wiki/Avicenna">Avicenna</a> (Ibn Sina) in <em><a title="The Canon of Medicine" href="http://en.wikipedia.org/wiki/The_Canon_of_Medicine">The Canon of Medicine</a></em>. He stated that the <a title="Excision" href="http://en.wikipedia.org/wiki/Excision">excision</a> should be radical and that all diseased <a title="Tissue (biology)" href="http://en.wikipedia.org/wiki/Tissue_(biology)">tissue</a> should be removed, which included the use of <a title="Amputation" href="http://en.wikipedia.org/wiki/Amputation">amputation</a> or the removal of <a title="Vein" href="http://en.wikipedia.org/wiki/Vein">veins</a> running in the direction of the <a title="Tumor" href="http://en.wikipedia.org/wiki/Tumor">tumor</a>. He also recommended the use of <a title="Cauterization" href="http://en.wikipedia.org/wiki/Cauterization">cauterization</a> for the area being treated if necessary.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Patricia-106">[107]</a></sup></p>
<p>In the 16th and 17th centuries, it became more acceptable for doctors to <a title="Autopsy" href="http://en.wikipedia.org/wiki/Autopsy">dissect bodies</a> to discover the cause of death. The German professor <a title="Wilhelm Fabry" href="http://en.wikipedia.org/wiki/Wilhelm_Fabry">Wilhelm Fabry</a> believed that breast cancer was caused by a milk clot in a mammary duct. The Dutch professor <a title="Francois de la Boe Sylvius" href="http://en.wikipedia.org/wiki/Francois_de_la_Boe_Sylvius">Francois de la Boe Sylvius</a>, a follower of <a title="Descartes" href="http://en.wikipedia.org/wiki/Descartes">Descartes</a>, believed that all disease was the outcome of chemical processes, and that acidic <a title="Lymph" href="http://en.wikipedia.org/wiki/Lymph">lymph</a> fluid was the cause of cancer. His contemporary <a title="Nicolaes Tulp" href="http://en.wikipedia.org/wiki/Nicolaes_Tulp">Nicolaes Tulp</a> believed that cancer was a poison that slowly spreads, and concluded that it was <a title="Infectious disease" href="http://en.wikipedia.org/wiki/Infectious_disease">contagious</a>.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-Marilyn_Yalom-107">[108]</a></sup></p>
<p>The first cause of cancer was identified by British surgeon <a title="Percivall Pott" href="http://en.wikipedia.org/wiki/Percivall_Pott">Percivall Pott</a>, who discovered in 1775 that cancer of the <a title="Scrotum" href="http://en.wikipedia.org/wiki/Scrotum">scrotum</a> was a common disease among <a title="Chimney sweep" href="http://en.wikipedia.org/wiki/Chimney_sweep">chimney sweeps</a>. The work of other individual physicians led to various insights, but when physicians started working together they could make firmer conclusions.</p>
<p>With the widespread use of the microscope in the 18th century, it was discovered that the &#8216;cancer poison&#8217; spread from the primary tumor through the lymph nodes to other sites (&#8220;<a title="Metastasis" href="http://en.wikipedia.org/wiki/Metastasis">metastasis</a>&#8220;). This view of the disease was first formulated by the English surgeon <a title="Campbell De Morgan" href="http://en.wikipedia.org/wiki/Campbell_De_Morgan">Campbell De Morgan</a> between 1871 and 1874.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-108">[109]</a></sup> The use of <a title="Surgery" href="http://en.wikipedia.org/wiki/Surgery">surgery</a> to treat cancer had poor results due to problems with hygiene. The renowned Scottish surgeon <a title="Alexander Monro" href="http://en.wikipedia.org/wiki/Alexander_Monro">Alexander Monro</a> saw only 2 breast tumor patients out of 60 surviving surgery for two years. In the 19th century, <a title="Asepsis" href="http://en.wikipedia.org/wiki/Asepsis">asepsis</a> improved surgical hygiene and as the <a title="Cancer survivor" href="http://en.wikipedia.org/wiki/Cancer_survivor">survival</a> statistics went up, surgical removal of the tumor became the primary treatment for cancer. With the exception of <a title="William Coley" href="http://en.wikipedia.org/wiki/William_Coley">William Coley</a> who in the late 1800s felt that the rate of cure after surgery had been higher <em>before</em> asepsis (and who injected bacteria into tumors with mixed results), cancer treatment became dependent on the individual art of the surgeon at removing a tumor. During the same period, the idea that the body was made up of various <a title="Tissue (biology)" href="http://en.wikipedia.org/wiki/Tissue_(biology)">tissues</a>, that in turn were made up of millions of cells, laid rest the humor-theories about chemical imbalances in the body. The age of <a title="Cellular pathology" href="http://en.wikipedia.org/wiki/Cellular_pathology">cellular pathology</a> was born.</p>
<p>When <a title="Marie Curie" href="http://en.wikipedia.org/wiki/Marie_Curie">Marie Curie</a> and <a title="Pierre Curie" href="http://en.wikipedia.org/wiki/Pierre_Curie">Pierre Curie</a> discovered <a title="Radiation" href="http://en.wikipedia.org/wiki/Radiation">radiation</a> at the end of the 19th century, they stumbled upon the first effective non-surgical cancer treatment. With radiation also came the first signs of multi-disciplinary approaches to cancer treatment. The surgeon was no longer operating in isolation, but worked together with hospital radiologists to help patients. The complications in communication this brought, along with the necessity of the patient&#8217;s treatment in a hospital facility rather than at home, also created a parallel process of compiling patient data into hospital files, which in turn led to the first statistical patient studies.</p>
<p>A founding paper of cancer epidemiology was the work of <a title="Janet Lane-Claypon" href="http://en.wikipedia.org/wiki/Janet_Lane-Claypon">Janet Lane-Claypon</a>, who published a comparative study in 1926 of 500 breast cancer cases and 500 control patients of the same background and lifestyle for the British Ministry of Health. Her ground-breaking work on cancer epidemiology was carried on by <a title="Richard Doll" href="http://en.wikipedia.org/wiki/Richard_Doll">Richard Doll</a> and <a title="Austin Bradford Hill" href="http://en.wikipedia.org/wiki/Austin_Bradford_Hill">Austin Bradford Hill</a>, who published &#8220;<a title="Lung Cancer" href="http://en.wikipedia.org/wiki/Lung_Cancer">Lung Cancer</a> and Other Causes of Death In Relation to <a title="Smoking" href="http://en.wikipedia.org/wiki/Smoking">Smoking</a>. A Second Report on the Mortality of British Doctors&#8221; followed in 1956 (otherwise known as the <a title="British doctors study" href="http://en.wikipedia.org/wiki/British_doctors_study">British doctors study</a>). Richard Doll left the <a title="London" href="http://en.wikipedia.org/wiki/London">London</a> Medical Research Center (MRC), to start the <a title="Oxford" href="http://en.wikipedia.org/wiki/Oxford">Oxford</a> unit for Cancer epidemiology in 1968. With the use of <a title="Computer" href="http://en.wikipedia.org/wiki/Computer">computers</a>, the unit was the first to compile large amounts of cancer data. Modern epidemiological methods are closely linked to current concepts of disease and <a title="Public health" href="http://en.wikipedia.org/wiki/Public_health">public health</a> policy. Over the past 50 years, great efforts have been spent on gathering data across medical practise, hospital, provincial, state, and even country boundaries, as a way to study the interdependence of environmental and cultural factors on cancer incidence.</p>
<p>Cancer patient treatment and studies were restricted to individual physicians&#8217; practices until <a title="World War II" href="http://en.wikipedia.org/wiki/World_War_II">World War II</a>, when medical research centers discovered that there were large international differences in disease incidence. This insight drove national public health bodies to make it possible to compile health data across practises and hospitals, a process that many countries do today. The Japanese medical community observed that the bone marrow of victims of the <a title="Atomic bombings of Hiroshima and Nagasaki" href="http://en.wikipedia.org/wiki/Atomic_bombings_of_Hiroshima_and_Nagasaki">atomic bombings of Hiroshima and Nagasaki</a> was completely destroyed. They concluded that diseased <a title="Bone marrow" href="http://en.wikipedia.org/wiki/Bone_marrow">bone marrow</a> could also be destroyed with radiation, and this led to the discovery of bone marrow transplants for <a title="Leukemia" href="http://en.wikipedia.org/wiki/Leukemia">leukemia</a>. Since World War II, trends in cancer treatment are to improve on a micro-level the existing treatment methods, standardize them, and globalize them as a way to find cures through <a title="Epidemiology" href="http://en.wikipedia.org/wiki/Epidemiology">epidemiology</a> and international partnerships.</p>
<p>Cancer research is the intense scientific effort to understand disease processes and discover possible therapies. The improved understanding of <a title="Molecular biology" href="http://en.wikipedia.org/wiki/Molecular_biology">molecular biology</a> and <a title="Cellular biology" href="http://en.wikipedia.org/wiki/Cellular_biology">cellular biology</a> due to cancer research has led to a number of new, effective treatments for cancer since President Nixon declared &#8220;<a title="War on Cancer" href="http://en.wikipedia.org/wiki/War_on_Cancer">War on Cancer</a>&#8221; in 1971. Since 1971 the <a title="United States" href="http://en.wikipedia.org/wiki/United_States">United States</a> has invested over $200 billion on cancer research; that total includes money invested by public and private sectors and foundations.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-109">[110]</a></sup> Despite this substantial investment, the country has seen only a five percent decrease in the cancer death rate (adjusting for size and age of the population) between 1950 and 2005.<sup><a href="http://en.wikipedia.org/wiki/Cancer#cite_note-110">[111]</a>                                                                                                                                                                                                                                                                                                                      </sup></p>
<p>TYPES OF CANCER:This list of common cancer types includes cancers that are diagnosed with the greatest frequency in the United States. Cancer incidence statistics from the American Cancer Society<a href="http://www.cancer.gov/cancertopics/commoncancers#1"><sup>1</sup></a> and other resources were used to create the list. To qualify as a common cancer, the estimated annual incidence for 2009 had to be 35,000 cases or more.</p>
<p>The most common type of cancer on the list is nonmelanoma skin cancer, with more than 1,000,000 new cases expected in the United States in 2009. Nonmelanoma skin cancers represent about half of all cancers diagnosed in this country.</p>
<p>The cancer on the list with the lowest incidence is thyroid cancer. The estimated number of new cases of thyroid cancer for 2009 is 37,200.</p>
<p>Because colon and rectal cancers are often referred to as &#8220;colorectal cancers,&#8221; these two cancer types are combined for the list. For 2009, the estimated number of new cases of colon cancer and rectal cancer are 106,100 and 40,870, respectively, adding to a total of 146,970 new cases of colorectal cancer.</p>
<p>Kidney cancers can be divided into two major groups, renal parenchyma cancers and renal pelvis cancers. Approximately 85 percent of kidney cancers develop in the renal parenchyma,<a href="http://www.cancer.gov/cancertopics/commoncancers#2"><sup>2</sup></a> and nearly all of these cancers are renal cell cancers. The estimated number of new cases of renal cell cancer for 2009 is 49,096.</p>
<p>Leukemia as a cancer type includes acute lymphoblastic (or lymphoid) leukemia, chronic lymphocytic leukemia, acute myeloid leukemia, chronic myelogenous (or myeloid) leukemia, and other forms of leukemia. It is estimated that more than 44,790 new cases of leukemia will be diagnosed in the United States in 2009, with chronic lymphocytic leukemia being the most common type (approximately 15,490 new cases).</p>
<p>The following table gives the estimated numbers of new cases and deaths for each common cancer type:</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top"><strong>Cancer Type</strong></td>
<td valign="top"><strong>Estimated New Cases</strong></td>
<td valign="top"><strong>Estimated Deaths</strong></td>
</tr>
<tr>
<td valign="top">Bladder</td>
<td valign="top">70,980</td>
<td valign="top">14,330</td>
</tr>
<tr>
<td valign="top">Breast (Female &#8211; Male)</td>
<td valign="top">192,370 &#8211; 1,910</td>
<td valign="top">40,170 &#8211; 440</td>
</tr>
<tr>
<td valign="top">Colon and Rectal (Combined)</td>
<td valign="top">146,970</td>
<td valign="top">49,920</td>
</tr>
<tr>
<td valign="top">Endometrial</td>
<td valign="top">42,160</td>
<td valign="top">7,780</td>
</tr>
<tr>
<td valign="top">Kidney (Renal Cell) Cancer</td>
<td valign="top">49,096</td>
<td valign="top">11,033</td>
</tr>
<tr>
<td valign="top">Leukemia (All)</td>
<td valign="top">44,790</td>
<td valign="top">21,870</td>
</tr>
<tr>
<td valign="top">Lung (Including Bronchus)</td>
<td valign="top">219,440</td>
<td valign="top">159,390</td>
</tr>
<tr>
<td valign="top">Melanoma</td>
<td valign="top">68,720</td>
<td valign="top">8,650</td>
</tr>
<tr>
<td valign="top">Non-Hodgkin Lymphoma</td>
<td valign="top">65,980</td>
<td valign="top">19,500</td>
</tr>
<tr>
<td valign="top">Pancreatic</td>
<td valign="top">42,470</td>
<td valign="top">35,240</td>
</tr>
<tr>
<td valign="top">Prostate</td>
<td valign="top">192,280</td>
<td valign="top">27,360</td>
</tr>
<tr>
<td valign="top">Skin (Nonmelanoma)</td>
<td valign="top">&gt;1,000,000</td>
<td valign="top">&lt;1,000</td>
</tr>
<tr>
<td valign="top">Thyroid</td>
<td valign="top">37,200</td>
<td valign="top">1,630</td>
</tr>
</tbody>
</table>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/know-about-what-is-cancer/'>know about what is cancer</a>, <a href='http://meherchilakalapudi.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1249/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1249&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/09/10/know-about-what-is-cancer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/cellularlogo.jpg" medium="image">
			<media:title type="html">CellularLogo</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/demo07logo.jpg" medium="image">
			<media:title type="html">Demo07Logo</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/digestivelogo.jpg" medium="image">
			<media:title type="html">DigestiveLogo</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/circulatorylogo.jpg" medium="image">
			<media:title type="html">CirculatoryLogo</media:title>
		</media:content>
	</item>
		<item>
		<title>Know about a Humanoid Robot(Artificial intelligence)</title>
		<link>http://meherchilakalapudi.wordpress.com/2011/09/09/know-about-a-humanoid-robotartificial-intelligence/</link>
		<comments>http://meherchilakalapudi.wordpress.com/2011/09/09/know-about-a-humanoid-robotartificial-intelligence/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 09:00:00 +0000</pubDate>
		<dc:creator>meherchilakalapudi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://meherchilakalapudi.wordpress.com/?p=1234</guid>
		<description><![CDATA[   History of artificial intelligence and Timeline of artificial intelligence &#8230;written by kurapati Sirisha(M.E.C.S) Thinking machines and artificial beings appear in Greek myths, such as Talos of Crete, the bronze robot of Hephaestus, and Pygmalion&#8217;s Galatea.[14] Human likenesses believed to have intelligence were built in every major civilization: animated cult images were worshipped in Egypt [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1234&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3 style="text-align:center;"> </h3>
<h2 style="text-align:center;"> <a title="History of artificial intelligence" href="http://en.wikipedia.org/wiki/History_of_artificial_intelligence">History of artificial intelligence</a> and <a title="Timeline of artificial intelligence" href="http://en.wikipedia.org/wiki/Timeline_of_artificial_intelligence">Timeline of artificial intelligence</a></h2>
<h3 style="text-align:right;"><span style="text-decoration:underline;">&#8230;written by kurapati Sirisha(M.E.C.S)</span></h3>
<p>Thinking machines and artificial beings appear in <a title="Greek myth" href="http://en.wikipedia.org/wiki/Greek_myth">Greek myths</a>, such as <a title="Talos" href="http://en.wikipedia.org/wiki/Talos">Talos</a> of <a title="Crete" href="http://en.wikipedia.org/wiki/Crete">Crete</a>, the bronze robot of <a title="Hephaestus" href="http://en.wikipedia.org/wiki/Hephaestus">Hephaestus</a>, and <a title="Pygmalion (mythology)" href="http://en.wikipedia.org/wiki/Pygmalion_%28mythology%29">Pygmalion&#8217;s</a> <a title="Galatea (mythology)" href="http://en.wikipedia.org/wiki/Galatea_%28mythology%29">Galatea</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_in_myth-13"><sup>[14]</sup></a> Human likenesses believed to have intelligence were built in every major civilization: animated <a title="Cult image" href="http://en.wikipedia.org/wiki/Cult_image">cult images</a> were worshipped in <a title="Egypt" href="http://en.wikipedia.org/wiki/Egypt">Egypt</a> and <a title="Greece" href="http://en.wikipedia.org/wiki/Greece">Greece</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Cult_images_as_artificial_intelligence-14"><sup>[15]</sup></a> and humanoid <a title="Automaton" href="http://en.wikipedia.org/wiki/Automaton">automatons</a> were built by <a title="King Mu of Zhou" href="http://en.wikipedia.org/wiki/King_Mu_of_Zhou">Yan Shi</a>, <a title="Hero of Alexandria" href="http://en.wikipedia.org/wiki/Hero_of_Alexandria">Hero of Alexandria</a> and <a title="Al-Jazari" href="http://en.wikipedia.org/wiki/Al-Jazari">Al-Jazari</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Humanoid_automata-15"><sup>[16]</sup></a> It was also widely believed that artificial beings had been created by <a title="Jābir ibn Hayyān" href="http://en.wikipedia.org/wiki/J%C4%81bir_ibn_Hayy%C4%81n">Jābir ibn Hayyān</a>, <a title="Judah Loew" href="http://en.wikipedia.org/wiki/Judah_Loew">Judah Loew</a> and <a title="Paracelsus" href="http://en.wikipedia.org/wiki/Paracelsus">Paracelsus</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Artificial_beings-16"><sup>[17]</sup></a> By the 19th and 20th centuries, artificial beings had become a common feature in fiction, as in <a title="Mary Shelley" href="http://en.wikipedia.org/wiki/Mary_Shelley">Mary Shelley</a>&#8216;s <a title="Frankenstein" href="http://en.wikipedia.org/wiki/Frankenstein"><em>Frankenstein</em></a> or <a title="Karel Čapek" href="http://en.wikipedia.org/wiki/Karel_%C4%8Capek">Karel Čapek</a>&#8216;s <a title="R.U.R. (Rossum's Universal Robots)" href="http://en.wikipedia.org/wiki/R.U.R._%28Rossum%27s_Universal_Robots%29"><em>R.U.R. (Rossum&#8217;s Universal Robots)</em></a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_in_early_science_fiction-17"><sup>[18]</sup></a> <a title="Pamela McCorduck" href="http://en.wikipedia.org/wiki/Pamela_McCorduck">Pamela McCorduck</a> argues that all of these are examples of an ancient urge, as she describes it, &#8220;to forge the gods&#8221;.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-McCorduck.27s_thesis-6"><sup>[7]</sup></a> Stories of these creatures and their fates discuss many of the same hopes, fears and <a title="Ethics of artificial intelligence" href="http://en.wikipedia.org/wiki/Ethics_of_artificial_intelligence">ethical concerns</a> that are presented by artificial intelligence.</p>
<p>Mechanical or <a title="Formal reasoning" href="http://en.wikipedia.org/wiki/Formal_reasoning">&#8220;formal&#8221; reasoning</a> has been developed by philosophers and mathematicians since antiquity. The study of logic led directly to the invention of the <a title="Computer" href="http://en.wikipedia.org/wiki/Computer">programmable digital electronic computer</a>, based on the work of <a title="Mathematician" href="http://en.wikipedia.org/wiki/Mathematician">mathematician</a> <a title="Alan Turing" href="http://en.wikipedia.org/wiki/Alan_Turing">Alan Turing</a> and others. Turing&#8217;s <a title="Theory of computation" href="http://en.wikipedia.org/wiki/Theory_of_computation">theory of computation</a> suggested that a machine, by shuffling symbols as simple as &#8220;0&#8243; and &#8220;1&#8243;, could simulate any conceivable act of mathematical deduction.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-18"><sup>[19]</sup></a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Formal_reasoning-19"><sup>[20]</sup></a> This, along with concurrent discoveries in <a title="Neurology" href="http://en.wikipedia.org/wiki/Neurology">neurology</a>, <a title="Information theory" href="http://en.wikipedia.org/wiki/Information_theory">information theory</a> and <a title="Cybernetic" href="http://en.wikipedia.org/wiki/Cybernetic">cybernetics</a>, inspired a small group of researchers to begin to seriously consider the possibility of building an electronic brain.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI.27s_immediate_precursors-20"><sup>[21]</sup></a></p>
<p>The field of AI research was founded at <a title="Dartmouth Conferences" href="http://en.wikipedia.org/wiki/Dartmouth_Conferences">a conference</a> on the campus of <a title="Dartmouth College" href="http://en.wikipedia.org/wiki/Dartmouth_College">Dartmouth College</a> in the summer of 1956.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Dartmouth_conference-21"><sup>[22]</sup></a> The attendees, including <a title="John McCarthy (computer scientist)" href="http://en.wikipedia.org/wiki/John_McCarthy_%28computer_scientist%29">John McCarthy</a>, <a title="Marvin Minsky" href="http://en.wikipedia.org/wiki/Marvin_Minsky">Marvin Minsky</a>, <a title="Allen Newell" href="http://en.wikipedia.org/wiki/Allen_Newell">Allen Newell</a> and <a title="Herbert Simon" href="http://en.wikipedia.org/wiki/Herbert_Simon">Herbert Simon</a>, became the leaders of AI research for many decades.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Hegemony_of_the_Dartmouth_conference_attendees-22"><sup>[23]</sup></a> They and their students wrote programs that were, to most people, simply astonishing:<sup><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-23">[24]</a></sup> computers were solving word problems in algebra, proving logical theorems and speaking English.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Golden_years_of_AI-24"><sup>[25]</sup></a> By the middle of the 1960s, research in the U.S. was heavily funded by the <a title="DARPA" href="http://en.wikipedia.org/wiki/DARPA">Department of Defense</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_funding_in_the_60s-25"><sup>[26]</sup></a> and laboratories had been established around the world.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_in_England-26"><sup>[27]</sup></a> AI&#8217;s founders were profoundly optimistic about the future of the new field: <a title="Herbert Simon" href="http://en.wikipedia.org/wiki/Herbert_Simon">Herbert Simon</a> predicted that &#8220;machines will be capable, within twenty years, of doing any work a man can do&#8221; and <a title="Marvin Minsky" href="http://en.wikipedia.org/wiki/Marvin_Minsky">Marvin Minsky</a> agreed, writing that &#8220;within a generation &#8230; the problem of creating &#8216;artificial intelligence&#8217; will substantially be solved&#8221;.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Optimism_of_early_AI-27"><sup>[28]</sup></a></p>
<p>They had failed to recognize the difficulty of some of the problems they faced.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-28"><sup>[29]</sup></a> In 1974, in response to the criticism of <a title="Sir James Lighthill" href="http://en.wikipedia.org/wiki/Sir_James_Lighthill">Sir James Lighthill</a> and ongoing pressure from the US Congress to fund more productive projects, both the U.S. and British governments cut off all undirected exploratory research in AI. The next few years, when funding for projects was hard to find, would later be called the &#8220;<a title="AI winter" href="http://en.wikipedia.org/wiki/AI_winter">AI winter</a>&#8220;.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-First_AI_winter-29"><sup>[30]</sup></a></p>
<p>In the early 1980s, AI research was revived by the commercial success of <a title="Expert systems" href="http://en.wikipedia.org/wiki/Expert_systems">expert systems</a>,<sup><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Expert_systems-30">[31]</a></sup> a form of AI program that simulated the knowledge and analytical skills of one or more human experts. By 1985 the market for AI had reached over a billion dollars. At the same time, Japan&#8217;s <a title="Fifth generation computer" href="http://en.wikipedia.org/wiki/Fifth_generation_computer">fifth generation computer</a> project inspired the U.S and British governments to restore funding for academic research in the field.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_in_the_80s-31"><sup>[32]</sup></a> However, beginning with the collapse of the <a title="Lisp Machine" href="http://en.wikipedia.org/wiki/Lisp_Machine">Lisp Machine</a> market in 1987, AI once again fell into disrepute, and a second, longer lasting <a title="AI winter" href="http://en.wikipedia.org/wiki/AI_winter">AI winter</a> began.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Second_AI_winter-32"><sup>[33]</sup></a></p>
<p>In the 1990s and early 21st century, AI achieved its greatest successes, albeit somewhat behind the scenes. Artificial intelligence is used for <a title="Logistics" href="http://en.wikipedia.org/wiki/Logistics">logistics</a>, <a title="Data mining" href="http://en.wikipedia.org/wiki/Data_mining">data mining</a>, <a title="Medical diagnosis" href="http://en.wikipedia.org/wiki/Medical_diagnosis">medical diagnosis</a> and many other areas throughout the technology industry.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_widely_used-9"><sup>[10]</sup></a> The success was due to several factors: the increasing computational power of computers (see <a title="Moore's law" href="http://en.wikipedia.org/wiki/Moore%27s_law">Moore&#8217;s law</a>), a greater emphasis on solving specific subproblems, the creation of new ties between AI and other fields working on similar problems, and a new commitment by researchers to solid mathematical methods and rigorous scientific standards.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Formal_methods_in_AI-33"><sup>[34]</sup></a></p>
<p>On 11 May 1997, <a title="IBM Deep Blue" href="http://en.wikipedia.org/wiki/IBM_Deep_Blue">Deep Blue</a> became the first computer chess-playing system to beat a reigning world chess champion, <a title="Garry Kasparov" href="http://en.wikipedia.org/wiki/Garry_Kasparov">Garry Kasparov</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-34"><sup>[35]</sup></a> In 2005, a Stanford robot won the <a title="DARPA Grand Challenge" href="http://en.wikipedia.org/wiki/DARPA_Grand_Challenge">DARPA Grand Challenge</a> by driving autonomously for 131 miles along an unrehearsed desert trail.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-35"><sup>[36]</sup></a> In February 2011, in a <a title="Jeopardy!" href="http://en.wikipedia.org/wiki/Jeopardy%21">Jeopardy!</a> <a title="Quiz show" href="http://en.wikipedia.org/wiki/Quiz_show">quiz show</a> exhibition match, <a title="IBM" href="http://en.wikipedia.org/wiki/IBM">IBM</a>&#8216;s <a title="Question answering system" href="http://en.wikipedia.org/wiki/Question_answering_system">question answering system</a>, <a title="Watson (artificial intelligence software)" href="http://en.wikipedia.org/wiki/Watson_%28artificial_intelligence_software%29">Watson</a>, defeated the two greatest Jeopardy! champions, <a title="Brad Rutter" href="http://en.wikipedia.org/wiki/Brad_Rutter">Brad Rutter</a> and <a title="Ken Jennings" href="http://en.wikipedia.org/wiki/Ken_Jennings">Ken Jennings</a>, by a significant margin.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-36"><sup>[37]</sup></a></p>
<p>The leading-edge definition of artificial intelligence <a title="Research" href="http://en.wikipedia.org/wiki/Research">research</a> is changing over time. One pragmatic definition is: &#8220;AI research is that which computing scientists do not know how to do cost-effectively today.&#8221; For example, in 1956 <a title="Optical character recognition" href="http://en.wikipedia.org/wiki/Optical_character_recognition">optical character recognition</a> (OCR) was considered AI, but today, sophisticated OCR software with a context-sensitive <a title="Spell checker" href="http://en.wikipedia.org/wiki/Spell_checker">spell checker</a> and <a title="Grammar checker" href="http://en.wikipedia.org/wiki/Grammar_checker">grammar checker</a> software comes for free with most <a title="Image scanner" href="http://en.wikipedia.org/wiki/Image_scanner">image scanners</a>. No one would any longer consider already-solved computing science problems like OCR &#8220;artificial intelligence&#8221; today.</p>
<p>Low-cost entertaining chess-playing software is commonly available for tablet computers. <a title="DARPA" href="http://en.wikipedia.org/wiki/DARPA">DARPA</a> no longer provides significant funding for chess-playing computing system development. The <a title="Kinect" href="http://en.wikipedia.org/wiki/Kinect">Kinect</a> which provides a 3D-body-motion interface for the <a title="Xbox 360" href="http://en.wikipedia.org/wiki/Xbox_360">Xbox 360</a> uses algorithms that emerged from lengthy AI research,<sup><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-37">[38]</a></sup> but few consumers realize the technology source.</p>
<p>AI applications are no longer the exclusive domain of <a title="Department of defense" href="http://en.wikipedia.org/wiki/Department_of_defense">Department of defense</a> R&amp;D, but are now common place consumer items and inexpensive intelligent toys.</p>
<p>In common usage, the term &#8220;AI&#8221; no longer seems to apply to off-the-shelf solved computing-science problems, which may have originally emerged out of years of AI research.</p>
<p><strong>Problems</strong></p>
<p>&#8221; <a title="Philosophy of artificial intelligence" href="http://en.wikipedia.org/wiki/Philosophy_of_artificial_intelligence">Can a machine act intelligently?</a>&#8221; is still an open problem. Taking &#8220;A machine can act intelligently.&#8221; as a <a title="Working hypothesis" href="http://en.wikipedia.org/wiki/Working_hypothesis">working hypothesis</a>, many researchers have attempted to build such a machine.</p>
<p>The general problem of simulating (or creating) intelligence has been broken down into a number of specific sub-problems. These consist of particular traits or capabilities that researchers would like an intelligent system to display. The traits described below have received the most attention.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Problems_of_AI-11"><sup>[12]</sup></a></p>
<p>For some of these traits, the <a title="History of AI" href="http://en.wikipedia.org/wiki/History_of_AI#The_problems">sub-problem</a> of how to build a machine that exhibits that trait has been completely solved. The rest remain open problems.</p>
<p><strong> Deduction, reasoning, problem solving</strong></p>
<p>Early AI researchers developed algorithms that imitated the step-by-step reasoning that humans were often assumed to use when they solve puzzles, play board games or make logical deductions.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Reasoning-38"><sup>[39]</sup></a> By the late 1980s and &#8217;90s, AI research had also developed highly successful methods for dealing with <a title="Uncertainty" href="http://en.wikipedia.org/wiki/Uncertainty">uncertain</a> or incomplete information, employing concepts from <a title="Probability" href="http://en.wikipedia.org/wiki/Probability">probability</a> and <a title="Economics" href="http://en.wikipedia.org/wiki/Economics">economics</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Uncertain_reasoning-39"><sup>[40]</sup></a></p>
<p>For difficult problems, most of these algorithms can require enormous computational resources — most experience a &#8220;<a title="Combinatorial explosion" href="http://en.wikipedia.org/wiki/Combinatorial_explosion">combinatorial explosion</a>&#8220;: the amount of memory or computer time required becomes astronomical when the problem goes beyond a certain size. The search for more efficient problem solving algorithms is a high priority for AI research.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Intractability-40"><sup>[41]</sup></a></p>
<p>Human beings solve most of their problems using fast, intuitive judgments rather than the conscious, step-by-step deduction that early AI research was able to model.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Psychological_evidence_of_sub-symbolic_reasoning-41"><sup>[42]</sup></a> AI has made some progress at imitating this kind of &#8220;sub-symbolic&#8221; problem solving: <a title="Embodied agent" href="http://en.wikipedia.org/wiki/Embodied_agent">embodied agent</a> approaches emphasize the importance of <a title="Sensorimotor" href="http://en.wikipedia.org/wiki/Sensorimotor">sensorimotor</a> skills to higher reasoning; <a title="Neural net" href="http://en.wikipedia.org/wiki/Neural_net">neural net</a> research attempts to simulate the structures inside human and animal brains that give rise to this skill.</p>
<p><strong> Knowledge representation</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/18.jpg"><img class="aligncenter size-medium wp-image-1235" title="1" src="http://meherchilakalapudi.files.wordpress.com/2011/09/18.jpg?w=290&#038;h=300" alt="" width="290" height="300" /></a></p>
<p>An ontology represents knowledge as a set of concepts within a domain and the relationships between those concepts.</p>
<p>Main articles: <a title="Knowledge representation" href="http://en.wikipedia.org/wiki/Knowledge_representation">Knowledge representation</a> and <a title="Commonsense knowledge" href="http://en.wikipedia.org/wiki/Commonsense_knowledge">Commonsense knowledge</a></p>
<p><a title="Knowledge representation" href="http://en.wikipedia.org/wiki/Knowledge_representation">Knowledge representation</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Knowledge_representation-42"><sup>[43]</sup></a> and <a title="Knowledge engineering" href="http://en.wikipedia.org/wiki/Knowledge_engineering">knowledge engineering</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Knowledge_engineering-43"><sup>[44]</sup></a> are central to AI research. Many of the problems machines are expected to solve will require extensive knowledge about the world. Among the things that AI needs to represent are: objects, properties, categories and relations between objects;<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Representing_categories_and_relations-44"><sup>[45]</sup></a> situations, events, states and time;<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Representing_time-45"><sup>[46]</sup></a> causes and effects;<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Representing_causation-46"><sup>[47]</sup></a> knowledge about knowledge (what we know about what other people know);<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Representing_knowledge_about_knowledge-47"><sup>[48]</sup></a> and many other, less well researched domains. A representation of &#8220;what exists&#8221; is an <a title="Ontology (computer science)" href="http://en.wikipedia.org/wiki/Ontology_%28computer_science%29">ontology</a> (borrowing a word from traditional <a title="Philosophy" href="http://en.wikipedia.org/wiki/Philosophy">philosophy</a>), of which the most general are called <a title="Upper ontology" href="http://en.wikipedia.org/wiki/Upper_ontology">upper ontologies</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Ontology-48"><sup>[49]</sup></a></p>
<p>Among the most difficult problems in knowledge representation are:</p>
<p><a title="Default reasoning" href="http://en.wikipedia.org/wiki/Default_reasoning">Default reasoning</a> and the <a title="Qualification problem" href="http://en.wikipedia.org/wiki/Qualification_problem">qualification problem</a></p>
<p>Many of the things people know take the form of &#8220;working assumptions.&#8221; For example, if a bird comes up in conversation, people typically picture an animal that is fist sized, sings, and flies. None of these things are true about all birds. <a title="John McCarthy (computer scientist)" href="http://en.wikipedia.org/wiki/John_McCarthy_%28computer_scientist%29">John McCarthy</a> identified this problem in 1969<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Qualification_problem-49"><sup>[50]</sup></a> as the qualification problem: for any commonsense rule that AI researchers care to represent, there tend to be a huge number of exceptions. Almost nothing is simply true or false in the way that abstract logic requires. AI research has explored a number of solutions to this problem.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Default_reasoning_and_non-monotonic_logic-50"><sup>[51]</sup></a></p>
<p>The breadth of <a title="Commonsense knowledge" href="http://en.wikipedia.org/wiki/Commonsense_knowledge">commonsense knowledge</a></p>
<p>The number of atomic facts that the average person knows is astronomical. Research projects that attempt to build a complete knowledge base of <a title="Commonsense knowledge" href="http://en.wikipedia.org/wiki/Commonsense_knowledge">commonsense knowledge</a> (e.g., <a title="Cyc" href="http://en.wikipedia.org/wiki/Cyc">Cyc</a>) require enormous amounts of laborious <a title="Ontology engineering" href="http://en.wikipedia.org/wiki/Ontology_engineering">ontological engineering</a> — they must be built, by hand, one complicated concept at a time.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Breadth_of_commonsense_knowledge-51"><sup>[52]</sup></a> A major goal is to have the computer understand enough concepts to be able to learn by reading from sources like the internet, and thus be able to add to its own ontology.<sup>[<em><a title="Wikipedia:Citation needed" href="http://en.wikipedia.org/wiki/Wikipedia:Citation_needed">citation needed</a></em>]</sup></p>
<p>The subsymbolic form of some <a title="Commonsense knowledge" href="http://en.wikipedia.org/wiki/Commonsense_knowledge">commonsense knowledge</a></p>
<p>Much of what people know is not represented as &#8220;facts&#8221; or &#8220;statements&#8221; that they could express verbally. For example, a chess master will avoid a particular chess position because it &#8220;feels too exposed&#8221;<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-52"><sup>[53]</sup></a> or an art critic can take one look at a statue and instantly realize that it is a fake.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-53"><sup>[54]</sup></a> These are intuitions or tendencies that are represented in the brain non-consciously and sub-symbolically.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Intuition-54"><sup>[55]</sup></a> Knowledge like this informs, supports and provides a context for symbolic, conscious knowledge. As with the related problem of sub-symbolic reasoning, it is hoped that <a title="Situated artificial intelligence" href="http://en.wikipedia.org/wiki/Situated_artificial_intelligence">situated AI</a> or <a title="Computational intelligence" href="http://en.wikipedia.org/wiki/Computational_intelligence">computational intelligence</a> will provide ways to represent this kind of knowledge.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Intuition-54"><sup>[55]</sup></a></p>
<p><strong>Planning</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/22.jpg"><img class="aligncenter size-medium wp-image-1236" title="2" src="http://meherchilakalapudi.files.wordpress.com/2011/09/22.jpg?w=300&#038;h=291" alt="" width="300" height="291" /></a></p>
<p>A <a title="Hierarchical control system" href="http://en.wikipedia.org/wiki/Hierarchical_control_system">hierarchical control system</a> is a form of <a title="Control system" href="http://en.wikipedia.org/wiki/Control_system">control system</a> in which a set of devices and governing software is arranged in a hierarchy.</p>
<p>Main article: <a title="Automated planning and scheduling" href="http://en.wikipedia.org/wiki/Automated_planning_and_scheduling">Automated planning and scheduling</a></p>
<p>Intelligent agents must be able to set goals and achieve them.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Planning-55"><sup>[56]</sup></a> They need a way to visualize the future (they must have a representation of the state of the world and be able to make predictions about how their actions will change it) and be able to make choices that maximize the <a title="Utility" href="http://en.wikipedia.org/wiki/Utility">utility</a> (or &#8220;value&#8221;) of the available choices.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Information_value_theory-56"><sup>[57]</sup></a></p>
<p>In classical planning problems, the agent can assume that it is the only thing acting on the world and it can be certain what the consequences of its actions may be.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Classical_planning-57"><sup>[58]</sup></a> However, if this is not true, it must periodically check if the world matches its predictions and it must change its plan as this becomes necessary, requiring the agent to reason under uncertainty.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Non-deterministic_planning-58"><sup>[59]</sup></a></p>
<p><a title="Multi-agent planning" href="http://en.wikipedia.org/wiki/Multi-agent_planning">Multi-agent planning</a> uses the <a title="Cooperation" href="http://en.wikipedia.org/wiki/Cooperation">cooperation</a> and <a title="Competition" href="http://en.wikipedia.org/wiki/Competition">competition</a> of many agents to achieve a given goal. <a title="Emergent behavior" href="http://en.wikipedia.org/wiki/Emergent_behavior">Emergent behavior</a> such as this is used by <a title="Evolutionary algorithms" href="http://en.wikipedia.org/wiki/Evolutionary_algorithms">evolutionary algorithms</a> and <a title="Swarm intelligence" href="http://en.wikipedia.org/wiki/Swarm_intelligence">swarm intelligence</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Multi-agent_planning-59"><sup>[60]</sup></a></p>
<p><strong> Learning</strong></p>
<p>Main article: <a title="Machine learning" href="http://en.wikipedia.org/wiki/Machine_learning">Machine learning</a></p>
<p><a title="Machine learning" href="http://en.wikipedia.org/wiki/Machine_learning">Machine learning</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Machine_learning-60"><sup>[61]</sup></a> has been central to AI research from the beginning.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-61"><sup>[62]</sup></a> In 1956, at the original Dartmouth AI summer conference, <a title="Ray Solomonoff" href="http://en.wikipedia.org/wiki/Ray_Solomonoff">Ray Solomonoff</a> wrote a report on unsupervised probabilistic machine learning: &#8220;An Inductive Inference Machine&#8221;.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-62"><sup>[63]</sup></a> <a title="Unsupervised learning" href="http://en.wikipedia.org/wiki/Unsupervised_learning">Unsupervised learning</a> is the ability to find patterns in a stream of input. <a title="Supervised learning" href="http://en.wikipedia.org/wiki/Supervised_learning">Supervised learning</a> includes both <a title="Statistical classification" href="http://en.wikipedia.org/wiki/Statistical_classification">classification</a> and numerical <a title="Regression analysis" href="http://en.wikipedia.org/wiki/Regression_analysis">regression</a>. Classification is used to determine what category something belongs in, after seeing a number of examples of things from several categories. Regression takes a set of numerical input/output examples and attempts to discover a continuous function that would generate the outputs from the inputs. In <a title="Reinforcement learning" href="http://en.wikipedia.org/wiki/Reinforcement_learning">reinforcement learning</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Reinforcement_learning-63"><sup>[64]</sup></a> the agent is rewarded for good responses and punished for bad ones. These can be analyzed in terms of <a title="Decision theory" href="http://en.wikipedia.org/wiki/Decision_theory">decision theory</a>, using concepts like <a title="Utility (economics)" href="http://en.wikipedia.org/wiki/Utility_%28economics%29">utility</a>. The mathematical analysis of machine learning algorithms and their performance is a branch of <a title="Theoretical computer science" href="http://en.wikipedia.org/wiki/Theoretical_computer_science">theoretical computer science</a> known as <a title="Computational learning theory" href="http://en.wikipedia.org/wiki/Computational_learning_theory">computational learning theory</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Computational_learning_theory-64"><sup>[65]</sup></a></p>
<p><strong> Natural language processing</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/32.jpg"><img class="aligncenter size-medium wp-image-1237" title="3" src="http://meherchilakalapudi.files.wordpress.com/2011/09/32.jpg?w=291&#038;h=300" alt="" width="291" height="300" /></a></p>
<p>A <a title="Parse tree" href="http://en.wikipedia.org/wiki/Parse_tree">parse tree</a> represents the <a title="Syntax" href="http://en.wikipedia.org/wiki/Syntax">syntactic</a> structure of a sentence according to some <a title="Formal grammar" href="http://en.wikipedia.org/wiki/Formal_grammar">formal grammar</a>.</p>
<p>Main article: <a title="Natural language processing" href="http://en.wikipedia.org/wiki/Natural_language_processing">Natural language processing</a></p>
<p><a title="Natural language processing" href="http://en.wikipedia.org/wiki/Natural_language_processing">Natural language processing</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Natural_language_processing-65"><sup>[66]</sup></a> gives machines the ability to read and understand the languages that humans speak. Many researchers hope that a sufficiently powerful natural language processing system would be able to acquire knowledge on its own, by reading the existing text available over the internet. Some straightforward applications of natural language processing include <a title="Information retrieval" href="http://en.wikipedia.org/wiki/Information_retrieval">information retrieval</a> (or <a title="Text mining" href="http://en.wikipedia.org/wiki/Text_mining">text mining</a>) and <a title="Machine translation" href="http://en.wikipedia.org/wiki/Machine_translation">machine translation</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Applications_of_natural_language_processing-66"><sup>[67]</sup></a></p>
<p><strong> Motion and manipulation</strong></p>
<p>Main article: <a title="Robotics" href="http://en.wikipedia.org/wiki/Robotics">Robotics</a></p>
<p>The field of <a title="Robotics" href="http://en.wikipedia.org/wiki/Robotics">robotics</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Robotics-67"><sup>[68]</sup></a> is closely related to AI. Intelligence is required for robots to be able to handle such tasks as object manipulation<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Configuration_space-68"><sup>[69]</sup></a> and <a title="Motion planning" href="http://en.wikipedia.org/wiki/Motion_planning">navigation</a>, with sub-problems of <a title="Robot localization" href="http://en.wikipedia.org/wiki/Robot_localization">localization</a> (knowing where you are), <a title="Robotic mapping" href="http://en.wikipedia.org/wiki/Robotic_mapping">mapping</a> (learning what is around you) and <a title="Motion planning" href="http://en.wikipedia.org/wiki/Motion_planning">motion planning</a> (figuring out how to get there).<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Robotic_mapping-69"><sup>[70]</sup></a></p>
<p><strong> Perception</strong></p>
<p>Main articles: <a title="Machine perception" href="http://en.wikipedia.org/wiki/Machine_perception">Machine perception</a>, <a title="Computer vision" href="http://en.wikipedia.org/wiki/Computer_vision">Computer vision</a>, and <a title="Speech recognition" href="http://en.wikipedia.org/wiki/Speech_recognition">Speech recognition</a></p>
<p><a title="Machine perception" href="http://en.wikipedia.org/wiki/Machine_perception">Machine perception</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Machine_perception-70"><sup>[71]</sup></a> is the ability to use input from sensors (such as cameras, microphones, sonar and others more exotic) to deduce aspects of the world. <a title="Computer vision" href="http://en.wikipedia.org/wiki/Computer_vision">Computer vision</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Computer_vision-71"><sup>[72]</sup></a> is the ability to analyze visual input. A few selected subproblems are <a title="Speech recognition" href="http://en.wikipedia.org/wiki/Speech_recognition">speech recognition</a>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Speech_recognition-72"><sup>[73]</sup></a> <a title="Facial recognition system" href="http://en.wikipedia.org/wiki/Facial_recognition_system">facial recognition</a> and <a title="Object recognition" href="http://en.wikipedia.org/wiki/Object_recognition">object recognition</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Object_recognition-73"><sup>[74]</sup></a></p>
<p><strong> Social intelligence</strong></p>
<p style="text-align:center;"><a title="Affective computing" href="http://en.wikipedia.org/wiki/Affective_computing">Affective computing</a></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/42.jpg"><img class="aligncenter size-medium wp-image-1238" title="4" src="http://meherchilakalapudi.files.wordpress.com/2011/09/42.jpg?w=300&#038;h=219" alt="" width="300" height="219" /></a></p>
<p>&nbsp;</p>
<p><a title="Kismet (robot)" href="http://en.wikipedia.org/wiki/Kismet_%28robot%29">Kismet</a>, a robot with rudimentary social skills</p>
<p>Emotion and social skills<sup><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Emotion_and_affective_computing-74">[75]</a></sup> play two roles for an intelligent agent. First, it must be able to predict the actions of others, by understanding their motives and emotional states. (This involves elements of <a title="Game theory" href="http://en.wikipedia.org/wiki/Game_theory">game theory</a>, <a title="Decision theory" href="http://en.wikipedia.org/wiki/Decision_theory">decision theory</a>, as well as the ability to model human emotions and the perceptual skills to detect emotions.) Also, for good <a title="Human-computer interaction" href="http://en.wikipedia.org/wiki/Human-computer_interaction">human-computer interaction</a>, an intelligent machine also needs to <em>display</em> emotions. At the very least it must appear polite and sensitive to the humans it interacts with. At best, it should have normal emotions itself.</p>
<p><strong> Creativity</strong></p>
<p>Main article: <a title="Computational creativity" href="http://en.wikipedia.org/wiki/Computational_creativity">Computational creativity</a></p>
<p>A sub-field of AI addresses <a title="Creativity" href="http://en.wikipedia.org/wiki/Creativity">creativity</a> both theoretically (from a philosophical and psychological perspective) and practically (via specific implementations of systems that generate outputs that can be considered creative, or systems that identify and assess creativity). A related area of computational research is <a title="Artificial Intuition (page does not exist)" href="http://en.wikipedia.org/w/index.php?title=Artificial_Intuition&amp;action=edit&amp;redlink=1">Artificial Intuition</a> and <a title="Artificial Imagination" href="http://en.wikipedia.org/wiki/Artificial_Imagination">Artificial Imagination</a>.<sup>[<em><a title="Wikipedia:Citation needed" href="http://en.wikipedia.org/wiki/Wikipedia:Citation_needed">citation needed</a></em>]</sup></p>
<p><strong> General intelligence</strong></p>
<p>Main articles: <a title="Strong AI" href="http://en.wikipedia.org/wiki/Strong_AI">Strong AI</a> and <a title="AI-complete" href="http://en.wikipedia.org/wiki/AI-complete">AI-complete</a></p>
<p>Most researchers hope that their work will eventually be incorporated into a machine with <em>general</em> intelligence (known as <a title="Strong AI" href="http://en.wikipedia.org/wiki/Strong_AI">strong AI</a>), combining all the skills above and exceeding human abilities at most or all of them.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-General_intelligence-12"><sup>[13]</sup></a> A few believe that <a title="Anthropomorphic" href="http://en.wikipedia.org/wiki/Anthropomorphic">anthropomorphic</a> features like <a title="Artificial consciousness" href="http://en.wikipedia.org/wiki/Artificial_consciousness">artificial consciousness</a> or an <a title="Artificial brain" href="http://en.wikipedia.org/wiki/Artificial_brain">artificial brain</a> may be required for such a project.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Artificial_consciousness-75"><sup>[76]</sup></a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Brain_simulation-76"><sup>[77]</sup></a></p>
<p>Many of the problems above are considered <a title="AI-complete" href="http://en.wikipedia.org/wiki/AI-complete">AI-complete</a>: to solve one problem, you must solve them all. For example, even a straightforward, specific task like <a title="Machine translation" href="http://en.wikipedia.org/wiki/Machine_translation">machine translation</a> requires that the machine follow the author&#8217;s argument (<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#Deduction.2C_reasoning.2C_problem_solving">reason</a>), know what is being talked about (<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#Knowledge_representation">knowledge</a>), and faithfully reproduce the author&#8217;s intention (<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#Social_intelligence">social intelligence</a>). <a title="Machine translation" href="http://en.wikipedia.org/wiki/Machine_translation">Machine translation</a>, therefore, is believed to be AI-complete: it may require <a title="Strong AI" href="http://en.wikipedia.org/wiki/Strong_AI">strong AI</a> to be done as well as humans can do it.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_complete-77"><sup>[78]</sup></a></p>
<p><strong> Approaches</strong></p>
<p>There is no established unifying theory or <a title="Paradigm" href="http://en.wikipedia.org/wiki/Paradigm">paradigm</a> that guides AI research. Researchers disagree about many issues.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-78"><sup>[79]</sup></a> A few of the most long standing questions that have remained unanswered are these: should artificial intelligence simulate natural intelligence by studying <a title="Psychology" href="http://en.wikipedia.org/wiki/Psychology">psychology</a> or <a title="Neurology" href="http://en.wikipedia.org/wiki/Neurology">neurology</a>? Or is human biology as irrelevant to AI research as bird biology is to <a title="Aeronautical engineering" href="http://en.wikipedia.org/wiki/Aeronautical_engineering">aeronautical engineering</a>?<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Biological_intelligence_vs._intelligence_in_general-79"><sup>[80]</sup></a> Can intelligent behavior be described using simple, elegant principles (such as <a title="Logic" href="http://en.wikipedia.org/wiki/Logic">logic</a> or <a title="Optimization (mathematics)" href="http://en.wikipedia.org/wiki/Optimization_%28mathematics%29">optimization</a>)? Or does it necessarily require solving a large number of completely unrelated problems?<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Neats_vs._scruffies-80"><sup>[81]</sup></a> Can intelligence be reproduced using high-level symbols, similar to words and ideas? Or does it require &#8220;sub-symbolic&#8221; processing?<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Symbolic_vs._sub-symbolic-81"><sup>[82]</sup></a> John Haugeland, who coined the term GOFAI (Good Old-Fashioned Artificial Intelligence), also proposed that AI should more properly be referred to as <a title="Synthetic intelligence" href="http://en.wikipedia.org/wiki/Synthetic_intelligence">synthetic intelligence</a>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-FOOTNOTEHaugeland1985255-82"><sup>[83]</sup></a> a term which has since been adopted by some non-GOFAI researchers.<a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.38.8384&amp;rep=rep1&amp;type=pdf">[2]</a><a href="http://books.google.com/books?hl=en&amp;lr=&amp;id=a_ZR81Z25z0C&amp;oi=fnd&amp;pg=PA63&amp;dq=related:iCpuTpmGk6gJ:scholar.google.com/&amp;ots=n1-TsvqXGJ&amp;sig=1xthOJ2WQmKtdSt7ISFH2yu2l3Q#v=onepage&amp;q&amp;f=false">[3]</a><a href="http://www.imagination-engines.com/">[4]</a></p>
<p><strong>Cybernetics and brain simulation</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/51.jpg"><img class="aligncenter size-medium wp-image-1239" title="5" src="http://meherchilakalapudi.files.wordpress.com/2011/09/51.jpg?w=300&#038;h=284" alt="" width="300" height="284" /></a></p>
<p>There is currently no consensus on how closely the brain should be <a title="Computer simulation" href="http://en.wikipedia.org/wiki/Computer_simulation">simulated</a>.</p>
<p>: <a title="Cybernetics" href="http://en.wikipedia.org/wiki/Cybernetics">Cybernetics</a> and <a title="Computational neuroscience" href="http://en.wikipedia.org/wiki/Computational_neuroscience">Computational neuroscience</a></p>
<p>In the 1940s and 1950s, a number of researchers explored the connection between <a title="Neurology" href="http://en.wikipedia.org/wiki/Neurology">neurology</a>, <a title="Information theory" href="http://en.wikipedia.org/wiki/Information_theory">information theory</a>, and <a title="Cybernetics" href="http://en.wikipedia.org/wiki/Cybernetics">cybernetics</a>. Some of them built machines that used electronic networks to exhibit rudimentary intelligence, such as <a title="W. Grey Walter" href="http://en.wikipedia.org/wiki/W._Grey_Walter">W. Grey Walter</a>&#8216;s <a title="Turtle (robot)" href="http://en.wikipedia.org/wiki/Turtle_%28robot%29">turtles</a> and the <a title="Johns Hopkins Beast" href="http://en.wikipedia.org/wiki/Johns_Hopkins_Beast">Johns Hopkins Beast</a>. Many of these researchers gathered for meetings of the Teleological Society at <a title="Princeton University" href="http://en.wikipedia.org/wiki/Princeton_University">Princeton University</a> and the <a title="Ratio Club" href="http://en.wikipedia.org/wiki/Ratio_Club">Ratio Club</a> in England.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI.27s_immediate_precursors-20"><sup>[21]</sup></a> By 1960, this approach was largely abandoned, although elements of it would be revived in the 1980s.</p>
<p><strong> Symbolic</strong></p>
<p> <a title="GOFAI" href="http://en.wikipedia.org/wiki/GOFAI">GOFAI</a></p>
<p>When access to digital computers became possible in the middle 1950s, AI research began to explore the possibility that human intelligence could be reduced to symbol manipulation. The research was centered in three institutions: <a title="Carnegie Mellon University" href="http://en.wikipedia.org/wiki/Carnegie_Mellon_University">CMU</a>, <a title="Stanford" href="http://en.wikipedia.org/wiki/Stanford">Stanford</a> and <a title="MIT" href="http://en.wikipedia.org/wiki/MIT">MIT</a>, and each one developed its own style of research. <a title="John Haugeland" href="http://en.wikipedia.org/wiki/John_Haugeland">John Haugeland</a> named these approaches to AI &#8220;good old fashioned AI&#8221; or &#8220;<a title="GOFAI" href="http://en.wikipedia.org/wiki/GOFAI">GOFAI</a>&#8220;.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-GOFAI-83"><sup>[84]</sup></a></p>
<p>Cognitive simulation</p>
<p><a title="Economist" href="http://en.wikipedia.org/wiki/Economist">Economist</a> <a title="Herbert Simon" href="http://en.wikipedia.org/wiki/Herbert_Simon">Herbert Simon</a> and <a title="Allen Newell" href="http://en.wikipedia.org/wiki/Allen_Newell">Allen Newell</a> studied human problem solving skills and attempted to formalize them, and their work laid the foundations of the field of artificial intelligence, as well as <a title="Cognitive science" href="http://en.wikipedia.org/wiki/Cognitive_science">cognitive science</a>, <a title="Operations research" href="http://en.wikipedia.org/wiki/Operations_research">operations research</a> and <a title="Management science" href="http://en.wikipedia.org/wiki/Management_science">management science</a>. Their research team used the results of <a title="Psychology" href="http://en.wikipedia.org/wiki/Psychology">psychological</a> experiments to develop programs that simulated the techniques that people used to solve problems. This tradition, centered at <a title="Carnegie Mellon University" href="http://en.wikipedia.org/wiki/Carnegie_Mellon_University">Carnegie Mellon University</a> would eventually culminate in the development of the <a title="Soar (cognitive architecture)" href="http://en.wikipedia.org/wiki/Soar_%28cognitive_architecture%29">Soar</a> architecture in the middle 80s.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_at_CMU_in_the_60s-84"><sup>[85]</sup></a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Soar-85"><sup>[86]</sup></a></p>
<p>Logic-based</p>
<p>Unlike <a title="Alan Newell" href="http://en.wikipedia.org/wiki/Alan_Newell">Newell</a> and <a title="Herbert Simon" href="http://en.wikipedia.org/wiki/Herbert_Simon">Simon</a>, <a title="John McCarthy (computer scientist)" href="http://en.wikipedia.org/wiki/John_McCarthy_%28computer_scientist%29">John McCarthy</a> felt that machines did not need to simulate human thought, but should instead try to find the essence of abstract reasoning and problem solving, regardless of whether people used the same algorithms.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Biological_intelligence_vs._intelligence_in_general-79"><sup>[80]</sup></a> His laboratory at <a title="Stanford University" href="http://en.wikipedia.org/wiki/Stanford_University">Stanford</a> (<a title="Stanford Artificial Intelligence Laboratory" href="http://en.wikipedia.org/wiki/Stanford_Artificial_Intelligence_Laboratory">SAIL</a>) focused on using formal <a title="Logic" href="http://en.wikipedia.org/wiki/Logic">logic</a> to solve a wide variety of problems, including <a title="Knowledge representation" href="http://en.wikipedia.org/wiki/Knowledge_representation">knowledge representation</a>, <a title="Automated planning and scheduling" href="http://en.wikipedia.org/wiki/Automated_planning_and_scheduling">planning</a> and <a title="Machine learning" href="http://en.wikipedia.org/wiki/Machine_learning">learning</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_at_Stanford_in_the_60s-86"><sup>[87]</sup></a> Logic was also focus of the work at the <a title="University of Edinburgh" href="http://en.wikipedia.org/wiki/University_of_Edinburgh">University of Edinburgh</a> and elsewhere in Europe which led to the development of the programming language <a title="Prolog" href="http://en.wikipedia.org/wiki/Prolog">Prolog</a> and the science of <a title="Logic programming" href="http://en.wikipedia.org/wiki/Logic_programming">logic programming</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_at_Edinburgh_and_France_in_the_60s-87"><sup>[88]</sup></a></p>
<p>&#8220;Anti-logic&#8221; or &#8220;scruffy&#8221;</p>
<p>Researchers at <a title="MIT" href="http://en.wikipedia.org/wiki/MIT">MIT</a> (such as <a title="Marvin Minsky" href="http://en.wikipedia.org/wiki/Marvin_Minsky">Marvin Minsky</a> and <a title="Seymour Papert" href="http://en.wikipedia.org/wiki/Seymour_Papert">Seymour Papert</a>)<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_at_MIT_in_the_60s-88"><sup>[89]</sup></a> found that solving difficult problems in <a title="Computer vision" href="http://en.wikipedia.org/wiki/Computer_vision">vision</a> and <a title="Natural language processing" href="http://en.wikipedia.org/wiki/Natural_language_processing">natural language processing</a> required ad-hoc solutions – they argued that there was no simple and general principle (like <a title="Logic" href="http://en.wikipedia.org/wiki/Logic">logic</a>) that would capture all the aspects of intelligent behavior. <a title="Roger Schank" href="http://en.wikipedia.org/wiki/Roger_Schank">Roger Schank</a> described their &#8220;anti-logic&#8221; approaches as &#8220;<a title="Neats vs. scruffies" href="http://en.wikipedia.org/wiki/Neats_vs._scruffies">scruffy</a>&#8221; (as opposed to the &#8220;<a title="Neats vs. scruffies" href="http://en.wikipedia.org/wiki/Neats_vs._scruffies">neat</a>&#8221; paradigms at <a title="Carnegie Mellon University" href="http://en.wikipedia.org/wiki/Carnegie_Mellon_University">CMU</a> and <a title="Stanford" href="http://en.wikipedia.org/wiki/Stanford">Stanford</a>).<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Neats_vs._scruffies-80"><sup>[81]</sup></a> <a title="Commonsense knowledge bases" href="http://en.wikipedia.org/wiki/Commonsense_knowledge_bases">Commonsense knowledge bases</a> (such as <a title="Doug Lenat" href="http://en.wikipedia.org/wiki/Doug_Lenat">Doug Lenat</a>&#8216;s <a title="Cyc" href="http://en.wikipedia.org/wiki/Cyc">Cyc</a>) are an example of &#8220;scruffy&#8221; AI, since they must be built by hand, one complicated concept at a time.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Cyc-89"><sup>[90]</sup></a></p>
<p>Knowledge-based</p>
<p>When computers with large memories became available around 1970, researchers from all three traditions began to build <a title="Knowledge representation" href="http://en.wikipedia.org/wiki/Knowledge_representation">knowledge</a> into AI applications.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Knowledge_revolution-90"><sup>[91]</sup></a> This &#8220;knowledge revolution&#8221; led to the development and deployment of <a title="Expert system" href="http://en.wikipedia.org/wiki/Expert_system">expert systems</a> (introduced by <a title="Edward Feigenbaum" href="http://en.wikipedia.org/wiki/Edward_Feigenbaum">Edward Feigenbaum</a>), the first truly successful form of AI software.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Expert_systems-30"><sup>[31]</sup></a> The knowledge revolution was also driven by the realization that enormous amounts of knowledge would be required by many simple AI applications.</p>
<p><strong> Sub-symbolic</strong></p>
<p>During the 1960s, symbolic approaches had achieved great success at simulating high-level thinking in small demonstration programs. Approaches based on <a title="Cybernetics" href="http://en.wikipedia.org/wiki/Cybernetics">cybernetics</a> or <a title="Neural network" href="http://en.wikipedia.org/wiki/Neural_network">neural networks</a> were abandoned or pushed into the background.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-91"><sup>[92]</sup></a> By the 1980s, however, progress in symbolic AI seemed to stall and many believed that symbolic systems would never be able to imitate all the processes of human cognition, especially <a title="Machine perception" href="http://en.wikipedia.org/wiki/Machine_perception">perception</a>, <a title="Robotics" href="http://en.wikipedia.org/wiki/Robotics">robotics</a>, <a title="Machine learning" href="http://en.wikipedia.org/wiki/Machine_learning">learning</a> and <a title="Pattern recognition" href="http://en.wikipedia.org/wiki/Pattern_recognition">pattern recognition</a>. A number of researchers began to look into &#8220;sub-symbolic&#8221; approaches to specific AI problems.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Symbolic_vs._sub-symbolic-81"><sup>[82]</sup></a></p>
<p>Bottom-up, <a title="Embodied agent" href="http://en.wikipedia.org/wiki/Embodied_agent">embodied</a>, <a title="Situated" href="http://en.wikipedia.org/wiki/Situated">situated</a>, <a title="Behavior-based AI" href="http://en.wikipedia.org/wiki/Behavior-based_AI">behavior-based</a> or <a title="Nouvelle AI" href="http://en.wikipedia.org/wiki/Nouvelle_AI">nouvelle AI</a></p>
<p>Researchers from the related field of <a title="Robotics" href="http://en.wikipedia.org/wiki/Robotics">robotics</a>, such as <a title="Rodney Brooks" href="http://en.wikipedia.org/wiki/Rodney_Brooks">Rodney Brooks</a>, rejected symbolic AI and focused on the basic engineering problems that would allow robots to move and survive.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Embodied_AI-92"><sup>[93]</sup></a> Their work revived the non-symbolic viewpoint of the early <a title="Cybernetic" href="http://en.wikipedia.org/wiki/Cybernetic">cybernetics</a> researchers of the 50s and reintroduced the use of <a title="Control theory" href="http://en.wikipedia.org/wiki/Control_theory">control theory</a> in AI. This coincided with the development of the <a title="Embodied mind thesis" href="http://en.wikipedia.org/wiki/Embodied_mind_thesis">embodied mind thesis</a> in the related field of <a title="Cognitive science" href="http://en.wikipedia.org/wiki/Cognitive_science">cognitive science</a>: the idea that aspects of the body (such as movement, perception and visualization) are required for higher intelligence.</p>
<p>Computational Intelligence</p>
<p>Interest in <a title="Neural networks" href="http://en.wikipedia.org/wiki/Neural_networks">neural networks</a> and &#8220;<a title="Connectionism" href="http://en.wikipedia.org/wiki/Connectionism">connectionism</a>&#8221; was revived by <a title="David Rumelhart" href="http://en.wikipedia.org/wiki/David_Rumelhart">David Rumelhart</a> and others in the middle 1980s.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Revival_of_connectionism-93"><sup>[94]</sup></a> These and other sub-symbolic approaches, such as <a title="Fuzzy system" href="http://en.wikipedia.org/wiki/Fuzzy_system">fuzzy systems</a> and <a title="Evolutionary computation" href="http://en.wikipedia.org/wiki/Evolutionary_computation">evolutionary computation</a>, are now studied collectively by the emerging discipline of <a title="Computational intelligence" href="http://en.wikipedia.org/wiki/Computational_intelligence">computational intelligence</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Computational_intelligence-94"><sup>[95]</sup></a></p>
<p><strong> Statistical</strong></p>
<p>In the 1990s, AI researchers developed sophisticated mathematical tools to solve specific subproblems. These tools are truly <a title="Scientific method" href="http://en.wikipedia.org/wiki/Scientific_method">scientific</a>, in the sense that their results are both measurable and verifiable, and they have been responsible for many of AI&#8217;s recent successes. The shared mathematical language has also permitted a high level of collaboration with more established fields (like <a title="Mathematics" href="http://en.wikipedia.org/wiki/Mathematics">mathematics</a>, <a title="Economics" href="http://en.wikipedia.org/wiki/Economics">economics</a> or <a title="Operations research" href="http://en.wikipedia.org/wiki/Operations_research">operations research</a>). <a title="Stuart J. Russell" href="http://en.wikipedia.org/wiki/Stuart_J._Russell">Stuart Russell</a> and <a title="Peter Norvig" href="http://en.wikipedia.org/wiki/Peter_Norvig">Peter Norvig</a> describe this movement as nothing less than a &#8220;revolution&#8221; and &#8220;the victory of the <a title="Neats and scruffies" href="http://en.wikipedia.org/wiki/Neats_and_scruffies">neats</a>.&#8221;<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Formal_methods_in_AI-33"><sup>[34]</sup></a></p>
<p><strong> Integrating the approaches</strong></p>
<p>Intelligent agent paradigm</p>
<p>An <a title="Intelligent agent" href="http://en.wikipedia.org/wiki/Intelligent_agent">intelligent agent</a> is a system that perceives its environment and takes actions which maximizes its chances of success. The simplest intelligent agents are programs that solve specific problems. More complicated agents include human beings and organizations of human beings (such as <a title="Firm" href="http://en.wikipedia.org/wiki/Firm">firms</a>). The paradigm gives researchers license to study isolated problems and find solutions that are both verifiable and useful, without agreeing on one single approach. An agent that solves a specific problem can use any approach that works — some agents are symbolic and logical, some are sub-symbolic <a title="Neural network" href="http://en.wikipedia.org/wiki/Neural_network">neural networks</a> and others may use new approaches. The paradigm also gives researchers a common language to communicate with other fields—such as <a title="Decision theory" href="http://en.wikipedia.org/wiki/Decision_theory">decision theory</a> and <a title="Economics" href="http://en.wikipedia.org/wiki/Economics">economics</a>—that also use concepts of abstract agents. The intelligent agent paradigm became widely accepted during the 1990s.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Intelligent_agents-2"><sup>[3]</sup></a></p>
<p><a title="Agent architecture" href="http://en.wikipedia.org/wiki/Agent_architecture">Agent architectures</a> and <a title="Cognitive architecture" href="http://en.wikipedia.org/wiki/Cognitive_architecture">cognitive architectures</a></p>
<p>Researchers have designed systems to build intelligent systems out of interacting <a title="Intelligent agents" href="http://en.wikipedia.org/wiki/Intelligent_agents">intelligent agents</a> in a <a title="Multi-agent system" href="http://en.wikipedia.org/wiki/Multi-agent_system">multi-agent system</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Agent_architectures-95"><sup>[96]</sup></a> A system with both symbolic and sub-symbolic components is a <a title="Hybrid intelligent system" href="http://en.wikipedia.org/wiki/Hybrid_intelligent_system">hybrid intelligent system</a>, and the study of such systems is <a title="Artificial intelligence systems integration" href="http://en.wikipedia.org/wiki/Artificial_intelligence_systems_integration">artificial intelligence systems integration</a>. A <a title="Hierarchical control system" href="http://en.wikipedia.org/wiki/Hierarchical_control_system">hierarchical control system</a> provides a bridge between sub-symbolic AI at its lowest, reactive levels and traditional symbolic AI at its highest levels, where relaxed time constraints permit planning and world modelling.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Hierarchical_control_system-96"><sup>[97]</sup></a> <a title="Rodney Brooks" href="http://en.wikipedia.org/wiki/Rodney_Brooks">Rodney Brooks</a>&#8216; <a title="Subsumption architecture" href="http://en.wikipedia.org/wiki/Subsumption_architecture">subsumption architecture</a> was an early proposal for such a hierarchical system.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Subsumption_architecture-97"><sup>[98]</sup></a></p>
<p><strong> Tools</strong></p>
<p>In the course of 50 years of research, AI has developed a large number of tools to solve the most difficult problems in <a title="Computer science" href="http://en.wikipedia.org/wiki/Computer_science">computer science</a>. A few of the most general of these methods are discussed below.</p>
<p><strong> Search and optimization</strong></p>
<p> <a title="Search algorithm" href="http://en.wikipedia.org/wiki/Search_algorithm">Search algorithm</a>, <a title="Mathematical optimization" href="http://en.wikipedia.org/wiki/Mathematical_optimization">Mathematical optimization</a>, and <a title="Evolutionary computation" href="http://en.wikipedia.org/wiki/Evolutionary_computation">Evolutionary computation</a></p>
<p>Many problems in AI can be solved in theory by intelligently searching through many possible solutions:<sup><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Search-98">[99]</a></sup> <a href="http://en.wikipedia.org/wiki/Artificial_intelligence#Deduction.2C_reasoning.2C_problem_solving">Reasoning</a> can be reduced to performing a search. For example, logical proof can be viewed as searching for a path that leads from <a title="Premise" href="http://en.wikipedia.org/wiki/Premise">premises</a> to <a title="Logical consequence" href="http://en.wikipedia.org/wiki/Logical_consequence">conclusions</a>, where each step is the application of an <a title="Inference rule" href="http://en.wikipedia.org/wiki/Inference_rule">inference rule</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Logic_as_search-99"><sup>[100]</sup></a> <a title="Automated planning and scheduling" href="http://en.wikipedia.org/wiki/Automated_planning_and_scheduling">Planning</a> algorithms search through trees of goals and subgoals, attempting to find a path to a target goal, a process called <a title="Means-ends analysis" href="http://en.wikipedia.org/wiki/Means-ends_analysis">means-ends analysis</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Planning_as_search-100"><sup>[101]</sup></a> <a title="Robotics" href="http://en.wikipedia.org/wiki/Robotics">Robotics</a> algorithms for moving limbs and grasping objects use <a title="Local search (optimization)" href="http://en.wikipedia.org/wiki/Local_search_%28optimization%29">local searches</a> in <a title="Configuration space" href="http://en.wikipedia.org/wiki/Configuration_space">configuration space</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Configuration_space-68"><sup>[69]</sup></a> Many <a title="Machine learning" href="http://en.wikipedia.org/wiki/Machine_learning">learning</a> algorithms use search algorithms based on <a title="Optimization (mathematics)" href="http://en.wikipedia.org/wiki/Optimization_%28mathematics%29">optimization</a>.</p>
<p>Simple exhaustive searches<sup><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Uninformed_search-101">[102]</a></sup> are rarely sufficient for most real world problems: the <a title="Search algorithm" href="http://en.wikipedia.org/wiki/Search_algorithm">search space</a> (the number of places to search) quickly grows to <a title="Astronomical" href="http://en.wikipedia.org/wiki/Astronomical">astronomical</a> numbers. The result is a search that is <a title="Computation time" href="http://en.wikipedia.org/wiki/Computation_time">too slow</a> or never completes. The solution, for many problems, is to use &#8220;<a title="Heuristics" href="http://en.wikipedia.org/wiki/Heuristics">heuristics</a>&#8221; or &#8220;rules of thumb&#8221; that eliminate choices that are unlikely to lead to the goal (called &#8220;<a title="Pruning (algorithm)" href="http://en.wikipedia.org/wiki/Pruning_%28algorithm%29">pruning</a> the <a title="Search tree" href="http://en.wikipedia.org/wiki/Search_tree">search tree</a>&#8220;). <a title="Heuristics" href="http://en.wikipedia.org/wiki/Heuristics">Heuristics</a> supply the program with a &#8220;best guess&#8221; for what path the solution lies on.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Informed_search-102"><sup>[103]</sup></a></p>
<p>A very different kind of search came to prominence in the 1990s, based on the mathematical theory of <a title="Optimization (mathematics)" href="http://en.wikipedia.org/wiki/Optimization_%28mathematics%29">optimization</a>. For many problems, it is possible to begin the search with some form of a guess and then refine the guess incrementally until no more refinements can be made. These algorithms can be visualized as blind <a title="Hill climbing" href="http://en.wikipedia.org/wiki/Hill_climbing">hill climbing</a>: we begin the search at a random point on the landscape, and then, by jumps or steps, we keep moving our guess uphill, until we reach the top. Other optimization algorithms are <a title="Simulated annealing" href="http://en.wikipedia.org/wiki/Simulated_annealing">simulated annealing</a>, <a title="Beam search" href="http://en.wikipedia.org/wiki/Beam_search">beam search</a> and <a title="Random optimization" href="http://en.wikipedia.org/wiki/Random_optimization">random optimization</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Optimization_search-103"><sup>[104]</sup></a></p>
<p><a title="Evolutionary computation" href="http://en.wikipedia.org/wiki/Evolutionary_computation">Evolutionary computation</a> uses a form of optimization search. For example, they may begin with a population of organisms (the guesses) and then allow them to mutate and recombine, <a title="Natural selection" href="http://en.wikipedia.org/wiki/Natural_selection">selecting</a> only the fittest to survive each generation (refining the guesses). Forms of <a title="Evolutionary computation" href="http://en.wikipedia.org/wiki/Evolutionary_computation">evolutionary computation</a> include <a title="Swarm intelligence" href="http://en.wikipedia.org/wiki/Swarm_intelligence">swarm intelligence</a> algorithms (such as <a title="Ant colony optimization" href="http://en.wikipedia.org/wiki/Ant_colony_optimization">ant colony</a> or <a title="Particle swarm optimization" href="http://en.wikipedia.org/wiki/Particle_swarm_optimization">particle swarm optimization</a>)<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Society_based_learning-104"><sup>[105]</sup></a> and <a title="Evolutionary algorithms" href="http://en.wikipedia.org/wiki/Evolutionary_algorithms">evolutionary algorithms</a> (such as <a title="Genetic algorithms" href="http://en.wikipedia.org/wiki/Genetic_algorithms">genetic algorithms</a> and <a title="Genetic programming" href="http://en.wikipedia.org/wiki/Genetic_programming">genetic programming</a>).<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Genetic_programming-105"><sup>[106]</sup></a></p>
<p><strong> Logic</strong></p>
<p> <a title="Logic programming" href="http://en.wikipedia.org/wiki/Logic_programming">Logic programming</a> and <a title="Automated reasoning" href="http://en.wikipedia.org/wiki/Automated_reasoning">Automated reasoning</a></p>
<p><a title="Logic" href="http://en.wikipedia.org/wiki/Logic">Logic</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Logic-106"><sup>[107]</sup></a> is used for knowledge representation and problem solving, but it can be applied to other problems as well. For example, the <a title="Satplan" href="http://en.wikipedia.org/wiki/Satplan">satplan</a> algorithm uses logic for <a title="Automated planning and scheduling" href="http://en.wikipedia.org/wiki/Automated_planning_and_scheduling">planning</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Satplan-107"><sup>[108]</sup></a> and <a title="Inductive logic programming" href="http://en.wikipedia.org/wiki/Inductive_logic_programming">inductive logic programming</a> is a method for <a title="Machine learning" href="http://en.wikipedia.org/wiki/Machine_learning">learning</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Symbolic_learning_techniques-108"><sup>[109]</sup></a></p>
<p>Several different forms of logic are used in AI research. <a title="Propositional logic" href="http://en.wikipedia.org/wiki/Propositional_logic">Propositional</a> or <a title="Sentential logic" href="http://en.wikipedia.org/wiki/Sentential_logic">sentential logic</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Propositional_logic-109"><sup>[110]</sup></a> is the logic of statements which can be true or false. <a title="First-order logic" href="http://en.wikipedia.org/wiki/First-order_logic">First-order logic</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-First-order_logic-110"><sup>[111]</sup></a> also allows the use of <a title="Quantifier" href="http://en.wikipedia.org/wiki/Quantifier">quantifiers</a> and <a title="Predicate (mathematical logic)" href="http://en.wikipedia.org/wiki/Predicate_%28mathematical_logic%29">predicates</a>, and can express facts about objects, their properties, and their relations with each other. <a title="Fuzzy logic" href="http://en.wikipedia.org/wiki/Fuzzy_logic">Fuzzy logic</a>,<sup><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Fuzzy_logic-111">[112]</a></sup> is a version of first-order logic which allows the truth of a statement to be represented as a value between 0 and 1, rather than simply True (1) or False (0). <a title="Fuzzy system" href="http://en.wikipedia.org/wiki/Fuzzy_system">Fuzzy systems</a> can be used for uncertain reasoning and have been widely used in modern industrial and consumer product control systems. <a title="Subjective logic" href="http://en.wikipedia.org/wiki/Subjective_logic">Subjective logic</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Subjective_logic-112"><sup>[113]</sup></a> models uncertainty in a different and more explicit manner than fuzzy-logic: a given binomial opinion satisfies belief + disbelief + uncertainty = 1 within a <a title="Beta distribution" href="http://en.wikipedia.org/wiki/Beta_distribution">Beta distribution</a>. By this method, ignorance can be distinguished from probabilistic statements that an agent makes with high confidence.</p>
<p><a title="Default logic" href="http://en.wikipedia.org/wiki/Default_logic">Default logics</a>, <a title="Non-monotonic logic" href="http://en.wikipedia.org/wiki/Non-monotonic_logic">non-monotonic logics</a> and <a title="Circumscription (logic)" href="http://en.wikipedia.org/wiki/Circumscription_%28logic%29">circumscription</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Default_reasoning_and_non-monotonic_logic-50"><sup>[51]</sup></a> are forms of logic designed to help with default reasoning and the <a title="Qualification problem" href="http://en.wikipedia.org/wiki/Qualification_problem">qualification problem</a>. Several extensions of logic have been designed to handle specific domains of <a title="Knowledge representation" href="http://en.wikipedia.org/wiki/Knowledge_representation">knowledge</a>, such as: <a title="Description logic" href="http://en.wikipedia.org/wiki/Description_logic">description logics</a>;<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Representing_categories_and_relations-44"><sup>[45]</sup></a> <a title="Situation calculus" href="http://en.wikipedia.org/wiki/Situation_calculus">situation calculus</a>, <a title="Event calculus" href="http://en.wikipedia.org/wiki/Event_calculus">event calculus</a> and <a title="Fluent calculus" href="http://en.wikipedia.org/wiki/Fluent_calculus">fluent calculus</a> (for representing events and time);<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Representing_time-45"><sup>[46]</sup></a> <a title="Causality" href="http://en.wikipedia.org/wiki/Causality#Causal_Calculus">causal calculus</a>;<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Representing_causation-46"><sup>[47]</sup></a> belief calculus; and <a title="Modal logic" href="http://en.wikipedia.org/wiki/Modal_logic">modal logics</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Representing_knowledge_about_knowledge-47"><sup>[48]</sup></a></p>
<p><strong>Probabilistic methods for uncertain reasoning</strong></p>
<p> <a title="Bayesian network" href="http://en.wikipedia.org/wiki/Bayesian_network">Bayesian network</a>, <a title="Hidden Markov model" href="http://en.wikipedia.org/wiki/Hidden_Markov_model">Hidden Markov model</a>, <a title="Kalman filter" href="http://en.wikipedia.org/wiki/Kalman_filter">Kalman filter</a>, <a title="Decision theory" href="http://en.wikipedia.org/wiki/Decision_theory">Decision theory</a>, and <a title="Utility theory" href="http://en.wikipedia.org/wiki/Utility_theory">Utility theory</a></p>
<p>Many problems in AI (in reasoning, planning, learning, perception and robotics) require the agent to operate with incomplete or uncertain information. AI researchers have devised a number of powerful tools to solve these problems using methods from <a title="Probability" href="http://en.wikipedia.org/wiki/Probability">probability</a> theory and <a title="Economics" href="http://en.wikipedia.org/wiki/Economics">economics</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Stochastic_methods_for_uncertain_reasoning-113"><sup>[114]</sup></a></p>
<p><a title="Bayesian network" href="http://en.wikipedia.org/wiki/Bayesian_network">Bayesian networks</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Bayesian_networks-114"><sup>[115]</sup></a> are a very general tool that can be used for a large number of problems: reasoning (using the <a title="Bayesian inference" href="http://en.wikipedia.org/wiki/Bayesian_inference">Bayesian inference</a> algorithm),<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Bayesian_inference-115"><sup>[116]</sup></a> <a title="Machine learning" href="http://en.wikipedia.org/wiki/Machine_learning">learning</a> (using the <a title="Expectation-maximization algorithm" href="http://en.wikipedia.org/wiki/Expectation-maximization_algorithm">expectation-maximization algorithm</a>),<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Bayesian_learning-116"><sup>[117]</sup></a> <a title="Automated planning and scheduling" href="http://en.wikipedia.org/wiki/Automated_planning_and_scheduling">planning</a> (using <a title="Decision network" href="http://en.wikipedia.org/wiki/Decision_network">decision networks</a>)<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Bayesian_decision_networks-117"><sup>[118]</sup></a> and <a title="Machine perception" href="http://en.wikipedia.org/wiki/Machine_perception">perception</a> (using <a title="Dynamic Bayesian network" href="http://en.wikipedia.org/wiki/Dynamic_Bayesian_network">dynamic Bayesian networks</a>).<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Stochastic_temporal_models-118"><sup>[119]</sup></a> Probabilistic algorithms can also be used for filtering, prediction, smoothing and finding explanations for streams of data, helping <a title="Machine perception" href="http://en.wikipedia.org/wiki/Machine_perception">perception</a> systems to analyze processes that occur over time (e.g., <a title="Hidden Markov model" href="http://en.wikipedia.org/wiki/Hidden_Markov_model">hidden Markov models</a> or <a title="Kalman filter" href="http://en.wikipedia.org/wiki/Kalman_filter">Kalman filters</a>).<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Stochastic_temporal_models-118"><sup>[119]</sup></a></p>
<p>A key concept from the science of <a title="Economic" href="http://en.wikipedia.org/wiki/Economic">economics</a> is &#8220;<a title="Utility" href="http://en.wikipedia.org/wiki/Utility">utility</a>&#8220;: a measure of how valuable something is to an intelligent agent. Precise mathematical tools have been developed that analyze how an agent can make choices and plan, using <a title="Decision theory" href="http://en.wikipedia.org/wiki/Decision_theory">decision theory</a>, <a title="Decision analysis" href="http://en.wikipedia.org/wiki/Decision_analysis">decision analysis</a>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Decisions_theory_and_analysis-119"><sup>[120]</sup></a> <a title="Applied information economics" href="http://en.wikipedia.org/wiki/Applied_information_economics">information value theory</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Information_value_theory-56"><sup>[57]</sup></a> These tools include models such as <a title="Markov decision process" href="http://en.wikipedia.org/wiki/Markov_decision_process">Markov decision processes</a>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Markov_decision_process-120"><sup>[121]</sup></a> dynamic <a title="Decision network" href="http://en.wikipedia.org/wiki/Decision_network">decision networks</a>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Stochastic_temporal_models-118"><sup>[119]</sup></a> <a title="Game theory" href="http://en.wikipedia.org/wiki/Game_theory">game theory</a> and <a title="Mechanism design" href="http://en.wikipedia.org/wiki/Mechanism_design">mechanism design</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Game_theory_and_mechanism_design-121"><sup>[122]</sup></a></p>
<p><strong> Classifiers and statistical learning methods</strong></p>
<p> <a title="Classifier (mathematics)" href="http://en.wikipedia.org/wiki/Classifier_%28mathematics%29">Classifier (mathematics)</a>, <a title="Statistical classification" href="http://en.wikipedia.org/wiki/Statistical_classification">Statistical classification</a>, and <a title="Machine learning" href="http://en.wikipedia.org/wiki/Machine_learning">Machine learning</a></p>
<p>The simplest AI applications can be divided into two types: classifiers (&#8220;if shiny then diamond&#8221;) and controllers (&#8220;if shiny then pick up&#8221;). Controllers do however also classify conditions before inferring actions, and therefore classification forms a central part of many AI systems. <a title="Classifier (mathematics)" href="http://en.wikipedia.org/wiki/Classifier_%28mathematics%29">Classifiers</a> are functions that use <a title="Pattern matching" href="http://en.wikipedia.org/wiki/Pattern_matching">pattern matching</a> to determine a closest match. They can be tuned according to examples, making them very attractive for use in AI. These examples are known as observations or patterns. In supervised learning, each pattern belongs to a certain predefined class. A class can be seen as a decision that has to be made. All the observations combined with their class labels are known as a data set. When a new observation is received, that observation is classified based on previous experience.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Classifiers-122"><sup>[123]</sup></a></p>
<p>A classifier can be trained in various ways; there are many statistical and <a title="Machine learning" href="http://en.wikipedia.org/wiki/Machine_learning">machine learning</a> approaches. The most widely used classifiers are the <a title="Artificial neural network" href="http://en.wikipedia.org/wiki/Artificial_neural_network">neural network</a>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Neural_networks-123"><sup>[124]</sup></a> <a title="Kernel methods" href="http://en.wikipedia.org/wiki/Kernel_methods">kernel methods</a> such as the <a title="Support vector machine" href="http://en.wikipedia.org/wiki/Support_vector_machine">support vector machine</a>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Kernel_methods-124"><sup>[125]</sup></a> <a title="K-nearest neighbor algorithm" href="http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm">k-nearest neighbor algorithm</a>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-K-nearest_neighbor_algorithm-125"><sup>[126]</sup></a> <a title="Gaussian mixture model" href="http://en.wikipedia.org/wiki/Gaussian_mixture_model">Gaussian mixture model</a>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Guassian_mixture_model-126"><sup>[127]</sup></a> <a title="Naive Bayes classifier" href="http://en.wikipedia.org/wiki/Naive_Bayes_classifier">naive Bayes classifier</a>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Naive_Bayes_classifier-127"><sup>[128]</sup></a> and <a title="Decision tree learning" href="http://en.wikipedia.org/wiki/Decision_tree_learning">decision tree</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Decision_tree-128"><sup>[129]</sup></a> The performance of these classifiers have been compared over a wide range of tasks. Classifier performance depends greatly on the characteristics of the data to be classified. There is no single classifier that works best on all given problems; this is also referred to as the &#8220;<a title="No free lunch in search and optimization" href="http://en.wikipedia.org/wiki/No_free_lunch_in_search_and_optimization">no free lunch</a>&#8221; theorem. Determining a suitable classifier for a given problem is still more an art than science.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Classifier_performance-129"><sup>[130]</sup></a></p>
<p><strong> Neural networks</strong></p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/61.jpg"><img class="aligncenter size-medium wp-image-1240" title="6" src="http://meherchilakalapudi.files.wordpress.com/2011/09/61.jpg?w=300&#038;h=257" alt="" width="300" height="257" /></a></p>
<p>&nbsp;</p>
<p>A neural network is an interconnected group of nodes, akin to the vast network of <a title="Neuron" href="http://en.wikipedia.org/wiki/Neuron">neurons</a> in the <a title="Human brain" href="http://en.wikipedia.org/wiki/Human_brain">human brain</a>.</p>
<p>The study of <a title="Artificial neural network" href="http://en.wikipedia.org/wiki/Artificial_neural_network">artificial neural networks</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Neural_networks-123"><sup>[124]</sup></a> began in the decade before the field AI research was founded, in the work of <a title="Walter Pitts" href="http://en.wikipedia.org/wiki/Walter_Pitts">Walter Pitts</a> and <a title="Warren McCullough" href="http://en.wikipedia.org/wiki/Warren_McCullough">Warren McCullough</a>. Other important early researchers were <a title="Frank Rosenblatt" href="http://en.wikipedia.org/wiki/Frank_Rosenblatt">Frank Rosenblatt</a>, who invented the <a title="Perceptron" href="http://en.wikipedia.org/wiki/Perceptron">perceptron</a> and <a title="Paul Werbos" href="http://en.wikipedia.org/wiki/Paul_Werbos">Paul Werbos</a> who developed the <a title="Backpropagation" href="http://en.wikipedia.org/wiki/Backpropagation">backpropagation</a> algorithm.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Backpropagation-130"><sup>[131]</sup></a></p>
<p>The main categories of networks are acyclic or <a title="Feedforward neural network" href="http://en.wikipedia.org/wiki/Feedforward_neural_network">feedforward neural networks</a> (where the signal passes in only one direction) and <a title="Recurrent neural network" href="http://en.wikipedia.org/wiki/Recurrent_neural_network">recurrent neural networks</a> (which allow feedback). Among the most popular feedforward networks are <a title="Perceptron" href="http://en.wikipedia.org/wiki/Perceptron">perceptrons</a>, <a title="Multi-layer perceptron" href="http://en.wikipedia.org/wiki/Multi-layer_perceptron">multi-layer perceptrons</a> and <a title="Radial basis network" href="http://en.wikipedia.org/wiki/Radial_basis_network">radial basis networks</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Feedforward_neural_networks-131"><sup>[132]</sup></a> Among recurrent networks, the most famous is the <a title="Hopfield net" href="http://en.wikipedia.org/wiki/Hopfield_net">Hopfield net</a>, a form of attractor network, which was first described by <a title="John Hopfield" href="http://en.wikipedia.org/wiki/John_Hopfield">John Hopfield</a> in 1982.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Recurrent_neural_networks-132"><sup>[133]</sup></a> Neural networks can be applied to the problem of <a title="Intelligent control" href="http://en.wikipedia.org/wiki/Intelligent_control">intelligent control</a> (for robotics) or <a title="Machine learning" href="http://en.wikipedia.org/wiki/Machine_learning">learning</a>, using such techniques as <a title="Hebbian learning" href="http://en.wikipedia.org/wiki/Hebbian_learning">Hebbian learning</a> and <a title="Competitive learning" href="http://en.wikipedia.org/wiki/Competitive_learning">competitive learning</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Learning_in_neural_networks-133"><sup>[134]</sup></a></p>
<p><a title="Hierarchical temporal memory" href="http://en.wikipedia.org/wiki/Hierarchical_temporal_memory">Hierarchical temporal memory</a> is an approach that models some of the structural and algorithmic properties of the <a title="Neocortex" href="http://en.wikipedia.org/wiki/Neocortex">neocortex</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Hierarchical_temporal_memory-134"><sup>[135]</sup></a></p>
<p><strong> Control theory</strong></p>
<p>: <a title="Intelligent control" href="http://en.wikipedia.org/wiki/Intelligent_control">Intelligent control</a></p>
<p><a title="Control theory" href="http://en.wikipedia.org/wiki/Control_theory">Control theory</a>, the grandchild of <a title="Cybernetics" href="http://en.wikipedia.org/wiki/Cybernetics">cybernetics</a>, has many important applications, especially in <a title="Robotics" href="http://en.wikipedia.org/wiki/Robotics">robotics</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Control_theory-135"><sup>[136]</sup></a></p>
<p><strong> Languages</strong></p>
<p>: <a title="List of programming languages for artificial intelligence" href="http://en.wikipedia.org/wiki/List_of_programming_languages_for_artificial_intelligence">List of programming languages for artificial intelligence</a></p>
<p>AI researchers have developed several specialized languages for AI research, including <a title="Lisp programming language" href="http://en.wikipedia.org/wiki/Lisp_programming_language">Lisp</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Lisp-136"><sup>[137]</sup></a> and <a title="Prolog" href="http://en.wikipedia.org/wiki/Prolog">Prolog</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Prolog-137"><sup>[138]</sup></a></p>
<p><strong> Evaluating progress</strong></p>
<p> <a title="Progress in artificial intelligence" href="http://en.wikipedia.org/wiki/Progress_in_artificial_intelligence">Progress in artificial intelligence</a></p>
<p>In 1950, Alan Turing proposed a general procedure to test the intelligence of an agent now known as the <a title="Turing test" href="http://en.wikipedia.org/wiki/Turing_test">Turing test</a>. This procedure allows almost all the major problems of artificial intelligence to be tested. However, it is a very difficult challenge and at present all agents fail.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Turing_test-138"><sup>[139]</sup></a></p>
<p>Artificial intelligence can also be evaluated on specific problems such as small problems in chemistry, hand-writing recognition and game-playing. Such tests have been termed <a title="Subject matter expert Turing test" href="http://en.wikipedia.org/wiki/Subject_matter_expert_Turing_test">subject matter expert Turing tests</a>. Smaller problems provide more achievable goals and there are an ever-increasing number of positive results.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Subject_matter_expert_Turing_test-139"><sup>[140]</sup></a></p>
<p>The broad classes of outcome for an AI test are: (1) Optimal: it is not possible to perform better. (2) Strong super-human: performs better than all humans. (3) Super-human: performs better than most humans. (4) Sub-human: performs worse than most humans.<sup>[</sup><a title="Wikipedia:Citation needed" href="http://en.wikipedia.org/wiki/Wikipedia:Citation_needed"><em><sup>citation needed</sup></em></a><sup>]</sup> For example, performance at <a title="Draughts" href="http://en.wikipedia.org/wiki/Draughts">draughts</a> is optimal,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Game_AI-140"><sup>[141]</sup></a> performance at chess is super-human and nearing strong super-human (see <a title="Computer chess" href="http://en.wikipedia.org/wiki/Computer_chess#Computers_versus_humans">Computer chess#Computers versus humans</a>) and performance at many everyday tasks (such as recognizing a face or crossing a room without bumping into something) is sub-human.</p>
<p>A quite different approach measures machine intelligence through tests which are developed from <em>mathematical</em> definitions of intelligence. Examples of these kinds of tests start in the late nineties devising intelligence tests using notions from <a title="Kolmogorov complexity" href="http://en.wikipedia.org/wiki/Kolmogorov_complexity">Kolmogorov complexity</a> and <a title="Data compression" href="http://en.wikipedia.org/wiki/Data_compression">data compression</a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Mathematical_definitions_of_intelligence-141"><sup>[142]</sup></a> Two major advantages of mathematical definitions are their applicability to nonhuman intelligences and their absence of a requirement for human testers.</p>
<p><strong>Competitions and prizes</strong></p>
<p>: <a title="Competitions and prizes in artificial intelligence" href="http://en.wikipedia.org/wiki/Competitions_and_prizes_in_artificial_intelligence">Competitions and prizes in artificial intelligence</a></p>
<p>There are a number of competitions and prizes to promote research in artificial intelligence. The main areas promoted are: general machine intelligence, conversational behavior, data-mining, driverless cars, robot soccer and games.</p>
<p><strong> Platforms</strong></p>
<p>A <a title="Platform (computing)" href="http://en.wikipedia.org/wiki/Platform_%28computing%29">platform</a> (or &#8220;<a title="Computing platform" href="http://en.wikipedia.org/wiki/Computing_platform">computing platform</a>&#8220;) is defined as &#8220;some sort of hardware architecture or software framework (including application frameworks), that allows software to run.&#8221; As Rodney Brooks<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-143"><sup>[144]</sup></a> pointed out many years ago, it is not just the artificial intelligence software that defines the AI features of the platform, but rather the actual platform itself that affects the AI that results, i.e., we<sup>[</sup><a title="Wikipedia:Avoid weasel words" href="http://en.wikipedia.org/wiki/Wikipedia:Avoid_weasel_words"><em><sup>who?</sup></em></a><sup>]</sup> need to be working out AI problems on real-world platforms rather than in isolation.</p>
<p>A wide variety of platforms has allowed different aspects of AI to develop, ranging from <a title="Expert systems" href="http://en.wikipedia.org/wiki/Expert_systems">expert systems</a>, albeit PC-based but still an entire real-world system, to various robot platforms such as the widely available <a title="Roomba" href="http://en.wikipedia.org/wiki/Roomba">Roomba</a> with open interface.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-144"><sup>[145]</sup></a></p>
<p><strong> Prediction</strong></p>
<p>Main articles: <a title="Artificial intelligence in fiction" href="http://en.wikipedia.org/wiki/Artificial_intelligence_in_fiction">Artificial intelligence in fiction</a>, <a title="Ethics of artificial intelligence" href="http://en.wikipedia.org/wiki/Ethics_of_artificial_intelligence">Ethics of artificial intelligence</a>, <a title="Transhumanism" href="http://en.wikipedia.org/wiki/Transhumanism">Transhumanism</a>, and <a title="Technological singularity" href="http://en.wikipedia.org/wiki/Technological_singularity">Technological singularity</a></p>
<p>Artificial Intelligence is a common topic in both <a title="Science fiction" href="http://en.wikipedia.org/wiki/Science_fiction">science fiction</a> and projections about the future of technology and society. The existence of an artificial intelligence that rivals human intelligence raises difficult ethical issues, and the potential power of the technology inspires both hopes and fears.</p>
<p>In fiction, Artificial Intelligence has appeared fulfilling many roles, including a servant (<a title="R2D2" href="http://en.wikipedia.org/wiki/R2D2">R2D2</a> in <a title="Star Wars" href="http://en.wikipedia.org/wiki/Star_Wars"><em>Star Wars</em></a>), a law enforcer (<a title="K.I.T.T." href="http://en.wikipedia.org/wiki/K.I.T.T.">K.I.T.T.</a> &#8220;<a title="Knight Rider (1982 TV series)" href="http://en.wikipedia.org/wiki/Knight_Rider_%281982_TV_series%29">Knight Rider</a>&#8220;), a comrade (<a title="Data (Star Trek)" href="http://en.wikipedia.org/wiki/Data_%28Star_Trek%29">Lt. Commander Data</a> in <a title="Star Trek: The Next Generation" href="http://en.wikipedia.org/wiki/Star_Trek:_The_Next_Generation"><em>Star Trek: The Next Generation</em></a>), a conqueror/overlord (<a title="The Matrix" href="http://en.wikipedia.org/wiki/The_Matrix"><em>The Matrix</em></a>), a dictator (<a title="With Folded Hands" href="http://en.wikipedia.org/wiki/With_Folded_Hands"><em>With Folded Hands</em></a>), a benevolent provider/de facto ruler (<a title="The Culture" href="http://en.wikipedia.org/wiki/The_Culture"><em>The Culture</em></a>), an assassin (<a title="Terminator (series)" href="http://en.wikipedia.org/wiki/Terminator_%28series%29"><em>Terminator</em></a>), a sentient race (<em><a title="Battlestar Galactica (re-imagining)" href="http://en.wikipedia.org/wiki/Battlestar_Galactica_%28re-imagining%29">Battlestar Galactica</a></em>/<a title="Transformers" href="http://en.wikipedia.org/wiki/Transformers">Transformers</a>), an extension to human abilities (<a title="Ghost in the Shell" href="http://en.wikipedia.org/wiki/Ghost_in_the_Shell"><em>Ghost in the Shell</em></a>) and the savior of the human race (<a title="R. Daneel Olivaw" href="http://en.wikipedia.org/wiki/R._Daneel_Olivaw">R. Daneel Olivaw</a> in the <a title="Asimov's Robot Series (page does not exist)" href="http://en.wikipedia.org/w/index.php?title=Asimov%27s_Robot_Series&amp;action=edit&amp;redlink=1"><em>Asimov&#8217;s Robot Series</em></a>).</p>
<p><a title="Mary Shelley" href="http://en.wikipedia.org/wiki/Mary_Shelley">Mary Shelley</a>&#8216;s <a title="Frankenstein" href="http://en.wikipedia.org/wiki/Frankenstein"><em>Frankenstein</em></a> considers a key issue in the <a title="Ethics of artificial intelligence" href="http://en.wikipedia.org/wiki/Ethics_of_artificial_intelligence">ethics of artificial intelligence</a>: if a machine can be created that has intelligence, could it also <a title="Sentience" href="http://en.wikipedia.org/wiki/Sentience"><em>feel</em></a>? If it can feel, does it have the same rights as a human? The idea also appears in modern <a title="Science fiction" href="http://en.wikipedia.org/wiki/Science_fiction">science fiction</a>, including the films <a title="I Robot (film)" href="http://en.wikipedia.org/wiki/I_Robot_%28film%29"><em>I Robot</em></a>, <a title="Blade Runner" href="http://en.wikipedia.org/wiki/Blade_Runner"><em>Blade Runner</em></a> and <a title="A.I.: Artificial Intelligence" href="http://en.wikipedia.org/wiki/A.I.:_Artificial_Intelligence"><em>A.I.: Artificial Intelligence</em></a>, in which humanoid machines have the ability to feel human emotions. This issue, now known as &#8220;<a title="Robot rights" href="http://en.wikipedia.org/wiki/Robot_rights">robot rights</a>&#8220;, is currently being considered by, for example, California&#8217;s <a title="Institute for the Future" href="http://en.wikipedia.org/wiki/Institute_for_the_Future">Institute for the Future</a>, although many critics believe that the discussion is premature.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Robot_rights-154"><sup>[155]</sup></a> The subject is profoundly discussed in the 2010 documentary film <a title="Plug &amp; Pray" href="http://en.wikipedia.org/wiki/Plug_%26_Pray"><em>Plug &amp; Pray</em></a>.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-155"><sup>[156]</sup></a></p>
<p>Martin Ford, author of <em>The Lights in the Tunnel: Automation, Accelerating Technology and the Economy of the Future</em>,<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Ford2009Lights-156"><sup>[157]</sup></a> and others argue that specialized artificial intelligence applications, robotics and other forms of automation will ultimately result in significant <a title="Unemployment" href="http://en.wikipedia.org/wiki/Unemployment">unemployment</a> as machines begin to match and exceed the capability of workers to perform most routine and repetitive jobs. Ford predicts that many knowledge-based occupations—and in particular entry level jobs—will be increasingly susceptible to automation via expert systems, machine learning<sup><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-157">[158]</a></sup> and other AI-enhanced applications. AI-based applications may also be used to amplify the capabilities of low-wage offshore workers, making it more feasible to <a title="Outsource" href="http://en.wikipedia.org/wiki/Outsource">outsource</a> knowledge work.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Replaced_by_machines-158"><sup>[159]</sup></a></p>
<p><a title="Joseph Weizenbaum" href="http://en.wikipedia.org/wiki/Joseph_Weizenbaum">Joseph Weizenbaum</a> wrote that AI applications can not, by definition, successfully simulate genuine human empathy and that the use of AI technology in fields such as <a title="Customer service" href="http://en.wikipedia.org/wiki/Customer_service">customer service</a> or <a title="Psychotherapy" href="http://en.wikipedia.org/wiki/Psychotherapy">psychotherapy</a><a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-159"><sup>[160]</sup></a> was deeply misguided. Weizenbaum was also bothered that AI researchers (and some philosophers) were willing to view the human mind as nothing more than a computer program (a position now known as <a title="Computationalism" href="http://en.wikipedia.org/wiki/Computationalism">computationalism</a>). To Weizenbaum these points suggest that AI research devalues human life.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Weizenbaum.27s_critique-160"><sup>[161]</sup></a></p>
<p>Many futurists believe that artificial intelligence will ultimately transcend the limits of progress. <a title="Ray Kurzweil" href="http://en.wikipedia.org/wiki/Ray_Kurzweil">Ray Kurzweil</a> has used <a title="Moore's law" href="http://en.wikipedia.org/wiki/Moore%27s_law">Moore&#8217;s law</a> (which describes the relentless exponential improvement in digital technology) to calculate that <a title="Desktop computer" href="http://en.wikipedia.org/wiki/Desktop_computer">desktop computers</a> will have the same processing power as human brains by the year 2029. He also predicts that by 2045 artificial intelligence will reach a point where it is able to improve <em>itself</em> at a rate that far exceeds anything conceivable in the past, a scenario that <a title="Science fiction" href="http://en.wikipedia.org/wiki/Science_fiction">science fiction</a> writer <a title="Vernor Vinge" href="http://en.wikipedia.org/wiki/Vernor_Vinge">Vernor Vinge</a> named the &#8220;<a title="Technological singularity" href="http://en.wikipedia.org/wiki/Technological_singularity">singularity</a>&#8220;.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Singularity-161"><sup>[162]</sup></a></p>
<p>Robot designer <a title="Hans Moravec" href="http://en.wikipedia.org/wiki/Hans_Moravec">Hans Moravec</a>, cyberneticist <a title="Kevin Warwick" href="http://en.wikipedia.org/wiki/Kevin_Warwick">Kevin Warwick</a> and inventor <a title="Ray Kurzweil" href="http://en.wikipedia.org/wiki/Ray_Kurzweil">Ray Kurzweil</a> have predicted that humans and machines will merge in the future into <a title="Cyborg" href="http://en.wikipedia.org/wiki/Cyborg">cyborgs</a> that are more capable and powerful than either.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-Transhumanism-162"><sup>[163]</sup></a> This idea, called <a title="Transhumanism" href="http://en.wikipedia.org/wiki/Transhumanism">transhumanism</a>, which has roots in <a title="Aldous Huxley" href="http://en.wikipedia.org/wiki/Aldous_Huxley">Aldous Huxley</a> and <a title="Robert Ettinger" href="http://en.wikipedia.org/wiki/Robert_Ettinger">Robert Ettinger</a>, has been illustrated in fiction as well, for example in the <a title="Manga" href="http://en.wikipedia.org/wiki/Manga">manga</a> <a title="Ghost in the Shell" href="http://en.wikipedia.org/wiki/Ghost_in_the_Shell"><em>Ghost in the Shell</em></a> and the science-fiction series <a title="Dune (novel)" href="http://en.wikipedia.org/wiki/Dune_%28novel%29"><em>Dune</em></a>.</p>
<p><a title="Edward Fredkin" href="http://en.wikipedia.org/wiki/Edward_Fredkin">Edward Fredkin</a> argues that &#8220;artificial intelligence is the next stage in evolution,&#8221; an idea first proposed by <a title="Samuel Butler (novelist)" href="http://en.wikipedia.org/wiki/Samuel_Butler_%28novelist%29">Samuel Butler</a>&#8216;s &#8220;<a title="Darwin among the Machines" href="http://en.wikipedia.org/wiki/Darwin_among_the_Machines">Darwin among the Machines</a>&#8221; (1863), and expanded upon by <a title="George Dyson (science historian)" href="http://en.wikipedia.org/wiki/George_Dyson_%28science_historian%29">George Dyson</a> in his book of the same name in 1998.<a href="http://en.wikipedia.org/wiki/Artificial_intelligence#cite_note-AI_as_evolution-163"><sup>[164]</sup></a></p>
<p><a title="Pamela McCorduck" href="http://en.wikipedia.org/wiki/Pamela_McCorduck">Pamela McCorduck</a> writes that all these scenarios are expressions of the ancient human desire to.</p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/71.jpg"><img class="aligncenter size-medium wp-image-1241" title="7" src="http://meherchilakalapudi.files.wordpress.com/2011/09/71.jpg?w=300&#038;h=221" alt="" width="300" height="221" /></a></p>
<p>&nbsp;</p>
<p><strong>Applications for computer vision</strong></p>
<p>One of the most prominent application fields is medical computer vision or medical image processing. This area is characterized by the extraction of information from image data for the purpose of making a medical diagnosis of a patient. Generally, image data is in the form of <a title="Microscopy" href="http://en.wikipedia.org/wiki/Microscopy">microscopy images</a>, <a title="X-ray" href="http://en.wikipedia.org/wiki/X-ray">X-ray images</a>, <a title="Angiography" href="http://en.wikipedia.org/wiki/Angiography">angiography images</a>, <a title="Ultrasonography" href="http://en.wikipedia.org/wiki/Ultrasonography">ultrasonic images</a>, and <a title="Tomography" href="http://en.wikipedia.org/wiki/Tomography">tomography images</a>. An example of information which can be extracted from such image data is detection of <a title="Tumour" href="http://en.wikipedia.org/wiki/Tumour">tumours</a>, <a title="Arteriosclerosis" href="http://en.wikipedia.org/wiki/Arteriosclerosis">arteriosclerosis</a> or other malign changes. It can also be measurements of organ dimensions, blood flow, etc. This application area also supports medical research by providing new information, e.g., about the structure of the brain, or about the quality of medical treatments.</p>
<p>A second application area in computer vision is in industry, sometimes called <a title="Machine vision" href="http://en.wikipedia.org/wiki/Machine_vision">machine vision</a>, where information is extracted for the purpose of supporting a manufacturing process. One example is quality control where details or final products are being automatically inspected in order to find defects. Another example is measurement of position and orientation of details to be picked up by a robot arm. Machine vision is also heavily used in agricultural process to remove undesirable food stuff from bulk material, a process called <a title="Optical sorting" href="http://en.wikipedia.org/wiki/Optical_sorting">optical sorting</a>.</p>
<p>Military applications are probably one of the largest areas for computer vision. The obvious examples are detection of enemy soldiers or vehicles and <a title="Missile guidance" href="http://en.wikipedia.org/wiki/Missile_guidance">missile guidance</a>. More advanced systems for missile guidance send the missile to an area rather than a specific target, and target selection is made when the missile reaches the area based on locally acquired image data. Modern military concepts, such as &#8220;battlefield awareness&#8221;, imply that various sensors, including image sensors, provide a rich set of information about a combat scene which can be used to support strategic decisions. In this case, automatic processing of the data is used to reduce complexity and to fuse information from multiple sensors to increase reliability.</p>
<p>&nbsp;</p>
<p>Artist&#8217;s Concept of Rover on Mars, an example of an unmanned land-based vehicle. Notice the <a title="Stereo cameras" href="http://en.wikipedia.org/wiki/Stereo_cameras">stereo cameras</a> mounted on top of the Rover.</p>
<p>One of the newer application areas is autonomous vehicles, which include <a title="Submersible" href="http://en.wikipedia.org/wiki/Submersible">submersibles</a>, land-based vehicles (small robots with wheels, cars or trucks), aerial vehicles, and unmanned aerial vehicles (<a title="Unmanned aerial vehicle" href="http://en.wikipedia.org/wiki/Unmanned_aerial_vehicle">UAV</a>). The level of autonomy ranges from fully autonomous (unmanned) vehicles to vehicles where computer vision based systems support a driver or a pilot in various situations. Fully autonomous vehicles typically use computer vision for navigation, i.e. for knowing where it is, or for producing a map of its environment (<a title="Simultaneous localization and mapping" href="http://en.wikipedia.org/wiki/Simultaneous_localization_and_mapping">SLAM</a>) and for detecting obstacles. It can also be used for detecting certain task specific events, e. g., a UAV looking for forest fires. Examples of supporting systems are obstacle warning systems in cars, and systems for autonomous landing of aircraft. Several car manufacturers have demonstrated systems for <a title="Driverless car" href="http://en.wikipedia.org/wiki/Driverless_car">autonomous driving of cars</a>, but this technology has still not reached a level where it can be put on the market. There are ample examples of military autonomous vehicles ranging from advanced missiles, to UAVs for recon missions or missile guidance. Space exploration is already being made with autonomous vehicles using computer vision, e. g., NASA&#8217;s <a title="Mars Exploration Rover" href="http://en.wikipedia.org/wiki/Mars_Exploration_Rover">Mars Exploration Rover</a> and ESA&#8217;s <a title="ExoMars" href="http://en.wikipedia.org/wiki/ExoMars">ExoMars</a> Rover.</p>
<p>Other application areas include:</p>
<ul>
<li>Support of <a title="Visual effects" href="http://en.wikipedia.org/wiki/Visual_effects">visual effects</a> creation for cinema and broadcast, e.g., <a title="Camera tracking" href="http://en.wikipedia.org/wiki/Camera_tracking">camera tracking</a> (matchmoving).</li>
<li><a title="Surveillance" href="http://en.wikipedia.org/wiki/Surveillance">Surveillance</a>.</li>
</ul>
<p>&nbsp;</p>
<p><strong> Typical tasks of computer vision</strong></p>
<p>Each of the application areas described above employ a range of computer vision tasks; more or less well-defined measurement problems or processing problems, which can be solved using a variety of methods. Some examples of typical computer vision tasks are presented below.</p>
<p><strong>[</strong><a title="Edit section: Recognition" href="http://en.wikipedia.org/w/index.php?title=Computer_vision&amp;action=edit&amp;section=5"><strong>edit</strong></a><strong>] Recognition</strong></p>
<p>The classical problem in computer vision, image processing, and machine vision is that of determining whether or not the image data contains some specific object, feature, or activity. This task can normally be solved <a title="wikt:robust" href="http://en.wiktionary.org/wiki/robust">robustly</a> and without effort by a human, but is still not satisfactorily solved in computer vision for the general case: arbitrary objects in arbitrary situations. The existing methods for dealing with this problem can at best solve it only for specific objects, such as simple geometric objects (e.g., polyhedra), human faces, printed or hand-written characters, or vehicles, and in specific situations, typically described in terms of well-defined illumination, background, and <a title="Pose (computer vision)" href="http://en.wikipedia.org/wiki/Pose_%28computer_vision%29">pose</a> of the object relative to the camera.</p>
<p>Different varieties of the recognition problem are described in the literature:</p>
<ul>
<li><a title="Object recognition" href="http://en.wikipedia.org/wiki/Object_recognition"><strong>Object recognition</strong></a>: one or several pre-specified or learned objects or object classes can be recognized, usually together with their 2D positions in the image or 3D poses in the scene.</li>
<li><strong>Identification</strong>: An individual instance of an object is recognized. Examples: identification of a specific person&#8217;s face or fingerprint, or identification of a specific vehicle.</li>
<li><strong>Detection</strong>: the image data is scanned for a specific condition. Examples: detection of possible abnormal cells or tissues in medical images or detection of a vehicle in an automatic road toll system. Detection based on relatively simple and fast computations is sometimes used for finding smaller regions of interesting image data which can be further analysed by more computationally demanding techniques to produce a correct interpretation.</li>
</ul>
<p>Several specialized tasks based on recognition exist, such as:</p>
<ul>
<li><a title="Content-based image retrieval" href="http://en.wikipedia.org/wiki/Content-based_image_retrieval"><strong>Content-based image retrieval</strong></a>: finding all images in a larger set of images which have a specific content. The content can be specified in different ways, for example in terms of similarity relative a target image (give me all images similar to image X), or in terms of high-level search criteria given as text input (give me all images which contains many houses, are taken during winter, and have no cars in them).</li>
<li><a title="Pose (computer vision)" href="http://en.wikipedia.org/wiki/Pose_%28computer_vision%29"><strong>Pose estimation</strong></a>: estimating the position or orientation of a specific object relative to the camera. An example application for this technique would be assisting a robot arm in retrieving objects from a conveyor belt in an <a title="Assembly line" href="http://en.wikipedia.org/wiki/Assembly_line">assembly line</a> situation.</li>
<li><a title="Optical character recognition" href="http://en.wikipedia.org/wiki/Optical_character_recognition"><strong>Optical character recognition</strong></a> (OCR): identifying <a title="Character (computing)" href="http://en.wikipedia.org/wiki/Character_%28computing%29">characters</a> in images of printed or handwritten text, usually with a view to encoding the text in a format more amenable to editing or <a title="Search index" href="http://en.wikipedia.org/wiki/Search_index">indexing</a> (e.g. <a title="ASCII" href="http://en.wikipedia.org/wiki/ASCII">ASCII</a>).</li>
</ul>
<p><strong> Motion analysis</strong></p>
<p>Several tasks relate to motion estimation where an image sequence is processed to produce an estimate of the velocity either at each points in the image or in the 3D scene, or even of the camera that produces the images . Examples of such tasks are:</p>
<ul>
<li><a title="Egomotion" href="http://en.wikipedia.org/wiki/Egomotion"><strong>Egomotion</strong></a>: determining the 3D rigid motion (rotation and translation) of the camera from an image sequence produced by the camera.</li>
<li><a title="Video tracking" href="http://en.wikipedia.org/wiki/Video_tracking"><strong>Tracking</strong></a>: following the movements of a (usually) smaller set of interest points or objects (e.g., vehicles or humans) in the image sequence.</li>
<li><a title="Optical flow" href="http://en.wikipedia.org/wiki/Optical_flow"><strong>Optical flow</strong></a>: to determine, for each point in the image, how that point is moving relative to the image plane, i.e., its apparent motion. This motion is a result both of how the corresponding 3D point is moving in the scene and how the camera is moving relative to the scene.</li>
<li><strong> Scene reconstruction</strong></li>
</ul>
<p>Given one or (typically) more images of a scene, or a video, scene reconstruction aims at computing a <a title="Computer model" href="http://en.wikipedia.org/wiki/Computer_model">3D model</a> of the scene. In the simplest case the model can be a set of 3D points. More sophisticated methods produce a complete 3D surface model.</p>
<p><strong> Image restoration</strong></p>
<p>The aim of image restoration is the removal of noise (sensor noise, motion blur, etc.) from images. The simplest possible approach for noise removal is various types of filters such as low-pass filters or median filters. More sophisticated methods assume a model of how the local image structures look like, a model which distinguishes them from the noise. By first analysing the image data in terms of the local image structures, such as lines or edges, and then controlling the filtering based on local information from the analysis step, a better level of noise removal is usually obtained compared to the simpler approaches. An example in this field is the <a title="Inpainting" href="http://en.wikipedia.org/wiki/Inpainting">inpainting</a>.</p>
<p><strong> 3D volume recognition</strong></p>
<p>&nbsp;</p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/91.jpg"><img class="aligncenter size-medium wp-image-1243" title="9" src="http://meherchilakalapudi.files.wordpress.com/2011/09/91.jpg?w=295&#038;h=300" alt="" width="295" height="300" /></a></p>
<p><strong>ARTIFICIAL INTELLIGENCE AND CONSCIOUSNESS IN ROBOTS</strong></p>
<p>For decades, artificial intelligence researchers and scientists have been laboring to create truly intelligent computers. While progress has been achieved in some specialized areas, the goal of creating conscious machines seems to have remained elusive. Though robots today are truly remarkable in their technology, the creation of intelligent machines like those that have populated so many science fiction books and films since the early fifties is still very much a pipe dream. One clear and important reason for this is that the nature of the human mind is still only partially understood, and this mysterious human mind must serve as the model for robots with artificial intelligence.</p>
<p>“Consciousness is perhaps the last remaining mystery in understanding what it is to be human,” Owen Holland, a scientist at Essex University said. “By attempting to build physical systems which can produce a form of artificial consciousness, we hope to learn more about the nature of consciousness.” Holland is only one of many scientists whose dream is to build a “conscious robot.” For him, succeeding in this work will not only bring intelligent, self-aware machines a step closer to reality, it could also provide valuable clues on how human consciousness develops.</p>
<p>The reason modern robots today are not completely regarded as truly intelligent is because although many are amazing for sure, they are still only capable of following instructions. They do not have the capability to “think” for themselves. Holland&#8217;s idea is that a conscious robot would have to build up internal models: one for the robot’s “self” and another for the world around it. These models would then be the basis from which the robot would build experience. Much like a human, the robot will learn by experimenting with how its own body reacts with the world around it, figuring out for itself what is beneficial to it and what is not. Robots with artificial intelligence have a long way to go.</p>
<p>But how can we verify that an intelligent being is actually self-conscious? And more importantly what is consciousness for machines? In 1950, computer science pioneer Alan Turing posed a similar problem concerning intelligence and proposed a famous test, known as the Turing test. He wanted to find out if a machine could be considered as intelligent as a human being. Two separate keyboards are connected, one to a computer, the other to a person. An examiner types in questions on any topic he likes, and both the computer and the human type back responses that appear on the respective computer screens. If the examiner cannot reliably determine which answer came from the person and which from the machine, then we say the machine has passed the Turing test. Today, no computer can pass the Turing test, unless the interaction is limited to topics that can yield very specific responses, like chess. Robots with artificial intelligence it seems have a long way to go.</p>
<p>Although most advanced robotic systems intend to model humans, most of the time they did not, like humans, acquire their knowledge through interaction with the real world. Holland and his team of researchers plan to build a robot which will be presented with a succession of increasingly complex environments which will eventually contain moving elements and things that will respond to the robot&#8217;s movements. Holland said that the robot will have to model and predict what they&#8217;re going to do and these things will have either positive or negative values for the robot. Although creating consciousness in a machine seems to simply mean producing better robots at some level, conscious robots would be able to react dynamically to their environment by adjusting their behavior on any information they could gather. This means seeing robots that don’t blindly follow their programming, no matter how intelligently it’s written, e.g. Deep Blue, the first ever “intelligent” computer to beat a world chess champion. But chess does not demonstrate robots with artificial intelligence, and perhaps any intelligence at all.</p>
<p>At present in the field of robots with artificial intelligence, we have a scope of researchers working on programs that aim to make robots learn and adapt. At the University of Tokyo, researchers are using a learning methodology they call interactive teaching to give robots the ability to drive their own development. The robot uses Bayesian Networks to map sensor evidence to behavior, and then assigns each mapping a confidence rating. With practice, the robot requires less intervention from the human trainers and eventually a task can be completed autonomously. Scientists have also begun to use attentional mechanisms to focus humanoid robots on visual areas of interest. Learning systems that allow a robot to autonomously recognize and categorize the environmental elements it extracts have begun to be developed. These robots are equipped to recognize perceptual clues such as sound, movement, color intensity or human body language (pointing, gazing and so on), but are they really robots with artificial intelligence?</p>
<p>We have robots like NOMAD (Neurally Organized Mobile Adaptive Device), developed by researchers at the Neurosciences Institute in La Jolla, who is a “real thinking robot who starts naive and learns from experience.” NOMAD’s behavior is controlled by the activity of simulated brain cells, and has already allowed researchers a “unique window to better understanding how the human brain works.” NOMAD can interact with its environment by sensing light and taste and by moving around and grabbing play blocks with striped or spotted patterns. And then we have robots like Adam, whose authors from Aberystwyth University in Wales report could “reason, formulate theories and discover scientific knowledge on their own.” At Cornell University in New York, researchers have reportedly designed a computer program that can uncover the fundamental physical laws behind a swinging double pendulum, and test out Issac Newton&#8217;s laws of motion as it does so. NOMAD is a step forward in the search for robots with artificial intelligence.</p>
<p>To be sure, these modern robots are “intelligent” but it is simply not possible to verify the presence of consciousness in another brain, whether human or artificial. This is a property that can only be verified by his possessor, and since we cannot enter in another being’s mind, we can never make assumptions about his consciousness. We could, however, follow Turing’s approach and say that a being can be considered self-conscious if he is able to convince us that he is human. Of course this is precisely the purpose of chatbots (or chatterbots), which are designed to simulate intelligent conversations with one or more human users via auditory or textual methods.</p>
<p>So how do we know if we have finally succeeded in making truly conscious and thinking robots with artificial intelligence, such as HAL 9000, the main character in the 1968 epic film “2001: A Space Odyssey?” Believe me, we’ll just know.</p>
<p><a href="http://meherchilakalapudi.files.wordpress.com/2011/09/101.jpg"><img class="aligncenter size-medium wp-image-1244" title="10" src="http://meherchilakalapudi.files.wordpress.com/2011/09/101.jpg?w=241&#038;h=300" alt="" width="241" height="300" /></a></p>
<br />Filed under: <a href='http://meherchilakalapudi.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meherchilakalapudi.wordpress.com/1234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meherchilakalapudi.wordpress.com/1234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meherchilakalapudi.wordpress.com/1234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meherchilakalapudi.wordpress.com/1234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/meherchilakalapudi.wordpress.com/1234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/meherchilakalapudi.wordpress.com/1234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/meherchilakalapudi.wordpress.com/1234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/meherchilakalapudi.wordpress.com/1234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meherchilakalapudi.wordpress.com/1234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meherchilakalapudi.wordpress.com/1234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meherchilakalapudi.wordpress.com/1234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meherchilakalapudi.wordpress.com/1234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meherchilakalapudi.wordpress.com/1234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meherchilakalapudi.wordpress.com/1234/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meherchilakalapudi.wordpress.com&amp;blog=5609619&amp;post=1234&amp;subd=meherchilakalapudi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://meherchilakalapudi.wordpress.com/2011/09/09/know-about-a-humanoid-robotartificial-intelligence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08b95690d7ec04fc15567da451c993a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meherchilakalapudi</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/18.jpg?w=290" medium="image">
			<media:title type="html">1</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/22.jpg?w=300" medium="image">
			<media:title type="html">2</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/32.jpg?w=291" medium="image">
			<media:title type="html">3</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/42.jpg?w=300" medium="image">
			<media:title type="html">4</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/51.jpg?w=300" medium="image">
			<media:title type="html">5</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/61.jpg?w=300" medium="image">
			<media:title type="html">6</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/71.jpg?w=300" medium="image">
			<media:title type="html">7</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/91.jpg?w=295" medium="image">
			<media:title type="html">9</media:title>
		</media:content>

		<media:content url="http://meherchilakalapudi.files.wordpress.com/2011/09/101.jpg?w=241" medium="image">
			<media:title type="html">10</media:title>
		</media:content>
	</item>
	</channel>
</rss>
