<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-689000895995978913</atom:id><lastBuildDate>Tue, 10 Nov 2009 19:48:23 +0000</lastBuildDate><title>Infomaniac</title><description>This blog is for all those 'Infomaniacs' and the tech suave</description><link>http://ragha-infomaniac.blogspot.com/</link><managingEditor>ragha_unique2000@yahoo.com (Ragha)</managingEditor><generator>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-6522665699182228476</guid><pubDate>Sun, 14 Jun 2009 04:24:00 +0000</pubDate><atom:updated>2009-06-14T10:12:44.072+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>java</category><category domain='http://www.blogger.com/atom/ns#'>netbeans platform</category><title>LookupListener problem?</title><description>There are many unanswered threads to this question. The common issue is that the resultChanged(...) method is never triggered!! Here is a proper use-case scenario (note the comments, they provide tips to avoid common loopholes)&lt;br /&gt;&lt;pre name="code" class="java"&gt;public SomeClass extends LookupListener&lt;br /&gt;{&lt;br /&gt;  //It is important that you hold a reference to Lookup.Result&lt;br /&gt;  //so that it doesn't get garbage collected. This also applies to Lookup.Template&lt;br /&gt;  private Lookup.Result result = lookup.getDefault().lookupResult(MyInterface.class);&lt;br /&gt;&lt;br /&gt;  public SomeClass()&lt;br /&gt;  {&lt;br /&gt;      result.addLookupListener(this);&lt;br /&gt;   &lt;br /&gt;      //It is important to call this method once...otherwise           &lt;br /&gt;      //resultChanged(...) method is never triggered!!&lt;br /&gt;      resultchanged(new LookupEvent(result));&lt;br /&gt;  } &lt;br /&gt;&lt;br /&gt;  public void resultChanged(LookupEvent ev)&lt;br /&gt;  {&lt;br /&gt;      //do your stuff here...&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;If you still have problems, then check the META-INF/services folder of your implementation, there is probably a typo in the flat file. Its better to use &lt;a href="http://wiki.netbeans.org/DeclarativeRegistrationUsingAnnotations"&gt;@Service&lt;/a&gt; annotation to avoid such mistakes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-6522665699182228476?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2009/06/lookuplistener-problem.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-5564175321209067985</guid><pubDate>Sun, 14 Jun 2009 03:42:00 +0000</pubDate><atom:updated>2009-06-14T14:59:34.303+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>java</category><category domain='http://www.blogger.com/atom/ns#'>netbeans platform</category><title>Plugin manager for standalone swing apps</title><description>Lookup API provides a more features than the typical &lt;a href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html"&gt;ServiceLoader&lt;/a&gt; mechanism introduced in JDK 6. It allows you to listen to changes using &lt;a href="http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/LookupListener.html"&gt;LookupListener&lt;/a&gt;. If your not aware of Lookup API, please read about it &lt;a href="http://wiki.netbeans.org/DevFaqLookup"&gt;here&lt;/a&gt; before continuing any further. For a more comprehensive tutorial on the subject, check out this &lt;a href="http://netbeans.dzone.com/news/top-10-netbeans-apis-part-2"&gt;screencast&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Lookup API provides amazing decoupling capabilities to your application, even in standalone and non visual applications. The problem comes when you have to install or remove modules from your applications (implementations of an interface). In Netbeans platform the plugin manager would automatically do this for you. To utilize the benefits of LookupListener, one has to add the module jar files to the classpath (at run time).&lt;br /&gt;&lt;br /&gt;This however cannot be achieved directly, here's a reflection hack to get it done:&lt;br /&gt;&lt;pre name="code" class="java"&gt;/**&lt;br /&gt;* Rescans the given folder and adds all the Jar files (plugins)&lt;br /&gt;* to class path...simply ignores if a jar file is already added...&lt;br /&gt;*&lt;br /&gt;* @param path The folder containing plugins...&lt;br /&gt;* @throws java.io.IOException&lt;br /&gt;*/&lt;br /&gt;public void rescan(String path) throws IOException&lt;br /&gt;{&lt;br /&gt;File pluginFolder = new File(path);&lt;br /&gt;File plugins[] = pluginFolder.listFiles(new FileFilter()&lt;br /&gt;{&lt;br /&gt;    public boolean accept(File pathname)&lt;br /&gt;    {&lt;br /&gt;        if(pathname.getPath().endsWith(".jar"))&lt;br /&gt;            return true;&lt;br /&gt;        else&lt;br /&gt;            return false;&lt;br /&gt;    }&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;for(File f : plugins)&lt;br /&gt;{    &lt;br /&gt;    addPlugin(f.toURI().toURL());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* The url (preferably jar) to be added to the classpath.&lt;br /&gt;* This is like an install plugin thingy...&lt;br /&gt;* Must be used in place of {@link #rescan(java.lang.String) rescan} method&lt;br /&gt;* if a single new plugin is to be installed...gives good performance ups&lt;br /&gt;*&lt;br /&gt;* @param url The url to be added to classpath&lt;br /&gt;*/&lt;br /&gt;public void addPlugin(URL url) throws IOException&lt;br /&gt;{&lt;br /&gt;addURLToClassPath(url);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* To avoid un-necessary object creation on method calls...&lt;br /&gt;*/&lt;br /&gt;private static final Class[] parameters = new Class[]{URL.class};&lt;br /&gt;/**&lt;br /&gt;* Adds a URL, preferably a JAR file to classpath. If URL already exists,&lt;br /&gt;* then this method simply returns...&lt;br /&gt;*&lt;br /&gt;* @param u The URL t be added to classpath&lt;br /&gt;* @throws java.io.IOException&lt;br /&gt;*/&lt;br /&gt;private void addURLToClassPath(URL u) throws IOException&lt;br /&gt;{&lt;br /&gt;URLClassLoader sysloader = URLClassLoader)ClassLoader.getSystemClassLoader();&lt;br /&gt;&lt;br /&gt;boolean isAdded = false;&lt;br /&gt;for(URL url : sysloader.getURLs())&lt;br /&gt;{&lt;br /&gt;   if(url.equals(u))&lt;br /&gt;       isAdded = true;&lt;br /&gt;}&lt;br /&gt;if(isAdded)&lt;br /&gt;   return;&lt;br /&gt;&lt;br /&gt;Class sysclass = URLClassLoader.class;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;   Method method = sysclass.getDeclaredMethod("addURL",parameters);&lt;br /&gt;   method.setAccessible(true);&lt;br /&gt;   method.invoke(sysloader, new Object[]{ u });&lt;br /&gt;}&lt;br /&gt;catch (Throwable t)&lt;br /&gt;{&lt;br /&gt;   t.printStackTrace();&lt;br /&gt;   throw new IOException("Error, could not add URL to system classloader");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;In the above code we are adding a URL (typically pointing to a jar file) to the system classloader by invoking its private method via reflection.&lt;br /&gt;&lt;br /&gt;In your plugin manager...all you have to do is paste the jar file to a certain folder (say user.dir/plugins), then execute the following code to add jars to classpath:&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;/**&lt;br /&gt;* Rescans the given folder and adds all the Jar files (plugins)&lt;br /&gt;* to class path...simply ignores if a jar file is already added...&lt;br /&gt;*&lt;br /&gt;* @param path The folder containing plugins...&lt;br /&gt;* @throws java.io.IOException&lt;br /&gt;*/&lt;br /&gt;public void rescan(String path) throws IOException&lt;br /&gt;{&lt;br /&gt;File pluginFolder = new File(path);&lt;br /&gt;File plugins[] = pluginFolder.listFiles(new FileFilter()&lt;br /&gt;{&lt;br /&gt;    public boolean accept(File pathname)&lt;br /&gt;    {&lt;br /&gt;        if(pathname.getPath().endsWith(".jar"))&lt;br /&gt;            return true;&lt;br /&gt;        else&lt;br /&gt;            return false;&lt;br /&gt;    }&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;for(File f : plugins)&lt;br /&gt;{   &lt;br /&gt;    addPlugin(f.toURI().toURL());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* The url (preferably jar) to be added to the classpath.&lt;br /&gt;* This is like an install plugin thingy...&lt;br /&gt;* Must be used in place of {@link #rescan(java.lang.String) rescan} method&lt;br /&gt;* if a single new plugin is to be installed...gives good performance ups&lt;br /&gt;*&lt;br /&gt;* @param url The url to be added to classpath&lt;br /&gt;*/&lt;br /&gt;public void addPlugin(URL url) throws IOException&lt;br /&gt;{&lt;br /&gt;addURLToClassPath(url);&lt;br /&gt;}&lt;/pre&gt;That's it! the newly registered service providers can be caught in resultChanged(...) method of the LookupListener. Similarly you can remove items from the classpath to deactivate the plugins from your application, i'll leave that as your home work assignment :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-5564175321209067985?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2009/06/plugin-manager-for-standalone-swing.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-3462085570429191833</guid><pubDate>Wed, 10 Jun 2009 15:10:00 +0000</pubDate><atom:updated>2009-06-14T09:53:35.741+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>java</category><category domain='http://www.blogger.com/atom/ns#'>netbeans platform</category><title>lookup third party service impl of an interface</title><description>If you have a jar file containing implementations of an interface that you want to be discovered by lookup...here's what you do:&lt;br /&gt;&lt;br /&gt;1) Use library wrapper wizard in Netbeans to create a jar module wrapper.&lt;br /&gt;2) Create a folder META-INF/services in the wrapper module.&lt;br /&gt;3) Create a file in META-INF/services named after the fully qualified name of the interface  containing the fully qualified names of the implementations (one per line)&lt;br /&gt;&lt;br /&gt;That's it!&lt;br /&gt;Third party service implementations to now be discovered by the global lookup on startup.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-3462085570429191833?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2009/06/lookup-third-party-service-impl-of.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-2349109121368281856</guid><pubDate>Sun, 07 Jun 2009 06:13:00 +0000</pubDate><atom:updated>2009-06-08T10:53:08.941+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>java</category><title>Unnecessary object creation...</title><description>Most of you might already know about this. I just found this out while working on my open source project &lt;a href="https://jneuralnet.dev.java.net/"&gt;JNeuralNet&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I had this situation:&lt;br /&gt;&lt;pre name="code" class="java"&gt;loop&lt;br /&gt;{&lt;br /&gt;  Double d = someclass.compute();&lt;br /&gt;}&lt;/pre&gt;When i ran the profiler. I noticed that the major portion of CPU was going into Double object creation. That's when i realized that its the classloader overload everytime the object is being created..so this is what i did:&lt;br /&gt;&lt;pre name="code" class="java"&gt;//init variable...&lt;br /&gt;Double d = 0.0;&lt;br /&gt;loop&lt;br /&gt;{&lt;br /&gt;   d = someclass.compute();&lt;br /&gt;}&lt;/pre&gt;This simple optimization reduced a lot of CPU overload! Also if u have situations such as:&lt;br /&gt;&lt;pre name="code" class="java"&gt;loop&lt;br /&gt;{&lt;br /&gt;   Obj o = new Obj();&lt;br /&gt;}&lt;/pre&gt;If feasible...try using:&lt;br /&gt;&lt;pre name="code" class="java"&gt;Obj o = new Obj();&lt;br /&gt;loop&lt;br /&gt;{&lt;br /&gt;   //use o...&lt;br /&gt;   o.set(abc);&lt;br /&gt;}&lt;/pre&gt;This approach is not always feasible...especially if you intend to use the reference of the object elsewhere, my point is, to reduce object creation wherever feasible.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-2349109121368281856?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2009/06/unnecessary-object-creation.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-1112637021660170088</guid><pubDate>Wed, 27 May 2009 11:52:00 +0000</pubDate><atom:updated>2009-06-12T16:08:52.553+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>java</category><title>My ideal desktop recipe</title><description>&lt;div&gt;Don't know about others, but i sure am confused by the vast ocean of frameworks and libraries available out there to help aid in java desktop applications.&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;br /&gt;&lt;div&gt;This blog is not about frameworks and libraries that offer the best functionality and power, but those that do with a faster learning curve.&lt;br /&gt;&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;br /&gt;&lt;div&gt;Typically, these are the pain points you'll encounter (sooner or later) in a large desktop application.&lt;br /&gt;&lt;/div&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Validation&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Binding Pojo's with GUI&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Database Management&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Cool and sleek GUI&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Code complexity&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Packaging and deployment&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Creating Trialware's &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color: rgb(51, 102, 102);font-size:130%;" &gt;1) Validation&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I never paid much attention initially, but validation is one aspect that tends to get laborious. There are popular validation frameworks out there to help you with it. But as a beginner you'll want to learn it quick and easy. I'd prefer the &lt;a href="http://kenai.com/projects/simplevalidation/pages/Home"&gt;Simple Validation Api&lt;/a&gt; by Tim Boudreau. Powerful and simple at the same time. Hardly takes 10 minutes to learn.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color: rgb(51, 102, 102);font-size:130%;" &gt;2) Binding POJO's with GUI&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;In my opinion there is no good tool for data binding, its currently unstable and there's no out of the box support for it. Its usually more pain than gain. But if u insist i suggest that you use the &lt;a href="http://www.netbeans.org/"&gt;Netbeans IDE&lt;/a&gt;, it features mattise GUI builder with binding support. It'd be nice if JComponent binds POJO via annotations. In either case be on a look out, some one is probably developing it right now.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color: rgb(51, 102, 102);font-size:130%;" &gt;3) Database Management&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;Would'nt it be nice if you didnt have to write all the plumbing code required to execute a database transaction and just concentrate on the task itself? ORM's typically sheild you from all the database junk. Hibernate will probably be the first result if u ever tried to google. It however has a lot of XML mapping stuff to be done.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;In my opinion, &lt;a href="https://activeobjects.dev.java.net/"&gt;ActiveObjects&lt;/a&gt; orm by Daniel Spiewak is the easiest to use, i.e., in case u dont have distributed databases to deal with. It conpletely sheilds you from database complexity. The only disadvantage is that u need to create POJO interfaces first to generate the database schema . If you already have a database then you must create the interfaces yourself (no generator tool for now). A great feature worth noting is that it has Database Migrations (useful for maintenance).&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color: rgb(51, 102, 102);font-size:130%;" &gt;4) Cool and sleek GUI&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Get &lt;a href="https://substance.dev.java.net/"&gt;substance look and feel&lt;/a&gt; by Kirill Grouchnikov is an excellent option to spice up you UI. All you have to do is add one line of code. If you're on MAC OS consider &lt;a href="http://www.randelshofer.ch/quaqua/"&gt;Quaqua&lt;/a&gt; lnf. Also check out &lt;a href="https://swingx.dev.java.net/"&gt;SwingX&lt;/a&gt;, &lt;a href="https://flamingo.dev.java.net/"&gt;Flamingo&lt;/a&gt;, &lt;a href="http://www.l2fprod.com/common/"&gt;L2fProd&lt;/a&gt;, &lt;a href="http://www.jgoodies.com/"&gt;JGoodies&lt;/a&gt; for cool swing components. &lt;/p&gt;If you have time to spare and want some extreme GUI with cool animation effects consider using &lt;a href="https://animatedtransitions.dev.java.net/"&gt;Animated Transitions Api&lt;/a&gt; and &lt;a href="https://timingframework.dev.java.net/"&gt;Timing Framework&lt;/a&gt; by Romain Guy and Chet Haase. I also suggest that you read &lt;a href="http://filthyrichclients.org/"&gt;Filthy Rich clients&lt;/a&gt; by the same authors.&lt;br /&gt;&lt;p&gt;For a quickie, with almost no learning curve u should use substance look and feel with SwingX components along with mattise in NetbeansIDE.&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color: rgb(51, 102, 102);font-size:130%;" &gt;5) Code Complexity&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Be it a small or a large project, a GUI application soon gets out of the hand or you'll find yourself handling messy code or writing lots of plumbing code instead of putting effort into the business logic of the application. There's no point in reinventing the wheel, its always better to reuse a well tested framework instead of making one on your own. &lt;/p&gt;For a small scale application its better to use to use your own MVC pattern to separate model, view and control. Major concerns in such application would be to maintain configuration. You'll probably use bean property change listeners...in this case consider using AbstractSerializableBean from swingX project to reduce the amount of boilerplate code for firing property change. It your application still gets out of hand consider using &lt;a href="http://www.jidesoft.com/jdaf/index.htm"&gt;JIDE Application framework&lt;/a&gt;...havent really tried it, but looks good and has a moderate learning curve (2-3 days)&lt;br /&gt;&lt;p&gt;For a large application it is best of you use Netbeans Platform, its pretty complex and has a high learning curve, i would'nt recommend it unless you want to reuse netbeans features such as pallete, property sheets and editors etc...but on the bottom line its got great support and excellent documentation. Since its developed by sun, you can expect great support. Moreover NetbeansIDE has lots of code completion features for leveraging a netbeans platform based application.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;If you have at least made 5-6 desktop applications and have good knowledge of OOPS, especially the use of interfaces and abstract classes (read this &lt;a href="http://ragha-infomaniac.blogspot.com/2008/11/why-use-object-oriented-programming2.html"&gt;post&lt;/a&gt; for information on abstract classes) then you must consider using the Netbeans platform. Start by viewing these excellent &lt;a href="http://platform.netbeans.org/tutorials/nbm-10-top-apis.html"&gt;screencasts&lt;/a&gt;. &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color: rgb(51, 102, 102);font-size:130%;" &gt;6) Packaging and deployment&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Consider an application based on java comm api. In such an app, you cant ask your client to copy and paste dll's at different locations, this should instead be done automatically at the deployment time, typically by distributing a setup file. To encash the benefits of cross platform nature of your java code, you'll need to use a cross platform deployer. Again, there are many of them, the easiest one to use and learn is by using &lt;a href="http://packjacket.sourceforge.net/"&gt;PackJacket&lt;/a&gt;, a GUI frontend to the IzPack project. It also lets you create runtime scripts to execute custom tasks. whats more, the project is open sourced and is free to use.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="color: rgb(51, 102, 102);"&gt;&lt;span style="font-size:130%;"&gt;7) Creating Trialwares&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Depending on your marketing strategy, you might want to create trialware applications that expire after a certain time period.I recommend using &lt;a href="https://truelicense.dev.java.net/"&gt;TrueLicense&lt;/a&gt; library. Will take 1 day to get a hang of it.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Hope the above collection of tools and libs help you be more productive... Please let me know if you find better and easier tools.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-1112637021660170088?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2009/05/my-ideal-desktop-recipe.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-1969374295722863955</guid><pubDate>Tue, 13 Jan 2009 06:17:00 +0000</pubDate><atom:updated>2009-06-07T14:31:30.820+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>cool stuff</category><title>Tyranny of autorun.inf</title><description>Irritated with the darn viruses...?&lt;br /&gt;A friend of mine came up with this cool idea.&lt;br /&gt;&lt;br /&gt;As u all might already know. Most of the viruses create an autorun.inf file (hidden obviously) in the drive. On double clicking the drive, the script is , triggering the virus (Trojans).&lt;br /&gt;&lt;br /&gt;Here's the big idea, create a autorun.inf file (blank one) with read only and hidden attributes set. Paste this file in all your drives...even your pen drives. That way, even if a virus is present, it wont be able to create its own autorun.inf, as one already exists, i.e., with the read only permission.&lt;br /&gt;&lt;br /&gt;Viola, the virus is as good as useless as it wont be triggered. This applies to most of them but not all.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-1969374295722863955?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2009/01/tyranny-of-autoruninf.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-5844844403297794005</guid><pubDate>Fri, 02 Jan 2009 10:54:00 +0000</pubDate><atom:updated>2009-06-07T14:31:24.317+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>cool stuff</category><category domain='http://www.blogger.com/atom/ns#'>web</category><title>Cool web pages...</title><description>Designing cool looking web pages is not a rocket science. Awesome effects can be acheived without javascript, flash etc etc...&lt;br /&gt;&lt;br /&gt;Dont let these things deter you, best example is my friend vivek...with just 2-3 days of work he managed to make a gr8 web page (just needed to learn CSS). Take a look at his &lt;a href="http://www.viveksunder.co.nr/"&gt;page&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Also he showed me some of the coolest web pages ever...very simple in concept and could have been implemented by YOU.&lt;br /&gt;&lt;br /&gt;Check out &lt;a href="http://www.sursly.com/#home"&gt;Tyler's web page&lt;/a&gt;, this page takes time to load...let it load completely before clicking on any thing. This page was made using the '#' element...pretty cool nah!&lt;br /&gt;&lt;br /&gt;Also there is a site called &lt;a href="http://www.cssbeauty.com/"&gt;&lt;span&gt;CSS beauty&lt;/span&gt;&lt;/a&gt;, it has a listing of all the cool web pages...hope this gives you enough inspiration to work on that innovate page of urs :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-5844844403297794005?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2009/01/cool-web-pages.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-1069665856792364251</guid><pubDate>Sat, 20 Dec 2008 18:06:00 +0000</pubDate><atom:updated>2009-06-07T14:31:11.309+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>cool stuff</category><title>Pure Genius...</title><description>I accidentally came across a lecture on 'human computing' by Louis Von Ahn, a professor at Carnegie Mellon University. This is one of the best works i have seen. Pure genius and totally awesome...&lt;br /&gt;&lt;br /&gt;Dont forget to check this out:&lt;br /&gt;http://video.google.com/videoplay?docid=-8246463980976635143&amp;amp;hl=en&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-1069665856792364251?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2008/12/pure-genius.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-1280354761822419287</guid><pubDate>Tue, 18 Nov 2008 05:03:00 +0000</pubDate><atom:updated>2009-06-07T14:31:05.966+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>OOP</category><title>Why use object oriented programming…2</title><description>In my previous post, I’ve written how OOP resolves basic issues such as&lt;br /&gt;&lt;br /&gt;• Functional Clutter&lt;br /&gt;• Problem with Global Variables&lt;br /&gt;• Unmanageable associations&lt;br /&gt;&lt;br /&gt;Apart from these OOP has other powerful features, namely Inheritance and abstract classes. In this blog I’m going to discuss what these terms mean and why are they so useful.&lt;br /&gt;&lt;br /&gt;We all know the common book definition of inheritance, but why is it so useful?&lt;br /&gt;Basically inheritance is used when you have to&lt;br /&gt;&lt;br /&gt;1) Modify the behavior of the object&lt;br /&gt;2) Add additional features to the existing class&lt;br /&gt;&lt;br /&gt;To modify the behavior all you gotta do is inherit the parent class into a new class called the base class and override the necessary methods. Take the example of JLabel in swing. The text in the label is rendered onto the screen by calling the paint method. Suppose you wanted to change the way border is shown, you have to override this method which is in turn called by swing framework to render the label.&lt;br /&gt;&lt;br /&gt;To add additional features to the label, you have to inherit it into the base class and write additional methods for enabling new features. The base class now contains all the previous functionality that lets keeps it compatible with the existing framework.&lt;br /&gt;&lt;br /&gt;Inheritance is essentially like copying and pasting all the code within the parent class into the base class. So why not copy and paste the code manually? I.e. copy code in class A to Class B instead of inheriting.&lt;br /&gt;&lt;br /&gt;Just imagine what would happen if class A is modified later on as a result of bug fix or enhancement. You’ll have to re-copy all the code from class A to class B, thereby hampering the code manageability. Moreover inheritance lets you reuse the well designed and tested classes you’ve already made.&lt;br /&gt;&lt;br /&gt;What’s more, inheritance also helps you debug the code. Suppose class A, B, C, D inherits class E. If there is a problem in classes A to D then it’s probable that the code in class A is buggy. If class A is buggy then it’s probable that the new code you’ve added is buggy. It may seem like a small thing but believe it or not, about 70% of development time is wasted in debugging and maintenance.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Abstract classes…Inherit benefits of Inheritance&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Suppose there are a lot of things in common between the two classes (A and B), i.e. you notice some sort of code redundancy, but there are also many marked differences between them at the same time. Furthermore the redundant code cannot be grouped within a single class as it doesn’t make any sense. If you come across this kind of a situation, you could put all that redundant code in an abstract class (X) and make then create the other two by inheriting the abstract class. This kind of model is blessed with the benefits of inheritance. In short it Inherit benefits of Inheritance ?&lt;br /&gt;&lt;br /&gt;Abstract classes don’t have an instance, i.e. it’s not possible to create an object without implementing the abstract methods. Simply make the class specific methods, the ones used by classes A and B as abstract. Sounds like Greek and Latin? Let’s consider an example.&lt;br /&gt;&lt;br /&gt;Yesterday I was trying to make a class that can add the ‘trail period’ feature to any software. To do this I’ll have to –&lt;br /&gt;&lt;br /&gt;1) Record the date when the software is first used.&lt;br /&gt;2) Whenever the software is started, check the current date with the start date and evaluate the difference&lt;br /&gt;3) If the difference is greater than say 30 days then prompt the user to enter the serial key.&lt;br /&gt;&lt;br /&gt;To record the start date there can be two possibilities.&lt;br /&gt;&lt;br /&gt;1) Save the data in an encrypted form within a file.&lt;br /&gt;2) Save the data in an encrypted form within a database in case of a distributed application.&lt;br /&gt;&lt;br /&gt;So you make two classes, DBValidator and NonDBValidator. Both of then contain redundant code…i.e. the logic that checks the date difference, a fraud detection system to see if the user tampers with the system date etc etc…The only point of change is the way in which the start date is persisted onto a storage medium.&lt;br /&gt;&lt;br /&gt;In this scenario you could create an abstract class called validator with all the redundant code and make the persistDate method abstract.&lt;br /&gt;&lt;br /&gt;Classes DBValidator and NonDNValidator inherit the validate class by implementing the abstract method persistDate, each one defining their own persistence logic.&lt;br /&gt;&lt;br /&gt;Why go through this entire headache? Read the inheritance part again. This helps in centralizing the changes that may be required. You just have to make a change at a particular common place (the parent) and the necessary updates are forwarded to all the base classes.&lt;br /&gt;&lt;br /&gt;Today’s software development standard is not about writing logical code, anyone can do that today. Instead more emphasis is laid on writing code that is better managed, even if you’ll have to compromise on the logic part. This is probably one the reasons as to why they look for people with work experience. Anyone involved in big projects would’ve certainly faced this problem before. This is also the reason why frameworks such as hibernate, JSF, struts are so popular in spite of the high learning curve involved.&lt;br /&gt;&lt;br /&gt;Now that the basics of OOP is laid out, in my next post I’ll discuss about UML diagrams. I hope this article was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-1280354761822419287?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2008/11/why-use-object-oriented-programming2.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-6042110353665245511</guid><pubDate>Mon, 10 Nov 2008 17:01:00 +0000</pubDate><atom:updated>2009-06-07T14:30:56.221+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>OOP</category><title>Why use Object Oriented Programming…</title><description>Do you get this feeling, “why use classes and objects un-necessarily when functions can achieve the same in a simpler manner?” If yes, this article is for you. It took me about 3-4 months to fully realize the potential of OOP over structural paradigm. The only way you’ll realize the importance of OOP is when you write big code, I mean BIG, around 50K lines or so.&lt;br /&gt;&lt;br /&gt;Here’s the scenario, consider yourself as a topnotch programmer who has written about 50,000 lines of code :) , say you’ve written some utility functions (around 800 of em) and have packaged them in a library.&lt;br /&gt;&lt;br /&gt;Why does big code gets messy and un-manageable??&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Problem 1…Functional clutter&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;From the usage point of view, the person using your library will probably be confused will all the functions you’ve provided (they’re about 800!!!) and moreover they have to remember all the parameters to the function, its behavior etc…&lt;br /&gt;&lt;br /&gt;Ex- funcA(param1, param2, param3)&lt;br /&gt;Param1, param2 are numbers…&lt;br /&gt;Param3 can take values 1,2,3&lt;br /&gt;&lt;br /&gt;1 would mean that the function will add param1 and param2…&lt;br /&gt;2, 3 means it’ll perform multiplication and division&lt;br /&gt;&lt;br /&gt;The whole point is that it’ll get real tough to remember the functions and its behavior, parameter’s when there are too many of them. Furthermore not all of the functions are of utility value. What I mean is that there will be some functions that are used by other utility value functions.&lt;br /&gt;&lt;br /&gt;Ex - funcA() uses funcB() and funcC()  to do its tasks. The end user is only concerned with funcA and not with funcB and funcC.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Problem 2…The headache of global variables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The usage of global variables is the most annoying thing for me. It’s very easy to confuse a global variable with a local one or vice-versa. Also tracking the usages of global variables is considerably difficult. It also increases dependencies between the functions.&lt;br /&gt;&lt;br /&gt;Ex-&lt;br /&gt;&lt;pre name="code" class="c"&gt;&lt;br /&gt;int x; //(global variable)&lt;br /&gt;&lt;br /&gt;void func1()&lt;br /&gt;{&lt;br /&gt;   //Uses global var x (reads and modifies)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void func2()&lt;br /&gt;{&lt;br /&gt;   //Uses global var x (reads and modifies)&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In this case, there exists a dependency between func1 and func2 indirectly via global variables…&lt;br /&gt;&lt;br /&gt;How?&lt;br /&gt;If in the future, you’ve found some bugs in func1 and corrected…it might as well affect func2 as they share the same global variable (dependency).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Problem 3…Unmanageable Associations&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Consider a game consisting of 300 circles which are moved randomly (say). Every circle has three status variables associated with it.&lt;br /&gt;&lt;br /&gt;x, y coordinate and the radius.&lt;br /&gt;Here’s how your code would work.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="c"&gt;&lt;br /&gt;loop&lt;br /&gt;{&lt;br /&gt;  //Clear screen&lt;br /&gt;  //Draw all circles by reading their respective status variables&lt;br /&gt;  //Update the positions of all the circles by updating the status variables,&lt;br /&gt;  //using some logic&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The thing is that there are three variables with each circle…So that makes it 300 * 3 variables&lt;br /&gt;&lt;br /&gt;You’ll probably end up naming variables as&lt;br /&gt;Int x1, y1, r1, y2, r2….x300, y300, r300&lt;br /&gt;&lt;br /&gt;What if there are more objects in the game, like clouds, trees etc (even more status variables). All of this makes the code look messy and also makes the associations harder. You’ll soon start confusing which function operates on what and which variable is associated with an object (circle in this case)&lt;br /&gt;&lt;br /&gt;So what are the solutions to these issues? If you think about it’ll almost seem obvious.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Solution to problem 2 &amp;amp; 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the world of OOP objects form the building blocks of the code. Suppose you’re coding a game, just think of any sprite (something that’s rendered onto the screen) as an object.&lt;br /&gt;&lt;br /&gt;An object is just like any other real world entity.&lt;br /&gt;&lt;br /&gt;- It has certain attributes or properties associated with it. In case of the circle consider its status variables as its attributes.&lt;br /&gt;&lt;br /&gt;- Has certain operations associated with it. You could have associated an operation (function) ‘move()’ with the circle object that would randomly alter its attributes. Also a function called ‘draw()’ can be added to render the circle onto the screen.&lt;br /&gt;&lt;br /&gt;Now there’s no more confusion…All the variables and operations are ‘encapsulated’ within an object&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Circle (class or prototype of an object)&lt;/span&gt;&lt;br /&gt;--------------------------------------&lt;br /&gt;&lt;span style="font-style: italic;"&gt;(Attributes)&lt;/span&gt;&lt;br /&gt;--------------------------------------&lt;br /&gt;Int x&lt;br /&gt;Int y&lt;br /&gt;Int radius&lt;br /&gt;--------------------------------------&lt;br /&gt;&lt;span style="font-style: italic;"&gt;(Operations)&lt;/span&gt;&lt;br /&gt;--------------------------------------&lt;br /&gt;Move()&lt;br /&gt;Draw()&lt;br /&gt;--------------------------------------&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Class is just a template; an object on the other hand is an instance of the class having its own attributes.&lt;br /&gt;&lt;br /&gt;Moreover there is no longer a menace of global variables as all the attributes (variables) are encapsulated within classes.&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Solution to problem 1&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To avoid the confusion all the related functions and shared global variables could be encapsulated within a class.&lt;br /&gt;Ex- Suppose you have some functions that perform certificate auth, encryption, decryption etc…You could combine (associate, encapsulate) them all in a class named security. Make all the shared global variables its attributes.&lt;br /&gt;&lt;br /&gt;As far as the utility of the function is concerned, OOP introduces access modifiers such as public, private etc…&lt;br /&gt;&lt;br /&gt;Make the real utility valued functions as public. The supporting functions can be made private so that they cannot be accessed directly from the object.&lt;br /&gt;&lt;br /&gt;This is only the beginning (yea, I know it’s a movie dialog). You haven’t tasted the real power yet. Apart from the issues I discussed, the key strength of OOP is in inheritance and abstraction.&lt;br /&gt;I’ll discuss more about those in my next post. I hope this article was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-6042110353665245511?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2008/11/why-use-object-oriented-programming.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-5031140906110812401</guid><pubDate>Fri, 31 Oct 2008 15:09:00 +0000</pubDate><atom:updated>2009-06-07T14:30:47.315+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>cool stuff</category><title>Better Explained?</title><description>Cant help but post this, Check out &lt;span style="text-decoration: underline;"&gt;&lt;a href="http://betterexplained.com/"&gt;http://betterexplained.com/&lt;/a&gt;&lt;/span&gt;. It has amazing new perspectives on simple issues...for starters, take a look at the &lt;a href="http://betterexplained.com/articles/surprising-uses-of-the-pythagorean-theorem/"&gt;pythagorean theorem&lt;/a&gt;. Im sure it'll amaze you as much as it did to me.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-5031140906110812401?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2008/10/better-explained.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-3619592874515308448</guid><pubDate>Wed, 29 Oct 2008 23:50:00 +0000</pubDate><atom:updated>2009-06-07T14:30:39.811+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>ai</category><category domain='http://www.blogger.com/atom/ns#'>cool stuff</category><title>Reverse Engineering the Brain</title><description>Oh yes, you heard it right. It’s no longer a stuff of science fiction. On July 25, 2008, Intelligence Realm Inc. has completed a simulation of 100 billion neurons, the estimated size of the human brain. The simulation used distributed computing and involved over 3000 volunteers, 10000 processors, 180 TB of data and it lasted for a couple of months. This was the first simulation that bypassed the 100 billion level and used database files to store the data. The simulation is one of the first steps in a long-term project that is aiming to build a large-scale artificial intelligence by reverse engineering the brain.&lt;br /&gt;&lt;br /&gt;So how are the neurons simulated? The concept of artificial neural networks (ANN) is used which can perform tasks like predicting stock market, hand writing recognition, face recognition and many more. A typical ANN hardly consists of 100 neurons. Imagine the potential of an ANN with 100 billion neurons. 'Google' on Artificial neural networks for more information...&lt;br /&gt;&lt;br /&gt;So what’s the catch? There are many challenges involved to simulate an ANN at this degree.&lt;br /&gt;1)    Interconnection of neurons and their weights associated.&lt;br /&gt;2)    The processing power and storage capabilities.&lt;br /&gt;&lt;br /&gt;The latter can be solved in an economical manner by using a distributed computing scheme similar to SETI (wherein, volunteers can share their processing power).  As for the storage, with TB’s of hard disks coming up, that shouldn’t be much of an issue.&lt;br /&gt;&lt;br /&gt;To solve the former, scientists have decided to mimic the connections and weights used in the brain. After all it is nothing less than marvelous. Take a look at &lt;a href="http://brainmaps.org/"&gt;www.brainmaps.org&lt;/a&gt;. They have created a brain map of many species. So far 92% of the human brain is mapped because of the complexity involved.&lt;br /&gt;&lt;br /&gt;To get the gravity of this research, imagine the following scenario. A person is permanently blinded because of damage to visual cortex of the brain. Since, human brain mapping is available. A Nano sized chip could be made containing all the ANN’s required to process visual data. The beauty of this is that we don’t even have to understand how the information is processed. All we have to do is device a way for it to interact with the remainder of the brain by interconnecting the neurons of the chip with the real ones with a Nano surgery just as described by the brain map. By this a permanently blind person’s vision can be restored. This is because; the visual cortex neurons, connections and weights are mimicked exactly as it was in the real brain.&lt;br /&gt;&lt;br /&gt;Seems far fetched? You’ll be in for a real surprise. Back in 1980’s, it was estimated that the number of computers to be used by the year 2000 would be about 100.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-3619592874515308448?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2008/10/reverse-engineering-brain-oh-yes-you.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-5421503116526692534</guid><pubDate>Wed, 29 Oct 2008 19:11:00 +0000</pubDate><atom:updated>2009-06-07T14:33:43.255+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>java</category><category domain='http://www.blogger.com/atom/ns#'>framework</category><category domain='http://www.blogger.com/atom/ns#'>OOP</category><title>Understanding frameworks by example...2</title><description>&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;br /&gt;Step 3: Check your code so far, revise and optimize&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;All might seem rosy at the moment but when you try out this code…you’ll notice that&lt;br /&gt;&lt;br /&gt;1)    Frame rates vary widely, some systems show FPS of up to 150 and some about 30&lt;br /&gt;To ensure frame-rate consistency we’ll add &lt;span style="font-weight: bold;"&gt;ensureMinFPS()&lt;/span&gt; and &lt;span style="font-weight: bold;"&gt;ensureMaxFPS()&lt;/span&gt; functions. This can be done by skipping calls too &lt;span style="font-weight: bold;"&gt;render()&lt;/span&gt; function, also known as frame skipping.&lt;br /&gt;&lt;br /&gt;That means we update status like 3 times but only draw it once onto the screen. The result is that the sprite may seem to be moving with large steps and may damage smoothness. But that’s the PC's problem nothing to do with us. Also we could add a convenience method &lt;span style="font-weight: bold;"&gt;getCurrentFPS()&lt;/span&gt;, just to check the performance.&lt;br /&gt;&lt;br /&gt;2)    For animating a moving object like a man, we’ll have to cycle through a set of images…&lt;br /&gt;This requires some handling which is again redundant. So we’ll add &lt;span style="font-weight: bold;"&gt;AnimatedSprite &lt;/span&gt;class. This class may contain methods such as &lt;span style="font-weight: bold;"&gt;addFrame(Image img, long persistenceTime);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We’ll extend this class with Renderable.class so that its update and render methods can be utilized by the Game.class when registered with it.&lt;br /&gt;&lt;pre name="code" class="java"&gt;@Override&lt;br /&gt;public void update(long time)&lt;br /&gt;{&lt;br /&gt;Image curFrame = frames.get(curFrameIndex);&lt;br /&gt;animTime += elapsedTime;&lt;br /&gt;&lt;br /&gt;if(animTime &gt;= curFrameduration)&lt;br /&gt;{&lt;br /&gt; curFrameIndex++;&lt;br /&gt;&lt;br /&gt; //provides roll-over for animTime accurately...&lt;br /&gt; animTime = animTime % curFrame.duration;&lt;br /&gt;                    &lt;br /&gt; if(curFrameIndex == frames.size())&lt;br /&gt;     curFrameIndex = 0;      &lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;But sprites can move to...So we could use xSpeed, ySpeed and update them using:&lt;br /&gt;&lt;pre name="code" class="java"&gt;xPos += xSpeed * (elapsedTime);&lt;br /&gt;yPos += ySpeed * (elapsedTime);&lt;br /&gt;&lt;/pre&gt;this xPos and yPos could be utilized in render()&lt;br /&gt;drawImage(getCurFrame() ,xPos,yPos);&lt;br /&gt;&lt;br /&gt;Now re-run your code again. This time when you add sufficient renderable objects to your game, you’ll notice Overlapping.&lt;br /&gt;&lt;br /&gt;i.e., the object added first is drawn first…&lt;br /&gt;how will it seem if the graphics of a tree is being drawn after drawing man??&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_7xvr19hYuG4/SQjiI2KO9oI/AAAAAAAAAA8/6gSIe9rlKUs/s1600-h/overlaps.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 199px;" src="http://4.bp.blogspot.com/_7xvr19hYuG4/SQjiI2KO9oI/AAAAAAAAAA8/6gSIe9rlKUs/s320/overlaps.JPG" alt="" id="BLOGGER_PHOTO_ID_5262704806187693698" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;Forgive me for my crappy drawing…that’s the best I can come up with!&lt;br /&gt;The problem occurs because in run() method of Game.class, we use:&lt;br /&gt;&lt;pre name="code" class="java"&gt;for(int i=0 to numRenderable)&lt;br /&gt;{&lt;br /&gt;arrRenderable.get(i).update(curTime - prevTime);&lt;br /&gt;arrRenderable.get(i).render();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;avoid this we could modify addRenderableObject as&lt;br /&gt;&lt;pre name="code" class="java"&gt;//image with smallest index is drawn 1st…&lt;br /&gt;addRenderableObject (Renderable rend, int index)&lt;br /&gt;{&lt;br /&gt;arrRenderable.add(rend, index);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Now that the drawing order can be determined, overlapping won’t be a problem.&lt;br /&gt;&lt;br /&gt;So far we have managed:&lt;br /&gt;-    Screen management, ensure min frame rate, a generic Renderable class that can be used with Game class followed by easier Animation handling.&lt;br /&gt;&lt;br /&gt;Now imagine that you’re coding the game using THIS framework, suppose the game works on 500 images…you probably will have to load all the images @ startup and show a progress bar like loading or something…Now we’ll integrate this feature into this framework&lt;br /&gt;&lt;br /&gt;Lets design a class called ResourceBox, that holds all the images.&lt;br /&gt;&lt;pre name="code" class="java"&gt;public abstract class ResourceBox&lt;br /&gt;{&lt;br /&gt;Private HashMap hm = new HashMap();&lt;br /&gt;&lt;br /&gt;//this is where you’ll load all the images…or ne other stuff&lt;br /&gt;Public abstract void init();&lt;br /&gt;&lt;br /&gt;Public void add(String id, Image img)&lt;br /&gt;{&lt;br /&gt;   hm.put(id, img);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//methods such as remove, replace and so on…&lt;br /&gt;//Include a method getImage(String Id)&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;We first create a ResourceBox object as:&lt;br /&gt;&lt;pre name="code" class="java"&gt;ResourceBox rb = new ResourceBox()&lt;br /&gt;{&lt;br /&gt;@Override&lt;br /&gt;Public void init()&lt;br /&gt;{&lt;br /&gt;    //Load whatever resources you want…&lt;br /&gt;    //Ex – add(“man”, imgMan);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Remember the Game class…?&lt;br /&gt;How do we register this object with the game class??&lt;br /&gt;&lt;pre name="code" class="java"&gt;Game(ResourceBox rb)&lt;br /&gt;{&lt;br /&gt;//Copy this ref into a private variable within game class&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;This is how the game would run previously:&lt;br /&gt;&lt;pre name="code" class="java"&gt;run()&lt;br /&gt;{&lt;br /&gt;Init();&lt;br /&gt;Game loop&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Here we plug in a bit of code:&lt;br /&gt;&lt;pre name="code" class="java"&gt;run()&lt;br /&gt;{&lt;br /&gt;Init();&lt;br /&gt;If(rb != null)&lt;br /&gt;    rb.init();&lt;br /&gt;Game loop&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Also we’ll add a utility method to game class as:&lt;br /&gt;&lt;pre name="code" class="java"&gt;public ResourceBox getResourceBox();&lt;br /&gt;&lt;/pre&gt;This method is needed as we could use:&lt;br /&gt;&lt;pre name="code" class="java"&gt;Image man = gameObj.getResourceBox().get(“man”);&lt;br /&gt;&lt;/pre&gt;Cool eh?&lt;br /&gt;&lt;br /&gt;What about the progress bar??&lt;br /&gt;We can’t provide an implementation as it would restrict the user from customizing/ making his own style of progress bar. More-over the user defined Loading screen or whatever must be shown when &lt;span style="color: rgb(204, 102, 0);"&gt;rb.init()&lt;/span&gt; method is called.&lt;br /&gt;&lt;br /&gt;We’re gonna try some sort of an event listener kinda thingy. Here goes:&lt;br /&gt;&lt;br /&gt;Include a method in ResourceBox.class&lt;br /&gt;&lt;pre name="code" class="java"&gt;public void registerListener(Listener l);&lt;br /&gt;&lt;br /&gt;//This is how Listener’s defined&lt;br /&gt;Public class Listener&lt;br /&gt;{&lt;br /&gt;Public abstract void onInit(Graphics g);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;First of all user’s gotta create an obj of Listener class for which you HAVE TO override the &lt;span style="font-weight: bold;"&gt;onInit()&lt;/span&gt; method&lt;br /&gt;&lt;pre name="code" class="java"&gt;Listener l = new Listener()&lt;br /&gt;{&lt;br /&gt;@Override&lt;br /&gt;Public void onInit(Graphics g)&lt;br /&gt;{&lt;br /&gt;    //Draw your stuff on this graphics context…&lt;br /&gt;    //Ex = ((Graphics2D)g).do any thing();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Now we’ll also include a method getRegisteredListener() in ResourceBox.class&lt;br /&gt;We now modify the game class run method as follows:&lt;br /&gt;&lt;pre name="code" class="java"&gt;run()&lt;br /&gt;{&lt;br /&gt;Init();&lt;br /&gt;if(rb != null)&lt;br /&gt;{&lt;br /&gt;   Listener l = rb.getRegisteredListener();&lt;br /&gt;   If(l != null)&lt;br /&gt;   {&lt;br /&gt;       // Assuming we have some hypothetical screen management class&lt;br /&gt;       Graphics g = ScreenManager.getGraphics();&lt;br /&gt;       l.onInit(g);&lt;br /&gt;   }&lt;br /&gt;   rb.init();&lt;br /&gt;   g.dispose();// or clear…&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Game loop&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Now user can show a progress bar or…loading screen with his/her own graphics style…&lt;br /&gt;So here’s a short summary,&lt;br /&gt;&lt;br /&gt;-    Abstract methods and stuff is absolutely integral in designing a good framework&lt;br /&gt;(Primarily to give user the control of things, just as swing lets us control the shape of a button)&lt;br /&gt;&lt;br /&gt;-    You might need event listeners in case where your internal handling code needs to call something…like the &lt;span style="font-weight: bold;"&gt;onInit()&lt;/span&gt;&lt;span style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;we just discussed (swing provides action listeners etc…to a button which are automatically called on mouse click on that component, hope you can associate this with the &lt;span style="font-weight: bold;"&gt;onInit()&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;-    Let your imagination run wild…experiment, try, you’ll eventually be able to write the top notch code. Okay, enough philosophy I suppose lets move further.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Go back to step 2:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The best way to add new feature(s) to your framework is like I said can be done by imagining the usage. So let’s start with some analysis...how do we integrate sounds? After all any game would suck without sounds…&lt;br /&gt;&lt;br /&gt;In my next blog I’ll put up a nice UML diagram of the concepts so far and also discuss sound integration. As always, do comment and help me improve my posts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-5421503116526692534?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2008/10/understanding-frameworks-by-example2_30.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_7xvr19hYuG4/SQjiI2KO9oI/AAAAAAAAAA8/6gSIe9rlKUs/s72-c/overlaps.JPG' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-689000895995978913.post-3876318319401034280</guid><pubDate>Thu, 25 Sep 2008 23:02:00 +0000</pubDate><atom:updated>2009-06-07T14:33:48.973+05:30</atom:updated><category domain='http://www.blogger.com/atom/ns#'>java</category><category domain='http://www.blogger.com/atom/ns#'>framework</category><category domain='http://www.blogger.com/atom/ns#'>OOP</category><title>Understanding Frameworks by example...1</title><description>You all must have heard about it, .Net, Swing etc.&lt;br /&gt;So what exactly is this ‘framework’?&lt;br /&gt;&lt;br /&gt;Simply put, it is a set of properly organized classes and packages with many features to offer.&lt;br /&gt;In case you want to make one, proper planning and design is a must.&lt;br /&gt;&lt;br /&gt;lets take the well known ‘swing ‘ in java&lt;br /&gt;To create a frame all we gotta do is:&lt;br /&gt;&lt;pre name="code" class="java"&gt;new JFrame().setVisible();&lt;br /&gt;&lt;/pre&gt;If I remember correctly, using windows.h in c++ we need to write a 100+ lines of code just to do that. Creating a simple frame involves registering the handleInstance and some other init steps. Moreover its just a simple frame. It we wanted to add a label to it, it’d take another 20-40 lines to do that. In swing its as simple as:&lt;br /&gt;&lt;pre name="code" class="java"&gt;frame.add(new JLabel());&lt;br /&gt;&lt;/pre&gt;In a sense most of the code is redundant (no one remembers all that init code, they just copy, paste it and modify it at a few places). That’s where a framework is needed. To avoid redundant stuff and provide several layers of abstraction over the inner mess that’s going on.&lt;br /&gt;&lt;br /&gt;Also swing manages repaints very cleverly, suppose we have a frame with blue background and a label with green background. Then the background is to be drawn first onto the screen followed by drawing the label. What’s more, it provides a lot of customization which could be achieved by over-ridding a few key methods.&lt;br /&gt;&lt;br /&gt;For example to make the button round all you gotta do is over-ride the necessary shaping method that swing calls internally to display a button.&lt;br /&gt;&lt;br /&gt;Now if you’re up to it lets try to design a 2D game framework.&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 1: Identify the requirements&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So what could we do to simplify 2D game designing??&lt;br /&gt;Here’s a few that I figured&lt;br /&gt;&lt;br /&gt;1) Screen management (change resolution, manage double buffering etc…)&lt;br /&gt;2) Input management (Keyboard polling and mapping)&lt;br /&gt;3) Animations Management (sprite handling)&lt;br /&gt;4) Sound management (sound effect and stuff)&lt;br /&gt;&lt;br /&gt;There are many more to it but I’d like to keep it simple&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Step 2: Imagine the usage&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;For a moment let us assume that the framework is designed.&lt;br /&gt;Then how would it help simplifying game programming??&lt;br /&gt;&lt;br /&gt;First we’ll discuss a few basics of game programming&lt;br /&gt;This is typically called ‘The game loop’&lt;br /&gt;&lt;pre name="code" class="java"&gt;loop&lt;br /&gt;{&lt;br /&gt;//Update status of the game objects&lt;br /&gt;//Render graphics onto the screen(typically by using double buffering)&lt;br /&gt;&lt;br /&gt;//Provide a certain delay…so that the game doesn’t seem to be&lt;br /&gt;//Running like a cheetah&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;As most of you might have already faced, this poses a severe problem...the delay is the villain here. The game runs at different speeds on different processors because of variable instruction execution speed but a fixed delay. To prevent this, we synchronize the events to a global Timer&lt;br /&gt;&lt;pre name="code" class="java"&gt;prevTime = getTimeInNanos();&lt;br /&gt;loop&lt;br /&gt;{&lt;br /&gt;curTime = getTimeInNanos();&lt;br /&gt;//Update status of the game objects using (curTime – prevTime)&lt;br /&gt;//Render graphics onto the screen&lt;br /&gt;prevTime = curTime;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;getTimeInNanos() returns an arbitrary timer, it can be the bios timer ticks or OS dependent timer. In JAVA one could use System.nanoTime()&lt;br /&gt;&lt;br /&gt;And what about pausing and resuming the game??&lt;br /&gt;The threads sleep and notify needs to be handled within the loop itself&lt;br /&gt;&lt;br /&gt;Also we should provide a way to handle screen resolution change…&lt;br /&gt;Also to avoid flickering double buffering must be done&lt;br /&gt;Most of this is almost a necessity to be handled and furthermore this stuff is redundant&lt;br /&gt;So we could add all these features into a class, lets call it Game&lt;br /&gt;&lt;pre name="code" class="java"&gt;public abstract class Game extends Thread&lt;br /&gt;{&lt;br /&gt;Public abstract void init();&lt;br /&gt;public void startGame();&lt;br /&gt;public void stopGame();&lt;br /&gt;public void pauseGame();&lt;br /&gt;public void resumeGame();&lt;br /&gt;public void setScreenRes(int width, int height) throws NotSupportedResException&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;init method is supplied as abstract so that user may customize it to his needs. All the Renderable objects (sprites as a few call it) have the update() and render() associated with it. So why not make a class called &lt;span style="font-weight: bold;"&gt;Renderable&lt;/span&gt; as:&lt;br /&gt;&lt;pre name="code" class="java"&gt;public abstract class Renderable&lt;br /&gt;{&lt;br /&gt;//update status calculations here…parameter time is the num of seconds elapsed since&lt;br /&gt;//last call&lt;br /&gt;Public void abstract update(long time);&lt;br /&gt;&lt;br /&gt;//all the graphics are to be drawn onto this graphics object…&lt;br /&gt;public void abstract render(Graphics g);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Using abstract methods one of the most commonly used techniques in JAVA.&lt;br /&gt;With this you tell the user to over-ride these methods in order to be used…&lt;br /&gt;(Instead of telling them to create a class which HAS TO contain update(long) and render() functions, which would in turn be used for internal purposes)&lt;br /&gt;&lt;br /&gt;Then we could do:&lt;br /&gt;&lt;pre name="code" class="java"&gt;game.addRenderableObject(rendObj);&lt;br /&gt;&lt;/pre&gt;and in the Game class we could use:&lt;br /&gt;&lt;pre name="code" class="java"&gt;private Arraylist arrRenderable;&lt;br /&gt;addRenderableObject(Renderable rend)&lt;br /&gt;{&lt;br /&gt;arrRenderable.add(rend);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;the run() in Game can be coded to handle thread start,stop,resume,pause and automatically calls all the registered Renderable objects update and render methods…&lt;br /&gt;this is what how run() would look like:&lt;br /&gt;&lt;pre name="code" class="java"&gt;public void run()&lt;br /&gt;{&lt;br /&gt; init();&lt;br /&gt; prevTime = getTimeMillis();&lt;br /&gt;&lt;br /&gt; while(!isStopped)&lt;br /&gt; {&lt;br /&gt;     curTime = getTimeMillis() - pausedTime;&lt;br /&gt;     pausedTime = 0;&lt;br /&gt;&lt;br /&gt;     for(int i=0 to numItemsRegistered) &lt;br /&gt;     {&lt;br /&gt;         arrRenderable.get(i).update(curTime - prevTime);&lt;br /&gt;         arrRenderable.get(i).render();&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     if(isPaused)&lt;br /&gt;     {&lt;br /&gt;         pausedTime = getTimeMillis();&lt;br /&gt;         while(isPaused)&lt;br /&gt;         {&lt;br /&gt;             Graphics g = screen.getGraphics();&lt;br /&gt;             screen.drawFrameContents(g);&lt;br /&gt;             g.dispose();&lt;br /&gt;             scr.updateGraphics();&lt;br /&gt;         }&lt;br /&gt;         pausedTime = getTimeMillis() - pausedTime;            &lt;br /&gt;     }    &lt;br /&gt;     prevTime = curTime;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void pauseGame()&lt;br /&gt;{&lt;br /&gt; isPaused = true;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void stopGame()&lt;br /&gt;{&lt;br /&gt; isStopped = true;&lt;br /&gt;}    &lt;br /&gt;&lt;/pre&gt;Hope you got the whole picture here…&lt;br /&gt;I suppose that’s enough stuff for now, I’ll add more in my next post. Do comment…&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689000895995978913-3876318319401034280?l=ragha-infomaniac.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ragha-infomaniac.blogspot.com/2008/09/understanding-frameworks_25.html</link><author>ragha_unique2000@yahoo.com (Ragha)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item></channel></rss>