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

<channel>
	<title>Ioannisth's Weblog</title>
	<atom:link href="http://ioannisth.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ioannisth.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Fri, 10 Apr 2009 13:23:02 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>el</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='ioannisth.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/f10c1f90fa1567d76b6d593aba1238ce?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Ioannisth's Weblog</title>
		<link>http://ioannisth.wordpress.com</link>
	</image>
			<item>
		<title>[STUB] &#8211; ABSTRACT CLASSES vs INTERFACES</title>
		<link>http://ioannisth.wordpress.com/2009/04/10/stub-abstract-classes-vs-interfaces/</link>
		<comments>http://ioannisth.wordpress.com/2009/04/10/stub-abstract-classes-vs-interfaces/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 12:51:59 +0000</pubDate>
		<dc:creator>ioannisth</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://ioannisth.wordpress.com/?p=31</guid>
		<description><![CDATA[Interfaces to abstract classes is what pure  virtual is to virtual classes in C++
Interfaces are also used to implement multiple inheritance functionality, missing from Java but present in C++
Also good for Strategy pattern
CAN-DO / IS-A relationship
see
http://www.javaworld.com/javaworld/javaqa/2001-04/03-qa-0420-abstract.html
http://geekswithblogs.net/mahesh/archive/2006/07/05/84120.aspx
http://www.leepoint.net/notes-java/oop/interfaces/interfaces.html
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=31&subd=ioannisth&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Interfaces to abstract classes is what pure  virtual is to virtual classes in C++</p>
<p>Interfaces are also used to implement multiple inheritance functionality, missing from Java but present in C++</p>
<p>Also good for Strategy pattern</p>
<p>CAN-DO / IS-A relationship</p>
<p>see</p>
<p>http://www.javaworld.com/javaworld/javaqa/2001-04/03-qa-0420-abstract.html</p>
<p>http://geekswithblogs.net/mahesh/archive/2006/07/05/84120.aspx</p>
<p>http://www.leepoint.net/notes-java/oop/interfaces/interfaces.html</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ioannisth.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ioannisth.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ioannisth.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ioannisth.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ioannisth.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ioannisth.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ioannisth.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ioannisth.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ioannisth.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ioannisth.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=31&subd=ioannisth&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ioannisth.wordpress.com/2009/04/10/stub-abstract-classes-vs-interfaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/89cf71902413711d758919d948fe4288?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ioannisth</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;This&#8221; keyword in Java explained</title>
		<link>http://ioannisth.wordpress.com/2009/04/08/this-keyword-in-java-explained/</link>
		<comments>http://ioannisth.wordpress.com/2009/04/08/this-keyword-in-java-explained/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 12:12:02 +0000</pubDate>
		<dc:creator>ioannisth</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://ioannisth.wordpress.com/?p=25</guid>
		<description><![CDATA[The keyword this is useful when you need to refer to instance of the class from its method. The keyword helps us to avoid name conflicts. As we can see in the program that we have declare the name of instance variable and local variables same. Now to avoid the confliction between them we use [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=25&subd=ioannisth&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The keyword this is useful when you need to refer to instance of the class from its method. The keyword helps us to avoid name conflicts. As we can see in the program that we have declare the name of instance variable and local variables same. Now to avoid the confliction between them we use  this keyword. Here, this section provides you an example with the complete code of the program for the illustration of how to what is this keyword and how to use it.</p>
<p>In the example, this.length and this.breadth refers to the instance variable length and breadth while length and breadth refers to the arguments passed in the method. We have made a program over this. After going through it you can better understand.</p>
<p><code><br />
class Rectangle{<br />
int length,breadth;<br />
void show(int length,int breadth){<br />
this.length=length;<br />
this.breadth=breadth;<br />
}<br />
int calculate(){<br />
return(length*breadth);<br />
}<br />
}<br />
public class UseOfThisOperator{<br />
public static void main(String[] args){<br />
Rectangle rectangle=new Rectangle();<br />
rectangle.show(5,6);<br />
int area = rectangle.calculate();<br />
System.out.println("The area of a Rectangle is  :  " + area);<br />
}<br />
}<br />
</code></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ioannisth.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ioannisth.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ioannisth.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ioannisth.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ioannisth.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ioannisth.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ioannisth.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ioannisth.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ioannisth.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ioannisth.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=25&subd=ioannisth&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ioannisth.wordpress.com/2009/04/08/this-keyword-in-java-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/89cf71902413711d758919d948fe4288?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ioannisth</media:title>
		</media:content>
	</item>
		<item>
		<title>ItemRenderers data property</title>
		<link>http://ioannisth.wordpress.com/2009/04/08/itemrenderers-data-property/</link>
		<comments>http://ioannisth.wordpress.com/2009/04/08/itemrenderers-data-property/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 12:10:44 +0000</pubDate>
		<dc:creator>ioannisth</dc:creator>
				<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://ioannisth.wordpress.com/?p=8</guid>
		<description><![CDATA[The list control gives each itemRenderer instance the record of the dataProvider by setting the itemRenderer&#8217;s data property
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=8&subd=ioannisth&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The list control gives each itemRenderer instance the record of the dataProvider by setting the itemRenderer&#8217;s data property</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ioannisth.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ioannisth.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ioannisth.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ioannisth.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ioannisth.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ioannisth.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ioannisth.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ioannisth.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ioannisth.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ioannisth.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=8&subd=ioannisth&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ioannisth.wordpress.com/2009/04/08/itemrenderers-data-property/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/89cf71902413711d758919d948fe4288?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ioannisth</media:title>
		</media:content>
	</item>
		<item>
		<title>An excerpt from Bruce Eckel&#8217;s &#8220;Thinking in Java&#8221;</title>
		<link>http://ioannisth.wordpress.com/2008/11/27/an-excerpt-from-bruce-eckels-thinking-in-java/</link>
		<comments>http://ioannisth.wordpress.com/2008/11/27/an-excerpt-from-bruce-eckels-thinking-in-java/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 20:47:07 +0000</pubDate>
		<dc:creator>ioannisth</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[finalization]]></category>
		<category><![CDATA[garbage_collection]]></category>

		<guid isPermaLink="false">http://ioannisth.wordpress.com/?p=18</guid>
		<description><![CDATA[Cleanup: finalization and garbage collection
Programmers know about the importance of initialization, but often forget the importance of cleanup. After all, who needs to clean up an int? But with libraries, simply “letting go” of an object once you’re done with it is not always safe. Of course, Java has the garbage collector to reclaim the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=18&subd=ioannisth&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2>Cleanup: finalization and garbage collection</h2>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">Programmers know about the importance of initialization, but often forget the importance of cleanup. After all, who needs to clean up an </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>int</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">? But with libraries, simply “letting go” of an object once you’re done with it is not always safe. Of course, Java has the <a name="Index294"></a>garbage collector to reclaim the memory of objects that are no longer used. Now consider a very special and unusual case. Suppose your object allocates “special” memory without using <a name="Index295"></a></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>new</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">. The garbage collector knows only how to release memory allocated </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><em>with</em></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>new</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">, so it won’t know how to release the object’s “special” memory. To handle this case, Java provides a method called <a name="Index296"></a></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> that you can define for your class. Here’s how it’s </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><em>supposed</em></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> to work. When the garbage collector is ready to release the storage used for your object, it will first call </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">, and only on the next garbage-collection pass will it reclaim the object’s memory. So if you choose to use </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">, it gives you the ability to perform some important cleanup </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><em>at the time of garbage collection </em></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">.<span id="more-18"></span></span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">This is a potential programming pitfall because some programmers, especially C++ programmers, might initially mistake </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> for the <a name="Index297"></a></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><em>destructor</em></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> in C++, which is a function that is always called when an object is destroyed. But it is important to distinguish between C++ and Java here, because in C++ </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><em>objects always get destroyed </em></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> (in a bug-free program), whereas in Java objects do not always get garbage-collected. Or, put another way: </span></div>
<div><span style="font-family:Calligraph421 BT;color:black;font-size:medium;">Garbage collection is not destruction. </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">If you remember this, you will stay out of trouble. What it means is that if there is some activity that must be performed before you no longer need an object, you must perform that activity yourself. Java has no destructor or similar concept, so you must create an ordinary method to perform this cleanup. For example, suppose in the process of creating your object it draws itself on the screen. If you don’t explicitly erase its image from the screen, it might never get cleaned up. If you put some kind of erasing functionality inside </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">, then if an object is garbage-collected, the image will first be removed from the screen, but if it isn’t, the image will remain. So a second point to remember is: </span></div>
<div><span style="font-family:Calligraph421 BT;color:black;font-size:medium;">Your objects might not get garbage collected. </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">You might find that the storage for an object never gets released because your program never nears the point of running out of storage. If your program completes and the garbage collector never gets around to releasing the storage for any of your objects, that storage will be returned to the operating system </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><em>en masse </em></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> as the program exits. This is a good thing, because garbage collection has some overhead, and if you never do it you never incur that expense. </span><a name="_Toc375545282"></a><a name="_Toc408018484"></a></div>
<p><a name="Heading148"></a></p>
<h3>What is finalize( ) for?</h3>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">You might believe at this point that you should not use </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> as a general-purpose cleanup method. What good is it? </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">A third point to remember is: </span></div>
<div><span style="font-family:Calligraph421 BT;color:black;font-size:medium;">Garbage collection is only about memory. </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">That is, the sole reason for the existence of the garbage collector is to recover memory that your program is no longer using. So any activity that is associated with garbage collection, most notably your </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> method, must also be only about memory and its deallocation. </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">Does this mean that if your object contains other objects </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> should explicitly release those objects? Well, no – the garbage collector takes care of the release of all object memory regardless of how the object is created. It turns out that the need for </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> is limited to special cases, in which your object can allocate some storage in some way other than creating an object. But, you might observe, everything in Java is an object so how can this be? </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">It would seem that </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> is in place because of the possibility that you’ll do something C-like by allocating memory using a mechanism other than the normal one in Java. This can happen primarily through </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><em>native methods </em></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">, which are a way to call non-Java code from Java. (Native methods are discussed in Appendix A.) C and C++ are the only languages currently supported by native methods, but since they can call subprograms in other languages, you can effectively call anything. Inside the non-Java code, C’s </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>malloc( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> family of functions might be called to allocate storage, and unless you call </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>free( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> that storage will not be released, causing a memory leak. Of course, </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>free( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> is a C and C++ function, so you’d need call it in a native method inside your </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">.</span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">After reading this, you probably get the idea that you won’t use </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> much. You’re correct; it is not the appropriate place for normal cleanup to occur. So where should normal cleanup be performed? </span><a name="_Toc375545283"></a><a name="_Toc408018485"></a><a name="_Toc312373857"></a></div>
<p><a name="Heading149"></a></p>
<h3>You must perform cleanup</h3>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">To clean up an object, the user of that object must call a <a name="Index298"></a>cleanup method at the point the cleanup is desired. This sounds pretty straightforward, but it collides a bit with the C++ concept of the <a name="Index299"></a>destructor. In C++, all objects are destroyed. Or rather, all objects </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><em>should be </em></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> destroyed. If the C++ object is created as a local, i.e. on the stack (not possible in Java), then the destruction happens at the closing curly brace of the scope in which the object was created. If the object was created using </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>new</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> (like in Java) the destructor is called when the programmer calls the C++ operator </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>delete</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> (which doesn’t exist in Java). If the programmer forgets, the destructor is never called and you have a memory leak, plus the other parts of the object never get cleaned up. </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">In contrast, Java doesn’t allow you to create local objects – you must always use </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>new</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">. But in Java, there’s no “delete” to call for releasing the object since the garbage collector releases the storage for you. So from a simplistic standpoint you could say that because of garbage collection, Java has no destructor. You’ll see as this book progresses, however, that the presence of a <a name="Index300"></a>garbage collector does not remove the need or utility of destructors. (And you should never call <a name="Index301"></a></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> directly, so that’s not an appropriate avenue for a solution.) If you want some kind of cleanup performed other than storage release you must </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><em>still</em></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> call a method in Java, which is the equivalent of a C++ destructor without the convenience. </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">One of the things </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> can be useful for is observing the process of garbage collection. The following example shows you what’s going on and summarizes the previous descriptions of garbage collection: </span></div>
<pre><span style="color:#009900;">//: Garbage.java</span>
<span style="color:#009900;">// Demonstration of the garbage</span>
<span style="color:#009900;">// collector and finalization</span>

<span style="color:#0000ff;">class</span> Chair {
  <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">boolean</span> gcrun = <span style="color:#0000ff;">false</span>;
  <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">boolean</span> f = <span style="color:#0000ff;">false</span>;
  <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">int</span> created = 0;
  <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">int</span> finalized = 0;
  <span style="color:#0000ff;">int</span> i;
  Chair() {
    i = ++created;
    <span style="color:#0000ff;">if</span>(created == 47)
      System.out.println("Created 47");
  }
  <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">void</span> finalize() {
    <span style="color:#0000ff;">if</span>(!gcrun) {
      gcrun = <span style="color:#0000ff;">true</span>;
      System.out.println(
        "Beginning to finalize after " +
        created + " Chairs have been created");
    }
    <span style="color:#0000ff;">if</span>(i == 47) {
      System.out.println(
        "Finalizing Chair #47, " +
        "Setting flag to stop Chair creation");
      f = <span style="color:#0000ff;">true</span>;
    }
    finalized++;
    <span style="color:#0000ff;">if</span>(finalized &gt;= created)
      System.out.println(
        "All " + finalized + " finalized");
  }
}

<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Garbage {
  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> main(String[] args) {
    <span style="color:#0000ff;">if</span>(args.length == 0) {
      System.err.println("Usage: \n" +
        "java Garbage before\n  or:\n" +
        "java Garbage after");
      <span style="color:#0000ff;">return</span>;
    }
    <span style="color:#0000ff;">while</span>(!Chair.f) {
      <span style="color:#0000ff;">new</span> Chair();
      <span style="color:#0000ff;">new</span> String("To take up space");
    }
    System.out.println(
      "After all Chairs have been created:\n" +
      "total created = " + Chair.created +
      ", total finalized = " + Chair.finalized);
    <span style="color:#0000ff;">if</span>(args[0].equals("before")) {
      System.out.println("gc():");
      System.gc();
      System.out.println("runFinalization():");
      System.runFinalization();
    }
    System.out.println("bye!");
    <span style="color:#0000ff;">if</span>(args[0].equals("after"))
      System.runFinalizersOnExit(<span style="color:#0000ff;">true</span>);
  }
} <span style="color:#009900;">///:~ </span></pre>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">The above program creates many </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>Chair</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> objects, and at some point after the garbage collector begins running, the program stops creating </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>Chair</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">s. Since the garbage collector can run at any time, you don’t know exactly when it will start up, so there’s a flag called </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>gcrun</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> to indicate whether the garbage collector has started running yet. A second flag </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>f</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> is a way for </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>Chair</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> to tell the </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>main( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> loop that it should stop making objects. Both of these flags are set within </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">, which is called during garbage collection. </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">Two other </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>static</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> variables, </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>created</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> and </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalized</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">, keep track of the number of </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>obj</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">s created versus the number that get finalized by the garbage collector. Finally, each </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>Chair</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> has its own (non- </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>static</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">) </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>int</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>i</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> so it can keep track of what number it is. When </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>Chair</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> number 47 is finalized, the flag is set to </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>true</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> to bring the process of </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>Chair </strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">creation to a stop. </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">All this happens in </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>main( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">, in the loop </span></div>
<pre>    <span style="color:#0000ff;">while</span>(!Chair.f) {
      <span style="color:#0000ff;">new</span> Chair();
      <span style="color:#0000ff;">new</span> String("To take up space");
    }</pre>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">You might wonder how this loop could ever finish, since there’s nothing inside that changes the value of </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>Chair.f</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">. However, the </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>finalize( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> process will, eventually, when it finalizes number 47. </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;"> The creation of a </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>String</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> object during each iteration is simply extra garbage being created to encourage the garbage collector to kick in, which it will do when it starts to get nervous about the amount of memory available. </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">When you run the program, you provide a command-line argument of “before” or “after.” The “before” argument will call the </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>System.gc( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> method (to force execution of the garbage collector) along with the </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>System.runFinalization( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> method to run the finalizers. These methods were available in <a name="Index302"></a>Java 1.0, but the <a name="Index303"></a></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>runFinalizersOnExit( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> method that is invoked by using the “after” argument is available only in Java 1.1<a name="Index304"></a></span><a name="fnB19" href="http://www.codeguru.com/java/tij/tij0051.shtml#fn19">[19]</a><span style="font-family:Carmina Md BT;color:black;font-size:small;"> and beyond. (Note you can call this method any time during program execution, and the execution of the finalizers is independent of whether the garbage collector runs). </span></div>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">The preceding program shows that, in Java 1.1, the promise that finalizers will always be run holds true, but only if you explicitly force it to happen yourself. If you use an argument that isn’t “before” or “after” (such as “none”), then neither finalization process will occur, and you’ll get an output like this: </span></div>
<pre>Created 47
Beginning to finalize after 8694 Chairs have been created
Finalizing Chair #47, Setting flag to stop Chair creation
After all Chairs have been created:
total created = 9834, total finalized = 108
bye!</pre>
<div><span style="font-family:Carmina Md BT;color:black;font-size:small;">Thus, not all finalizers get called by the time the program completes. </span><a name="fnB20" href="http://www.codeguru.com/java/tij/tij0051.shtml#fn20">[20]</a><span style="font-family:Carmina Md BT;color:black;font-size:small;"> To force finalization to happen, you can call </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>System.gc( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> followed by </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>System.runFinalization( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">. This will destroy all the objects that are no longer in use up to that point. The odd thing about this is that you call </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>gc( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><em>before</em></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> you call </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>runFinalization( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">, which seems to contradict the Sun documentation, which claims that finalizers are run first, and then the storage is released. However, if you call </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>runFinalization( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;"> first, and then </span><span style="font-family:Carmina Md BT;color:black;font-size:small;"><strong>gc( )</strong></span><span style="font-family:Carmina Md BT;color:black;font-size:small;">, the finalizers will not be executed. </span></div>
<p><span style="font-family:Carmina Md BT;color:black;font-size:small;">One reason that Java 1.1<a name="Index305"></a> might default to skipping finalization for all objects is because it seems to be expensive. When you use either of the approaches that force garbage collection you might notice longer delays than you would without the extra finalization. </span></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>original link &#8211; The whole book is available below and it rocks!</p>
<p>http://www.codeguru.com/java/tij/tij0051.shtml</p>
<p><span style="font-family:Carmina Md BT;color:black;font-size:small;"><br />
</span></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ioannisth.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ioannisth.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ioannisth.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ioannisth.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ioannisth.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ioannisth.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ioannisth.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ioannisth.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ioannisth.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ioannisth.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=18&subd=ioannisth&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ioannisth.wordpress.com/2008/11/27/an-excerpt-from-bruce-eckels-thinking-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/89cf71902413711d758919d948fe4288?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ioannisth</media:title>
		</media:content>
	</item>
		<item>
		<title>Memory control for Eclipse</title>
		<link>http://ioannisth.wordpress.com/2008/11/12/memory-control-for-eclipse/</link>
		<comments>http://ioannisth.wordpress.com/2008/11/12/memory-control-for-eclipse/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 19:23:42 +0000</pubDate>
		<dc:creator>ioannisth</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ioannisth.wordpress.com/?p=15</guid>
		<description><![CDATA[- Install Memory Monitor and Status Memory Monitor from Kyrsoft.
By installing these Eclipse plugins, you gain complete control over the
memory garbage of Eclipse. Install them via Help &#62; Software Updates
&#62; Find and install &#8211; Search for new features to install and choose a
new remote site. Enter http://www.kyrsoft.com/updates/ as the URL.
Improving performance of Eclipse/FlexBuilder
May 13th, 2008 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=15&subd=ioannisth&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>- Install Memory Monitor and Status Memory Monitor from Kyrsoft.</strong><br />
By installing these Eclipse plugins, you gain complete control over the<br />
memory garbage of Eclipse. Install them via Help &gt; Software Updates<br />
&gt; Find and install &#8211; Search for new features to install and choose a<br />
new remote site. Enter http://www.kyrsoft.com/updates/ as the URL.</p>
<blockquote><h2><a href="http://polygeek.com/508_flex_improving-performance-of-eclipseflexbuilder" rel="bookmark" title="Permanent Link to Improving performance of Eclipse/FlexBuilder">Improving performance of Eclipse/FlexBuilder</a></h2>
<div class="timeDate">May 13th, 2008 . by polygeek   </div>
<p>I’m working on a Flex project that is just kicking Eclipse in the ass. It takes forever to build and I keep getting <em>out of memory </em>errors.<br />
Finally, I complained about the issue on Twitter and @tomcornilliac was<br />
nice enough to twit back that I needed to give Eclipse a bigger heap by<br />
editing the <em>eclipse.ini</em> file.</p>
<p>Simple enough. My<em> eclipse.ini</em> file is in the root folder of the Eclipse installation and looks like this:</p>
<p>-showsplash<br />
org.eclipse.platform<br />
–launcher.XXMaxPermSize<br />
256M<br />
-vmargs<br />
-Dosgi.requiredJavaVersion=1.5<br />
<strong>-Xms40m<br />
-Xmx256m </strong><br />
-Djava.net.preferIPv4Stack=true<br />
-Djava.net.preferIPv4Stack=true</p>
<p>I changed the two bolded lines to:</p>
<p><strong>-Xms256m<br />
-Xmx512m </strong></p>
<p>And everything runs much faster and I haven’t gotten any of those pesky errors since.</p>
<p>You can also go Window &gt; Preferences &gt; General &gt; Show heap<br />
status to get a display of how much RAM Eclipse has to work with and<br />
how much it’s actually using. Very handy to turn that on to see if you<br />
need to increase your RAM allowance.</p>
</blockquote>
<p><!-- This is the date and author --></p>
<p>Thanks Polygeek! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ioannisth.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ioannisth.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ioannisth.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ioannisth.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ioannisth.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ioannisth.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ioannisth.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ioannisth.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ioannisth.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ioannisth.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=15&subd=ioannisth&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ioannisth.wordpress.com/2008/11/12/memory-control-for-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/89cf71902413711d758919d948fe4288?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ioannisth</media:title>
		</media:content>
	</item>
		<item>
		<title>Real time Monitoring of Apache Error Log</title>
		<link>http://ioannisth.wordpress.com/2008/09/25/real-time-monitoring-of-apache-error-log/</link>
		<comments>http://ioannisth.wordpress.com/2008/09/25/real-time-monitoring-of-apache-error-log/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 07:28:30 +0000</pubDate>
		<dc:creator>ioannisth</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://ioannisth.wordpress.com/?p=12</guid>
		<description><![CDATA[Log in via SSH to your Web server. Now run
tail -f /var/log/httpd/error_log
Now you can have that window monitoring your server



       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=12&subd=ioannisth&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Log in via SSH to your Web server. Now run</p>
<blockquote><p><strong>tail -f /var/log/httpd/error_log</strong></p></blockquote>
<p>Now you can have that window monitoring your server</p>
<blockquote>
<blockquote></blockquote>
</blockquote>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ioannisth.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ioannisth.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ioannisth.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ioannisth.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ioannisth.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ioannisth.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ioannisth.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ioannisth.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ioannisth.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ioannisth.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=12&subd=ioannisth&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ioannisth.wordpress.com/2008/09/25/real-time-monitoring-of-apache-error-log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/89cf71902413711d758919d948fe4288?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ioannisth</media:title>
		</media:content>
	</item>
		<item>
		<title>Static Keyword in C and Java</title>
		<link>http://ioannisth.wordpress.com/2008/07/09/static-keyword-in-c-and-java/</link>
		<comments>http://ioannisth.wordpress.com/2008/07/09/static-keyword-in-c-and-java/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 13:38:04 +0000</pubDate>
		<dc:creator>ioannisth</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[static]]></category>

		<guid isPermaLink="false">http://ioannisth.wordpress.com/?p=11</guid>
		<description><![CDATA[This is a beginner programming concept but since I tend to switch from C to Java and vice versa over long periods of time, I tend to forget it, so here it is.
from http://www.java-samples.com/showtutorial.php?tutorialid=285
There will be times when you will want to define a class member that will be used independently of any object of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=11&subd=ioannisth&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This is a beginner programming concept but since I tend to switch from C to Java and vice versa over long periods of time, I tend to forget it, so here it is.</p>
<p>from http://www.java-samples.com/showtutorial.php?tutorialid=285</p>
<blockquote><p>There will be times when you will want to define a class member that will be used independently of any object of that class. Normally a class member must be accessed only in conjunction with an object of its class. However, it is possible to create a member that can be used by itself, without reference to a specific instance. To create such a member, precede its declaration with the keyword <strong>static</strong>. When a member is declared <strong> static</strong>, it can be accessed before any objects of its class are created, and without reference to any object. You can declare both methods and variables to be <strong>static</strong>. The most common example of a <strong>static </strong>member is <strong>main( )</strong>. <strong>main( ) </strong>is declared as <strong>static </strong><br />
because it must be called before any objects exist.Instance variables declared as <strong>static </strong>are, essentially, global variables. When objects of its class are declared, no copy of a <strong>static </strong>variable is made. Instead, all instances of the class share the same <strong>static </strong>variable.</p>
<p>Methods declared as <strong>static </strong>have several restrictions:</p>
<ul>
<li>They can only call other <strong>static </strong>methods.</li>
<li>They must only access <strong>static </strong>data.</li>
<li>They cannot refer to <strong>this </strong>or <strong>super </strong>in any way. (The keyword <strong>super </strong>relates to<br />
inheritance.)</li>
</ul>
<p>If you need to do computation in order to initialize your <strong>static </strong>variables, you can declare a <strong>static </strong>block which gets executed exactly once, when the class is first loaded. The following example shows a class that has a <strong>static </strong>method, some <strong>static </strong>variables, and a <strong> static </strong>initialization block:</p>
<blockquote><p>// Demonstrate static variables, methods, and blocks.<br />
class UseStatic {<br />
static int a = 3;<br />
static int b;<br />
static void meth(int x) {<br />
System.out.println(&#8220;x = &#8221; + x);<br />
System.out.println(&#8220;a = &#8221; + a);<br />
System.out.println(&#8220;b = &#8221; + b);<br />
}<br />
static {<br />
System.out.println(&#8220;Static block initialized.&#8221;);<br />
b = a * 4;<br />
}<br />
public static void main(String args[]) {<br />
meth(42);<br />
}<br />
}</p></blockquote>
<p>As soon as the <strong>UseStatic </strong>class is loaded, all of the <strong>static </strong>statements are run. First, <strong>a </strong>is set to <strong>3</strong>, then the <strong>static </strong>block executes (printing a message), and finally, <strong>b </strong>is initialized to <strong> a * 4 </strong>or <strong>12</strong>. Then <strong>main( ) </strong>is called, which calls <strong>meth( )</strong>, passing <strong>42 </strong>to <strong>x</strong>. The three <strong> println( ) </strong>statements refer to the two <strong>static </strong>variables <strong>a </strong>and <strong>b</strong>, as well as to the local variable <strong>x</strong>.</p>
<p><strong> Note </strong>It is illegal to refer to any instance variables inside of a <strong>static </strong>method. Here is the output of the program:</p>
<p>Static block initialized.<br />
x = 42<br />
a = 3<br />
b = 12</p>
<p>Outside of the class in which they are defined, <strong>static </strong>methods and variables can be used independently of any object. To do so, you need only specify the name of their class followed by the dot operator. For example, if you wish to call a <strong>static </strong>method from outside its class, you can do so using the following general form:</p>
<p><em> classname.method</em>( )</p>
<p>Here, <em>classname </em>is the name of the class in which the <strong>static </strong>method is declared. As you can see, this format is similar to that used to call non-<strong>static </strong>methods through object reference variables. A <strong>static </strong>variable can be accessed in the same way—by use of the dot operator on the name of the class. This is how Java implements a controlled version of global functions and global variables.<br />
Here is an example. Inside <strong>main( )</strong>, the <strong>static </strong>method <strong>callme( ) </strong>and the <strong>static </strong>variable <strong>b </strong> are accessed outside of their class.</p></blockquote>
<blockquote><p>class StaticDemo {<br />
static int a = 42;<br />
static int b = 99;<br />
static void callme() {<br />
System.out.println(&#8220;a = &#8221; + a);<br />
}<br />
}<br />
class StaticByName {<br />
public static void main(String args[]) {<br />
StaticDemo.callme();<br />
System.out.println(&#8220;b = &#8221; + StaticDemo.b);<br />
}<br />
}<br />
Here is the output of this program:<br />
a = 42<br />
b = 99</p></blockquote>
<p>In C however it serves the purpose of preserving a function &#8217;s member value beetween calls to that function. Pretty much like instantiating an &#8220;object&#8221; containing that variable, upon calling the function.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ioannisth.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ioannisth.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ioannisth.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ioannisth.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ioannisth.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ioannisth.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ioannisth.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ioannisth.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ioannisth.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ioannisth.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ioannisth.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ioannisth.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=11&subd=ioannisth&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ioannisth.wordpress.com/2008/07/09/static-keyword-in-c-and-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/89cf71902413711d758919d948fe4288?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ioannisth</media:title>
		</media:content>
	</item>
		<item>
		<title>Flex ColumnWise Datagrid</title>
		<link>http://ioannisth.wordpress.com/2008/05/31/flex-columnwise-datagrid/</link>
		<comments>http://ioannisth.wordpress.com/2008/05/31/flex-columnwise-datagrid/#comments</comments>
		<pubDate>Sat, 31 May 2008 09:03:33 +0000</pubDate>
		<dc:creator>ioannisth</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ioannisth.wordpress.com/?p=10</guid>
		<description><![CDATA[Original Blog Article on http://vipuljhawar.wordpress.com/2008/03/27/comparable-datagrid-in-flex/
Using a datagrid in Flex seems very easy, but it has the inherent problem as ready to eat meal. It may not allow you to do all the modifications and may not allow you to present it in a view you desire.
A few months back i had a requirement to create [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=10&subd=ioannisth&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Original Blog Article on http://vipuljhawar.wordpress.com/2008/03/27/comparable-datagrid-in-flex/</p>
<p>Using a datagrid in Flex seems very easy, but it has the inherent problem as ready to eat meal. It may not allow you to do all the modifications and may not allow you to present it in a view you desire.</p>
<p>A few months back i had a requirement to create a datagrid, which displayed data column wise instead row wise i.e. the datagrid was suppose to be used for comparing and viewing data across columns rather than rows. So, how do we deal with such a problem in Flex. If you are working on HTML, its easy as you can just alter the logic in the for loop printing the rows. The whole point is using multi dimension arrays.</p>
<p>After finding no easy way to do it in Flex, i had to use to the same programming talent to display data column wise.</p>
<p>As datagrid expects the dataprovider to be in the form of an Array or ArrayCollection of objects and then it iterates over these objects to display a property of these objects in each column when you use the <strong>dataField </strong>property or you can reformat your test using the <strong>labelFunction</strong> property for the column. I used a combination of programming logic and labelFunction to display the list.</p>
<p>Lets say we intend to display Person objects columnWise,  as displayed below.<a title="comparable-table.png" href="http://vipuljhawar.files.wordpress.com/2008/03/comparable-table.png"><img src="http://vipuljhawar.files.wordpress.com/2008/03/comparable-table.png" alt="comparable-table.png" /></a></p>
<p>Now we would receive person object from the server to the client and there is no way that you can use labelfield property or the lablefunction straight away to create such a table.</p>
<p>The wrokaround is to keep the person array aside and create an array of indexes equal to the number of rows that each column would have or the max. number of rows that a column could have in the whole table. So we will create an array with numbers {1,2,3,4…} each number denoting a particular row in the column. Now, iterate through the person object array and keep on adding DataGridColumn objects to the datagrid for as many Person object. So, the dataprovider to the datagrid is an array of indexes and the number of columns is equal to the number of Person objects. Assign a labelFunction to each column such that</p>
<p><em><strong>public function getCompareLabel(item : Object, column : DataGridColumn) : String {<br />
var cIndex : int = int(Number(column.dataField)); //this will give you the column for which you have to get data.<br />
if (cIndex == 0)<br />
return getRowLabel(item, column); //Now in getRowLabel just write a switch function which will give label’s for each row, such as “First”, “Last” etc. This gives the first column.<br />
var person : PersonDAO = personArray[cIndex-1] as PersonDAO;<br />
//Now from second column onwards we will get the particular person object from the dataArray and display data for a particular field accordingly.<br />
switch(item) {<br />
case 1 : return getCmpStr(person.firstName);<br />
case 2 : return getCmpStr(person.lastName);<br />
case 3 : return getCmpStr(person.age);<br />
….</strong></em></p>
<p><em><strong>…..</strong></em></p>
<p><em><strong>}</strong></em></p>
<p>The output will be a table like above. Strange, isn’t it Flex is suppose to make things easier but i had to swing around the whole place to get this is in place.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ioannisth.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ioannisth.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ioannisth.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ioannisth.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ioannisth.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ioannisth.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ioannisth.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ioannisth.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ioannisth.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ioannisth.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ioannisth.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ioannisth.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=10&subd=ioannisth&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ioannisth.wordpress.com/2008/05/31/flex-columnwise-datagrid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/89cf71902413711d758919d948fe4288?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ioannisth</media:title>
		</media:content>

		<media:content url="http://vipuljhawar.files.wordpress.com/2008/03/comparable-table.png" medium="image">
			<media:title type="html">comparable-table.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamic tree control in flex</title>
		<link>http://ioannisth.wordpress.com/2008/05/31/dynamic-tree-control-in-flex/</link>
		<comments>http://ioannisth.wordpress.com/2008/05/31/dynamic-tree-control-in-flex/#comments</comments>
		<pubDate>Sat, 31 May 2008 09:02:12 +0000</pubDate>
		<dc:creator>ioannisth</dc:creator>
				<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://ioannisth.wordpress.com/?p=9</guid>
		<description><![CDATA[

Blog reference to http://vipuljhawar.wordpress.com/2008/03/28/creating-a-dynamic-tree-in-flex/
more flex articles there!
Tree control is one of the most powerful control in Flex. You must have stumbled upon N number of articles explaining the tree control, where they pick up the data from an XML for the tree, but that does not really happen too often if you have a tree [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=9&subd=ioannisth&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div class="entry">
<div class="snap_preview">
<p>Blog reference to http://vipuljhawar.wordpress.com/2008/03/28/creating-a-dynamic-tree-in-flex/</p>
<p>more flex articles there!</p>
<p>Tree control is one of the most powerful control in Flex. You must have stumbled upon N number of articles explaining the tree control, where they pick up the data from an XML for the tree, but that does not really happen too often if you have a tree which is to be built dynamically as loading a new XML everytime to build a tree is a costly affair.</p>
<p>So, let’s create a tree in Flex using actionscript objects which may be serialized version of server side objects or you may want to create a tree using some business logic rather than some plain input text. So, we will create a TreeNode class in Actionscript which will represent each and every node in the tree. The advantage of working with node objects is that you can have different types of objects at different levels and also use the inheritance concept pretty nicely. So a basic node may be a Node with variables &#8211; id, name, type.  A subclass of this node may be a PersonNode with additional variables &#8211; age, sex etc… and you can go on like this creating trees with the apt information and you can display any kind of data just by clicking on the node by fetching that node from the tree.</p>
<p>The top level class will be TreeNode.</p>
<p><em>public class TreeNode {</em></p>
<p><em> public var id : int;</em></p>
<p><em> public var name : String;</em></p>
<p><em> public var type : int;</em></p>
<p><em> public var children : ArrayCollection;</em></p>
<p><em> public function addChild(node : TreeNode) : void {</em></p>
<p><em> if (this.children == null)</em></p>
<p><em> this.children = new ArrayCollection();</em></p>
<p><em> children.addItem(node);<br />
</em></p>
<p><em> }<br />
//Similarly you could have getNode();<br />
</em></p>
<p><em>}</em></p>
<p>A sublcass of this could be a DataTreeNode</p>
<p><em>public class DataTreeNode extends TreeNode {</em></p>
<p><em> public var data : Object; </em></p>
<p><em>}</em></p>
<p>Now you can simply create a tree in Flex, by creating a RootNode of type DataTreeNode.</p>
<p>var rootNode : DataTreeNode = new DataTreeNode();</p>
<p>rootNode.id = 0;</p>
<p>rootNode.name = “Root”;</p>
<p>rootNode.type = -1;</p>
<p>Now you can keep creating nodes of different types and keep adding to the rootNode. Just assign the rootNode to you tree as a dataProvider and there you are, the flex tree will display automatically. I have found this approach much better and easy as it allows easy extension and also allows me to do much more on when i click a treeNode. Also, this way you don’t solely rely on the Tree api in Flex to do something with your tree, you can manipulate or swift your tree in any manner you want and reap the benefits.</p>
<p>If you have better way of creating dynamic tree in flex do comment, i would be more than pleased to improve or use that for my project, with all the regard definitely <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
</div>
</div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ioannisth.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ioannisth.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ioannisth.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ioannisth.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ioannisth.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ioannisth.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ioannisth.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ioannisth.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ioannisth.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ioannisth.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ioannisth.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ioannisth.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=9&subd=ioannisth&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ioannisth.wordpress.com/2008/05/31/dynamic-tree-control-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/89cf71902413711d758919d948fe4288?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ioannisth</media:title>
		</media:content>
	</item>
		<item>
		<title></title>
		<link>http://ioannisth.wordpress.com/2008/05/26/7/</link>
		<comments>http://ioannisth.wordpress.com/2008/05/26/7/#comments</comments>
		<pubDate>Mon, 26 May 2008 13:30:14 +0000</pubDate>
		<dc:creator>ioannisth</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ioannisth.wordpress.com/?p=7</guid>
		<description><![CDATA[This allows us to access application memebers from within a comp based on container. Not very OOP
super.parentApplication
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=7&subd=ioannisth&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This allows us to access application memebers from within a comp based on container. Not very OOP</p>
<blockquote><p>super.parentApplication</p></blockquote>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ioannisth.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ioannisth.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ioannisth.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ioannisth.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ioannisth.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ioannisth.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ioannisth.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ioannisth.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ioannisth.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ioannisth.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ioannisth.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ioannisth.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ioannisth.wordpress.com&blog=3200458&post=7&subd=ioannisth&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ioannisth.wordpress.com/2008/05/26/7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/89cf71902413711d758919d948fe4288?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ioannisth</media:title>
		</media:content>
	</item>
	</channel>
</rss>