<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1681547402308503342</id><updated>2024-10-25T08:03:05.193+05:30</updated><category term="technology"/><category term="java"/><category term="mysql"/><category term="open source"/><category term="programming"/><category term="source code"/><category term="BIS 2011"/><category term="Bureau of Indian Standards"/><category term="Computer Engineering"/><category term="India"/><category term="TDD"/><category term="apache"/><category term="best practices"/><category term="code"/><category term="coding"/><category term="collections framework"/><category term="core java"/><category term="data"/><category term="dependency injection"/><category term="design patterns"/><category term="development"/><category term="embedding code in HTML"/><category term="git"/><category term="highlighting"/><category term="interview"/><category term="j2ee"/><category term="optimize"/><category term="oracle"/><category term="php"/><category term="questions"/><category term="references"/><category term="rows"/><category term="sample arraylist implementation"/><category term="sample hashtable implementation"/><category term="sample linkedlist implementation"/><category term="sample vector implementation"/><category term="scientist b"/><category term="size"/><category term="software"/><category term="sql"/><category term="symfony"/><category term="table"/><category term="unit test cases"/><category term="utils"/><title type='text'>Cognitive DNA</title><subtitle type='html'>Percept, Learn, Judge and Solve</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://linux4genext.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://linux4genext.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Bharat Verma</name><uri>http://www.blogger.com/profile/12817316332686822982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1681547402308503342.post-5424975173402966367</id><published>2015-04-16T16:34:00.000+05:30</published><updated>2015-07-29T18:19:35.327+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="apache"/><category scheme="http://www.blogger.com/atom/ns#" term="best practices"/><category scheme="http://www.blogger.com/atom/ns#" term="code"/><category scheme="http://www.blogger.com/atom/ns#" term="coding"/><category scheme="http://www.blogger.com/atom/ns#" term="dependency injection"/><category scheme="http://www.blogger.com/atom/ns#" term="design patterns"/><category scheme="http://www.blogger.com/atom/ns#" term="development"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="references"/><category scheme="http://www.blogger.com/atom/ns#" term="software"/><category scheme="http://www.blogger.com/atom/ns#" term="symfony"/><category scheme="http://www.blogger.com/atom/ns#" term="TDD"/><category scheme="http://www.blogger.com/atom/ns#" term="unit test cases"/><category scheme="http://www.blogger.com/atom/ns#" term="utils"/><title type='text'>The Clean Code Talks - Don&#39;t Look For Things! </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; id=&quot;docs-internal-guid-db2a5caf-c1e3-7817-d0bb-7184eb94f52e&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;﻿&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;img height=&quot;479px;&quot; src=&quot;https://lh6.googleusercontent.com/ol8eqG2vymKdy-zX8PUOB3Op7xiYSCXBV6HTrTao-jvx1f_kgABxEv7CAu14eLXlvxt4l6VZOrIMR6EZdGBmWaYkP-wHi3tJubMEMmQ63aJhnkQG-Rw2gqILgzdr91JBwTzfes4&quot; style=&quot;-webkit-transform: rotate(0.00rad); border: none; transform: rotate(0.00rad);&quot; width=&quot;638px;&quot; /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Source: &lt;/span&gt;&lt;a href=&quot;https://youtu.be/RlfLCWKxHJ0&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: #1155cc; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline;&quot;&gt;https://youtu.be/RlfLCWKxHJ0&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Clean Code is maintainable&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Source code must be:&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;1) Readable&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;2) Extensible&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;3) Testable&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;We are going to stress on the most neglected of these attributes.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;To test a method:&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;1) we need to instantiate an object (system under test) and all the helpers(mock providers, stubs) etc.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;line-height: 1.38;&quot;&gt;but it turns out that we put lot of code in constructor which makes it very difficult for create object of it.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Suppose we have a pest call in our constructor. Now while testing, we actually have to make a pest call for instantiation process.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Story{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;public function&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; __construct() {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;$pestObj = new Pest();&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;$this-&amp;gt;content = $pestObj-&amp;gt;get(&#39;&lt;/span&gt;&lt;a href=&quot;http://www.getstory.com/&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: #1155cc; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline;&quot;&gt;http://www.getStory.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&#39;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;But instead of this, if I ask for what I need :&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; Story{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;public function&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; __construct($pestObj) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;$this-&amp;gt;content = $pestObj-&amp;gt;get(&#39;&lt;/span&gt;&lt;a href=&quot;http://www.getstory.com/&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: #1155cc; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline;&quot;&gt;http://www.getStory.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;’);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;What I can do now is, while testing, I can mock get method of &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;$pestObj&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; and we wont actually have to make get request.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Now everything looks alright but look at this for a moment:&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;1) Story knows about a pest client and makes a GET request just for its content.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;How about this:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: inherit; font-weight: bold; line-height: 1.38; vertical-align: baseline;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: black; font-family: inherit; line-height: 1.38; vertical-align: baseline;&quot;&gt; Story{&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;public function __construct($text) {&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-left: 72pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;$this-&amp;gt;content = $text;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;and&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; StoryStore{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;public function&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; __construct($pestObj) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;$this-&amp;gt;pest = $pestObj;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;public function&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; getStory(){&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;return new Story($pest-&amp;gt;get(&#39;&lt;/span&gt;&lt;a href=&quot;http://www.getstory.com/&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: #1155cc; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline;&quot;&gt;http://www.getStory.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&#39;));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;This helps because tests are about instantiating small portions of application and run them and assert some output.&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;And if it is difficult to instantiate an object its not just going to be difficult to test that object but also other parts that need that object.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Its a kind of &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;transitive&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; problem.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;1) So test case has to successfully navigate the constructor each time the object is needed.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;SO constructor ideally should be very simple. Just simple assignments and we are good to go.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit; font-weight: bold; line-height: 1.38;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; font-weight: bold; line-height: 1.38;&quot;&gt;Service Locator (context, service container):&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;In this system we pass the responsibility of creating very hard to instantiate objects to service locator and then in code we pass this service locator around.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: inherit; font-weight: bold; line-height: 1.38; vertical-align: baseline;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: black; font-family: inherit; line-height: 1.38; vertical-align: baseline;&quot;&gt; MyController extends Symfony\Bundle\FrameworkBundle\Controller\Controller&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;public function&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; testAction()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;$this-&amp;gt;get(&#39;my_service&#39;)-&amp;gt;func();&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;and Symfony Controller does implement &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;ContainerAwareInterface&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;, and has a service locator role.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit; font-weight: bold; line-height: 1.38;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; font-weight: bold; line-height: 1.38;&quot;&gt;But the problem with service locators is that they encourage the APIs that lie.&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;You can&#39;t tell from looking at the definition of a class what its dependencies are because they aren&#39;t being injected,&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;instead they are being yanked out of the service locator&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Now we need to test a class that only says I need a service locator.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;But we have no idea what all we need to make the test run. we have to see the source code.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;what all are needed to run the class or see where it crashes and what needs to be over ridden.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: black; font-family: inherit; line-height: 1.38; vertical-align: baseline;&quot;&gt;and most of all it violates the &lt;/span&gt;&lt;span style=&quot;color: black; font-family: inherit; font-weight: bold; line-height: 1.38; vertical-align: baseline;&quot;&gt;law of demeter&lt;/span&gt;&lt;span style=&quot;color: black; font-family: inherit; line-height: 1.38; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;Law of Demeter also known as principle of least knowledge is a coding principle, which says that a module should not know about the inner details of the objects it manipulates.&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;If a code depends upon internal details of a particular object, there is good chance that it will break as soon as internal of that object changes.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;(Always ask for the things/references you need instead of searching for those references.)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;According to Law of Demeter, a method M of object O should only call following types of methods :&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit; font-weight: bold; line-height: 1.38;&quot;&gt;Methods of Object O itself&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Methods of Object passed as an argument&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Method of object, which is held in instance variable&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Any Object which is CREATED locally in method M&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;More importantly method should not invoke methods on objects that are returned by any subsequent method calls specified above&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;and as &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Clean Code&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; says &quot;talk to friends, not to strangers&quot;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;-&amp;gt; Only Ask for objects you DIRECTLY need to operate on.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;-&amp;gt; $a-&amp;gt;getX()-&amp;gt;getY() is a no no&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;-&amp;gt; $serviceLocator-&amp;gt;getService() breaks law of demeter&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;-&amp;gt;Dependency Injection of specific objects we need.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Also if we want to reuse the class that require service locator then we have to supply client with all the compile time dependencies which include service locator.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;But service locator contains many other services and dependencies.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;So here we have a problem, in order to give a class we need to give service locator and in order to give service locator we need to give most part of our application.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;Breaking the Law of Demeter is Like Looking for a Needle in the Haystack&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: inherit; font-weight: bold; line-height: 1.38; vertical-align: baseline;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: inherit; font-weight: bold; line-height: 1.38; vertical-align: baseline;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black; font-family: inherit; line-height: 1.38; vertical-align: baseline;&quot;&gt; class XMLUtils {&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;public function&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; getFirstBookCategoryFromXML(XMLMessage $xml) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;return $xml-&amp;gt;getXML()-&amp;gt;getBooks()-&amp;gt;getBookArrary(0)-&amp;gt;getBookCategory();&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-indent: 36pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;This code is now dependent upon lot of classes e.g.&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;XMLMessage&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;XML&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Book&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;BookCategory&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Which means this function knows about XMLMessage, XML, Book and BookCategory.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;It knows that XML has list of Book, which in-turn has BookCategory, that&#39;s a lot of information.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;If any of the intermediate class or accessor method in this chained method call changes, then this code will break.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Its an understanding between you and code how to traverse the haystack and get the thing you need.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;All the things in between are irrelevant all u need is the book Category&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Fundamentally this is what&#39;s wrong with service locator, asking for things we don’t directly need but retrieving the needed from it.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;In summary, abandon the use of new operator.&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;-&amp;gt; new operator ideally should either be inside factory or in tests.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;But in some cases it is perfectly OK like instantiating a HashMap(), a collection . No need to ask for it in the constructor.&lt;/span&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;This is because they are the leaves in your application graph. There is nothing behind these. Its the end of the road.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;But for services, objects that need collaboration, those need to ask for their dependencies.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Construction should be done either by DI container (symfony container), or builders or factories.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Any kind of indirections we introduce in the code makes it very hard for writing tests.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;This cost becomes double the cost if this is done in constructor. As now it has to be shared by lots and lots of the tests that use that specific object.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Writing Testable Code&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;﻿&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: italic; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Flaw #1: Constructor does Real Work&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Warning Signs&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;new keyword in a constructor or at field declaration&lt;/span&gt;&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Static method calls in a constructor or at field declaration&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Anything more than field assignment in constructors&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Object not fully initialized after the constructor finishes (watch out for initialize methods)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Control flow (conditional or looping logic) in a constructor&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Code &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;does complex object graph construction inside a constructor rather than using a factory or builder.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Adding or using an initialization block&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: italic; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Flaw #2: Digging into Collaborators&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Warning Signs -&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Objects are passed in but never used directly (only used to get access to other objects)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Law of Demeter violation: method call chain walks an object graph with more than one dot (.) &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Suspicious &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;names: context, environment, principal, container, or manager&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: italic; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Flaw #3: Brittle Global State &amp;amp; Singletons&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt; Warning Signs&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Adding or using singletons&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Adding or using static fields or static methods&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Adding or using static initialization blocks&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Adding or using registries&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Adding or using service locators&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: italic; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Flaw #4: Class Does Too Much&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Warning Signs&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Summing up what the class does includes the word “and”&lt;/span&gt;&lt;span style=&quot;font-family: inherit; line-height: 1.38;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Class would be challenging for new team members to read and quickly “get it”&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Class has fields that are only used in some methods&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;Class has static methods that only operate on parameters&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit; font-weight: bold; line-height: 1.38;&quot;&gt;So now we know how to write UN TESTABLE code and wreck havoc on person writing UTs:&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;﻿&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Make Your Own Dependencies&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – Instantiate objects using new in the middle of methods, don’t pass the object in.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Heavy Duty Constructors&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – Make constructors that do lots of work in them.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Depend on Concrete Classes&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – Tie things down to concrete classes – to avoid interfaces wherever possible.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Conditional Slalom&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – Always, always, feel good when writing lengthy if branches and switch statements. These increase the number of possible execution paths that tests will need to cover when exercising the code under test.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;﻿&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Depend on Large Context Objects&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – Pass around ginormous context objects (or small ones with hard to construct contents).&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;﻿&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Use Statics&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – Statics, statics everywhere!&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;﻿&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Use More Statics&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – Statics are a really powerful tool to bring TDD Infected engineers to their knees. Static methods can’t be overridden in a subclass (sometimes subclassing a class and overriding methods is a technique for testing). When you use static methods, they can’t be mocked using mocking libraries&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;﻿&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Use Global Flags&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – Why call a method explicitly? Just like using flag to set a flag in one part of your code, in order to cause an effect in a totally different part of your application&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;﻿&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Use Singletons Everywhere&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – Why pass in a dependency and make it obvious when you can use a singleton?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;﻿&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Look for Everything You Need&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – By Looking for things you are asserting your objects dominance as the object which knows where everything is. This will make the life of tester hard, since he will have to mimic the environment so that your code can get a hold of what it needs.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li dir=&quot;ltr&quot; style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; list-style-type: decimal; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;Utils, Utils, Utils!&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt; – Code smell? No way – code perfume! Litter about as many util and helper classes as you wish. These folks are helpful, and when you stick them off somewhere, someone else can use them too. That’s code reuse, and good for everyone, right? Be forewarned, the OO-police will say that functionality belongs in some object, as that object’s responsibility.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;&quot;&gt;References:&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;1) https://youtu.be/RlfLCWKxHJ0&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;2) http://en.wikipedia.org/wiki/Law_of_Demeter&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;3) http://www.slideshare.net/theojungeblut/2013-106-clean-code-part-i-design-patterns&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;4) http://nschoenmaker.nl/2013/11/defining-symfony-2-controllers-in-two-ways/&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; font-family: inherit; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;&quot;&gt;5) http://misko.hevery.com/2008/07/24/how-to-write-3v1l-untestable-code/&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://linux4genext.blogspot.com/feeds/5424975173402966367/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1681547402308503342/5424975173402966367' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/5424975173402966367'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/5424975173402966367'/><link rel='alternate' type='text/html' href='http://linux4genext.blogspot.com/2015/04/the-clean-code-talks-dont-look-for.html' title='The Clean Code Talks - Don&#39;t Look For Things! '/><author><name>Bharat Verma</name><uri>http://www.blogger.com/profile/12817316332686822982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh6.googleusercontent.com/ol8eqG2vymKdy-zX8PUOB3Op7xiYSCXBV6HTrTao-jvx1f_kgABxEv7CAu14eLXlvxt4l6VZOrIMR6EZdGBmWaYkP-wHi3tJubMEMmQ63aJhnkQG-Rw2gqILgzdr91JBwTzfes4=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1681547402308503342.post-8997916959598430130</id><published>2013-09-20T12:45:00.001+05:30</published><updated>2013-09-22T14:16:27.671+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="data"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="optimize"/><category scheme="http://www.blogger.com/atom/ns#" term="oracle"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="rows"/><category scheme="http://www.blogger.com/atom/ns#" term="size"/><category scheme="http://www.blogger.com/atom/ns#" term="sql"/><category scheme="http://www.blogger.com/atom/ns#" term="table"/><title type='text'>Table size and problem of unused table space after row deletion in MySQL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Finally got some time to give some useful advice for all developers dealing with MySQL.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Problem Scenario -&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
I had a table with schema like this -&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;http://pastie.org/8345883.js&quot;&gt;
&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I deleted some 1.2 lac records on the basis of date and when I retrieved the table size using this query I got exactly the same size of table before deleting.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;http://pastie.org/8345862.js&quot;&gt;
&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;After removing the &#39;DATA_FREE&#39; from the same.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;http://pastie.org/8345868.js&quot;&gt;
&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;There I came to pause and ponder that why the free space is still unusable ?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;Reason -&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&#39;DELETE&#39; invalidates the record and size of the records used to occupy data. it may be reused later. This problem is quite similar to de-fragmentation of disk drive in windows to improved the disk efficiency.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Also, this scenario is common with the tables using variable length rows having column types like &#39;VARCHAR&#39;, &#39;TEXT&#39;, &#39;BLOB&#39;, &#39;TEXT&#39;, &#39;VARBINARY&#39;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Solution -&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Meanwhile this cannot be stated as a problem cause according to MySQL guys - &quot;Deleted rows are maintained in a linked list and subsequent INSERT operations reuse old row positions&quot;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
However if you want to get that space now for peace of mind and soul, so you can run &#39;OPTIMIZE&#39; on the table like -&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;http://pastie.org/8345847.js&quot;&gt;
&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
Remember &#39;OPTMIZE&#39; works only on &#39;MyISAM&#39; and &#39;InnoDB&#39; engines. So this can be done in manner when ever you deleting the records from the table either manually or by CRON job place one more query to get this done.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Addon -&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Posting the query to get the size of all the tables with sorting on the basis of size with exact data and after removing data free.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;script src=&quot;http://pastie.org/8345850.js&quot;&gt;
&lt;/script&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Thanks and will be posting more ...&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://linux4genext.blogspot.com/feeds/8997916959598430130/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1681547402308503342/8997916959598430130' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/8997916959598430130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/8997916959598430130'/><link rel='alternate' type='text/html' href='http://linux4genext.blogspot.com/2013/09/table-size-and-problem-of-unused-table.html' title='Table size and problem of unused table space after row deletion in MySQL'/><author><name>Bharat Verma</name><uri>http://www.blogger.com/profile/12817316332686822982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>India</georss:featurename><georss:point>28.613459424004414 77.2283935546875</georss:point><georss:box>28.167536924004416 76.5829465546875 29.059381924004413 77.8738405546875</georss:box></entry><entry><id>tag:blogger.com,1999:blog-1681547402308503342.post-9111893109932797823</id><published>2012-03-23T12:57:00.000+05:30</published><updated>2012-05-25T21:39:04.602+05:30</updated><title type='text'>Installing node.js on Ubuntu 11.10 or Ubuntu 12.04</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

 &lt;title&gt;&lt;/title&gt;
 
 
 
 
 
 
 
 
 
 
 
 &lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 1in }
  P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }
  A:link { color: #0000ff; so-language: zxx }
 --&gt;
 
&lt;/style&gt;


&lt;br /&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;font-family: Georgia,serif;&quot;&gt;&lt;u&gt;N&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;http://nodejs.org/&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;font-family: Georgia,serif;&quot;&gt;&lt;u&gt;ode.js&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Georgia,serif; font-size: small;&quot;&gt;&amp;nbsp;-
A server side JavaScript framework highly scalable works on the back
of the giant beast V8 JavaScript Engine from Google.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Georgia,serif; font-size: small;&quot;&gt;Always
favor to do some compiling to get the best -&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-family: Georgia,serif; font-size: small;&quot;&gt;1.)
Download the latest from node.js website -&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 100%; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;bharat@ProBook:~/node/node-v0.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;13&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;$
wget &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #804040; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;&lt;b&gt;&quot;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;a href=&quot;http://nodejs.org/dist/v0.6.13/node-v0.6.13.tar.gz&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;http://nodejs.org/dist/v0.6.13/node-v0.6.13.tar.gz&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=&quot;color: #804040; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;&lt;b&gt;&quot;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Georgia,serif;&quot;&gt;2.)
Dependencies to be resolved first -&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;bharat@ProBook:~/node/node-v0.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;13&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;$
sudo apt-get install g++ curl libssl-dev apache2-utils&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Georgia,serif;&quot;&gt;3.)
Unzip the downloaded item –&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;tar
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: slateblue; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;-xvf&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;
node-v0.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;13&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;.tar.gz&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Georgia,serif;&quot;&gt;4.)
Final installation -&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;bharat@ProBook:~/node/$
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #804040; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;&lt;b&gt;cd&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;
node-v0.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;13&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;bharat@ProBook:~/node/node-v0.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;13&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;$
./configure&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;bharat@ProBook:~/node/node-v0.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;13&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;$
make&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;bharat@ProBook:~/node/node-v0.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: magenta; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;13&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas,serif;&quot;&gt;$
sudo make install&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(255, 255, 255); line-height: 0.19in; margin-bottom: 0in;&quot;&gt;
&lt;span style=&quot;color: black; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Georgia,serif;&quot;&gt;and
its done here.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://linux4genext.blogspot.com/feeds/9111893109932797823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1681547402308503342/9111893109932797823' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/9111893109932797823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/9111893109932797823'/><link rel='alternate' type='text/html' href='http://linux4genext.blogspot.com/2012/03/installing-nodejs-on-ubuntu-1110-or.html' title='Installing node.js on Ubuntu 11.10 or Ubuntu 12.04'/><author><name>Bharat Verma</name><uri>http://www.blogger.com/profile/12817316332686822982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1681547402308503342.post-8870512079135072452</id><published>2011-11-08T18:00:00.000+05:30</published><updated>2013-10-02T17:36:41.073+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="core java"/><category scheme="http://www.blogger.com/atom/ns#" term="interview"/><category scheme="http://www.blogger.com/atom/ns#" term="j2ee"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="questions"/><category scheme="http://www.blogger.com/atom/ns#" term="source code"/><category scheme="http://www.blogger.com/atom/ns#" term="technology"/><title type='text'>Java Interview Questions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
pre { font-family: consolas; color: #000000; background-color: #ffffff; }
.Comment { color: #0000ff; }
.Constant { color: #ff00ff; }
.Type { color: #2e8b57; font-weight: bold; }
.Statement { color: #804040; font-weight: bold; }
.Identifier { color: #008080; }
&lt;/style&gt;

--&amp;gt;
This is one of the important post that I decided to give it to you all, it contains most of the questions asked (worth asking) to me in various technical job interviews. This is not a one time post, I will be regularly updating it like any other wiki page, so you might encounter some new questions and facts once you come back again.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;[Q-01] What are the use of static variables also state the ways how it is different from a constant ?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;[A-01] &lt;/b&gt;Static variables are class variables, as local variables cannot be declared as static. In most of the cases &#39;static&#39; is accompanied by &#39;final&#39; as by definition it should be used as CONSTANTS, some very special cases includes the statistics-gathering for that class where non-final-static member variables are used to deal with rare and specific conditions like counting the number of instances created.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
&lt;b&gt;[Q-02] Give the code for singleton pattern implementation, also take care of multi-threaded environment.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;[A-02] &lt;/b&gt;The code are given below for the same:&lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;class&lt;/span&gt; Singleton
{
   &lt;span class=&quot;Type&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;static&lt;/span&gt; Singleton singleInstance = &lt;span class=&quot;Constant&quot;&gt;null&lt;/span&gt;;

   &lt;span class=&quot;Type&quot;&gt;private&lt;/span&gt; Singleton()
   {
      &lt;span class=&quot;Comment&quot;&gt;// Exists only to defeat instantiation.&lt;/span&gt;
   }
   &lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;static&lt;/span&gt; Singleton getSingleInstance()
   {
      &lt;span class=&quot;Statement&quot;&gt;if&lt;/span&gt;(singleInstance == &lt;span class=&quot;Constant&quot;&gt;null&lt;/span&gt;)
      {
              synchronised (Singleton&lt;span class=&quot;Type&quot;&gt; class&lt;/span&gt;)
              {
                      &lt;span class=&quot;Statement&quot;&gt;if&lt;/span&gt;(singleInstance == &lt;span class=&quot;Constant&quot;&gt;null&lt;/span&gt;)
                      {
                             singleInstance = &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Singleton();
                      }
              }

      }
      &lt;span class=&quot;Statement&quot;&gt;return&lt;/span&gt; singleInstance;
   }
}

&lt;/pre&gt;
&lt;b&gt;&amp;nbsp;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-03] What are the two methods that every object class overrides ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;[A-03] &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;&#39;hashcode()&#39; and &#39;equals()&#39; are the methods which overrides object class.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-04] What property will a Class and a Method acquires when subjected to association with the &#39;final&#39; keyword ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;[A-04] &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;A final Class cannot be subclasses or extended while a final method cannot be overridden, in case of final member variable it is counted as constant.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-05] How many types of exceptions do we have in java, what are the differences between them?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;[A-05]&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here we have following types of exceptions: &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;dl&gt;
&lt;dt style=&quot;color: #cc0000;&quot;&gt;Checked Exceptions&lt;/dt&gt;
&lt;dd&gt;Environmental error that cannot necessarily be detected by testing; e.g.
 disk full, broken socket, database unavailable, etc.
&lt;/dd&gt;
&lt;dt style=&quot;color: #cc0000;&quot;&gt;Errors&lt;/dt&gt;
&lt;dd&gt;Virtual machine error: class not found, out of memory, 
no such method, illegal access to private field, etc.
&lt;/dd&gt;
&lt;dt style=&quot;color: #cc0000;&quot;&gt;Run-time Exceptions&lt;/dt&gt;
&lt;dd&gt;Programming errors that should be detected in testing:
index out of bounds, null pointer, illegal argument, etc. 
&lt;/dd&gt;&lt;/dl&gt;
Checked exceptions must be handled at compile time. Run-time
exceptions do not need to be. Errors often cannot be. 
&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-06] Can we stop the execution of finally block in exception handling ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;[A-06] &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Generally a finally block is something meant to be executed irrespective of the occurrences of the exceptions, but however it can be by passed if we irreversibly terminate the execution of the program like this - System.exit(1);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-07] Discuss multiple inheritance in java ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;[A-07] &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;Some object oriented languages, allow a class to
inherit from more than one unrelated class. This is called multiple
inheritance which java eventually does not supports and is different from the multi-level inheritance in
this section. Most of the things that can be accomplished via
multiple inheritance can be handled by interfaces in Java.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-08] Why java cannot have multiple inheritance ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;[A-08] &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The simple answer to the big question is that it will add too much complexity with a very little benefit, in terms of literal basics, we can say that &quot;Classes&quot; in java represents &quot;Noun&quot;, whereas &quot;interfaces&quot; represents &quot;adjectives&quot;. A child cannot have more than one father, but they can have multiple behaviors (interfaces). A specific problem is associated when we used multiple inherited classes object which is known as &quot;&lt;a href=&quot;http://en.wikipedia.org/wiki/Diamond_problem&quot;&gt;Double Diamond Inheritance Problem&lt;/a&gt;&quot;.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The following example explains more about it...&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Type&quot;&gt;class&lt;/span&gt; Base {
    &lt;span class=&quot;Type&quot;&gt;protected&lt;/span&gt; String text;
}
&lt;span class=&quot;Type&quot;&gt;class&lt;/span&gt; SuperOne &lt;span class=&quot;Type&quot;&gt;extends&lt;/span&gt; Base {
    &lt;span class=&quot;Type&quot;&gt;protected&lt;/span&gt; SuperOne() {
        &lt;span class=&quot;Type&quot;&gt;super&lt;/span&gt;(&lt;span class=&quot;Constant&quot;&gt;&quot;one&quot;&lt;/span&gt;);
    }
}
&lt;span class=&quot;Type&quot;&gt;class&lt;/span&gt; SuperTwo &lt;span class=&quot;Type&quot;&gt;extends&lt;/span&gt; Base {
    &lt;span class=&quot;Type&quot;&gt;protected&lt;/span&gt; SuperTwo() {
        &lt;span class=&quot;Type&quot;&gt;super&lt;/span&gt;(&lt;span class=&quot;Constant&quot;&gt;&quot;two&quot;&lt;/span&gt;);
    }
}
&lt;span class=&quot;Comment&quot;&gt;// Impossible multiple inheritance class; just to explain the problem&lt;/span&gt;
&lt;span class=&quot;Type&quot;&gt;class&lt;/span&gt; Derived &lt;span class=&quot;Type&quot;&gt;extends&lt;/span&gt; SuperOne, SuperTwo {
    &lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;void&lt;/span&gt; printText() {
        System.out.println(text);
    }
}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
What would you expect that the method printText() prints? Should it print &quot;one&quot; or &quot;two&quot;? Are there two instances of class Base that are part of the instance of class Derived?
You don&#39;t have this problem with multiple interface inheritance, because an interface does not contain data.
Multiple interface inheritance is something completely different from multiple class inheritance, and I don&#39;t see any big problems with multiple interface inheritance.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-08] What is JVM memory types ? &lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;[A-08] &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Java has two types of memory when we talk about JVM, that is Heap Memory and Non Heap Memory.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
# Heap Memory&amp;nbsp;&lt;/div&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Its a shared memory where multiple threads share the same data, class instances and arrays are stored in heap memory.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
# Non-Heap Memory&lt;/div&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; It comprises of ‘Method Area’ and other memory required for internal processing. So here the major player is ‘Method Area’. As given in the last line, method area is part of non-heap memory. It
 stores per-class structures, code for methods and constructors. 
Per-class structure means runtime constants and static fields.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgryZQHDeC5UhxQTLWC3mdSyCtY4wQxIdMssoXU5VKMFKr37ZGB8wsFKtl04g0J_8Ml3fQVWeVNTZWqJ9VmKJfclEeDpfXJDwd2Bmya5JpIPS3eN1CT8BvEfVH_U9TrQuldY4PKMJSCFKjm/s1600/jvm-memory.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgryZQHDeC5UhxQTLWC3mdSyCtY4wQxIdMssoXU5VKMFKr37ZGB8wsFKtl04g0J_8Ml3fQVWeVNTZWqJ9VmKJfclEeDpfXJDwd2Bmya5JpIPS3eN1CT8BvEfVH_U9TrQuldY4PKMJSCFKjm/s320/jvm-memory.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-09] Explain the significance of &#39;this&#39; keyword in java programming ? &lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;[A-09] &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&#39;this&#39; refers to the current instance of the method in which it is used. The following are the scenarios which uses &#39;this&#39; keyword in java programming -&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
# 1&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; - To specifically differentiate between instance variable to arguments or other local variables.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;&lt;span class=&quot;Type&quot;&gt;protected&lt;/span&gt; String _userName;

&lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;void&lt;/span&gt; setUserName(String _userName)
{
        &lt;span class=&quot;Type&quot;&gt;this&lt;/span&gt;._userName = _userName; &lt;span class=&quot;Comment&quot;&gt;//extensively used in case of writing getters/setters&lt;/span&gt;
}
&lt;/pre&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
# 2&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; - To pass the current java instance as parameter.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;obj.someMethod(&lt;span class=&quot;Type&quot;&gt;this&lt;/span&gt;);
&lt;/pre&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
# 3&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; - To return the current java instance.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;ClassName someMethod() {
        &lt;span class=&quot;Statement&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;this&lt;/span&gt;;
}
&lt;/pre&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Note: Should be used carefully while dealing with inner class context, which returns inner class instance rather than outer class.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/span&gt;

&lt;br /&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
# 4&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; - To get the handle of current class.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;Class SampleClass = &lt;span class=&quot;Type&quot;&gt;this&lt;/span&gt;.getClass(); &lt;span class=&quot;Comment&quot;&gt;// this methodology is preferable in java&lt;/span&gt;
&lt;/pre&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Though this can be done by, Class className = ABC.class; // here ABC refers to the class name and you need to know that!&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;As always, java this is associated with its instance and this will not work in static methods.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-10] Elaborate the association of keyword &#39;static&#39; in java programming ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;[A-10] &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Lets take it as in term of parts starting from -&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
# static variables&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;variable that belongs to a class not to an object or instance.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;They are initialized only once at the very beginning, these are initialized first before any instance variable.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;A single copy to be shared by all the instances.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;It can be accessed directly by class name without any need for creation of instances.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
#static methods&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;method that belongs to class not to an object or instance.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;It can only access static data, cannot use instance variables.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;It can only call static methods not any instance method.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;It can be called using class name no need for object creation.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;It cannot refer to &#39;this&#39; or &#39;super&#39; keywords in anyway.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;It can be shadowed by another static method in a subclass, as long as original method is not declared as final.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;A static method cannot be overridden by a non-static method (instance method).&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Static method is implicitly final in nature.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;A main method is always static in nature because it must be accessible for an application to run, before any instantiation should take place.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #cc0000;&quot;&gt;
# static block&lt;/div&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The static block, is a block of statement inside a Java class that will be executed when a class is first loaded in to the JVM. A static block helps to initialize the static data members, just like constructors help to initialize instance members&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-11]&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;Why Strings are immutable (Objects) ?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;[A-11]&amp;nbsp;- &lt;/b&gt;First of lets understand what the term immutable stands for. In generic terminology immutable objects are the ones whose every modification creates a new String (Object)or more over an immutable object is something whose state cannot be modified when after it has been created.&lt;br /&gt;
&lt;br /&gt;
- &lt;b&gt;Referenced Variables&lt;/b&gt; - In a string pool facility a same string can be referenced through many “referenced variables” for example “&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;sampleStr&lt;/span&gt;” can be denoted by two String objects &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Str1=”sampleStr”;&lt;/span&gt; and &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Str2 = “sampleStr”; &lt;/span&gt;&amp;nbsp;in case of mutable scenario changes in &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;sampleStr&lt;/span&gt; for &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Str1&lt;/span&gt; will be reflected everywhere which is not required.&lt;br /&gt;
&lt;br /&gt;
- &lt;b&gt;Security Threat &lt;/b&gt;- Strings are passed as the parameters for various secure methods if make it mutable then anyone can gain access or modify it, that leads to serious vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
- &lt;b&gt;Sync issues &lt;/b&gt;- immutability offers safe handling of strings in multi-threaded environments, needn’t to synchronize the string operations externally.&lt;br /&gt;
&lt;br /&gt;
- &lt;b&gt;Caching hashcode&lt;/b&gt; - &amp;nbsp;Being immutable Strings caches its hashcode and don’t re-calculate them again and again making it fast and usable as hashmap key, thus guarantees hashcode to be same on multiple occurences.&lt;br /&gt;
&lt;br /&gt;
- &lt;b&gt;Class Loading&lt;/b&gt; - &amp;nbsp;Strings is used by class loading mechanism and have profound and fundamental aspects of security with it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-12]&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;Why Char arrays are preferred over Strings for storing passwords?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;[A-12]&amp;nbsp;&lt;/b&gt;-&amp;nbsp;Since strings are immutable they might be present in string pool till garbage collector truncates them, thats why the probability of their reuse by someone who have access to memory dump (as if the password is stored in plain text). java itself recommends the same. printing of plain text on consoles and logs is pretty high as in case of char array only memory location gets printed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-13]&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;What is the difference between String Builder and String Buffer classes ?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;[A-13]&amp;nbsp;&lt;/b&gt;-&amp;nbsp;String Buffer’s all public methods are synchronized which make it thread-safe but at the same time slow. String Builder is not synchronized thus fast, else everything is nearly same. These are the used to get rid of String class immutable problem which overwhelms the memory heap on various operations over string.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-14]&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;Why use of == comparison operator in comparing Strings are discouraged ?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;[A-14]&amp;nbsp;&lt;/b&gt;-&amp;nbsp;Because ‘==’ just check the if the compared reference variables points towards the same string in the java heap (reference equality) and since strings are immutable thats why it gives sense to the fact that two string literals in the string pool set refer same string object which gives sense that ‘==’ comparison is almost wrong way to do this.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-15]&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;Significance of Runnable interface ?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;[A-15]&amp;nbsp;&lt;/b&gt;-&amp;nbsp;Implementing runnable interface is one of the ways to create java thread, public void run() is the only method that needs to be overridden for the same.&lt;br /&gt;
- Runnable provides the means for the class to be active while not sub-classing it.&lt;br /&gt;
- Runnable should be used by any class whose instances are intented to be used by a thread.&lt;br /&gt;
- Runnable interface should be used when you are planning to override the run() method not any other Thread Class method.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;[Q-16]&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;What is an Adapter Class ?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;[A-16]&amp;nbsp;&lt;/b&gt;- &amp;nbsp;Adapter Class is normal class that acts as an Adapter between the Interface and the Class implementing it, such as it only contains empty implementations of all the interface methods.&lt;br /&gt;
Benefit - Concrete class using adapter class needn&#39;t to implement all the methods unlike implementing the interface. Thus reducing code length and code complexity.&lt;br /&gt;
Example - Generic Servlet acts as adapter class for Servlet Interface.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://linux4genext.blogspot.com/feeds/8870512079135072452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1681547402308503342/8870512079135072452' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/8870512079135072452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/8870512079135072452'/><link rel='alternate' type='text/html' href='http://linux4genext.blogspot.com/2011/11/java-interview-questions.html' title='Java Interview Questions'/><author><name>Bharat Verma</name><uri>http://www.blogger.com/profile/12817316332686822982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgryZQHDeC5UhxQTLWC3mdSyCtY4wQxIdMssoXU5VKMFKr37ZGB8wsFKtl04g0J_8Ml3fQVWeVNTZWqJ9VmKJfclEeDpfXJDwd2Bmya5JpIPS3eN1CT8BvEfVH_U9TrQuldY4PKMJSCFKjm/s72-c/jvm-memory.jpg" height="72" width="72"/><thr:total>1</thr:total><georss:featurename>Capt Shashi Kant Sharma Marg, Sector 37, NOIDA, Uttar Pradesh, India</georss:featurename><georss:point>28.5710418 77.3499811</georss:point><georss:box>0.886500299999998 36.920293599999994 56.2555833 117.7796686</georss:box></entry><entry><id>tag:blogger.com,1999:blog-1681547402308503342.post-8544424957915411510</id><published>2011-10-23T19:59:00.000+05:30</published><updated>2011-11-08T16:03:53.077+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="BIS 2011"/><category scheme="http://www.blogger.com/atom/ns#" term="Bureau of Indian Standards"/><category scheme="http://www.blogger.com/atom/ns#" term="Computer Engineering"/><category scheme="http://www.blogger.com/atom/ns#" term="India"/><category scheme="http://www.blogger.com/atom/ns#" term="scientist b"/><category scheme="http://www.blogger.com/atom/ns#" term="technology"/><title type='text'>BIS - Scientist &#39;B&#39; Written Exam Questions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Today &lt;b&gt;(Sunday Oct 23, 2011)&lt;/b&gt; I have given the exam of&lt;b&gt; Bureau of Indian Standards &lt;/b&gt;for the post of &lt;b&gt;Scientist - &#39;B&#39;.&lt;/b&gt;&lt;br /&gt;
Here are some of the questions which I remember from it:-&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Computer Engineering Section&lt;/b&gt; &lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;If a Non-Finite-Automata (NFA) has N states then what are the number of states will its minimized Definite-Finite-Automata will have ?&amp;nbsp;&lt;/li&gt;
&lt;li&gt;How many test cases of robustness are possible for the function with 2 variables?&lt;/li&gt;
&lt;li&gt;What is the probability that the divisor of 10^99 is the multiple of 10^96?&lt;/li&gt;
&lt;li&gt;How many substrings of 00 this automata will hold (0+1)*0(0+1)*0(0+1)* ?&lt;/li&gt;
&lt;li&gt; Solve T(1) = 1 and T(n) = 2 + (n-1) + n where n &amp;gt;= 2&amp;nbsp;&lt;/li&gt;
&lt;li&gt;A fair dice is rolled 360 times find out the range of probability of getting &#39;6&#39; on the face 70 times?&lt;/li&gt;
&lt;li&gt;What are the state of 2-SAT and 3-SAT problems are they NP-Complete ?&lt;/li&gt;
&lt;li&gt;A LAN is 2 Kilometers long and has the bandwidth of 10^7 and is using CSMA/CD the signals travels inside it with the speed of 2 X 10^8 mts/sec what it the minimum packet size ?&amp;nbsp;&lt;/li&gt;
&lt;li&gt;What is Ackerman&#39;s Function ?&lt;/li&gt;
&lt;li&gt;To solve the root of 13 and find the value after one iteration using Newton Raphson Method.&lt;/li&gt;
&lt;li&gt;What is the high level abstraction over Semaphore ?&lt;/li&gt;
&lt;li&gt;Using boolean rules simplify x&#39;y&#39; + xy +x&#39;y ?&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Solve finite integral - Integration [0, Pie/4] ( 1 - Tan X ) / (1 + Tan X) dx = 0.&lt;/li&gt;
&lt;li&gt;A 6 MHZ channel used by digital signaling system utilizing 4 level signals, what is the maximum possible transfer value ?&amp;nbsp;&lt;/li&gt;
&lt;li&gt;What is the value of i when i = (++i) / (i ++) ; with initial value of 5 ? &lt;/li&gt;
&lt;li&gt;An double dimensional integer array in &#39;C&#39; S[6][6] was filled like -&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for ( i = 0; i &amp;lt; 6; i++&amp;nbsp; )&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for ( j = 0; j &amp;lt; 6; j++) { s[i][j] == (i+j)%6; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; then what is the value for S [ S[5][3] ] [ S[1][3] ] = ? &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
All of the above questions gives you the glimpse of the paper and also signifies that it covers almost all the questions of computer engineering course, mainly the paper seen by me in this discipline is flooded with &lt;b&gt;Digital Systems questions on combination circuits , Signals and Systems, Binary conversions with 2&#39;s complement, LAN subnet questions max (8-9 questions), Data Structures questions from Binary tree, BST and AVL Tree with few questions on sorting also, Compiler based conceptual questions on Linkers and Loaders, algorithms with minimum spanning trees and shortest path methods, Operating Systems questions like reading disk, paging, addressing memory etc.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;General Knowledge, Reasoning and General English Section&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;When was Magna Carta signed in England ?&amp;nbsp;&lt;/li&gt;
&lt;li&gt;When is world health day celebrated ?&lt;/li&gt;
&lt;li&gt;Where will the summit of NAM in 2012 will held ?&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Which country is the largest producer of wheat?&lt;/li&gt;
&lt;li&gt;Which emperor built GT roads in India?&lt;/li&gt;
&lt;/ol&gt;
Question in these three sections were easy and requires a fair general knowledge to do the best, 10 questions were of English comprising of synonyms and antonyms checking sentences with errors and filling the appropriate words in the blanks. reasoning was like also easy with some positions and blood relations questions.&lt;br /&gt;
&lt;br /&gt;
Thats all folks, I hoped it may give you the fair idea about how to give the exam in future, if you are motivated towards it.&lt;br /&gt;
&lt;br /&gt;
Good Luck ... All the best&lt;br /&gt;
&lt;b style=&quot;color: #cc0000;&quot;&gt;- Bharat Verma&amp;nbsp; &lt;/b&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://linux4genext.blogspot.com/feeds/8544424957915411510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1681547402308503342/8544424957915411510' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/8544424957915411510'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/8544424957915411510'/><link rel='alternate' type='text/html' href='http://linux4genext.blogspot.com/2011/10/today-sunday-oct-23-2011-i-have-given.html' title='BIS - Scientist &#39;B&#39; Written Exam Questions'/><author><name>Bharat Verma</name><uri>http://www.blogger.com/profile/12817316332686822982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>New Delhi, Delhi, India</georss:featurename><georss:point>28.635308 77.22496</georss:point><georss:box>28.4123265 76.909103 28.858289499999998 77.54081699999999</georss:box></entry><entry><id>tag:blogger.com,1999:blog-1681547402308503342.post-7957595061681596641</id><published>2011-07-29T03:17:00.000+05:30</published><updated>2011-07-30T22:21:50.331+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="collections framework"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="sample arraylist implementation"/><category scheme="http://www.blogger.com/atom/ns#" term="sample hashtable implementation"/><category scheme="http://www.blogger.com/atom/ns#" term="sample linkedlist implementation"/><category scheme="http://www.blogger.com/atom/ns#" term="sample vector implementation"/><category scheme="http://www.blogger.com/atom/ns#" term="technology"/><title type='text'>Java Collections - A Relative Study</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;font-family: inherit; text-align: left;&quot;&gt;&lt;div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Collection &lt;/b&gt;refers to a group of multiple elements kept together to do a specific task of choice. A collection can be of same or different types as per the need but it could be relational. Collection is used to store, retrieve, manipulate and communicate aggregated data. Collections are used to ease our need of implementation of new data structure which has required functionality by reducing our programming effort and also reduces the complexity in terms of space and time by increasing the program speed and quality.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Core Collection Interfaces&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Collection &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; |  &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Set &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; |  &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; |  &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Queue &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; |  &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Map&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Collection&lt;/b&gt; - it is the basic root of the collection hierarchy. We doesn&#39;t have any direct implementation of this interface but there is more specific sub interfaces, such as &lt;i&gt;Set &lt;/i&gt;and &lt;i&gt;List&lt;/i&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Set&lt;/b&gt; - it cannot contains duplicate. It signifies the mathematical abstraction of set theory, like wise you can add the same element many times but you will see it only once when you iterates the collection. Implemented by &lt;i&gt;HashSet &lt;/i&gt;and &lt;i&gt;TreeSet&lt;/i&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;List &lt;/b&gt;- its a kind of sequence, a ordered collection. It can have duplicate elements. It is useful in the terms like positional access, search, iteration and range view. Implemented by &lt;i&gt;ArrayList &lt;/i&gt;and &lt;i&gt;Linked List.&lt;/i&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Map&lt;/b&gt; -&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; color: black; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt; a object that maps keys to values.&amp;nbsp;A&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;Map&lt;/code&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;cannot contain duplicate keys; each key can map to at most one value. &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; color: black; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;It models the mathematical&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;i&gt;function&lt;/i&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;abstraction.&lt;span class=&quot;Apple-converted-space&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; color: black; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt; Implemented by &lt;i&gt;HashMap&lt;/i&gt;, &lt;i&gt;TreeMap &lt;/i&gt;and &lt;i&gt;LinkedHashMap&lt;/i&gt;.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; color: black; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-converted-space&quot;&gt;&lt;b&gt;Queue&lt;/b&gt; - is a special collection used to hold multiple elements prior to processing. Queue provides additional insertion, extraction and inspection operations. &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;/ul&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggz3r7ozr0DLz-aq42CVLy44OyL5DHSju8A9La5L4F0Ig4t-C-cmNcn4oxtZWu8Nwdc5vIGBOo0_othAeVORH4icUfb9PoGLEUh8Gt3q8P2je_qusiDGZbhJwMQIntVOPjD2Y6Cuwzdn22/s1600/java-collection.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;496&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggz3r7ozr0DLz-aq42CVLy44OyL5DHSju8A9La5L4F0Ig4t-C-cmNcn4oxtZWu8Nwdc5vIGBOo0_othAeVORH4icUfb9PoGLEUh8Gt3q8P2je_qusiDGZbhJwMQIntVOPjD2Y6Cuwzdn22/s640/java-collection.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Implementation of Collection Classes with source codes&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;1.) ArrayList&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt; - &lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Can expand automatically, access to any element O(1), insertions and deletions O(N), have methods for inserting, deleting and searching, can be traversed using foreach loop, iterators or indexes.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Code Snippet:&lt;/u&gt;&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
pre { font-family: consolas; color: #000000; background-color: #ffffff; }

.Statement { color: #804040; font-weight: bold; }
.Constant { color: #ff00ff; }
.Type { color: #2e8b57; font-weight: bold; }
.Special { color: #6a5acd; }
.Comment { color: #0000ff; }
.PreProc { color: #a020f0; }
--&gt;
&lt;/style&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;PreProc&quot;&gt;package&lt;/span&gt; questions;

&lt;span class=&quot;PreProc&quot;&gt;import&lt;/span&gt; java.util.*;
&lt;span class=&quot;Comment&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Comment&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;Special&quot;&gt;@author&lt;/span&gt;&lt;span class=&quot;Comment&quot;&gt; Bharat Verma&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt; */&lt;/span&gt;
&lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;class&lt;/span&gt; ArrayListDemo
{
        &lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;void&lt;/span&gt; printArrayList (ArrayList p_arraylist)
        {
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;------------------------------------------&quot;&lt;/span&gt;);
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;Content of ArrayList : &quot;&lt;/span&gt;+p_arraylist);
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;Size of ArrayList = &quot;&lt;/span&gt;+p_arraylist.size());
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;------------------------------------------&quot;&lt;/span&gt;);
        }
        &lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;void&lt;/span&gt; main(String[] args)
        {
                ArrayList&amp;lt;Object&amp;gt; sampleArrayList =&lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; ArrayList&amp;lt;Object&amp;gt;(); &lt;span class=&quot;Comment&quot;&gt;// you can specify the object type&lt;/span&gt;

                Integer intr = &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;729&lt;/span&gt;);
                String str =&lt;span class=&quot;Constant&quot;&gt;&quot;Bharat&quot;&lt;/span&gt;;
                &lt;span class=&quot;Type&quot;&gt;double&lt;/span&gt; dtr = &lt;span class=&quot;Constant&quot;&gt;169.721&lt;/span&gt;;

                printArrayList(sampleArrayList);

                sampleArrayList.add(intr);
                sampleArrayList.add(str);
                sampleArrayList.add(dtr);
                printArrayList(sampleArrayList);

                Integer i5=&lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;50&lt;/span&gt;);
                sampleArrayList.add(&lt;span class=&quot;Constant&quot;&gt;3&lt;/span&gt;, i5); &lt;span class=&quot;Comment&quot;&gt;// using add(int index, object obj)&lt;/span&gt;
                printArrayList(sampleArrayList);

                sampleArrayList.remove(&lt;span class=&quot;Constant&quot;&gt;3&lt;/span&gt;); &lt;span class=&quot;Comment&quot;&gt;// using remove()&lt;/span&gt;
                printArrayList(sampleArrayList);

                Object a=sampleArrayList.clone(); &lt;span class=&quot;Comment&quot;&gt;// using clone&lt;/span&gt;

                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;The clone is: &quot;&lt;/span&gt; + a);

                printArrayList(sampleArrayList);

                System.out.println(sampleArrayList.contains(&lt;span class=&quot;Constant&quot;&gt;&quot;Bharat&quot;&lt;/span&gt;)); &lt;span class=&quot;Comment&quot;&gt;// True as it contains&lt;/span&gt;

                &lt;span class=&quot;Comment&quot;&gt;// iteration using iterator&lt;/span&gt;
                Iterator iter = sampleArrayList.iterator();
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;Using Iterator&quot;&lt;/span&gt;);
                &lt;span class=&quot;Statement&quot;&gt;while&lt;/span&gt; (iter.hasNext())
                {
                        System.out.println(iter.next());
                }

                &lt;span class=&quot;Comment&quot;&gt;// using for loop and indexes &lt;/span&gt;
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;Using for loop and index&quot;&lt;/span&gt;);
                &lt;span class=&quot;Statement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;Type&quot;&gt;int&lt;/span&gt; i=&lt;span class=&quot;Constant&quot;&gt;0&lt;/span&gt;; i&amp;lt;sampleArrayList.size(); i++)
                {
                        System.out.println(sampleArrayList.get(i));
                }
        }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;2.) Vector &lt;/b&gt;- initially it was commonly used in place of arrays just because of their expansion property. The main difference between ArrayList and Vector is the synchronization, ArrayLists are fast as they are unsynchronized as compared to Vectors but less secure in multithreaded environment. Vector can hold objects but not primitive data types (for that wrapper classes is used which is immutable).&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Code Snippet:&lt;/u&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;PreProc&quot;&gt;package&lt;/span&gt; questions;
