tag:blogger.com,1999:blog-63051567782468886922024-02-20T01:21:07.273-08:00The Thought MachineSai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.comBlogger27125tag:blogger.com,1999:blog-6305156778246888692.post-1252756824609012262013-10-14T10:06:00.000-07:002015-07-15T16:12:23.593-07:00While At Home<div dir="ltr" style="text-align: left;" trbidi="on">
Writing a post after so long!<br />
<div>
<div>
So what am I doing these days: </div>
<div>
<ul style="text-align: left;">
<li>Working on Rails and backbone</li>
<li>Switching to Emacs </li>
<li>Staring badly at the Rubik's cube ( as if a third eye would open any minute and there'd be tsunamis and volcanoes followed with the cube being solved; heehahhahha.. mmmm sorry!)</li>
<li>Making stupid mistakes ( this is a well planned goal ok, someday I got to write a book on 'Stupidity In Programming ;) ' )</li>
</ul>
</div>
<div>
Then there is playing guitar, breaking things at home, fighting for the tv remote and of course, accompanying dad in laughing at the daily soaps while mum watches them ;)<br />
<br />
<br /></div>
</div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-49471207354225088562012-11-22T04:55:00.001-08:002013-10-16T07:57:43.515-07:00Boolean Logic : Activity 16<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 16 : Build an 8 WAY DMUX<br />
<br />
<br />
<br />
WILL SOON PUBLISH NOTES ON THIS !!<br />
<br />
<br />
/**<br />
<br />
* 8-way demultiplexor. <br />
* {a,b,c,d,e,f,g,h} = {in,0,0,0,0,0,0,0} if sel==000<br />
* {0,in,0,0,0,0,0,0} if sel==001<br />
* etc.<br />
* {0,0,0,0,0,0,0,in} if sel==111<br />
*/<br />
<br />
<br />
CHIP DMux8Way {<br />
IN in, sel[3];<br />
OUT a, b, c, d, e, f, g, h;<br />
<br />
PARTS:<br />
// Put your code here.<br />
DMux(in=in, sel=sel[2], a=w1, b=w2);<br />
<br />
DMux(in=w1, sel=sel[1], a=w3, b=w4);<br />
DMux(in=w2, sel=sel[1], a=w5, b=w6);<br />
<br />
DMux(in=w3, sel=sel[0], a=a, b=b);<br />
DMux(in=w4, sel=sel[0], a=c, b=d);<br />
DMux(in=w5, sel=sel[0], a=e, b=f);<br />
DMux(in=w6, sel=sel[0], a=g, b=h);<br />
<br />
<br />
}<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Downloads :</div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkYTVNbFhWODNWOU0/edit">activity 16</a></div>
<div>
<br /></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-39519046415588032892012-11-22T03:29:00.000-08:002013-10-16T07:57:43.513-07:00Boolean Logic : Activity 15<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 15 : Build a 4 WAY DMUX<br />
<br />
<br />
<br />
<br />
<br />
/**<br />
* 4-way demultiplexor. <br />
* {a,b,c,d} = {in,0,0,0} if sel==00<br />
* {0,in,0,0} if sel==01<br />
* {0,0,in,0} if sel==10<br />
* {0,0,0,in} if sel==11<br />
*/<br />
<br />
<br />
CHIP DMux4Way {<br />
<br />
<br />
IN in, sel[2];<br />
<br />
OUT a, b, c, d;<br />
<br />
PARTS:<br />
// Put your code here.<br />
Not(in=sel[0], out=nots1);<br />
Not(in=sel[1], out=nots2);<br />
And(a=sel[0], b=sel[0], out=s1); <br />
And(a=sel[1], b=sel[1], out=s2);<br />
<br />
<br />
<br />
And(a=nots1, b=nots2, out=a1);<br />
And(a=nots1, b=s2, out=b1);<br />
And(a=s1, b=nots2, out=c1);<br />
And(a=s1, b=s2, out=d1);<br />
<br />
And(a=a1, b=in, out=a);<br />
And(a=b1, b=in, out=c);<br />
And(a=c1, b=in, out=b);<br />
And(a=d1, b=in, out=d);<br />
<br />
<br />
<br />
<br />
}<br />
<div>
<br /></div>
<div>
////////////////////////////////////</div>
<div>
<b>00-a,</b></div>
<div>
<b>01-b, </b></div>
<div>
<b>10-c, </b></div>
<div>
<b>11-d </b></div>
<div>
<b>where ordering is sel[1]sel[0].. (After 20 mins of hovering over DMUX diagram) </b></div>
<div>
<br /></div>
<div>
<br />
<b>Can I use DMUX to make this ??</b><br />
Using DMUX ><br />
<br />
<br />
/**<br />
* 4-way demultiplexor. <br />
* {a,b,c,d} = {in,0,0,0} if sel==00<br />
* {0,in,0,0} if sel==01<br />
* {0,0,in,0} if sel==10<br />
* {0,0,0,in} if sel==11<br />
*/<br />
<br />
<br />
CHIP DMux4Way {<br />
<br />
<br />
IN in, sel[2];<br />
<br />
OUT a, b, c, d;<br />
<br />
PARTS:<br />
// Put your code here.<br />
DMux(in=in, sel=sel[1], a=w1, b=w2);<br />
DMux(in=w1, sel=sel[0], a=a, b=b);<br />
DMux(in=w2, sel=sel[0], a=c, b=d);<br />
<br />
}<br />
<div>
<br /></div>
<br />
<br />
<br /></div>
<div>
<br /></div>
<div>
Downloads :</div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkNWdvSFRMUzY3R00/edit">activity 15</a></div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkMGFjeURiTVpFZzQ/edit">activity 15 | using DMux</a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-39196802204235604912012-11-21T08:40:00.001-08:002013-10-16T07:57:43.510-07:00Boolean Logic : Activity 14<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 14 : Build 16 bit / 8 WAY MUX using the gates previously built<br />
<br />
<br />
<br />
<br />
/**<br />
* 8-way 16-bit multiplexor. <br />
* out = a if sel==000<br />
* b if sel==001<br />
* etc.<br />
* h if sel==111<br />
*/<br />
<br />
<br />
CHIP Mux8Way16 {<br />
IN a[16], b[16], c[16], d[16],<br />
e[16], f[16], g[16], h[16],<br />
sel[3];<br />
OUT out[16];<br />
<br />
PARTS:<br />
// Put your code here.<br />
Mux16(a=a,b=b,sel=sel[0],out=selab);<br />
Mux16(a=c,b=d,sel=sel[0],out=selcd);<br />
Mux16(a=e,b=f,sel=sel[0],out=selef);<br />
Mux16(a=g,b=h,sel=sel[0],out=selgh);<br />
Mux16(a=selab,b=selcd,sel=sel[1],out=selabcd);<br />
Mux16(a=selef,b=selgh,sel=sel[1],out=selefgh);<br />
Mux16(a=selabcd,b=selefgh,sel=sel[2],out=out);<br />
}<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Downloads :</div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkb1kxSlVRdE8xWUU/edit">activity 14</a></div>
<div>
<br /></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-88571865837305665502012-11-21T08:34:00.001-08:002013-10-16T07:57:43.546-07:00Boolean Logic : Activity 13<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 13 : Build 16 bit / 4 WAY MUX using the gates previously built<br />
<br />
<br />
<br />
<br />
<br />
// This file is part of the materials accompanying the book<br />
// "The Elements of Computing Systems" by Nisan and Schocken,<br />
// MIT Press. Book site: www.idc.ac.il/tecs<br />
// File name: projects/01/Mux4Way16.hdl<br />
<br />
/**<br />
* 4-way 16-bit multiplexor. <br />
* out = a if sel==00<br />
* b if sel==01<br />
* c if sel==10<br />
* d if sel==11<br />
*/<br />
<br />
<br />
CHIP Mux4Way16 {<br />
<br />
<br />
IN a[16], b[16], c[16], d[16], sel[2];<br />
<br />
OUT out[16];<br />
<br />
PARTS:<br />
// Put your code here.<br />
<br />
<br />
Mux16(a=a, b=b, sel=sel[0], out=w1);<br />
Mux16(a=c, b=d, sel=sel[0], out=w2);<br />
Mux16(a=w1, b=w2, sel=sel[1], out=out);<br />
<br />
<br />
}<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Downloads :</div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkQlhzWGpabUFTWEE/edit">activity 13</a></div>
<br />
<br /></div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-75800586085514342012-11-21T06:02:00.002-08:002013-10-16T07:57:43.533-07:00Boolean Logic : Activity 12<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 12 : Build 8 WAY OR using any of the gates previously built<br />
<br />
<br />
<b>Yes, it says 8 Way OR and not 8 bit..</b><br />
<b>la la la.. open the book !!</b><br />
<br />
<br />
<br />
<br />
<br />
<br />
/**<br />
* 8-way or gate: out = in[0] or in[1] or ... or in[7].<br />
*/<br />
<br />
CHIP Or8Way {<br />
IN in[8];<br />
OUT out;<br />
<br />
PARTS:<br />
// Put your code here.<br />
Or(a=in[0], b=in[1], out=p0);<br />
Or(a=p0, b=in[2], out=p1);<br />
Or(a=p1, b=in[3], out=p2);<br />
Or(a=p2, b=in[4], out=p3);<br />
Or(a=p3, b=in[5], out=p4);<br />
Or(a=p4, b=in[6], out=p5);<br />
Or(a=p5, b=in[7], out=out);<br />
<br />
}<br />
<div>
<br /></div>
<br />
<b><br /></b>
<b>////////////////////////////////</b><br />
<b><br /></b>
Downloads :<br />
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkT01fQmJUMWJtRU0/edit">activity 12</a><br />
<br />
<b><br /></b></div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-18324008970636409242012-11-21T05:41:00.004-08:002013-10-16T07:57:43.493-07:00Boolean Logic : Activity 11<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 11 : Build 16 bit Mux using (NAND, AND, OR, XOR, MUX, DMUX, 16-AND, 16-OR, 16-NOT)<br />
<br />
<br />
hmm.. boring !!<br />
<br />
<br />
<br />
/**<br />
* 16 bit multiplexor. If sel==1 then out=b else out=a.<br />
*/<br />
<br />
CHIP Mux16 {<br />
IN a[16], b[16], sel;<br />
OUT out[16];<br />
<br />
PARTS:<br />
// Put your code here.<br />
Mux(a=a[0], b=b[0], sel=sel, out=out[0]);<br />
Mux(a=a[1], b=b[1], sel=sel, out=out[1]);<br />
Mux(a=a[2], b=b[2], sel=sel, out=out[2]);<br />
Mux(a=a[3], b=b[3], sel=sel, out=out[3]);<br />
Mux(a=a[4], b=b[4], sel=sel, out=out[4]);<br />
Mux(a=a[5], b=b[5], sel=sel, out=out[5]);<br />
Mux(a=a[6], b=b[6], sel=sel, out=out[6]);<br />
Mux(a=a[7], b=b[7], sel=sel, out=out[7]);<br />
Mux(a=a[8], b=b[8], sel=sel, out=out[8]);<br />
Mux(a=a[9], b=b[9], sel=sel, out=out[9]);<br />
Mux(a=a[10], b=b[10], sel=sel, out=out[10]);<br />
Mux(a=a[11], b=b[11], sel=sel, out=out[11]);<br />
Mux(a=a[12], b=b[12], sel=sel, out=out[12]);<br />
Mux(a=a[13], b=b[13], sel=sel, out=out[13]);<br />
Mux(a=a[14], b=b[14], sel=sel, out=out[14]);<br />
Mux(a=a[15], b=b[15], sel=sel, out=out[15]);<br />
}<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
Downloads :</div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkX1N5SnN6UDN2WnM/edit">activity 11</a></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-12384859302935101822012-11-21T05:25:00.003-08:002013-10-16T07:57:43.482-07:00Boolean Logic : Activity 10<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 10 : Build 16 bit OR using (NAND, AND, XOR, OR, MUX, DMUX)<br />
<br />
<br />
<b>You can do this using only Or; the below solution is by using only Nand..</b><br />
<b>If you read the previous solutions, you really wont be checking this out !! ;)</b><br />
<br />
<br />
<br />
/**<br />
* 16-bit bitwise Or gate: for i=0..15 out[i] = a[i] or b[i].<br />
*/<br />
<br />
CHIP Or16 {<br />
IN a[16], b[16];<br />
OUT out[16];<br />
<br />
PARTS:<br />
// Put your code here.<br />
<br />
Nand(a=a[0], b=a[0], out=p0);<br />
Nand(a=a[1], b=a[1], out=p1);<br />
Nand(a=a[2], b=a[2], out=p2);<br />
Nand(a=a[3], b=a[3], out=p3);<br />
Nand(a=a[4], b=a[4], out=p4);<br />
Nand(a=a[5], b=a[5], out=p5);<br />
Nand(a=a[6], b=a[6], out=p6);<br />
Nand(a=a[7], b=a[7], out=p7);<br />
Nand(a=a[8], b=a[8], out=p8);<br />
Nand(a=a[9], b=a[9], out=p9);<br />
Nand(a=a[10], b=a[10], out=p10);<br />
Nand(a=a[11], b=a[11], out=p11);<br />
Nand(a=a[12], b=a[12], out=p12);<br />
Nand(a=a[13], b=a[13], out=p13);<br />
Nand(a=a[14], b=a[14], out=p14);<br />
Nand(a=a[15], b=a[15], out=p15);<br />
<br />
<br />
Nand(a=b[0], b=b[0], out=q0);<br />
Nand(a=b[1], b=b[1], out=q1);<br />
Nand(a=b[2], b=b[2], out=q2);<br />
Nand(a=b[3], b=b[3], out=q3);<br />
Nand(a=b[4], b=b[4], out=q4);<br />
Nand(a=b[5], b=b[5], out=q5);<br />
Nand(a=b[6], b=b[6], out=q6);<br />
Nand(a=b[7], b=b[7], out=q7);<br />
Nand(a=b[8], b=b[8], out=q8);<br />
Nand(a=b[9], b=b[9], out=q9);<br />
Nand(a=b[10], b=b[10], out=q10);<br />
Nand(a=b[11], b=b[11], out=q11);<br />
Nand(a=b[12], b=b[12], out=q12);<br />
Nand(a=b[13], b=b[13], out=q13);<br />
Nand(a=b[14], b=b[14], out=q14);<br />
Nand(a=b[15], b=b[15], out=q15);<br />
<br />
<br />
<br />
Nand(a=p0, b=q0, out=out[0]);<br />
Nand(a=p1, b=q1, out=out[1]);<br />
Nand(a=p2, b=q2, out=out[2]);<br />
Nand(a=p3, b=q3, out=out[3]);<br />
Nand(a=p4, b=q4, out=out[4]);<br />
Nand(a=p5, b=q5, out=out[5]);<br />
Nand(a=p6, b=q6, out=out[6]);<br />
Nand(a=p7, b=q7, out=out[7]);<br />
Nand(a=p8, b=q8, out=out[8]);<br />
Nand(a=p9, b=q9, out=out[9]);<br />
Nand(a=p10, b=q10, out=out[10]);<br />
Nand(a=p11, b=q11, out=out[11]);<br />
Nand(a=p12, b=q12, out=out[12]);<br />
Nand(a=p13, b=q13, out=out[13]);<br />
Nand(a=p14, b=q14, out=out[14]);<br />
Nand(a=p15, b=q15, out=out[15]);<br />
<br />
}<br />
<div>
<br /></div>
<div>
////////////////////////////////////////////////////////</div>
<div>
<br /></div>
<div>
<b>Wanted to make use of Mux which I did, but dha !! I am using Or too</b></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
<br /></div>
<div>
<br /></div>
<div>
/**</div>
<div>
* 16-bit bitwise Or gate: for i=0..15 out[i] = a[i] or b[i].</div>
<div>
*/</div>
<div>
<br /></div>
<div>
CHIP Or16 {</div>
<div>
IN a[16], b[16];</div>
<div>
OUT out[16];</div>
<div>
<br /></div>
<div>
PARTS:</div>
<div>
// Put your code here.</div>
<div>
<br /></div>
<div>
Mux(a=a[0], b=b[0], out=w0);</div>
<div>
Mux(a=a[1], b=b[1], out=w1);</div>
<div>
Mux(a=a[2], b=b[2], out=w2);</div>
<div>
Mux(a=a[3], b=b[3], out=w3);</div>
<div>
Mux(a=a[4], b=b[4], out=w4);</div>
<div>
Mux(a=a[5], b=b[5], out=w5);</div>
<div>
Mux(a=a[6], b=b[6], out=w6);</div>
<div>
Mux(a=a[7], b=b[7], out=w7);</div>
<div>
Mux(a=a[8], b=b[8], out=w8);</div>
<div>
Mux(a=a[9], b=b[9], out=w9);</div>
<div>
Mux(a=a[10], b=b[10], out=w10);</div>
<div>
Mux(a=a[11], b=b[11], out=w11);</div>
<div>
Mux(a=a[12], b=b[12], out=w12);</div>
<div>
Mux(a=a[13], b=b[13], out=w13);</div>
<div>
Mux(a=a[14], b=b[14], out=w14);</div>
<div>
Mux(a=a[15], b=b[15], out=w15);</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Or(a=a[0], b=w0, out=p0);</div>
<div>
Or(a=a[1], b=w1, out=p1);</div>
<div>
Or(a=a[2], b=w2, out=p2);</div>
<div>
Or(a=a[3], b=w3, out=p3);</div>
<div>
Or(a=a[4], b=w4, out=p4);</div>
<div>
Or(a=a[5], b=w5, out=p5);</div>
<div>
Or(a=a[6], b=w6, out=p6);</div>
<div>
Or(a=a[7], b=w7, out=p7);</div>
<div>
Or(a=a[8], b=w8, out=p8);</div>
<div>
Or(a=a[9], b=w9, out=p9);</div>
<div>
Or(a=a[10], b=w10, out=p10);</div>
<div>
Or(a=a[11], b=w11, out=p11);</div>
<div>
Or(a=a[12], b=w12, out=p12);</div>
<div>
Or(a=a[13], b=w13, out=p13);</div>
<div>
Or(a=a[14], b=w14, out=p14);</div>
<div>
Or(a=a[15], b=w15, out=p15);</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Or(a=b[0], b=p0, out=out[0]);</div>
<div>
Or(a=b[1], b=p1, out=out[1]);</div>
<div>
Or(a=b[2], b=p2, out=out[2]);</div>
<div>
Or(a=b[3], b=p3, out=out[3]);</div>
<div>
Or(a=b[4], b=p4, out=out[4]);</div>
<div>
Or(a=b[5], b=p5, out=out[5]);</div>
<div>
Or(a=b[6], b=p6, out=out[6]);</div>
<div>
Or(a=b[7], b=p7, out=out[7]);</div>
<div>
Or(a=b[8], b=p8, out=out[8]);</div>
<div>
Or(a=b[9], b=p9, out=out[9]);</div>
<div>
Or(a=b[10], b=p10, out=out[10]);</div>
<div>
Or(a=b[11], b=p11, out=out[11]);</div>
<div>
Or(a=b[12], b=p12, out=out[12]);</div>
<div>
Or(a=b[13], b=p13, out=out[13]);</div>
<div>
Or(a=b[14], b=p14, out=out[14]);</div>
<div>
Or(a=b[15], b=p15, out=out[15]);</div>
<div>
<br /></div>
<div>
}</div>
<div style="font-weight: bold;">
<br /></div>
</div>
<div>
<b>eeks.. better to use only Or.. but just wanted to write Mux :)</b></div>
<div>
<b>Did you notice? I didn't write sel in the Mux definition and it worked perfectly !!</b></div>
<br />
<br />
<br />
Downloads :<br />
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkQVNHVkRNS1VsS2M/edit">activity 10 | using Nand</a><br />
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkX1V2a25vTnZERGc/edit">activity 10 | using Mux and Or</a></div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-16798428092937096272012-11-21T04:57:00.002-08:002013-10-16T07:57:43.488-07:00Boolean Logic : Activity 9<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 9 : Build 16 bit AND using (NAND, AND , OR, XOR, MUX, DMUX)<br />
<br />
<br />
<b>and again and again ;)</b><br />
<br />
<br />
<br />
/**<br />
* 16-bit-wise and gate: for i = 0..15: out[i] = a[i] and b[i]<br />
*/<br />
<br />
CHIP And16 {<br />
IN a[16], b[16];<br />
OUT out[16];<br />
<br />
PARTS:<br />
// Put your code here.<br />
And(a=a[0], b=b[0], out=out[0]);<br />
And(a=a[1], b=b[1], out=out[1]);<br />
And(a=a[2], b=b[2], out=out[2]);<br />
And(a=a[3], b=b[3], out=out[3]);<br />
And(a=a[4], b=b[4], out=out[4]);<br />
And(a=a[5], b=b[5], out=out[5]);<br />
And(a=a[6], b=b[6], out=out[6]);<br />
And(a=a[7], b=b[7], out=out[7]);<br />
And(a=a[8], b=b[8], out=out[8]);<br />
And(a=a[9], b=b[9], out=out[9]);<br />
And(a=a[10], b=b[10], out=out[10]);<br />
And(a=a[11], b=b[11], out=out[11]);<br />
And(a=a[12], b=b[12], out=out[12]);<br />
And(a=a[13], b=b[13], out=out[13]);<br />
And(a=a[14], b=b[14], out=out[14]);<br />
And(a=a[15], b=b[15], out=out[15]);<br />
}<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
/////////////////////////////////////////////<br />
<br />
<b>Now backtracking to represent it in Nand only :</b><br />
<br />
<br />
<br />
<br />
/**<br />
* 16-bit-wise and gate: for i = 0..15: out[i] = a[i] and b[i]<br />
*/<br />
<br />
CHIP And16 {<br />
IN a[16], b[16];<br />
OUT out[16];<br />
<br />
PARTS:<br />
// Put your code here.<br />
<br />
Nand(a=a[0], b=b[0], out=p0);<br />
Nand(a=a[1], b=b[1], out=p1);<br />
Nand(a=a[2], b=b[2], out=p2);<br />
Nand(a=a[3], b=b[3], out=p3);<br />
Nand(a=a[4], b=b[4], out=p4);<br />
Nand(a=a[5], b=b[5], out=p5);<br />
Nand(a=a[6], b=b[6], out=p6);<br />
Nand(a=a[7], b=b[7], out=p7);<br />
Nand(a=a[8], b=b[8], out=p8);<br />
Nand(a=a[9], b=b[9], out=p9);<br />
Nand(a=a[10], b=b[10], out=p10);<br />
Nand(a=a[11], b=b[11], out=p11);<br />
Nand(a=a[12], b=b[12], out=p12);<br />
Nand(a=a[13], b=b[13], out=p13);<br />
Nand(a=a[14], b=b[14], out=p14);<br />
Nand(a=a[15], b=b[15], out=p15);<br />
<br />
Nand(a=p0, b=p0, out=out[0]);<br />
Nand(a=p1, b=p1, out=out[1]);<br />
Nand(a=p2, b=p2, out=out[2]);<br />
Nand(a=p3, b=p3, out=out[3]);<br />
Nand(a=p4, b=p4, out=out[4]);<br />
Nand(a=p5, b=p5, out=out[5]);<br />
Nand(a=p6, b=p6, out=out[6]);<br />
Nand(a=p7, b=p7, out=out[7]);<br />
Nand(a=p8, b=p8, out=out[8]);<br />
Nand(a=p9, b=p9, out=out[9]);<br />
Nand(a=p10, b=p10, out=out[10]);<br />
Nand(a=p11, b=p11, out=out[11]);<br />
Nand(a=p12, b=p12, out=out[12]);<br />
Nand(a=p13, b=p13, out=out[13]);<br />
Nand(a=p14, b=p14, out=out[14]);<br />
Nand(a=p15, b=p15, out=out[15]);<br />
<br />
}<br />
<div style="font-weight: bold;">
<br /></div>
<br />
<br />
<br />
<br />
Downloads :<br />
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkWWVlVXlnWWlmRUU/edit">activity 9</a><br />
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkei01dE12RHNqZ0E/edit">activity 9 | using Nand</a><br />
<br /></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-22794549652205575152012-11-21T01:01:00.003-08:002013-10-16T07:57:43.501-07:00Boolean Logic : Activity 8<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 8 : Build 16 bit NOT using (NAND, AND, OR, XOR, MUX, DMUX)<br />
<br />
<br />
<br />
<b>The simplest solution to this :</b><br />
using NOT ><br />
<br />
<br />
/**<br />
<br />
* 16-bit Not gate: for i=0..15: out[i] = not in[i]<br />
*/<br />
<br />
CHIP Not16 {<br />
IN in[16];<br />
OUT out[16];<br />
<br />
PARTS:<br />
Not(in=in[0], out=out[0]);<br />
Not(in=in[1], out=out[1]);<br />
Not(in=in[2], out=out[2]);<br />
Not(in=in[3], out=out[3]);<br />
Not(in=in[4], out=out[4]);<br />
Not(in=in[5], out=out[5]);<br />
Not(in=in[6], out=out[6]);<br />
Not(in=in[7], out=out[7]);<br />
Not(in=in[8], out=out[8]);<br />
Not(in=in[9], out=out[9]);<br />
Not(in=in[10], out=out[10]);<br />
Not(in=in[11], out=out[11]);<br />
Not(in=in[12], out=out[12]);<br />
Not(in=in[13], out=out[13]);<br />
Not(in=in[14], out=out[14]);<br />
Not(in=in[15], out=out[15]);<br />
}<br />
<div>
<br /></div>
<br />
//////////////////////////////////////////////<br />
You really dont want to type so much; what you can do is use your fav prog lang to get this as o/p :<br />
<br />
for(int i=0; i<=15; i++){<br />
System.out.println("Not(in=in[" + i + "], out=out[" + i + "]);");<br />
}<br />
<br />
<br />
<br />
<b>Hey, how about we use Nand to solve this !!</b><br />
using Nand ><br />
<br />
<br />
<br />
/**<br />
* 16-bit Not gate: for i=0..15: out[i] = not in[i]<br />
*/<br />
<br />
CHIP Not16 {<br />
IN in[16];<br />
OUT out[16];<br />
<br />
PARTS:<br />
Nand(a=in[0], b=in[0], out=out[0]);<br />
Nand(a=in[1], b=in[1], out=out[1]);<br />
Nand(a=in[2], b=in[2], out=out[2]);<br />
Nand(a=in[3], b=in[3], out=out[3]);<br />
Nand(a=in[4], b=in[4], out=out[4]);<br />
Nand(a=in[5], b=in[5], out=out[5]);<br />
Nand(a=in[6], b=in[6], out=out[6]);<br />
Nand(a=in[7], b=in[7], out=out[7]);<br />
Nand(a=in[8], b=in[8], out=out[8]);<br />
Nand(a=in[9], b=in[9], out=out[9]);<br />
Nand(a=in[10], b=in[10], out=out[10]);<br />
Nand(a=in[11], b=in[11], out=out[11]);<br />
Nand(a=in[12], b=in[12], out=out[12]);<br />
Nand(a=in[13], b=in[13], out=out[13]);<br />
Nand(a=in[14], b=in[14], out=out[14]);<br />
Nand(a=in[15], b=in[15], out=out[15]);<br />
<br />
<br />
}<br />
<div>
<br /></div>
<br />
<b>//////////////////////////////////////////////////</b><br />
<b><br /></b>
<b>Trying to use Mux; here I learnt that we cannot create array variables like w[0], w[1].. </b><br />
using Mux ><br />
<br />
<br />
<br />
/**<br />
* 16-bit Not gate: for i=0..15: out[i] = not in[i]<br />
*/<br />
<br />
CHIP Not16 {<br />
IN in[16];<br />
OUT out[16];<br />
<br />
PARTS:<br />
Mux(a=in[0], b=in[0], out=w0);<br />
Mux(a=in[1], b=in[1], out=w1);<br />
Mux(a=in[2], b=in[2], out=w2);<br />
Mux(a=in[3], b=in[3], out=w3);<br />
Mux(a=in[4], b=in[4], out=w4);<br />
Mux(a=in[5], b=in[5], out=w5);<br />
Mux(a=in[6], b=in[6], out=w6);<br />
Mux(a=in[7], b=in[7], out=w7);<br />
Mux(a=in[8], b=in[8], out=w8);<br />
Mux(a=in[9], b=in[9], out=w9);<br />
Mux(a=in[10], b=in[10], out=w10);<br />
Mux(a=in[11], b=in[11], out=w11);<br />
Mux(a=in[12], b=in[12], out=w12);<br />
Mux(a=in[13], b=in[13], out=w13);<br />
Mux(a=in[14], b=in[14], out=w14);<br />
Mux(a=in[15], b=in[15], out=w15);<br />
<br />
<br />
Nand(a=w0, b=w0, out=out[0]);<br />
Nand(a=w1, b=w1, out=out[1]);<br />
Nand(a=w2, b=w2, out=out[2]);<br />
Nand(a=w3, b=w3, out=out[3]);<br />
Nand(a=w4, b=w4, out=out[4]);<br />
Nand(a=w5, b=w5, out=out[5]);<br />
Nand(a=w6, b=w6, out=out[6]);<br />
Nand(a=w7, b=w7, out=out[7]);<br />
Nand(a=w8, b=w8, out=out[8]);<br />
Nand(a=w9, b=w9, out=out[9]);<br />
Nand(a=w10, b=w10, out=out[10]);<br />
Nand(a=w11, b=w11, out=out[11]);<br />
Nand(a=w12, b=w12, out=out[12]);<br />
Nand(a=w13, b=w13, out=out[13]);<br />
Nand(a=w14, b=w14, out=out[14]);<br />
Nand(a=w15, b=w15, out=out[15]);<br />
<br />
<br />
}<br />
<div>
<br /></div>
<br />
////////////////////////////////////////////////////////<br />
<br />
<b>We can always substitute chip definitions, the expressions for which we found in earlier activities</b><br />
<br />
<br />
<br />
Downloads :<br />
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkNkdHb0VtVDkyYmc/edit">activity 8 | using not</a><br />
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkRWpQcnhkS24xN00/edit">activity 8 | using Nand</a><br />
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkZEFjXzJueExQa00/edit">activity 8 | using mux</a></div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-51090023459636348332012-11-20T08:09:00.001-08:002013-10-16T07:57:43.521-07:00Boolean Logic : Activity 7<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 7 : Build DMUX by using (NAND, OR, AND, NOT, MUX)<br />
<span style="color: #555555; font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;"><br /></span>
<span style="color: #555555; font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;"><br /></span>
<span style="font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;">/**</span><br />
<br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> * Dmultiplexor. </span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> * {a,b} = {in,0} if sel==0</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> * {0,in} if sel==1</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> */</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"><br /></span></span>
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"><br /></span></span>
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;">CHIP DMux {</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> IN in, sel;</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> OUT a, b;</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"><br /></span></span>
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> PARTS:</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> // Put your code here.</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> Not(in=sel, out=notsel);</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"><br /></span></span>
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> And(a=in, b=notsel, out=a);</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;"> And(a=in, b=sel, out=b);</span></span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif;"><span style="line-height: 24px;">}</span></span><br />
<div style="font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;">
<br /></div>
<br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;"><br /></span>
<span style="font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;">/////////////////////////////////</span><br />
<span style="font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;">This should be a piece of cake !!</span><br />
<span style="color: #555555; font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;"><br /></span>
<span style="color: #555555; font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;"><br /></span>
<span style="color: #555555; font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;"><br /></span>
<span style="color: #555555; font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;"><br /></span>
Downloads :<br />
<span style="color: #555555; font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;"> </span><a href="https://docs.google.com/folder/d/0B40n_HegUjvkUmctVGY3RWtSRTg/edit" style="font-family: Arial, Tahoma, Verdana, sans-serif; line-height: 24px;">activity 7</a></div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-7782163631109661012012-11-20T07:37:00.001-08:002013-10-16T07:57:43.535-07:00Boolean Logic : Activity 6<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 6 : Build MUX by using (NAND, OR, AND, NOT)<br />
<br />
<br />
<b>Write truth table -> canonical form </b><br />
<b><br /></b>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUT_tHLWrfZVSCuZPZfPsQkidffZE1WkCt9kRSxM5C_Mujg6Ja7HNNOyNcdXrTwSmhcsF0TU7_wc5sXgDy1k9vY6DYdP94ZQjOlRK7J5yFf4oh0vBPicP30o4KswxunvoTfbLJAQj6fMyk/s1600/20121120_204048.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUT_tHLWrfZVSCuZPZfPsQkidffZE1WkCt9kRSxM5C_Mujg6Ja7HNNOyNcdXrTwSmhcsF0TU7_wc5sXgDy1k9vY6DYdP94ZQjOlRK7J5yFf4oh0vBPicP30o4KswxunvoTfbLJAQj6fMyk/s320/20121120_204048.jpg" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
/**<br />
* Multiplexor. If sel==1 then out=b else out=a.<br />
*/<br />
<br />
CHIP Mux {<br />
IN a, b, sel;<br />
OUT out;<br />
<br />
PARTS:<br />
// Put your code here.<br />
Not(in=a, out=nota);<br />
Not(in=b, out=notb);<br />
Not(in=sel, out=notsel);<br />
<br />
<br />
And(a=nota, b=b, out=a1);<br />
And(a=a, b=b, out=a2);<br />
Or(a=a1, b=a2, out=o1);<br />
And(a=sel, b=o1, out=p1);<br />
<br />
And(a=a, b=notb, out=a3);<br />
Or(a=a2, b=a3, out=o2);<br />
And(a=notsel, b=o2, out=p2);<br />
<br />
<br />
Or(a=p1, b=p2, out=out);<br />
}<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
<b>On simplifying further :</b></div>
<div>
way 2 ></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_b_-v1OVylt7X596Zlrnb4OCdVpruMBPbl1QxUUZzYAVZ_JBPm1kMuT_U1UZk_Y4Fs5Ta658s2dtymxUIBJC02x17FPjgDk1cWnt6dhSsrnf2kgiFQ4qpCpBq75VjgkbG52NX_PQG53sZ/s1600/20121120_204326.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_b_-v1OVylt7X596Zlrnb4OCdVpruMBPbl1QxUUZzYAVZ_JBPm1kMuT_U1UZk_Y4Fs5Ta658s2dtymxUIBJC02x17FPjgDk1cWnt6dhSsrnf2kgiFQ4qpCpBq75VjgkbG52NX_PQG53sZ/s320/20121120_204326.jpg" width="320" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
/** </div>
<div>
* Multiplexor. If sel==1 then out=b else out=a.</div>
<div>
*/</div>
<div>
<br /></div>
<div>
CHIP Mux {</div>
<div>
IN a, b, sel;</div>
<div>
OUT out;</div>
<div>
<br /></div>
<div>
PARTS:</div>
<div>
// Put your code here.</div>
<div>
Not(in=a, out=nota);</div>
<div>
Not(in=b, out=notb);</div>
<div>
Not(in=sel, out=notsel);</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
And(a=a, b=b, out=a3);</div>
<div>
<br /></div>
<div>
And(a=nota, b=b, out=t1);</div>
<div>
And(a=t1, b=sel, out=a1);</div>
<div>
<br /></div>
<div>
And(a=a, b=notb, out=t2);</div>
<div>
And(a=t2, b=notsel, out=a2);</div>
<div>
<br /></div>
<div>
Or(a=a1, b=a2, out=o1);</div>
<div>
Or(a=o1, b=a3, out=out);</div>
<div>
<br /></div>
<div>
</div>
<div>
}</div>
</div>
<div>
<br /></div>
<div>
<b>Both the above solutions were built sequentially. Now its time to shorten it.. </b></div>
<div>
way 3></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2mvLMZESgOnfqW0llHYcufMlreXP8xkH4DtteEoJHWndxHcO4IcuEGtYCkeSsA5N_h2DOTLikUU9sq9Usua5JY-jiZgg-jk57-3QBh_9GiJnCsZA9w08FKQyC_FKQJa2i1Vi_AchKzSpY/s1600/20121120_210237.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2mvLMZESgOnfqW0llHYcufMlreXP8xkH4DtteEoJHWndxHcO4IcuEGtYCkeSsA5N_h2DOTLikUU9sq9Usua5JY-jiZgg-jk57-3QBh_9GiJnCsZA9w08FKQyC_FKQJa2i1Vi_AchKzSpY/s320/20121120_210237.jpg" width="320" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
/** </div>
<div>
* Multiplexor. If sel==1 then out=b else out=a.</div>
<div>
*/</div>
<div>
<br /></div>
<div>
CHIP Mux {</div>
<div>
IN a, b, sel;</div>
<div>
OUT out;</div>
<div>
<br /></div>
<div>
PARTS:</div>
<div>
// Put your code here.</div>
<div>
Not(in=sel, out=notsel);</div>
<div>
And(a=a, b=notsel, out=w1);</div>
<div>
And(a=b, b=sel, out=w2);</div>
<div>
Or(a=w1, b=w2, out=out);</div>
<div>
</div>
<div>
}</div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Downloads : </div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkc3RkWmVaQUNsak0/edit">activity 6</a></div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkLVRGb0tBZENXUVE/edit">activity 6 | way 2</a></div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkR3Y5VzRHNWlUX0U/edit">activity 6 | way 3</a></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-7934758645794437702012-11-20T05:27:00.001-08:002013-10-16T07:57:43.541-07:00Boolean Logic : Activity 5<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 5 : Build XOR from primitive NAND<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
// This file is part of the materials accompanying the book </div>
<div>
// "The Elements of Computing Systems" by Nisan and Schocken, </div>
<div>
// MIT Press. Book site: www.idc.ac.il/tecs</div>
<div>
// File name: projects/01/Xor.hdl</div>
<div>
<br /></div>
<div>
/**</div>
<div>
* Exclusive-or gate: out = !(a == b).</div>
<div>
*/</div>
<div>
<br /></div>
<div>
CHIP Xor {</div>
<div>
<br /></div>
<div>
IN a, b;</div>
<div>
OUT out;</div>
<div>
<br /></div>
<div>
PARTS:</div>
<div>
// Put your code here.</div>
<div>
Nand(a=a, b=a, out=nota);</div>
<div>
Nand(a=b, b=b, out=notb);</div>
<div>
<br /></div>
<div>
Nand(a=a, b=notb, out=w1);</div>
<div>
Nand(a=w1, b=w1, out=a1);</div>
<div>
<br /></div>
<div>
Nand(a=nota, b=b, out=w2);</div>
<div>
Nand(a=w2, b=w2, out=a2);</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Nand(a=a1, b=a1, out=p1);</div>
<div>
Nand(a=a2, b=a2, out=p2);</div>
<div>
Nand(a=p1, b=p2, out=out);</div>
<div>
<br /></div>
<div>
</div>
<div>
}</div>
</div>
<div>
<br /></div>
<div>
////////////////////////////////////////////////////</div>
<div>
<br /></div>
<div>
hmm.. so what we do is make truth table - write canonical rep - and replace the and, or and not def with those of nand which we found out in previous activities.</div>
<div>
<br /></div>
<div>
truth table -> canonical form -> substitute nand def</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Downloads : </div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkVTBuN2ZKUUwxMmc/edit">activity 5</a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-70146502043450652842012-11-20T04:41:00.002-08:002013-10-16T07:57:43.527-07:00Boolean Logic : Activity 4<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 4 : Build OR from primitive NAND<br />
<br />
<br />
<br />
<br />
// This file is part of the materials accompanying the book<br />
// "The Elements of Computing Systems" by Nisan and Schocken,<br />
// MIT Press. Book site: www.idc.ac.il/tecs<br />
// File name: projects/01/Or.hdl<br />
<br />
<br />
/**<br />
* Or gate: out = 1 if {a==1 or b==1}, 0 otherwise <br />
*/<br />
<br />
CHIP Or {<br />
IN a, b;<br />
OUT out;<br />
<br />
PARTS:<br />
// Put your code here.<br />
Nand(a=a, b=a, out=w1);<br />
Nand(a=b, b=b, out=w2);<br />
Nand(a=w1, b=w2, out=out);<br />
}<br />
<div>
<br /></div>
<br />
<br />
<div>
<br /></div>
<div>
//////////////////////////////////////////////////////</div>
<div>
Well, I just made truth tables for basic gates and saw that Nand of nota and notb matched that of or.</div>
<div>
So this solution was out of observation. Please share if this can be done logically.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Downloads :</div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkbFA0ZHN6TEhKQk0/edit">activity 4</a></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-63272161228418694072012-11-20T03:57:00.000-08:002013-10-16T07:57:43.524-07:00Boolean Logic : Activity 3<div dir="ltr" style="text-align: left;" trbidi="on">
Activity 3 : Build AND from primitive NAND<br />
<br />
<br />
<br />
<br />
// This file is part of the materials accompanying the book<br />
// "The Elements of Computing Systems" by Nisan and Schocken,<br />
// MIT Press. Book site: www.idc.ac.il/tecs<br />
// File name: projects/01/And.hdl<br />
<br />
/**<br />
* And gate: out = 1 if {a==1 and b==1}, 0 otherwise <br />
*/<br />
<br />
CHIP And {<br />
IN a, b;<br />
OUT out;<br />
<br />
PARTS:<br />
// Put your code here.<br />
//Nand(a='Nand(a=a, b=b, out=w1)', b='Nand(a=a, b=b, out=w2)', out=out);<br />
Nand(a=a, b=b, out=w1);<br />
Nand(a=w1, b=w1, out=out);<br />
}<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
////////////////////////////////////////////////////////////////</div>
<div>
Another way would be :</div>
<div>
Nand(a=a, b=b, out=w1);</div>
<div>
Not(in=w1, out=out);</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
I wonder although if we could write it as Nand(a=Nand(a=a, b=b, out=w1), b=Nand(a=a, b=b, out=w2), out=out);</div>
<div>
Am I missing something ??</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Downloads:</div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkNjJlTkh2bnlUMTQ/edit">Activity 3</a></div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkMUNsWlZDNVNGcFE/edit">Activity 3 | another way</a></div>
<div>
<br /></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-27589298241815543852012-11-20T03:09:00.002-08:002013-10-16T07:57:43.504-07:00Boolean Logic : Activity 2 (with summary of ch-1)<div dir="ltr" style="text-align: left;" trbidi="on">
DISCLAIMER: Meant to be read during coffee breaks as a summary // Author is not responsible for your frustration<br />
<br />
chips - made of logic gates<br />
and chips make up almost everything in computing science.<br />
<br />
logic gates run on 0s and 1s - what we call as boolean and getting fidgetive with it called as boolean algebra.<br />
Next, boolean functions operate on boolean i/p to give boolean o/p.<br />
<br />
Truth table : we see all combinations of i/ps and their o/ps. From this we can form canonical representation.<br />
This in turn proves that any boolean function can be formed out of 'And', "Or' and 'Not'.<br />
<br />
Then we check out many boolean functions - And, Not, Constant, Equivalence, If then, Xor, Or, Nand, Nor.....<br />
Nand function has an interesting property : And, Or and Not can be constructed from it. If you notice what we said about canonical representation, this means we can construct any boolean function from Nand alone.<br />
<br />
Then we moved with gate symbols, interface and implementation.<br />
<br />
Multiplexor (nick name: mux) has an extra i/p bit called selector to o/p one of the i/ps depending on the selector/selection-bit.<br />
Demultiplexor (demux) is just the other way around.. the selection bit decides which o/p bit should give the i/p value as the o/p.<br />
<br />
The project is meant to simplify our logic about the boolean logic :)<br />
<br />
<br />
Activity 2 : Building NOT from primitive NAND<br />
<br />
<br />
This goes in the .hdl file<br />
// This file is part of the materials accompanying the book<br />
// "The Elements of Computing Systems" by Nisan and Schocken,<br />
// MIT Press. Book site: www.idc.ac.il/tecs<br />
// File name: projects/01/Not.hdl<br />
<br />
/**<br />
* Not gate: out = not in<br />
*/<br />
<br />
CHIP Not {<br />
IN in;<br />
OUT out;<br />
<br />
PARTS:<br />
// Put your code here.<br />
Nand(a=in, b=in, out=out);<br />
}<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
Downloads:</div>
<div>
<a href="https://docs.google.com/folder/d/0B40n_HegUjvkaEpRclBGQW95N00/edit">Activity 2</a></div>
<div>
<br /></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-78915865951457374782012-11-20T02:27:00.002-08:002013-10-16T07:57:43.538-07:00Boolean Logic : Activity 1<div dir="ltr" style="text-align: left;" trbidi="on">
0s and 1s can make you kneel on your knees or raise your head high !! A dive into the binary world from scratch..<br />
<br />
For the lucky ones out there : <a href="http://diycomputerscience.com/courses/course/the-elements-of-computing-systems">Elements of Computing Systems</a> (we all are lucky here ;) )<br />
<br />
You can buy this book from <a href="http://www.amazon.com/dp/B004HHORGA/ref=as_li_tf_til?tag=adaplearonli-20&camp=14573&creative=327641&linkCode=as1&creativeASIN=B004HHORGA&adid=1MZCGZF2VYAKGYMQ7KY3&&ref-refURL=http%3A%2F%2Fdiycomputerscience.com%2Fcourses%2Fcourse%2Fthe-elements-of-computing-systems">here</a><br />
Download TECS h/w simulator <a href="http://www1.idc.ac.il/tecs/software/tecs-software-suite-2.5.zip">here</a> and read part I, II, III in this <a href="http://www1.idc.ac.il/tecs/tutorials/hardware-simulator.pdf">tutorial</a><br />
<br />
Thanks to Professor Shimon Schocken and Professor Noam Nisan for making everything available online and making it simple for us.<br />
<br />
<br />
You may want to visit the <a href="http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/">Q/A forum </a><br />
<br />
<br />
<br />
<br /></div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-19609543096501871662011-10-17T08:30:00.000-07:002013-10-16T07:57:43.496-07:00Java Exceptions <div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: Times,"Times New Roman",serif;">
<div>
<span style="font-size: x-large;">You must be familiar with <b style="color: #bf9000;">java compile errors</b>, the most common ones being syntax errors, missing return statements, using uninitialized variables, attempt to access non-static members from static method, etc..</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">The compiler is optimized to detect them for you and asks you to correct them before they can be run. However, compiler's ability to detect errors is limited. Some errors are not known until runtime. These are called <b style="color: #bf9000;">exceptions</b>. On most of the sites, you must have heard it to be 'abnormal' or 'unexpected' but the whole gist of it is the fact that they are undetermined at compile time.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">So why care about something you cannot handle anyway.. You can always run and check what error it gives !</span><br />
<span style="font-size: x-large;">Hmmm, first of all handing over an unpredictable code is a bad idea. Secondly, hurray!! We can handle exceptions. We may not be able to be precise on what exactly may go wrong during runtime but then we can make use of the known types of exceptions a particular task may throw.</span><br />
<span style="font-size: x-large;"><br /></span>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>For this, lets classify Exceptions on the basic of how they may be handled:</b></span></div>
<span style="font-size: x-large;">Some exceptions are expected to be handled for sure before compilation. These are meant to assure recovery or make the program predictable even in worse scenarios. Example, if a file that is to be opened does not exist or if a user inputs an invalid data type.. These can be foreseen and MUST be handled. These exceptions are called <b style="color: #bf9000;">Checked Exceptions</b>.</span><br />
<span style="font-size: x-large;">Then there are exceptions which are caused due to logical errors. We are expected to make the code bug free rather than handling them. They are called as <b><span style="color: #bf9000;">Runtime Exceptions</span></b>. It is optional to handle it.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Then what are errors? In java exception terminology, '<b style="color: #bf9000;">Error</b>' is beyond the reach of a programmer. They cannot be predicted or recovered from. They are caused mainly at hardware level and not our concern !!</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">By the way, in java, Exception (which actually is an event) is class-ified and any exception (but not error) thrown are objects of this <b style="color: #bf9000;">class - Exception</b>.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Lets clarify more on the above:</span><br />
<ul style="text-align: left;">
<li><span style="font-size: x-large;">Checked exceptions MUST be handled. They mean to serve <b><span style="color: #bf9000;">User Errors</span></b>.</span></li>
<li><span style="font-size: x-large;">Runtime exceptions and Errors are together called, '<b><span style="color: #bf9000;">Unchecked exceptions</span></b>'.</span></li>
<li><span style="font-size: x-large;">Runtime exceptions can be fixed by bug fixes and through logic. They mean to serve <b style="color: #bf9000;">Programmer Error</b>.</span></li>
<li><span style="font-size: x-large;">Errors are not in our hands.</span></li>
<li><span style="font-size: x-large;">In Java, there is this class - Exception. Any exception thrown is an object of this class ;)</span></li>
</ul>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">A look into Exception classes and <b style="color: #bf9000;">Hierarchy</b> now:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: x-large;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZARUgwQMW5MHb2pUUHB0CGoLxKxqG6LtoYBkP6btX5p8G_cCTHPujbnnpXjsM-QYfKMCy-C3zT3g6dYkpXZvTJDbfsHQPMqlGseseT8ie4dF_4fEhjtkiSXcUWISSsUdWkqpWoGA8z2WQ/s1600/throwableHierarchy.trans.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="331" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZARUgwQMW5MHb2pUUHB0CGoLxKxqG6LtoYBkP6btX5p8G_cCTHPujbnnpXjsM-QYfKMCy-C3zT3g6dYkpXZvTJDbfsHQPMqlGseseT8ie4dF_4fEhjtkiSXcUWISSsUdWkqpWoGA8z2WQ/s640/throwableHierarchy.trans.gif" width="640" /></a></span></div>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">We know by now that all classes have java.lang.Object as a superclass directly or indirectly.</span><br />
<span style="font-size: x-large;">You can see the class 'java.lang.Exception' which encompasses all checked exceptions and runtime exceptions.</span><br />
<span style="font-size: x-large;"><br /></span>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>Some common checked exceptions are:</b></span></div>
<span style="font-size: x-large;">InstantiationException</span><br />
<span style="font-size: x-large;">InterruptedException</span><br />
<span style="font-size: x-large;">NoSuchFieldException</span><br />
<span style="font-size: x-large;">NoSuchMethodException</span><br />
<span style="font-size: x-large;">ClassNotFoundException</span><br />
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b><br /></b></span></div>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>Runtime Exceptions:</b></span></div>
<span style="font-size: x-large;">NullPointerException</span><br />
<span style="font-size: x-large;">ArithmeticException</span><br />
<span style="font-size: x-large;">IndexOutOfBoundsException</span><br />
<span style="font-size: x-large;">ArrayIndexOutOfBoundsException</span><br />
<span style="font-size: x-large;">StringIndexOutOfBounds </span><br />
<span style="font-size: x-large;">IllegalArgumentException</span><br />
<span style="font-size: x-large;">ClassCastException</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: x-large;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjexQCBwyMQxmjb_Fiv_2e6fXoa4Cr2wFi6tGT7mr0XvHBvu5k0LdjKcXgkWtCErDtf2dUZOOx3-CqapHWvOBmoCGLBgKqUVYndu0p6NVUuE1vs7uP07piSPY8k0XxZ3Woz9q-Y20M4eJOi/s1600/hierarchy.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjexQCBwyMQxmjb_Fiv_2e6fXoa4Cr2wFi6tGT7mr0XvHBvu5k0LdjKcXgkWtCErDtf2dUZOOx3-CqapHWvOBmoCGLBgKqUVYndu0p6NVUuE1vs7uP07piSPY8k0XxZ3Woz9q-Y20M4eJOi/s640/hierarchy.png" width="446" /></a></span></div>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">You must be clear with the hierarchy to proceed..</span><br />
<span style="font-size: x-large;">The <b style="color: #bf9000;">Exception class </b>contains some methods that we may need while handling exceptions instances:</span><br />
<ul style="text-align: left;">
<li><span style="font-size: x-large;">getMessage() - gives info of the exception. </span></li>
<li><span style="font-size: x-large;">getCause() </span></li>
<li><span style="font-size: x-large;">printStackTrace() - gives info and also prints it to System.err (error o/p stream)</span></li>
<li><span style="font-size: x-large;">getStackTrace() </span></li>
</ul>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>So ready to write handlers?</b></span></div>
<span style="font-size: x-large;">Well, before that let us check out the flow of exceptions.</span><br />
<span style="font-size: x-large;">Say your program flow is as below:</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Main() -> makeTree() -> checkRoot() -> printTreeToFile()</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><u><i>Scenario 1:</i></u></span><br />
<span style="font-size: x-large;">makeTree() handles IOException.</span><br />
<span style="font-size: x-large;">checkRoot() handles EOFException.</span><br />
<span style="font-size: x-large;">printTreeToFile() throws FileNotFoundException.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Will the exception be handled? Which method will handle it?</span><br />
<span style="font-size: x-large;">For this, you must start to know some basic Exception hierarchies. Here's help with the same..</span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: x-large;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5nZzY3g3nmmr4pQkKgIR2IIfvOE3a4VzroINzuxSEs_kZPlsAPlyy6Eb2wqF9GsdXLO4DWSV5TKKvjq-5j_J83aG1HDh_TyImuYTX2gFFkSUGAMzjh-iwTxpFNqW1wEjIbzbCD3OrfZg9/s1600/f10-3.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="184" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5nZzY3g3nmmr4pQkKgIR2IIfvOE3a4VzroINzuxSEs_kZPlsAPlyy6Eb2wqF9GsdXLO4DWSV5TKKvjq-5j_J83aG1HDh_TyImuYTX2gFFkSUGAMzjh-iwTxpFNqW1wEjIbzbCD3OrfZg9/s640/f10-3.gif" width="640" /></a></span></div>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Since printTreeToFile() does not handle any exception, it is propagated to its calling method, checkRoot(). checkRoot() doesn't handle it too and so it's propagated to makeTree() {visualize call stack to check the flow of unhandled exception}. Now, makeTree() handles doesn't handle it BUT it handles an exception which is super to the thrown one. Therefore it is handled here !!</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><u><i>Scenario 2:</i></u></span><br />
<span style="font-size: x-large;">makeTree() handles IOException.</span><br />
<span style="font-size: x-large;">checkRoot() handles FileNotFoundException.</span><br />
<span style="font-size: x-large;">printTreeToFile() throws FileNotFoundException. </span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Moving along the call stack, we see that checkRoot() will handle this.. quite obvious after understanding scenario 1.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">There are many such scenarios where one needs to be able to predict the flow of an exception. However, once clear with <b style="color: #bf9000;">call stack and exception hierarchy</b>, it's easy to check on the flow.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b><br /></b></span></div>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b><br /></b></span></div>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>How do we handle exceptions?</b></span></div>
<span style="font-size: x-large;">The most awaited question so far.. For this we use <b style="color: #bf9000;">try-catch-finally blocks</b>.</span><br />
<span style="font-size: x-large;">The code snippet that is anticipated to produce checked exceptions, which as per java MUST be handled, must be enclosed in try block.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">For example, creating a new FileInputStream may cause FileNotFoundException which is a checked exception and must be handled. Therefore, we handle it by writing it in a try block as below.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<pre class="prettyprint"><span class="kwd" style="font-size: x-large;">try</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">{</span><span class="pln" style="font-size: x-large;">
file </span><span class="pun" style="font-size: x-large;">=</span><span class="pln" style="font-size: x-large;"> </span><span class="kwd" style="font-size: x-large;">new</span><span class="pln" style="font-size: x-large;"> </span><span class="typ" style="font-size: x-large;">FileInputStream</span><span class="pun" style="font-size: x-large;">(</span><span class="pln" style="font-size: x-large;">fileName</span><span class="pun" style="font-size: x-large;">);</span><span class="pln" style="font-size: x-large;">
x </span><span class="pun" style="font-size: x-large;">=</span><span class="pln" style="font-size: x-large;"> </span><span class="pun" style="font-size: x-large;">(</span><span class="kwd" style="font-size: x-large;">byte</span><span class="pun" style="font-size: x-large;">)</span><span class="pln" style="font-size: x-large;"> file</span><span class="pun" style="font-size: x-large;">.</span><span class="pln" style="font-size: x-large;">read</span><span class="pun" style="font-size: x-large;">();</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">}</span></pre>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Simple, isn't it.. Some basic rules to remember:</span><br />
<ul style="text-align: left;">
<li><span style="font-size: x-large;">Every try block MUST be succeeded by EITHER catch block OR finally block.</span></li>
<li><span style="font-size: x-large;">All three blocks can also be written if required.</span></li>
<li><span style="font-size: x-large;">A try block can have multiple catch blocks.</span></li>
<li><span style="font-size: x-large;">It can have only one finally block ATMOST. </span></li>
</ul>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>What is catch block used for?</b></span></div>
<span style="font-size: x-large;">The try block is only meant to contain the lines of code that could throw exceptions. However, if the try block is followed by catch blocks, then the <b><span style="color: #bf9000;">closest suitable block</span></b> that can handle that particular exception is chosen to handle it.</span><br />
<span style="font-size: x-large;">Example:</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<pre class="prettyprint"><span class="kwd" style="font-size: x-large;">try</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">{</span><span class="pln" style="font-size: x-large;">
</span><span class="com" style="font-size: x-large;">//Protected code</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">}</span><span class="kwd" style="font-size: x-large;">catch</span><span class="pun" style="font-size: x-large;">(</span><span class="typ" style="font-size: x-large;">ExceptionType1</span><span class="pln" style="font-size: x-large;"> e1</span><span class="pun" style="font-size: x-large;">)</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">{</span><span class="pln" style="font-size: x-large;">
</span><span class="com" style="font-size: x-large;">//Catch block</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">}</span><span class="kwd" style="font-size: x-large;">catch</span><span class="pun" style="font-size: x-large;">(</span><span class="typ" style="font-size: x-large;">ExceptionType2</span><span class="pln" style="font-size: x-large;"> e2</span><span class="pun" style="font-size: x-large;">)</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">{</span><span class="pln" style="font-size: x-large;">
</span><span class="com" style="font-size: x-large;">//Catch block</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">}</span><span class="kwd" style="font-size: x-large;">catch</span><span class="pun" style="font-size: x-large;">(</span><span class="typ" style="font-size: x-large;">ExceptionType3</span><span class="pln" style="font-size: x-large;"> e3</span><span class="pun" style="font-size: x-large;">)</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">{</span><span class="pln" style="font-size: x-large;">
</span><span class="com" style="font-size: x-large;">//Catch block</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">}</span><span class="kwd" style="font-size: x-large;">finally</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">{</span><span class="pln" style="font-size: x-large;">
</span><span class="com" style="font-size: x-large;">//The finally block always executes.</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">}</span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<span style="font-size: x-large;">Say in the above try block, ExceptionType2 is thrown.. This will be handled by the second catch block.</span><br />
<span style="font-size: x-large;">If the try block throws an exception which is subtype of ExceptionType1, then the first catch block will handle it</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Important things here to be noted:</span><br />
<ul style="text-align: left;">
<li><span style="font-size: x-large;">Finally block MUST always be placed as the last block.</span></li>
<li><span style="font-size: x-large;">The order of catch blocks if handling exceptions in hierarchy must be from the most specific to general type of exception.</span></li>
<li><span style="font-size: x-large;">A catch clause cannot exist without a try statement.</span></li>
<li><span style="font-size: x-large;">It is not compulsory to have finally clauses when ever a try/catch block is present.</span></li>
<li style="color: #bf9000;"><span style="font-size: x-large;"><b>Any code cannot be present in between the try, catch, finally blocks. </b></span></li>
</ul>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<span style="font-size: x-large;">This is not all folks! There is a lot more to Java Exceptions..</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">If a method wants its calling method to handle an exception, it can skip the try-catch-finally and just <b style="color: #bf9000;">SPECIFY</b> that the exception can be thrown with throws clause. This will cause the exception to further up to the calling method on the call stack which again must either handle it or specify it for its calling method to handle.</span><br />
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>So how do we specify?</b></span></div>
<span style="font-size: x-large;">By using <b style="color: #bf9000;">throws</b> clause..</span><br />
<span style="font-size: x-large;">Example:</span><br />
<span style="font-size: x-large;"><br /></span>
<pre><span style="font-size: x-large;">public void printTree() <b>throws IOException{</b></span></pre>
<pre><span style="font-size: x-large;"><b>}</b></span></pre>
<pre><span style="font-size: x-large;"><b> </b></span></pre>
<pre><span style="font-size: x-large;"><b> </b></span></pre>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">What happens here is, if any line of code in printTree() throws an exception or if any exception has propagated to this method, then as it has specified using throws clause, this exception will be handled to its calling method to be handled. Note that the exception that has been specified here is IOException and therefore only this exception can be propagated. For all other exceptions it may throw, it should <b style="color: #bf9000;">handle or specify</b>.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">We can create and throw exceptions as well.</span><br />
<span style="font-size: x-large;"><br /></span>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b><br /></b></span></div>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>How to throw an exception? </b></span></div>
<span style="font-size: x-large;">For this we use a throw statement.</span><br />
<span style="font-size: x-large;">Example:</span><br />
<span style="font-size: x-large;"><br /></span>
<pre><span style="font-size: x-large;"><b>throw new EmptyStackException();</b></span></pre>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Note that '<b style="color: #bf9000;">throw'</b> can be used to throw a java.lang.Throwable exception which means it can throw checked and runtime exception.</span><br />
<span style="font-size: x-large;">In the above example, EmptyStackException is a runnable exception (unchecked). Runtime exceptions indicate invalid client code or invalid usage of client API. <b style="color: #bf9000;">Throwing this runtime exception will give the client useful information on recovery.</b></span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>How to declare/create exception?</b></span></div>
<span style="font-size: x-large;">All exceptions must be a child of Throwable.</span><br />
<span style="font-size: x-large;">If you want to write a checked exception that is automatically enforced
by the <b style="color: #bf9000;">Handle or Declare Rule</b>, you need to extend the Exception class.</span><br />
<span style="font-size: x-large;">If you want to write a runtime exception, you need to extend the RuntimeException class.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Example:</span><br />
<pre class="prettyprint"><span class="kwd" style="font-size: x-large;">class</span><span class="pln" style="font-size: x-large;"> </span><span class="typ" style="font-size: x-large;">MyException</span><span class="pln" style="font-size: x-large;"> </span><span class="kwd" style="font-size: x-large;">extends</span><span class="pln" style="font-size: x-large;"> </span><span class="typ" style="font-size: x-large;">Exception</span><span class="pun" style="font-size: x-large;">{</span><span class="pln" style="font-size: x-large;">
</span><span class="pun" style="font-size: x-large;">}</span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>Why would I create my own exception?</b></span></div>
<span style="font-size: x-large;">As mentioned in <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/creating.html">Oracle Documentation</a>, if you say yes for any of the following, then it means you need to create your own exception.</span><br />
<ul>
<li><span style="font-size: x-large;">Do you need an exception type that isn't represented by those in the Java platform?</span></li>
<li><span style="font-size: x-large;">Would it help users if they could differentiate your exceptions from those thrown by classes written by other vendors?</span></li>
<li><span style="font-size: x-large;">Does your code throw more than one related exception?</span></li>
<li><span style="font-size: x-large;">If you use someone else's exceptions, will users have access to
those exceptions? A similar question is, should your package be
independent and self-contained?</span></li>
</ul>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<span style="font-size: x-large;"><br /></span>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<div style="color: #bf9000;">
<span style="font-size: x-large;"><b>What about chaining exceptions?</b></span></div>
<span style="font-size: x-large;">As we saw, we can throw an exception using throws clause. If in handle code of of one exception, you are throwing another exception and so on, then it is called chained exception.</span><br />
<span style="font-size: x-large;">There is not much of space science to it. The gist of this lies in how you can utilize this feature in your logic.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;">Already Tired??</span><br />
<span style="font-size: x-large;">Well, we are done with the basics but this topic is more about how well you can put it to use rather its than rules and syntax.</span><br />
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<div style="color: yellow;">
<span style="font-size: x-large;">Coffee Break:</span></div>
<span style="font-size: x-large;">Checked exceptions MUST be handled. They mean to serve User Errors.</span><br />
<span style="font-size: x-large;">Runtime exceptions and Errors are together called, 'Unchecked exceptions'.</span><br />
<span style="font-size: x-large;">Runtime exceptions can be fixed by bug fixes and through logic. They mean to serve Programmer Error.</span><br />
<span style="font-size: x-large;">Errors are not in our hands.</span><br />
<span style="font-size: x-large;">In Java, there is this class - Exception. Any exception thrown is an object of this class. ;)</span><br />
<span style="font-size: x-large;">Every try block MUST be succeeded by EITHER catch block OR finally block.</span><br />
<span style="font-size: x-large;">All three blocks can also be written if required.</span><br />
<span style="font-size: x-large;">A try block can have multiple catch blocks.</span></div>
<span style="font-size: x-large;">It can have only one finally block ATMOST.</span><br />
<span style="font-size: x-large;">Finally block MUST always be placed as the last block.</span><br />
<span style="font-size: x-large;">The order of catch blocks if handling exceptions in hierarchy must be from the most specific to general type of exception.</span><br />
<span style="font-size: x-large;">A catch clause cannot exist without a try statement.</span><br />
<span style="font-size: x-large;">It is not compulsory to have finally clauses when ever a try/catch block is present.</span></div>
<div style="font-family: Times,"Times New Roman",serif;">
<span style="font-size: x-large;">Any code cannot be present in between the try, catch, finally blocks.</span></div>
<div style="font-family: Times,"Times New Roman",serif;">
<span style="font-size: x-large;"><br /></span></div>
<div style="font-family: Times,"Times New Roman",serif;">
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<pre><span style="font-size: x-large;"> </span></pre>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<pre class="prettyprint"><span class="pun" style="font-size: x-large;"> </span></pre>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span>
<span style="font-size: x-large;"><br /></span></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-8575624983437504482011-07-20T04:25:00.000-07:002013-10-16T07:57:43.543-07:00Design Pattern<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Life is full of problems. Some problems occur frequently and are common. Keeping solutions to such problems in mind is good. This saves time in solving the problem. At least you will be knowing how to approach the problem. Its not necessary that you approach it the same way or use the same solution but then you will be aware of the known solution that may help you to make your own solutions... better one <b><span class="Apple-style-span" style="color: #bf9000;">:)</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Design patterns are no different except that these are intended for problems in software design. They are reusable solutions for common problems. It may be a simple description of solution or a template. It is language independent. They are not complete solutions since they only provide description or template which needs to be converted into code for final use.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">In simple words design patterns are recurring solutions to design problems. The documentation format(explaining about the design pattern) as given by Erich Gamma<span class="Apple-style-span" style="line-height: 19px;">,Richard Helm, Ralph Johnson and John Vlissides </span><span class="Apple-style-span" style="line-height: 19px;">(collectively known as the "Gang of Four", or GoF for short) in their book <i>Design Patterns contains:</i></span></span><br />
<span class="Apple-style-span" style="line-height: 19px;"><i><span class="Apple-style-span" style="font-style: normal;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">1. <b><span class="Apple-style-span" style="color: #bf9000;">Pattern Name and Classification:</span></b> A descriptive and unique name that helps in identifying and referring to the pattern.</span></span></i></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;"><i><span class="Apple-style-span" style="font-style: normal;">2. </span></i></span><span class="Apple-style-span" style="line-height: 19px;"><b><span class="Apple-style-span" style="color: #bf9000;">Intent:</span></b> A description of the goal behind the pattern and the reason for using it.</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">3. </span><span class="Apple-style-span" style="line-height: 19px;"><b><span class="Apple-style-span" style="color: #bf9000;">Also Known As:</span></b> Other names for the pattern.</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">4. </span><span class="Apple-style-span" style="line-height: 19px;"><b><span class="Apple-style-span" style="color: #bf9000;">Motivation (Forces):</span></b> A scenario consisting of a problem and a context in which this pattern can be used.</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">5. </span><span class="Apple-style-span" style="line-height: 19px;"><b><span class="Apple-style-span" style="color: #bf9000;">Applicability:</span></b> Situations in which this pattern is usable; the context for the pattern.</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">6. </span><span class="Apple-style-span" style="line-height: 19px;"><b><span class="Apple-style-span" style="color: #bf9000;">Structure:</span><span class="Apple-style-span" style="color: #b45f06;"> </span></b>A graphical representation of the pattern. Class diagrams and Interaction diagrams may be used for this purpose.</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">7. </span><span class="Apple-style-span" style="line-height: 19px;"><b><span class="Apple-style-span" style="color: #bf9000;">Participants:</span></b> A listing of the classes and objects used in the pattern and their roles in the design.</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">8. </span><span class="Apple-style-span" style="line-height: 19px;"><span class="Apple-style-span" style="color: #bf9000;"><b>Consequences:</b> </span>A description of the results, side effects, and trade offs caused by using the pattern.</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">9. <b><span class="Apple-style-span" style="color: #bf9000;">I</span></b></span><span class="Apple-style-span" style="line-height: 19px;"><b><span class="Apple-style-span" style="color: #bf9000;">mplementation:</span></b> A description of an implementation of the pattern; the solution part of the pattern.</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">10. </span><span class="Apple-style-span" style="line-height: 19px;"><span class="Apple-style-span" style="color: #bf9000;"><b>Sample Code:</b> </span>An illustration of how the pattern can be used in a programming language.</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;"></span><span class="Apple-style-span" style="line-height: 19px;">11.</span><span class="Apple-style-span" style="line-height: 19px;"><b><span class="Apple-style-span" style="color: #bf9000;">Known Uses:</span></b> Examples of real usages of the pattern.</span><span class="Apple-style-span" style="line-height: 19px;"> </span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">12.<b><span class="Apple-style-span" style="color: #b45f06;"> </span></b><span class="Apple-style-span" style="line-height: 19px;"><span class="Apple-style-span" style="color: #bf9000;"><b>Related Patterns:</b> </span>Other patterns that have some relationship with the pattern; discussion of the differences between the pattern and similar patterns.</span></span><br />
<span class="Apple-style-span" style="line-height: 19px;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">There are many design patterns known so far out of which 23 java design patterns are commonly practiced. They are grouped as follows</span><br />
<img src="http://www.tech121.info/be/image.axd?picture=2010%2F9%2FTypesOfDesignPatterns.png" /><br />
<br />
<br />
<br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Well let me give you some brief idea on them. We will see more on it later.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">Creational patterns</span></b> are the ones that deal with object creation mechanism. In java, creating an object by simple statement Class_A a = new Class_A(); is hardcoding and should be avoided for having a quality software. So we should choose the object creation mechanism depending on the situations or scenario and requirement. Creational patt</span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">erns include many patterns that will help us in doing this.</span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: large;"> </span><br />
<img src="http://www.c-sharpcorner.com/UploadFile/nipuntomar/5550/Images/CREATIONAL2.gif" /><br />
<br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">Behavioral patterns</span></b> define common communication patterns between objects to provide flexibility in communication. So basically it deals with object interactions. The objects should be interacting with loose coupling.</span><br />
<img alt="BehaPatte1.gif" src="http://www.c-sharpcorner.com/UploadFile/nipuntomar/5634/Images/BehaPatte1.gif" /><br />
<br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">Structural patterns</span></b> are patterns for realizing relationship between entities. They are for describing how objects, classes and other entities are associated with each other and therefore giving us a complete structure in abstraction.</span><br />
<img alt="StructDesiPatte1.gif" src="http://www.c-sharpcorner.com/UploadFile/nipuntomar/5748/Images/StructDesiPatte1.gif" /><br />
<br />
<br />
<br />
<br />
<span class="Apple-style-span" style="color: yellow; font-family: Times, 'Times New Roman', serif; font-size: x-large;">Coffee Break</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Design Patterns are for making use of solutions(predefined or known) for commonly known problems.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">They are language independent.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">They are description or template of solution.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">They are incomplete solutions(need to be transformed into code).</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Grouped under creational, structural and behavioral.</span><br />
<br /></div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-73998440256030385702011-05-27T14:02:00.000-07:002013-10-16T07:57:43.530-07:00J2EE Part 3 - J2EE Containers<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">While writing business logic in J2EE application many programmers faced many similar problems for which they had to re-implement the solutions. Enterprise JavaBeans(EJB) was intended to handle such common concerns.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">The <b><span class="Apple-style-span" style="color: #bf9000;">EJB container</span></b> is a runtime environment that controls the enterprise beans and provides them with important system-level services. Since you don't have to develop these services yourself, you are free to concentrate on the business methods in the enterprise beans. </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">The <b><span class="Apple-style-span" style="color: #bf9000;">EJB container</span></b> provides solutions for common concerns to the enterprise beans such as:</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">1. <b>Transaction Management</b></span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">2.<b> Security</b></span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">3.<b> Remote Client Connectivity</b></span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">4. <b>Lifecycle Management</b></span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">5. <b>Database Connection</b></span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;"><span class="Apple-style-span" style="line-height: normal;">For each enterprise bean, the container is responsible for registering the object, providing a remote interface for the object, creating and destroying object instances, checking security for the object, managing the active state for the object, and coordinating distributed transactions. Optionally, the container can also manage all persistent data within the object. Therefore the programmer can focus on the main logic and leave all this work for the container.</span></span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large; line-height: 19px;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large; line-height: 19px;"><img height="354" src="http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/images/Fig5.gif" width="640" /></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;"><br />
</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">J2EE Client contains application client container that manages execution of application client components. </span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;">J2EE Server contains EJB containers and web containers. EJB containers manages execution of enterprise beans. Web containers manages the JSPs and servelet components. </span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;"><br />
</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: 19px;"><span class="Apple-style-span" style="line-height: normal;">Enterprise beans are server components written in the Java programming language. Enterprise beans contain the business logic for your application.</span></span></span><br />
<span class="Apple-style-span" style="line-height: 19px;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Enterprise JavaBeans technology supports both transient and persistent objects. A transient object is called a session bean, and a persistent object is called an entity bean.</span></span><br />
<div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">A <b><span class="Apple-style-span" style="color: #bf9000;">session bean</span></b> exists only for the duration of a single client/server session. A session bean performs operations such as accessing a database or performing calculations. Session beans can be transactional, but normally are not recoverable following a system crash. Session beans can be stateless, or they can maintain conversational state across methods and transactions. A session bean must manage its own persistent data.</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">An <b><span class="Apple-style-span" style="color: #bf9000;">entity bean</span></b> is an object representation of persistent data maintained in a permanent data store, such as a database. An entity object can manage its own persistence, or it can delegate its persistence to its container.</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">Purpose of <b><span class="Apple-style-span" style="color: #bf9000;">sessions bean</span></b> is to perform a task for a client and is not persistent. It may have one client only. <b><span class="Apple-style-span" style="color: #bf9000;">Entity bean</span></b> on the other hand represents business entity object in persistent storage. It can have multiple clients. </span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">Simple <b><span class="Apple-style-span" style="color: #bf9000;">example</span></b> showing both:</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: small; line-height: normal;"><img src="http://download.oracle.com/javaee/1.2.1/devguide/images/Shopping.gif" /></span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: small; line-height: normal;"><br />
</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">The customer, order and product require persistent storage and hence entity bean.</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">A good rule of thumb is that <b><span class="Apple-style-span" style="color: #bf9000;">entity beans</span></b> model business concept expresses as 'noun' since they model real world objects that are persistent. For the above <b><span class="Apple-style-span" style="color: #bf9000;">example -> product, order and customer are entity beans.</span></b> </span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><b><span class="Apple-style-span" style="color: #bf9000;">Session beans</span></b> only manages the client processes and tasks. It manages activities like for the above example<b><span class="Apple-style-span" style="color: #bf9000;"> 'shopping activity'</span></b>. It does not represent any persistent data in database. It is transient because it performs the set of activities it is supposed to and then it ends. It therefore models interactions.</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">Lets have a brief look at how to implement an <b><span class="Apple-style-span" style="color: #bf9000;">enterprise bean:</span></b></span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">1. you need to define two interfaces and two classes.</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">2. <b><span class="Apple-style-span" style="color: #bf9000;">Remote Interface:</span></b> defines business methods of the bean. It extends <span class="Apple-style-span" style="color: orange;">javax.ejb.EJBObject </span>that in turn extends <span class="Apple-style-span" style="color: orange;">java.rmi.Remote</span>.</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">3. <b><span class="Apple-style-span" style="color: #bf9000;">Home Interface:</span></b> defines bean's lifecycle methods. Therefore it includes methods for creating new beans, finding beans and removing them. It extends <span class="Apple-style-span" style="color: orange;">javax.ejb.EJBHome</span> that in turn extends <span class="Apple-style-span" style="color: orange;">java.rmi.Remote</span>.</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">4. <b><span class="Apple-style-span" style="color: #bf9000;">Bean Class:</span></b> actually implements bean's business methods. An entity bean must extend <span class="Apple-style-span" style="color: orange;">javax.ejb.EntityBean</span> and a session bean must extend <span class="Apple-style-span" style="color: orange;">javax.ejb.SessionBean</span>. Also both should extend <span class="Apple-style-span" style="color: orange;">javax.ejb.EnterpriseBean</span>. <b><span class="Apple-style-span" style="color: #bf9000;">NOTE -> </span></b>This class does not implement either of the above interfaces but must have methods matching signatures of methods in Remote Interface and must implement some methods of Home Interface... We will see more on this later.</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;">4. <b><span class="Apple-style-span" style="color: #bf9000;">Primary Key:</span></b> It is a simple class that provides a pointer into the database. It should implement <span class="Apple-style-span" style="color: orange;">Serializable</span>. As we already know that only entity beans deals with persistent data, only entity beans will need primary key and session beans clearly doesn't.</span></span></div>
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">You need to know two <b><span class="Apple-style-span" style="color: #bf9000;">basic things</span></b> before we proceed:</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">1. Client never interacts with Bean Class directly. It makes use of both the interfaces only to interact with stubs that are generated automatically.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">2. A bean that needs services of another bean is a client to it if seen in a relative manner and therefore the above applies to it too.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Container is primarily responsible for creating <b><span class="Apple-style-span" style="color: #bf9000;">'instances'</span></b> of beans and making sure they are stored properly by the server. There are many containers provided by different vendors in market providing different tools and therefore must be selected accordingly... At least one tool will deal with mapping of beans with database. Some tools will generate a code that will implement the interfaces to create bean and store it in database. This is why the Bean Class need not implement them <b><span class="Apple-style-span" style="color: #bf9000;">:) </span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">So why did they make container...</span></b> Why not just make the server do the container's work for the beans. One of the reasons is that a third party can provide containers and it can plugged into any server. The vendors can decide whether to make server or container and focus on it. One disadvantage of this container-server interface could </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">be performance. <b><span class="Apple-style-span" style="color: #bf9000;">Advantage follows the rule -> </span></b>Higher the abstraction, greater the flexibility. <b><span class="Apple-style-span" style="color: #bf9000;">Disadvantage is due to the rule -></span></b> Tighter the integration, better the performance. In the case of container-server interface the integration is not tight and hence low performance but the abstraction is at a higher level and hence the flexibility.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">The responsibilities of server and container is dependent on the vendors. Many different types are available based on this and we should make a choice depending on our need.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Anyways we will talk more on EJB container only. I know we did a lot for the day... So details covered in next post and for now you can go for your coffee break<b><span class="Apple-style-span" style="color: #bf9000;"> :)</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="color: yellow;">Coffee Break</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Enterprise Beans are business object components.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Two types of beans - Session and Entity beans.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Session beans is transient.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Entity beans is persistent.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Beans contained in container.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Container handles common concerns of the app.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">EJB container used for J2EE app. </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Container also manages object's database optionally</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Container therefore relieves the programmer of common tasks and he can focus on business logic implementation only.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Enterprise Bean implemented by two classes and two interfaces.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Client has no direct interaction with beans.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">A bean needing service from another bean acts like a client to it.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Remote Interface defines methods for the bean's business logic.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Home Interface defines methods for the bean's lifecycle.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Bean Class implements state and behaviour of beans.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Primary Key provides pointer into the database.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="line-height: normal;"><br />
</span></span></div>
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<div style="line-height: 19px;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: small; line-height: normal;"><br />
</span></span></div>
<br /></div>
</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com4tag:blogger.com,1999:blog-6305156778246888692.post-51010391299643252542011-05-18T12:43:00.000-07:002013-10-16T07:57:43.518-07:00J2EE Part 2<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Although a J2EE application can consist of the three or four tiers, J2EE multitiered applications are generally considered to be three-tiered applications because they are distributed over three different locations: client machines, the J2EE server machine, and the database.</span><br />
<br />
<br />
<img height="491" src="http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/images/Fig1.gif" width="640" /><br />
<br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">The above shows multi-tiered applications.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">J2EE CLIENTS: </span></b>can be web client or application client. Web clients consists of dynamic web pages generated by web components running in web-tier and web browser that renders the dynamic pages received from server in presentable format. Applet is a small client application that executes in JVM installed in web browser. Web clients are also called as <b><span class="Apple-style-span" style="color: #bf9000;">'thin clients'</span></b> as they do not do heavy weight operations such as database queries or implementation of complex business logic. Another type of client is application client. Application client makes use of typical swing or Abstract Window Toolkit(AWT) APIs to provide a rich user interface.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">The <b><span class="Apple-style-span" style="color: #bf9000;">difference</span></b> between standalone client and J2EE client is that J2EE client can connect to J2EE services.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Now we know that the client communicates to the business tier(meaning business layer on another computing system... therefore <b><span class="Apple-style-span" style="color: #bf9000;">'tier'</span></b>) either directly or through the presentation tier(meaning presentation layer on another computing system... through JSPs and servelets).</span><br />
<img height="427" src="http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/images/Fig2.gif" width="640" /><br />
<br />
<span class="Apple-style-span" style="color: #bf9000; font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b>J2EE SERVER:</b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;"><i>Web Component:</i></span></b> They can be servelets or JSPs. Servelets are java classes having embedded html pages for dynamically processing requests and constructing responses. JSPs on the other hand are html pages having embedded java code.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;"><i>Business Component:</i></span></b> It contains the business logic or the implementation part... implementation of all the business rules.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;"><i>JavaBeans Component:</i></span></b> They can be on client side for managing data flow between applet or any other client to the components on J2EE server or it can be on J2EE server side for managing data flow between J2EE server components and database.</span><br />
<img height="339" src="http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/images/Fig3.gif" width="640" /><br />
<br />
<br />
<br />
<br />
<br />
<span class="Apple-style-span" style="color: #bf9000; font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b>DATABASE SERVER:</b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">EIS Tier: It includes Enterprise Resource Planning(ERP) and handles information systems. It manages all the database connectivity stuff.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Finally we get:</span><br />
<img height="276" src="http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/images/Fig4.gif" width="640" /><br />
<br />
<br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="color: yellow; font-family: Times, 'Times New Roman', serif; font-size: x-large;">Coffee Break</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Noramlly J2EE used is 3 tiered architecture.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">The tiers are J2EE client, J2EE server and database server.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Client tier can be web client or application client.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">JavaBeans components are NOT considered as J2EE components by specification.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">J2EE server consists of web tier and business tier. </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Database server consists of EIS tier.</span></div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com3tag:blogger.com,1999:blog-6305156778246888692.post-32964233169039987872011-04-28T11:41:00.000-07:002013-10-16T07:57:43.507-07:00J2EE Part 1<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">J2EE - Java 2 Enterprise Edition is one of the 3 java platforms, the other being J2SE and J2ME. It is set of specifications or standards consisting of many APIs useful for building java based enterprise applications. At such it is not some software to be installed but is just a bundle of many technologies having set of APIs.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">J2EE applications are java applications that span over LAN, WAN and broader. They are used when it comes to distributed environment and disparate systems and also when in need to make use of its technologies.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">J2EE technologies are broadly classified into two <b><span class="Apple-style-span" style="color: #bf9000;">categories:</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">1. <span class="Apple-style-span" style="color: #bf9000;"><b>Component technologies</b></span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">2. <b><span class="Apple-style-span" style="color: #bf9000;">Service technologies</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Kinds of J2EE <b><span class="Apple-style-span" style="color: #bf9000;">Components:</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><span class="Apple-style-span" style="color: #bf9000; font-weight: bold;">Client Side Comonents -> </span><span class="Apple-style-span">includes applets.</span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">Web Components -></span></b> includes servelets and JSPs</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">Business Components -></span></b> includes EJB</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Web components and Business components run on Server Side...</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Kinds of J2EE <b><span class="Apple-style-span" style="color: #bf9000;">Services:</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">JNDI -></span></b> Java Naming and Directory service</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">JMS -></span></b> java Messaging Service</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">JTA -></span></b> Java Transaction API</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">JAAS -></span></b> Java Authentication and Authorization Service</span><br />
<span class="Apple-style-span" style="color: #bf9000; font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b>Java Mail</b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">J2EE is meant for building the 3 layers of java based enterprise application. The <b><span class="Apple-style-span" style="color: #bf9000;">layers</span></b> being:</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">1. <b><span class="Apple-style-span" style="color: #bf9000;">Presentation Layer</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">2. <span class="Apple-style-span" style="color: #bf9000;"><b>Service/Business Layer</b></span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">3. <span class="Apple-style-span" style="color: #bf9000;"><b>Data Access Layer</b></span></span><br />
<br />
<br />
<br />
<img src="http://www.ibm.com/developerworks/wireless/library/wi-entwap/wapj2ee-fig1.gif" /><br />
<br />
<br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">We have been talking on java based enterprise application... To clear you on it:</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">A computer application used to manage business services of an enterprise is called enterprise application and if the application is coded in java and is deployed into J2EE compliant application server then it becomes java based. <b><span class="Apple-style-span" style="color: #bf9000;">:)</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Any enterprise application generally covers <b><span class="Apple-style-span" style="color: #bf9000;">4 main tasks:</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">1. <b><span class="Apple-style-span" style="color: #bf9000;">providing user interface(UI) to the user.</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">2. <span class="Apple-style-span" style="color: #bf9000;"><b>processing of data according to some business logic(rules)</b></span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">3. <b><span class="Apple-style-span" style="color: #bf9000;">interacting with database(data access)</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">4. <b><span class="Apple-style-span" style="color: #bf9000;">storing of data</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">These tasks are logically divided into <span class="Apple-style-span" style="color: #bf9000;"><b>4 layers</b></span></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"> A. <b><i><span class="Apple-style-span" style="color: #bf9000;">Presentation layer</span></i></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"> B. <b><i><span class="Apple-style-span" style="color: #bf9000;">Business/Service layer</span></i></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"> C. <b><i><span class="Apple-style-span" style="color: #bf9000;">Data Access Layer</span></i></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"> D. <b><i><span class="Apple-style-span" style="color: #bf9000;">Data Layer</span></i></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<img alt="tiered-Architecture_thumb2" src="http://lh3.ggpht.com/_mFRuRea3y6s/TPBrXCVuFcI/AAAAAAAAAvk/-h4S3qhYkTg/tiered-Architecture_thumb2_thumb%5B2%5D.png?imgmax=800" /> <br />
<br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">J2EE developers are responsible for the first 3 layers while the data layer is the responsibility of database administrator(DBA).</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Hope you are clear on the layers... Remember they are just the logical division. Now coming to actual or physical division...</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">The physical partition of enterprise application is known as<b><span class="Apple-style-span" style="color: #bf9000;"> 'tier'</span></b>. The enterprise application can be single-tier, two-tier, three-tier, n-tier or distributed-tier depending on number of computing systems on which the layers are installed.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Lets talk more on layers... </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">Presentation Layer</span></b> is the user interface part of the application. If the app is web based then Servelets and JSPs are used to build it on server side. The main design patterns used in this layer are Front Controller, Model-View-Controller(MVC), Composite View.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">Business/Service Layer</span></b> is nothing but a code that processes data according to business logic(rules). Some important design patterns used in this layer are Service Locator, Business Delegate, Session Facade. Job of service layer is to receive the business request from presentation layer or some other service layer, communicate with data access layer to get the enterprise data, process that data using defined business rules, return the result to the requested component</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><b><span class="Apple-style-span" style="color: #bf9000;">Data Access layer</span></b> is again a code which communicates with the database. It performs CRUD(Create, Read, Update, Delete). Therefore it is just a code communicating with database specific APIs such as JDBC. The design patterns used are Data Access Object(DTO), Data Transfer Object(DTO), Value Object. Can you guess what its job is??? It receives request from service layer, communicates with the database to perform the requested operations and sends the result back to service layer. </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">So now you clear on J2EE basics<b><span class="Apple-style-span" style="color: #bf9000;"> :)</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Let me tell you more on business/service layer and then you can have your coffee break<b><span class="Apple-style-span" style="color: #bf9000;"> :)</span></b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">We already know what is the job of service layer but in order for it to implement it, it needs some capabilities... like transactional capability, distributed computing capability, security implementation capability. </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">To have these capabilities we make use of J2EE technologies(both components and services). Just scroll up and read the first three paragraphs... This should make it clear for you. </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="color: yellow; font-family: Times, 'Times New Roman', serif; font-size: x-large;">Coffee Break</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">J2EE is not a software but is a set of standards/specifications having APIs to make java enterprise app.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Provides a standard for developing multi-tier enterprise services.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">It is useful for building apps that span over LAN and needs to make use of its technologies.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">It is platform independent.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">J2EE technologies include components and services.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Business logic is organized into reusable components... so J2EE is helpful.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Layers are logical divisions of J2EE while tiers are physical partitions depending on number of computing systems used.</span><br />
<span class="Apple-style-span" style="color: lime; font-family: Times, 'Times New Roman', serif; font-size: x-large;">The J2EE platform uses a multitiered distributed application model. Application logic is divided into components according to function, and the various application components that make up a J2EE application are installed on different machines depending on the tier in the multitiered J2EE environment to which the application component belongs.</span><br />
<br /></div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com12tag:blogger.com,1999:blog-6305156778246888692.post-79522022006237728712011-04-20T08:14:00.000-07:002013-10-16T07:58:47.018-07:00HTTP - More...<div dir="ltr" style="text-align: left;" trbidi="on">
We already are familiar with the basic idea and structure of HTTP. Well now lets move ahead... with gear 1 so no worries :)<br />
<br />
Remember HTTP is a request/response protocol... !!! If 'no' then read the earlier post - 5 minutes of basics !!!<br />
<br />
<br />
The key elements of HTTP request are:<br />
> HTTP method<br />
> URL<br />
> Form parameters<br />
<br />
HTTP method is nothing but the action the client wants to perform. The client may want to get something from the server or to post something to it - some data that the server can use for responding accordingly or can save it in a database for further utility. HTTP method specifies what 'action' the client performs. Basic HTTP methods are GET, POST, PUT, DELETE.<br />
<br />
URL of course is for accessing the page the client wishes to... of the server !!!<br />
<br />
Form parameters are some data that the client wishes to send to the server.<br />
<br />
<br />
<br />
The key elements of HTTP response are:<br />
> Status code<br />
> Content - type<br />
> Content<br />
<br />
Status code for example can be something like 301, 302, etc... or something like 'not found', 'ok', etc...<br />
This is information about the status of the request whether it was successful or not. So the response will tell the client the status of the request.<br />
<br />
Content - type can be 'text', 'picture', 'html', etc... Just to specify the type of content to the client so that it can accordingly display it.<br />
<br />
Finally the content - this is the actual text file, image or html that the server sends to the client for the request it has made.<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-47577521206416927002011-04-17T08:01:00.000-07:002013-10-16T07:58:47.006-07:00Middleware<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">The term 'middleware' is generally used in the context of distributed systems. It is a software that helps two software components talk and share data. When the software components on both sides are applications, then we refer to this type of middleware as Enterprise Application Integration(EAI). Actually it acts like a glue between software components or software component and a network. It could glue application to database managers. A better way to define is to say that it <span class="Apple-style-span" style="color: #bf9000;">'mediates'</span> between an application and network or between software components and software facilities as required in heterogeneous computing platform.</span><br />
<img src="http://www.networkworld.com/Micronet%20images/middleware.gif" /><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">A simple example of middleware is Object Request Broker(ORB) that manges communication between objects. </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Middleware is used in context with High Level Architecture(HLA) that applies to many distributed systems. It is sometimes called <span class="Apple-style-span" style="color: #bf9000;">'plumbing'</span> because it connects two applications and passes data between them. </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">It was intended basically for following purposes:</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">1. For linking newer applications to older systems or applications.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">2. Connecting multiple applications over a network and hence facilitating distributed processing.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">3. To provide interaction between network and application or service</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">4. To provide interaction on network transparently.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">5. To be independent of network services and always available</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">You could think of more uses but these are the basic ones...</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">A <b><span class="Apple-style-span" style="color: #bf9000;">typical example</span></b> of Middleware can be TCP/IP stack for telecommunications.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Some basic types of middleware are:</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">1.<b><span class="Apple-style-span" style="color: #bf9000;"> Message Oriented Middleware:</span></b> Transactions or event notifications are sent between disparate systems via messages</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">2. <span class="Apple-style-span" style="color: #bf9000;"><b>Object Middleware:</b></span> Consists of Object Request Brokers for communication between the objects. It is possible for applications to send objects and request services in object oriented system.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">3.<b><span class="Apple-style-span" style="color: #bf9000;"> Remote Procedure Call(RPC) Middleware:</span></b> used to call procedures on remote system. It can be synchronous or asynchronous.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">There are many others... </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"><br />
</span><br />
<span class="Apple-style-span" style="color: yellow; font-family: Times, 'Times New Roman', serif; font-size: x-large;">Coffee Break</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Middleware is a glue between software components and network.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Software components can be service or application.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">When glued between two applications it is called EAI</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">It is also called 'plumbing'</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">It is used in context with distributed systems.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;"></span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Mainly needed for disparate applications/systems.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">Serves message passing, data sharing and interaction between disparate </span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif; font-size: x-large;">disparate applications/systems.</span><br />
<br />
<br />
<br />
<br />
<br />
<br />
</div>Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0tag:blogger.com,1999:blog-6305156778246888692.post-73476468679450541362011-04-17T01:53:00.000-07:002013-10-16T07:58:47.013-07:00HTTP - Getting Started<div dir="ltr" style="text-align: left;" trbidi="on">
HTTP - HyperText Transfer Protocol<br />
It is a <span class="Apple-style-span" style="color: #e69138;"><b>request response oriented protocol</b></span>
which defines the way how a client and server talk to each other. By
protocol we mean some set of rules. The client is typically a web
browser.<br />
<br />
So how it works?<br />
Well, the client sends a request for some resource to a server and the
server sends it back a response corresponding to the resource requested
for. This is the basic idea.<br />
<br />
The request is also called as 'query'. The server generally makes use
of a database to find the resource that the client has requested for.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyL8AvFWs_juqQ-otMHykSPLlEyWCFS-6AsvwjzB6QfG36-x5_n8qyVfu_8SCfipHPhECOGFoeaH7k3GIP_s7qsEaRGmD1RKTD-7zaVKeqbWIm97WReS8k83QdMEWaYw-ex3rmRn8bjWwN/s1600/1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyL8AvFWs_juqQ-otMHykSPLlEyWCFS-6AsvwjzB6QfG36-x5_n8qyVfu_8SCfipHPhECOGFoeaH7k3GIP_s7qsEaRGmD1RKTD-7zaVKeqbWIm97WReS8k83QdMEWaYw-ex3rmRn8bjWwN/s1600/1.jpg" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
Clients and Servers both know HTTP and communicate over it. For this the client (web browser) must know <br />
html. If the response of a server to client's request is an html document then it needs to send it using HTTP protocol.<br />
<br />
<span class="Apple-style-span" style="color: #e69138;"><b>Bottom line</b></span> is: A web server uses HTTP to talk to client.<br />
<br />
HTTP<b> <span class="Apple-style-span" style="color: #e69138;">runs on top of TCP/IP protocol</span> </b>to
ensure that the files that are being sent as a response are received at
destination as a complete file although it is broken up into chunks
when sent. Anyways thats all going into networking and transport layer
protocol so we wont talk more on it. <span class="Apple-style-span" style="color: #b45f06;">:)</span> Just remember that HTTP is an application layer protocol.<br />
<br />
<span class="Apple-style-span" style="color: #e69138;"><b>Basic structure</b></span> of HTTP conversation is an easy guess now <span class="Apple-style-span" style="color: #e69138;"><b>!!!</b></span> - request/response sequence : client requests and server responds...<br />
<br />
<br />
<br />
<span class="Apple-style-span" style="color: yellow;"><b>Coffee Break</b></span><br />
HTTP is the protocol clients and servers use on the web to communicate.<br />
The server uses HTTP to send html to client. So html is a part of HTTP response.<span class="Apple-style-span" style="color: #b45f06;"> </span><span class="Apple-style-span" style="color: #e69138;"><b>:)</b></span><br />
html tells the client (browser) how to display contents to the user.<br />
HTTP is an application layer protocol.</div>
Sai Rajeshwarihttp://www.blogger.com/profile/05857488967503077001noreply@blogger.com0