&lt;span class=&quot;PreProc&quot;&gt;import&lt;/span&gt; java.util.*;
&lt;span class=&quot;Comment&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Comment&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;Special&quot;&gt;@author&lt;/span&gt;&lt;span class=&quot;Comment&quot;&gt; Bharat Verma&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt; */&lt;/span&gt;
&lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;class&lt;/span&gt; VectorDemo
{
        &lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;void&lt;/span&gt; printVector (Vector p_vector)
        {
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;------------------------------------------&quot;&lt;/span&gt;);
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;Content of Vector : &quot;&lt;/span&gt;+p_vector);
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;Size of Vector = &quot;&lt;/span&gt;+p_vector.size());
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;------------------------------------------&quot;&lt;/span&gt;);
        }
        &lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;void&lt;/span&gt; main(String[] args)
        {
                Vector&amp;lt;Object&amp;gt; vector = &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Vector&amp;lt;Object&amp;gt;();
                &lt;span class=&quot;Type&quot;&gt;int&lt;/span&gt; primitiveType = &lt;span class=&quot;Constant&quot;&gt;10&lt;/span&gt;;
                Integer wrapperType = &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;20&lt;/span&gt;);
                String str = &lt;span class=&quot;Constant&quot;&gt;&quot;Bharat Verma&quot;&lt;/span&gt;;

                vector.add(primitiveType);
                vector.add(wrapperType);
                vector.add(str);
                vector.add(&lt;span class=&quot;Constant&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;30&lt;/span&gt;));

                printVector(vector);

                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;The elements at position 2 is: &quot;&lt;/span&gt;
                                + vector.elementAt(&lt;span class=&quot;Constant&quot;&gt;2&lt;/span&gt;));
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;The first element of vector is: &quot;&lt;/span&gt;
                                + vector.firstElement());
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;The last element of vector is: &quot;&lt;/span&gt;
                                + vector.lastElement());

                vector.removeElementAt(&lt;span class=&quot;Constant&quot;&gt;2&lt;/span&gt;);

                vector.add(&lt;span class=&quot;Constant&quot;&gt;1&lt;/span&gt; , &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;10&lt;/span&gt;));
                vector.add(&lt;span class=&quot;Constant&quot;&gt;3&lt;/span&gt; , &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;10&lt;/span&gt;));
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;The last index of 10 : &quot;&lt;/span&gt;
                                + vector.lastIndexOf(&lt;span class=&quot;Constant&quot;&gt;10&lt;/span&gt;));

                Enumeration e=vector.elements();
                printVector(vector);
                &lt;span class=&quot;Statement&quot;&gt;while&lt;/span&gt;(e.hasMoreElements())
                {
                        System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;The elements are: &quot;&lt;/span&gt; + e.nextElement());
                }
        }
}&amp;nbsp; &lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;3.) Linked List &lt;/b&gt;- it provides insertion of all the elements including NULL. It can be used for implementation of various other associated data structures like Arrays and Queues.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Code Snippet:&lt;/u&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;PreProc&quot;&gt;package&lt;/span&gt; questions;
&lt;span class=&quot;PreProc&quot;&gt;import&lt;/span&gt; java.util.*;
&lt;span class=&quot;Comment&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Comment&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;Special&quot;&gt;@author&lt;/span&gt;&lt;span class=&quot;Comment&quot;&gt; Bharat Verma&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt; */&lt;/span&gt;
&lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;class&lt;/span&gt; LinkedListDemo
{
        &lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;void&lt;/span&gt; printLinkedList (LinkedList p_ll)
        {
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;------------------------------------------&quot;&lt;/span&gt;);
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;Content of LinkedList : &quot;&lt;/span&gt;+p_ll);
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;Size of LinkedList = &quot;&lt;/span&gt;+p_ll.size());
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;------------------------------------------&quot;&lt;/span&gt;);
        }
        &lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;void&lt;/span&gt; main(String[] args)
        {
                LinkedList link=&lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; LinkedList();
                link.add(&lt;span class=&quot;Constant&quot;&gt;&quot;a&quot;&lt;/span&gt;);
                link.add(&lt;span class=&quot;Constant&quot;&gt;&quot;b&quot;&lt;/span&gt;);
                link.add(&lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;10&lt;/span&gt;));

                printLinkedList(link);

                link.offerFirst(&lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;20&lt;/span&gt;));
                printLinkedList(link);

                link.addLast(&lt;span class=&quot;Constant&quot;&gt;&quot;c&quot;&lt;/span&gt;);
                printLinkedList(link);

                link.add(&lt;span class=&quot;Constant&quot;&gt;2&lt;/span&gt;,&lt;span class=&quot;Constant&quot;&gt;&quot;j&quot;&lt;/span&gt;);
                printLinkedList(link);

                link.add(&lt;span class=&quot;Constant&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;Constant&quot;&gt;&quot;t&quot;&lt;/span&gt;);
                printLinkedList(link);
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;The Last element : &quot;&lt;/span&gt;+link.getLast());

                link.offerLast(&lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;123&lt;/span&gt;));
                printLinkedList(link);

                link.remove(&lt;span class=&quot;Constant&quot;&gt;3&lt;/span&gt;);
                printLinkedList(link);

                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&quot;The First element : &quot;&lt;/span&gt;+link.element());
        }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;4.) HashTable -&amp;nbsp; &lt;/b&gt;Hash table similar to HashMap but is synchronized and comes with its cost, only a single thread can accesss it.&lt;br /&gt;
Hash table does not allows NULL for either keys or values.&lt;br /&gt;
Just like Hashmap you can add same or different values to one key but it will be overwrite them and will store only last one.&lt;br /&gt;
Hash table stores only those objects which overrides the hashcode() and equals() methods defined by the Object Class.Fortunately many object comes with the built in implementation of it like String.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Code Snippet:&lt;/u&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;PreProc&quot;&gt;package&lt;/span&gt; collection;

&lt;span class=&quot;PreProc&quot;&gt;import&lt;/span&gt; java.util.Enumeration;
&lt;span class=&quot;PreProc&quot;&gt;import&lt;/span&gt; java.util.HashMap;
&lt;span class=&quot;PreProc&quot;&gt;import&lt;/span&gt; java.util.Hashtable;
&lt;span class=&quot;PreProc&quot;&gt;import&lt;/span&gt; java.util.Iterator;
&lt;span class=&quot;PreProc&quot;&gt;import&lt;/span&gt; java.util.Set;
&lt;span class=&quot;Comment&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Comment&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;Special&quot;&gt;@author&lt;/span&gt;&lt;span class=&quot;Comment&quot;&gt; Bharat Verma&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt; */&lt;/span&gt;
&lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;class&lt;/span&gt; HashTableDemo
{
        &lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;void&lt;/span&gt; printHashTable (Hashtable hashtable)
        {
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;Retrieving all keys from the Hashtable&amp;quot;&lt;/span&gt;);
                Enumeration e = hashtable.keys();

                &lt;span class=&quot;Statement&quot;&gt;while&lt;/span&gt;( e. hasMoreElements() )
                {
                        System.out.println(e.nextElement());
                }
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;Retrieving all values from the Hashtable&amp;quot;&lt;/span&gt;);

                e = hashtable.elements();

                &lt;span class=&quot;Statement&quot;&gt;while&lt;/span&gt;(e. hasMoreElements())
                {
                        System.out.println(e.nextElement());
                }
        }
        &lt;span class=&quot;Type&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;void&lt;/span&gt; main(String[] args)
        {
                &lt;span class=&quot;Comment&quot;&gt;// First Constructor&lt;/span&gt;
                Hashtable&amp;lt;String, Integer&amp;gt; hashtable = &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Hashtable&amp;lt;String, Integer&amp;gt;();
                &lt;span class=&quot;Comment&quot;&gt;// 2nd with initial Capacity &lt;/span&gt;
                Hashtable ht2 = &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Hashtable(&lt;span class=&quot;Constant&quot;&gt;5&lt;/span&gt;);
                &lt;span class=&quot;Comment&quot;&gt;// 3rd with intial capacity and fill Ratio [0.0 - 1.0]&lt;/span&gt;
                &lt;span class=&quot;Comment&quot;&gt;//default load factor is 0.75&lt;/span&gt;
                Hashtable ht3 = &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Hashtable(&lt;span class=&quot;Constant&quot;&gt;10&lt;/span&gt;, (&lt;span class=&quot;Type&quot;&gt;float&lt;/span&gt;) &lt;span class=&quot;Constant&quot;&gt;0.50&lt;/span&gt;);
                &lt;span class=&quot;Comment&quot;&gt;// 4th with initialisation from a Map&lt;/span&gt;
                Hashtable ht4 = &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Hashtable (&lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; HashMap());

                hashtable.put(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;One&amp;quot;&lt;/span&gt;, &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;1&lt;/span&gt;));
                hashtable.put(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;, &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;2&lt;/span&gt;));
                hashtable.put(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;Three&amp;quot;&lt;/span&gt;, &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;3&lt;/span&gt;));
                hashtable.put(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;Four&amp;quot;&lt;/span&gt;, &lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;4&lt;/span&gt;));

                &lt;span class=&quot;Comment&quot;&gt;// Get the number of key value pairs&lt;/span&gt;
                System.out.println(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;Hashtable contains &amp;quot;&lt;/span&gt; + hashtable.size() + &lt;span class=&quot;Constant&quot;&gt;&amp;quot; key value pairs.&amp;quot;&lt;/span&gt;);

                &lt;span class=&quot;Comment&quot;&gt;// Finding the Element using &amp;quot;Contains&amp;quot;&lt;/span&gt;
                &lt;span class=&quot;Statement&quot;&gt;if&lt;/span&gt;( hashtable.contains(&lt;span class=&quot;Statement&quot;&gt;new&lt;/span&gt; Integer(&lt;span class=&quot;Constant&quot;&gt;1&lt;/span&gt;))){
                        System.out.println(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;Hashtable contains 1 as value&amp;quot;&lt;/span&gt;);
                }&lt;span class=&quot;Statement&quot;&gt;else&lt;/span&gt;{
                        System.out.println(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;Hashtable does not contain 1 as value&amp;quot;&lt;/span&gt;);
                }
                &lt;span class=&quot;Comment&quot;&gt;// Finding the element using the key and &amp;quot;contains key&amp;quot;&lt;/span&gt;
                &lt;span class=&quot;Statement&quot;&gt;if&lt;/span&gt;(hashtable.containsKey(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;One&amp;quot;&lt;/span&gt;)){
                        System.out.println(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;Hashtable contains One as key&amp;quot;&lt;/span&gt;);
                }&lt;span class=&quot;Statement&quot;&gt;else&lt;/span&gt;{
                        System.out.println(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;Hashtable does not contain One as value&amp;quot;&lt;/span&gt;);
                }
                &lt;span class=&quot;Comment&quot;&gt;// we need to have set-view to use iterators &lt;/span&gt;
                Set set = hashtable.keySet();
                Iterator itr = set.iterator();

                String str;
                &lt;span class=&quot;Statement&quot;&gt;while&lt;/span&gt;(itr.hasNext())
                {
                        str = (String) itr.next();
                        System.out.println(str + &lt;span class=&quot;Constant&quot;&gt;&amp;quot;: &amp;quot;&lt;/span&gt; +hashtable.get(str));
                }
                &lt;span class=&quot;Comment&quot;&gt;// String Representation of HashTable&lt;/span&gt;
                System.out.println(hashtable.toString());

                System.out.println( hashtable.remove(&lt;span class=&quot;Constant&quot;&gt;&amp;quot;One&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;Constant&quot;&gt;&amp;quot; is removed from the Hashtable.&amp;quot;&lt;/span&gt;);
        }

}
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://linux4genext.blogspot.com/feeds/7957595061681596641/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1681547402308503342/7957595061681596641' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/7957595061681596641'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/7957595061681596641'/><link rel='alternate' type='text/html' href='http://linux4genext.blogspot.com/2011/07/collections-in-java.html' title='Java Collections - A Relative Study'/><author><name>Bharat Verma</name><uri>http://www.blogger.com/profile/12817316332686822982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggz3r7ozr0DLz-aq42CVLy44OyL5DHSju8A9La5L4F0Ig4t-C-cmNcn4oxtZWu8Nwdc5vIGBOo0_othAeVORH4icUfb9PoGLEUh8Gt3q8P2je_qusiDGZbhJwMQIntVOPjD2Y6Cuwzdn22/s72-c/java-collection.jpg" height="72" width="72"/><thr:total>6</thr:total><georss:featurename>New Delhi, Delhi, India</georss:featurename><georss:point>28.635308 77.22496000000001</georss:point><georss:box>28.405279999999998 76.9810245 28.865336 77.468895500000016</georss:box></entry><entry><id>tag:blogger.com,1999:blog-1681547402308503342.post-3936979801167686363</id><published>2011-06-16T17:10:00.000+05:30</published><updated>2011-07-30T02:50:05.975+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="embedding code in HTML"/><category scheme="http://www.blogger.com/atom/ns#" term="highlighting"/><category scheme="http://www.blogger.com/atom/ns#" term="open source"/><category scheme="http://www.blogger.com/atom/ns#" term="source code"/><category scheme="http://www.blogger.com/atom/ns#" term="technology"/><title type='text'>Best way to embed source code in Blog</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
pre { font-family: consolas; color: #000000; background-color: #ffffff; }
.Comment { color: #0000ff; }
.Constant { color: #ff00ff; }
.Type { color: #2e8b57; font-weight: bold; }
.Statement { color: #804040; font-weight: bold; }
.Identifier { color: #008080; }
--&gt;
&lt;/style&gt;&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;I have came across to many ways in embedding source code in Blogger but found the best one as &lt;a href=&quot;http://www.vim.org/download.php&quot;&gt;Vim&lt;/a&gt;. The best way is to write open your source code in &lt;b&gt;Gvim&lt;/b&gt; and from the &quot;Syntax&quot; choose &quot;Convert to HTML&quot;. gVim creates the file .html file with the same name, for example like if you are using &quot;abc.py&quot; it will create &quot;abc.py.html&quot;. Following are the steps to use its code:&lt;br /&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;The file generated would have code like given below you need to copy the text between the style tags an remove the body tag as it may distort your blog&#39;s main formatting.  (although I have used &quot;Consolas&quot; it is by default &quot;monospace&quot;) :&lt;/li&gt;
&lt;pre&gt;&lt;span class=&quot;Identifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;Statement&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;Identifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Type&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;Identifier&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;&quot;text/css&quot;&lt;/span&gt;&lt;span class=&quot;Identifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt;&amp;lt;!--&lt;/span&gt;
&lt;span class=&quot;Statement&quot;&gt;pre&lt;/span&gt; &lt;span class=&quot;Identifier&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;font-family&lt;/span&gt;: consolas; &lt;span class=&quot;Type&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;Constant&quot;&gt;#000000&lt;/span&gt;; &lt;span class=&quot;Type&quot;&gt;background-color&lt;/span&gt;: &lt;span class=&quot;Constant&quot;&gt;#ffffff&lt;/span&gt;; &lt;span class=&quot;Identifier&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;Identifier&quot;&gt;.Constant&lt;/span&gt; &lt;span class=&quot;Identifier&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;Constant&quot;&gt;#ff00ff&lt;/span&gt;; &lt;span class=&quot;Identifier&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;Identifier&quot;&gt;.Identifier&lt;/span&gt; &lt;span class=&quot;Identifier&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;Constant&quot;&gt;#008080&lt;/span&gt;; &lt;span class=&quot;Identifier&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;Identifier&quot;&gt;.Statement&lt;/span&gt; &lt;span class=&quot;Identifier&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;Type&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;Constant&quot;&gt;#804040&lt;/span&gt;; &lt;span class=&quot;Type&quot;&gt;font-weight&lt;/span&gt;: &lt;span class=&quot;Type&quot;&gt;bold&lt;/span&gt;; &lt;span class=&quot;Identifier&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt;--&amp;gt;&lt;/span&gt;
&lt;span class=&quot;Identifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;Statement&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;Identifier&quot;&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;li&gt;Use &amp;lt;pre&amp;gt; &amp;lt;/pre&amp;gt; tags to write the code in HTML editing mode for the blog just copy the converted code in between of it and the good thing is that gVim produces HTML escaped characters. Example of a python program has been given below for binary search.&lt;/li&gt;
&lt;pre&gt;&lt;span class=&quot;Statement&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;Identifier&quot;&gt;search&lt;/span&gt;(sequence, number, lower=&lt;span class=&quot;Constant&quot;&gt;0&lt;/span&gt;, upper=&lt;span class=&quot;Identifier&quot;&gt;None&lt;/span&gt;):
        &lt;span class=&quot;Statement&quot;&gt;if&lt;/span&gt; upper &lt;span class=&quot;Statement&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;Identifier&quot;&gt;None&lt;/span&gt;: upper = &lt;span class=&quot;Identifier&quot;&gt;len&lt;/span&gt;(sequence)-&lt;span class=&quot;Constant&quot;&gt;1&lt;/span&gt;
        &lt;span class=&quot;Statement&quot;&gt;if&lt;/span&gt; lower == upper:
                &lt;span class=&quot;Statement&quot;&gt;assert&lt;/span&gt; number == sequence[upper]
                &lt;span class=&quot;Statement&quot;&gt;return&lt;/span&gt; upper+&lt;span class=&quot;Constant&quot;&gt;1&lt;/span&gt;
        &lt;span class=&quot;Statement&quot;&gt;else&lt;/span&gt;:
                middle = (lower + upper) // &lt;span class=&quot;Constant&quot;&gt;2&lt;/span&gt;
                &lt;span class=&quot;Statement&quot;&gt;if&lt;/span&gt; number &amp;gt; sequence[middle]:
                        &lt;span class=&quot;Statement&quot;&gt;return&lt;/span&gt; search(sequence, number, middle+&lt;span class=&quot;Constant&quot;&gt;1&lt;/span&gt;, upper)
                &lt;span class=&quot;Statement&quot;&gt;else&lt;/span&gt;:
                        &lt;span class=&quot;Statement&quot;&gt;return&lt;/span&gt; search(sequence, number, lower, middle)&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/ol&gt;&lt;div&gt;Other ways includes the use of &lt;b&gt;Javascript Library &lt;/b&gt;(&lt;a href=&quot;http://code.google.com/p/syntaxhighlighter/&quot;&gt;Syntax Highlighter Code Project&lt;/a&gt;) its client side scripting and support languages like C++, C#, CSS, Delphi, Pascal, Java, Javascript, PHP, Python, Ruby, SQL, Visual Basic, HTML, XML etc. Major issues in using this are adding .js and .css files and also making changes in master template and right angle characters must be &lt;a href=&quot;http://www.htmlescape.net/htmlescape_tool.html&quot;&gt;HTML escaped&lt;/a&gt;, if you are a blogging novice, I advice not to use it.&lt;br /&gt;
&lt;br /&gt;
Some other uses methods include &lt;b&gt;external code hosting projects&lt;/b&gt; like &lt;a href=&quot;http://pastie.org/&quot;&gt;Pastie&lt;/a&gt;, &lt;a href=&quot;http://snipplr.com/&quot;&gt;Snipplr&lt;/a&gt; etc in which my personal favorite is pastie.org but it also have some issues of size and code syntax. see the code snippet below.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;http://pastie.org/2291798.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
As you can see the code in the 2nd line if haven&#39;t taken to the 3rd one it by passes the boundary and goes out of frame, so its also not well suited for this purpose. It comes with an advantage that it allows conversion into plain text and direct download of the code.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://linux4genext.blogspot.com/feeds/3936979801167686363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1681547402308503342/3936979801167686363' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/3936979801167686363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/3936979801167686363'/><link rel='alternate' type='text/html' href='http://linux4genext.blogspot.com/2011/07/best-way-to-embed-source-code-in-blog.html' title='Best way to embed source code in Blog'/><author><name>Bharat Verma</name><uri>http://www.blogger.com/profile/12817316332686822982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>New Delhi, Delhi, India</georss:featurename><georss:point>28.635308 77.22496000000001</georss:point><georss:box>28.405279999999998 76.9810245 28.865336 77.468895500000016</georss:box></entry><entry><id>tag:blogger.com,1999:blog-1681547402308503342.post-4455758554834490323</id><published>2011-05-23T23:47:00.000+05:30</published><updated>2011-08-02T21:56:06.972+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="git"/><category scheme="http://www.blogger.com/atom/ns#" term="open source"/><category scheme="http://www.blogger.com/atom/ns#" term="technology"/><title type='text'>Git - Version Control System</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;b&gt;An Introduction to GIT -&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
Git is open source distributed version control system developed by &lt;a href=&quot;http://en.wikipedia.org/wiki/Linus_Torvalds&quot;&gt;Linus Torvalds&lt;/a&gt;&lt;b&gt; &lt;/b&gt;to handle projects with great speed and efficiency ... &lt;a href=&quot;http://en.wikipedia.org/wiki/Git_%28software%29&quot;&gt;Learn more&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Scenario (what I have been working in) -&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
I have a server of Ubuntu on Amazon EC2 and there I hosted one Django project on which I used to commit and deploy the code frequently.&lt;br /&gt;
&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
pre { font-family: consolas; color: #000000; background-color: #ffffff; }
.Constant { color: #ff00ff; }
.Statement { color: #804040; font-weight: bold; }
.Special { color: #6a5acd; }
--&gt;
&lt;/style&gt;&lt;br /&gt;
&lt;b&gt;Checking Out ...&lt;/b&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
you need to generate an SSH key and set it up.&lt;b&gt; &lt;/b&gt;&lt;br /&gt;
&lt;pre&gt;ssh-keygen&lt;/pre&gt;(You can leave everything to default when keygen asks you questions, thats the easiest way to go along)&lt;br /&gt;
Run this command next, and copy the output to clipboard or something..&lt;br /&gt;
&lt;pre&gt;cat ~/.ssh/id_rsa.pub&lt;/pre&gt;&lt;br /&gt;
Now login to development server:&lt;br /&gt;
&lt;pre&gt;ssh &lt;span class=&quot;Special&quot;&gt;-i&lt;/span&gt; amazonkey.pem ubuntu@myproject.bharat.in &lt;/pre&gt;&lt;br /&gt;
Then update the key as:&lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;Statement&quot;&gt;cd&lt;/span&gt; .ssh
cat &lt;span class=&quot;Statement&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; authorized_keys&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;(mind the double redirection operator to append to the file)&lt;br /&gt;
paste the copied string, and you are good to go.&lt;br /&gt;
&lt;br /&gt;
Next, clone from GIT.&lt;br /&gt;
&lt;pre&gt;git clone ubuntu@devel.bharat.in:/opt/repos/myproject.git&lt;/pre&gt;&lt;br /&gt;
(Afterwards, you&#39;ll pull to get the latest changes as)&lt;br /&gt;
&lt;pre&gt;git pull origin master&lt;/pre&gt;&lt;br /&gt;
You&#39;ll get a directory called myproject in your working directory, cd into it and fire..&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;python manage.py runserver&lt;/pre&gt;&lt;br /&gt;
(That should be all to run the development instance)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Pushing/Commiting/Deploying etc etc&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
When you are done working, you may want to commit the changes..&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;git commit &lt;span class=&quot;Special&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;Special&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;Some message&lt;/span&gt;&lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
IMP TIP: If the message contains refs #ISSUEID, the commit will automatically be associated with the issue in its log,&lt;br /&gt;
if the message contains fixes #ISSUEID, the issue will be marked resolved,&lt;br /&gt;
and if the message contains closes #ISSUEID, the issue will be closed. *&lt;br /&gt;
&lt;br /&gt;
Then you may push the changes to the server back as:&lt;br /&gt;
&lt;pre&gt;git push origin master&lt;/pre&gt;&lt;br /&gt;
(All the commits from the last push in the branch master)&lt;br /&gt;
&lt;br /&gt;
Finally to deploy, add a remote (one time)&lt;br /&gt;
&lt;pre&gt;git remote add stage ubuntu@myproject.bharat.in:/opt/repos/myprojectstage.git&lt;/pre&gt;&lt;br /&gt;
All you have to do is to push into this remote&#39;s master as:&lt;br /&gt;
&lt;pre&gt;git push stage master&lt;/pre&gt;&lt;br /&gt;
(The changes will immediately reflect at http://myproject.bharat.in)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Production remote:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;git remote add production ubuntu@bharat.in:/home/ubuntu/repos/myprojectprod&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Admin remote:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;git remote add admin ubuntu@stage.bharat.in:/opt/repos/admin.git&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Note for Beginners -&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
Don&#39;t loose your heart if you don&#39;t have a Amazon EC2 or stuff like that ... you can start doing it using &lt;a href=&quot;https://github.com/&quot;&gt;GitHub&lt;/a&gt; Please have a note that you have Git installed on any of the operating system you use. You can have git download &quot;Jargon&quot; at &lt;a href=&quot;http://git-scm.com/download&quot;&gt;Git - Fast Version Control System&lt;/a&gt;. &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;For Windows &lt;/b&gt;- You can download its latest version from here &lt;a href=&quot;http://code.google.com/p/msysgit/downloads/list&quot;&gt;http://code.google.com/p/msysgit/downloads/list&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;For Linux &lt;/b&gt;- You can use &quot;apt-get install git&quot; in Ubuntu or better to compile it&lt;a href=&quot;http://www.blogger.com/goog_531891061&quot;&gt; &lt;/a&gt;&lt;a href=&quot;http://www.blogger.com/goog_531891061&quot;&gt;Click Here to Download it.&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;Comment&quot;&gt;# for this you need to first have a account on GitHub&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt;# open git bash through start up launcher and check for .ssh if not then do &lt;/span&gt;

ssh-keygen &lt;span class=&quot;Special&quot;&gt;-t&lt;/span&gt; rsa &lt;span class=&quot;Special&quot;&gt;-C&lt;/span&gt; &lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;youremail@provider.domain&lt;/span&gt;&lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;Comment&quot;&gt;# now come to .ssh and copy public key&#39;s content to github site&lt;/span&gt;

cat id_rsa.pub

&lt;span class=&quot;Comment&quot;&gt;# After doing it fine to check use this command &lt;/span&gt;

ssh &lt;span class=&quot;Special&quot;&gt;-T&lt;/span&gt; git@github.com

&lt;span class=&quot;Comment&quot;&gt;# If it works well then do it like &lt;/span&gt;

git config &lt;span class=&quot;Special&quot;&gt;--global&lt;/span&gt; user.name &lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;FirstName LastName&lt;/span&gt;&lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;
git config &lt;span class=&quot;Special&quot;&gt;--global&lt;/span&gt; user.email &lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;handle@provider.domain&lt;/span&gt;&lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;

git config &lt;span class=&quot;Special&quot;&gt;--global&lt;/span&gt; github.user githubusername &lt;span class=&quot;PreProc&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Special&quot;&gt;bindian0509&lt;/span&gt;&lt;span class=&quot;PreProc&quot;&gt;)&lt;/span&gt;
git config &lt;span class=&quot;Special&quot;&gt;--global&lt;/span&gt; github.token the_token_you_have_seen_on_github_website

&lt;span class=&quot;Comment&quot;&gt;# now go to the project directory which you have specified in the website (like mine &quot;bharat&quot;)&lt;/span&gt;

&lt;span class=&quot;Statement&quot;&gt;cd&lt;/span&gt; bharat

git init

&lt;span class=&quot;Comment&quot;&gt;# to add a sample file&lt;/span&gt;

touch README.txt

git add &lt;span class=&quot;Special&quot;&gt;-A&lt;/span&gt; &lt;span class=&quot;PreProc&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Special&quot;&gt;to add all the files present in your directory&lt;/span&gt;&lt;span class=&quot;PreProc&quot;&gt;)&lt;/span&gt;
git add README &lt;span class=&quot;PreProc&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;Special&quot;&gt;to add only readme&lt;/span&gt;&lt;span class=&quot;PreProc&quot;&gt;)&lt;/span&gt;

git commit &lt;span class=&quot;Special&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;Special&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;Message&lt;/span&gt;&lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;
git commit &lt;span class=&quot;Special&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;Constant&quot;&gt;Message&lt;/span&gt;&lt;span class=&quot;Statement&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;Comment&quot;&gt;# for adding a remote origin to github repos&lt;/span&gt;

git remote add origin git@github.com:bindian0509/bharat.git

&lt;span class=&quot;Comment&quot;&gt;# now push the code to &lt;/span&gt;

git push origin master

&lt;span class=&quot;Comment&quot;&gt;# and now you are done with it&lt;/span&gt;

&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://linux4genext.blogspot.com/feeds/4455758554834490323/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1681547402308503342/4455758554834490323' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/4455758554834490323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/4455758554834490323'/><link rel='alternate' type='text/html' href='http://linux4genext.blogspot.com/2011/07/git-version-control-system.html' title='Git - Version Control System'/><author><name>Bharat Verma</name><uri>http://www.blogger.com/profile/12817316332686822982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>New Delhi, Delhi, India</georss:featurename><georss:point>28.635308 77.22496000000001</georss:point><georss:box>28.405279999999998 76.9810245 28.865336 77.468895500000016</georss:box></entry><entry><id>tag:blogger.com,1999:blog-1681547402308503342.post-8804760566372991402</id><published>2008-06-25T21:18:00.000+05:30</published><updated>2011-06-28T23:39:21.850+05:30</updated><title type='text'>Is Open Source Code Secure?</title><content type='html'>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5rFqFdN08J8nl5ImgT-Kj9oT6ludzfC4Lo8WPg7BMRHBtuaON-qdS9erB5kJYQqibdTW8vThFdHIfuoDRBeix1IF3GfJ_S9kWoqUNYWnO2GY6c5l4hQ1eYHGTsq4rTfXElk3VIscJWehW/s1600/linux.jpg&quot;&gt;&lt;img style=&quot;float: left; margin: 0pt 10px 10px 0pt; cursor: pointer; width: 214px; height: 238px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5rFqFdN08J8nl5ImgT-Kj9oT6ludzfC4Lo8WPg7BMRHBtuaON-qdS9erB5kJYQqibdTW8vThFdHIfuoDRBeix1IF3GfJ_S9kWoqUNYWnO2GY6c5l4hQ1eYHGTsq4rTfXElk3VIscJWehW/s320/linux.jpg&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5623301307212193298&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;The contention that open-source code programs are more reliable and secure will hold no water. Those who argue in favor of this assertion believe that an open-source code system is tested by a huge number of people on the code level who discover all possible errors. Yes, testing for errors on the code level concurrently with is easy and effective, but the results of such testing are far from ideal. Even after extensive testing by thousands of users, errors crop up in Linux. Moreover, judging from the army of users that tested the latest Windows versions, you would think that it would finally become the perfect operating system. We do know better than that, don&#39;t we? Testing is one thing, but running under real-life conditions is another, with unpredictable results popping up.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Linux support is rather expensive, so you might encounter problems obtaining timely updates. Moreover, administering Linux is more difficult than administering Windows. But why is Linux so difficult to master? The answer is simple: Performance and convenience are two incompatible things. Linux is a performance product, and Windows is a convenience product.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Security is often sacrificed for performance or convenience. For example, some programs may have options that make the administrator&#39;s work easier (e.g., the PHP interpreter may have the debug option enabled) but at the same time make it easier for hackers to break into the system. Nevertheless, Linux security is higher than that of Windows, and this has nothing to do with it being open source. Simply, many security-related aspects in Linux are implemented better than in Windows. For Example you can see the today&#39;s pathetic situation of a windows effected by viruses or malicious programs. Other examples includes the memory allocation of programs in Linux, like in normal circumstances a program cannot oversteps the bound of allocated memory whereas in Windows any program can use the any memory area resulting in the danger of faulty operations or system crash if the memory area of one program being over written by other.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So over all you can grade LINUX far much better for Quality and Development than windows and once you get into it ... you will never look back and if you are still in catch22 try to re-recognize your needs and then decide!!</content><link rel='replies' type='application/atom+xml' href='http://linux4genext.blogspot.com/feeds/8804760566372991402/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1681547402308503342/8804760566372991402' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/8804760566372991402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1681547402308503342/posts/default/8804760566372991402'/><link rel='alternate' type='text/html' href='http://linux4genext.blogspot.com/2008/06/contention-that-open-source-code.html' title='Is Open Source Code Secure?'/><author><name>Bharat Verma</name><uri>http://www.blogger.com/profile/12817316332686822982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5rFqFdN08J8nl5ImgT-Kj9oT6ludzfC4Lo8WPg7BMRHBtuaON-qdS9erB5kJYQqibdTW8vThFdHIfuoDRBeix1IF3GfJ_S9kWoqUNYWnO2GY6c5l4hQ1eYHGTsq4rTfXElk3VIscJWehW/s72-c/linux.jpg" height="72" width="72"/><thr:total>4</thr:total></entry></feed>