Reality is a perception. Perceptions are not always based on facts, and are strongly influenced by illusions. Inquisitiveness is hence indispensable

Saturday, December 22, 2007

Xbox 360

I bought a xbox 360, never thought that it should be blogged :) I am doing it anyway. The seventh generation of consoles are absolute number crunchers. If any one has worked on a graphics program like adobe photoshop or gimp, they would understand it. Most computers of yester years were good at things like browsing, drafting documents and playing media files. The graphic programers always went for a extra special offering called apple. Any good rendering involves operations that are cpu hungry and memory hungry. Now a days the chasm is being bridged but the divide still exists.

Coming back, the xbox sits like a cute little puppy in the drawing room just beneath the TV. It at time looks melancholic as well. All this changes in a spur of a moment, just switch on the power and insert your favourite game (mine being Gears of war). There is no thunder or lightning, apart from the noise made by the cooling unit. The graphics and visual effects at times dazzle me. I often wonder whose idea was the rocking controller. I have a strong feeling that the 3.2 Ghz 6 core machine will stay with me for a long time.

Jibx with Netbeans

There are times when we face the need to marshall and unmarshall java objects. What better than XML for this! Most programmers can write their own XML parsers and unparsers, why do that when we have a beautiful utility tool. Infact there are several tools. Jibx is one of them, it is offers better performance than many other rivals by using the pull-event mechansim, to top that it is free for use and opensourced. Jibx essentially asks the users to provide a mapping between java objects and xml data. This mapping is provided by users in form of xml file. Lets call it binding xml. Then the users are asked to compile the the project and compile the bindings. The byte code is modified (another reason for the high performance) during this process.

A sample code snippet:
##############################

package ajibx_learning;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ResourceBundle;

import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;


public class Main {
/**
* Unmarshal the sample document from a file, then marshal it back out to
* another file.
*/
public static void main(String[] args) {
String ajibxProperties = "ajibx_learning.bizProperties";
String fileInput = "fileOutput";
String fileOutput = "fileInput";
String className = "className";
File fOut = null;
File fIn = null;
Object bean = null;
try {

ResourceBundle rbundle = ResourceBundle.getBundle(ajibxProperties);

fOut = new File(rbundle.getString(fileInput));
fIn = new File(rbundle.getString(fileOutput));
Class c = Class.forName(rbundle.getString(className));
bean = c.newInstance();
} catch (Exception ex) {
ex.printStackTrace();
System.out.print("Exiting ...");
return;
}
System.out.print("Unmarshalling ...");
// unmarshal customer information from file
bean = unMarshall(fIn, bean);
// you can add code here to alter the unmarshalled customer
System.out.print("marshalling ...");
// marshal object back out to file (with nice indentation, as UTF-8)
marshall(bean, fOut);
}

public static Object unMarshall( File fileIn, Object bean){
boolean status = true;
try {
// note that you can use multiple bindings with the same class, in
// which case you need to use the getFactory() call that takes the
// binding name as the first parameter
Class beanClass = bean.getClass();
IBindingFactory bfact = BindingDirectory.getFactory(beanClass);
// unmarshal customer information from file
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
if(!fileIn.exists()) {
System.out.println("File doesnt' exist: "+fileIn.getAbsoluteFile());
return status=false;
}
FileInputStream in = new FileInputStream(fileIn);
bean = uctx.unmarshalDocument(in, null);
in.close();
} catch(Exception e){
status = false;
e.printStackTrace();
} finally {
if(status)
return bean;
else
return null;
}

}

public static boolean marshall( Object bean, File fileOut){
boolean status = true;
try {
// note that you can use multiple bindings with the same class, in
// which case you need to use the getFactory() call that takes the
// binding name as the first parameter
Class beanClass = bean.getClass();
IBindingFactory bfact = BindingDirectory.getFactory(beanClass);
// marshal object back out to file (with nice indentation, as UTF-8)
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.setIndent(2);
if(fileOut.exists()){
fileOut.delete();
}
if(fileOut.createNewFile()) {
System.out.println("Creating file: "+fileOut.getAbsoluteFile());
}
else {
System.out.println("Failed to create file: "+fileOut.getAbsoluteFile());
return status=false;
}
FileOutputStream out = new FileOutputStream(fileOut);
mctx.marshalDocument(bean, "UTF-8", null, out);
out.flush();
out.close();
} catch(Exception e) {
status = false;
e.printStackTrace();
} finally {
return status;
}
}
}
###############################

I decided to use the following properties file
#bizProperties.properties
# the input file is the source of xml data
fileInput = D:\\temp\\jibx-gen\\Example1.xml
# the outfile is written by the program
fileOutput = D:\\temp\\jibx-gen\\Gen-Example1_2.xml
# the bean which I intended to use
className = beandef.Person
###############################

I then decided to use the good old 'ant' script to compile this. The issue with ant scripts was that, the code cannt be debugged straight away in IDE. So, I decided to have look at the IDE generated ant script. This itself deserved another posting!!. The expressive power of ant is better illustrated in such examples. The modifications done to build.xml are given below. Note that I was using Netbeans5.5.1
##############################

blah blah of netbeans...
Please replace < with <

<!-- modified for the sake of Jibx bindings -->
<property file="nbproject/buildExample1.properties"/>
<!-- JiBX binding compiler task definition -->

<taskdef name="bind" classname="org.jibx.binding.ant.CompileTask" classpath="${file.reference.jibx-bind.jar}"></taskdef>
<!--
-->
<target name="-post-compile">
<echo message= "${file.reference.jibx-bind.jar}" >
</echo>

<!-- Run JiBX binding compiler -->
<bind verbose="true" load="true" >
<classpath path="${run.classpath}"></classpath>
<bindingfileset dir="${binding.dir}" includes="${binding.filenamepattern}" >
</bindingfileset>
</bind>

</target>
</project>
</quote>
###################################

The modifications are done to the "-post-compile" target. The prefix "-" indicates that this target cannot be called directly. This also uses a "buildExample1.properties" file. The binding information is given this file. The bindings are compiled using this information. In case you are perplexed, the actual information for build is given in build-impl.xml. The build.xml is just a wrapper. Some of the tasks are exposed to the user for allowing customisation and in this case "-post-compile" was choosen.
The contents of buildExample1.properties:
##################################
# The directory containing binding files
binding.dir= D:\\temp\\jibx-gen
# for nested files use **/*binding*.xml, for this example we dont' need it
binding.filenamepattern = *binding*.xml
###################################
The complete code for bean and xml used are also given
##############################
package beandef;

import beandef.Address;

public class Person {
private String name;
private String surname;
private Address address;
/** Creates a new instance of Person */
public Person() {
}

}

package beandef;

public class Address {

private String houseno, street1, street2;
/** Creates a new instance of Address */
public Address() {
}

}
##################################
A good source for learning jibx is http://jibx.sourceforge.net/tutorial/binding-tutorial.html. The above mechanism shows how we can debug projects using netbeans even when there is a need for custom ant tasks.

Saturday, December 1, 2007

The 'Stig' factor - Philosophy

What is Stig factor?
ZEN>>Isolation but observation. Visibility in Invisibility.

Why do I need to know this?
ZEN>> Because Top-gear has this. Because this is the ultimate truth (well a step short of if there is one). Because you asked me. And if you think zen doesnt' involve one thinking of Aston martins, you are wrong. It is always about things like Spider vs. Beetle in the parking lot. I like both of them by the way.

Master explain this in simple English to us 'not so crazy nuts'
ZEN>> Now that you have asked. In this world all entities are related. Some call it 'Butterfly effect'. This association is responsible for all joys and sorrows. Now wise men and truth seekers, who have realized this truth wanted to let others escape the miseries offered by this cruel life. They came up with an brilliant suggestion. That speaks of:
1. Association to disassociation
2. The hardships in breaking all bonds to keep a single bond.

Master but I am a simple programmer
ZEN>> Thats what they said when they came to me. They were simple tv program producers. I still remember that as if it were yesterday.

Master, but who said that
ZEN>> The top-gear chaps of course. They were very concerned about the presenters being more popular than the show. There was a bloke called Gerome clarkson who has nasty prejudice against general motors you know. They wanted some thing which is immune to change. So they brought in Stig. You can realise more about him from http://en.wikipedia.org/wiki/The_Stig . You see there was more than one stig but there is only one stig.

Oh, the zen factor. Things may change but the conception is unique. This what decoupling between modules means
ZEN>> Excellent, now meditate more about decoupling between modules and data bases. One can easily say that data bases are similar to modules with a different avatar. The trick is to store the mapping away from the modules. The modules change but the mapping rarely does. Even if it does you can easily adapt the mapping to the discovered truth

Saturday, November 17, 2007

Autumn in Leeds

Autumn wind in Yorkshire Leeds, cold chill within causes fluttering leaves,
Stands a tree painting tarmac in orange, awaiting the forgotten spring,
She hopes for new life, and the cost she pays is the misery she paints,
A splendid lass baring robes for her new-born, such scene, is it obscene?

Thursday, November 8, 2007

Learning languages

This article is an extract from
http://www.fourhourworkweek.com/blog/2007/11/07/how-to-learn-but-not-master-any-language-in-1-hour-plus-a-favor/



The content copied for ease of lazy few :) Credits to the guy who wrote it




How to Learn (But Not Master) Any Language in 1 Hour (Plus: A Favor)

Filling the Void, Language

arabic-script.jpg
Deconstructing Arabic in 45 Minutes

deconstructing-russian.jpg
Conversational Russian in 60 minutes?

This post is by request. How long does it take to learn Chinese or Japanese vs. Spanish or Irish Gaelic? I would argue less than an hour.

Here’s the reasoning…

Before you invest (or waste) hundreds and thousands of hours on a language, you should deconstruct it. During my thesis research at Princeton, which focused on neuroscience and unorthodox acquisition of Japanese by native English speakers, as well as when redesigning curricula for Berlitz, this neglected deconstruction step surfaced as one of the distinguishing habits of the fastest language learners.

So far, I’ve deconstructed Japanese, Mandarin Chinese, Spanish, Italian, Brazilian Portuguese, German, Norwegian, Irish Gaelic, Korean, and perhaps a dozen others. I’m far from perfect in these languages, and I’m terrible at some, but I can converse in quite a few with no problems whatsoever—just ask the MIT students who came up to me last night and spoke in multiple languages.

How is it possible to become conversationally fluent in one of these languages in 2-12 months? It starts with deconstructing them, choosing wisely, and abandoning all but a few of them.

Consider a new language like a new sport.

There are certain physical prerequisites (height is an advantage in basketball), rules (a runner must touch the bases in baseball), and so on that determine if you can become proficient at all, and—if so—how long it will take.

Languages are no different. What are your tools, and how do they fit with the rules of your target?

If you’re a native Japanese speaker, respectively handicapped with a bit more than 20 phonemes in your language, some languages will seem near impossible. Picking a compatible language with similar sounds and word construction (like Spanish) instead of one with a buffet of new sounds you cannot distinguish (like Chinese) could make the difference between having meaningful conversations in 3 months instead of 3 years.

Let’s look at few of the methods I recently used to deconstructed Russian and Arabic to determine if I could reach fluency within a 3-month target time period. Both were done in an hour or less of conversation with native speakers sitting next to me on airplanes.

Six Lines of Gold

Here are a few questions that I apply from the outset. The simple versions come afterwards:

1. Are there new grammatical structures that will postpone fluency? (look at SOV vs. SVO, as well as noun cases)

2. Are there new sounds that will double or quadruple time to fluency? (especially vowels)

3. How similar is it to languages I already understand? What will help and what will interfere? (Will acquisition erase a previous language? Can I borrow structures without fatal interference like Portuguese after Spanish?)

4. All of which answer: How difficult will it be, and how long would it take to become functionally fluent?

It doesn’t take much to answer these questions. All you need are a few sentences translated from English into your target language.

Some of my favorites, with reasons, are below:

The apple is red.
It is John’s apple.
I give John the apple.
We give him the apple.
He gives it to John.
She gives it to him.

These six sentences alone expose much of the language, and quite a few potential deal killers.

First, they help me to see if and how verbs are conjugated based on speaker (both according to gender and number). I’m also able to immediately identify an uber-pain in some languages: placement of indirect objects (John), direct objects (the apple), and their respective pronouns (him, it). I would follow these sentences with a few negations (“I don’t give…”) and different tenses to see if these are expressed as separate words (“bu” in Chinese as negation, for example) or verb changes (“-nai” or “-masen” in Japanese), the latter making a language much harder to crack.

Second, I’m looking at the fundamental sentence structure: is it subject-verb-object (SOV) like English and Chinese (“I eat the apple”), is it subject-object-verb (SOV) like Japanese (“I the apple eat”), or something else? If you’re a native English speaker, SOV will be harder than the familiar SVO, but once you pick one up (Korean grammar is almost identical to Japanese, and German has a lot of verb-at-the-end construction), your brain will be formatted for new SOV languages.

Third, the first three sentences expose if the language has much-dreaded noun cases. What are noun cases? In German, for example, “the” isn’t so simple. It might be der, das, die, dem, den and more depending on whether “the apple” is an object, indirect object, possessed by someone else, etc. Headaches galore. Russian is even worse. This is one of the reasons I continue to put it off.

All the above from just 6-10 sentences! Here are two more:

I must give it to him.
I want to give it to her.

These two are to see if auxiliary verbs exist, or if the end of the each verb changes. A good short-cut to independent learner status, when you no longer need a teacher to improve, is to learn conjugations for “helping” verbs like “to want,” “to need,” “to have to,” “should,” etc. In Spanish and many others, this allows you to express yourself with “I need/want/must/should” + the infinite of any verb. Learning the variations of a half dozen verbs gives you access to all verbs. This doesn’t help when someone else is speaking, but it does help get the training wheels off self-expression as quickly as possible.

If these auxiliaries are expressed as changes in the verb (often the case with Japanese) instead of separate words (Chinese, for example), you are in for a rough time in the beginning.

Sounds and Scripts

I ask my impromptu teacher to write down the translations twice: once in the proper native writing system (also called “script” or “orthography”), and again in English phonetics, or I’ll write down approximations or use IPA.

If possible, I will have them take me through their alphabet, giving me one example word for each consonant and vowel. Look hard for difficult vowels, which will take, in my experience, at least 10 times longer to master than any unfamiliar consonant or combination thereof (”tsu” in Japanese poses few problems, for example). Think Portuguese is just slower Spanish with a few different words? Think again. Spend an hour practicing the “open” vowels of Brazilian Portuguese. I recommend you get some ice for your mouth and throat first.

russian-alphabet.jpg
The Russian Phonetic Menu, and…

reading-real-russian.jpg
Reading Real Cyrillic 20 Minutes Later

Going through the characters of a language’s writing system is really only practical for languages that have at least one phonetic writing system of 50 or fewer sounds—Spanish, Russian, and Japanese would all be fine. Chinese fails since tones multiply variations of otherwise simple sounds, and it also fails miserably on phonetic systems. If you go after Mandarin, choose the somewhat uncommon GR over pinyin romanization if at all possible. It’s harder to learn at first, but I’ve never met a pinyin learner with tones even half as accurate as a decent GR user. Long story short, this is because tones are indicated by spelling in GR, not by diacritical marks above the syllables.

In all cases, treat language as sport.

Learn the rules first, determine if it’s worth the investment of time (will you, at best, become mediocre?), then focus on the training. Picking your target is often more important than your method.

[To be continued?]

###

Is this helpful or just too dense? Would you like me to write more about this or other topics? Please let me know in the comments. Here’s something from Harvard Business School to play with in the meantime…

###

Odds and Ends:

Please help me break the Technorati 1000 today!

I’m around 1070 on Technorati’s rankings, and it’s killing me. Can those of you with blogs PULEEEEASE register your blogs with Technorati and find something interesting to link to on this 4HWW blog? It would really be a milestone for me and I’m so close! Just breaking 1000 would be enough. If you can find something to link to in the most popular posts or elsewhere, please do whatever you can in the next 24-36 hours! Thanks so much :)

Wednesday, November 7, 2007

Ratatouille - Any one can cook!

Movies have always been an amusing ways of selling dreams. I have recently seen a magic lantern titled ratatouille. It is far from the Oscars, (probably will get one) definitely doesn’t' strain your tear glands nor stain your hankies. Ratatouille is a fascinating way of reminding ourselves the age old art of story telling. Think of the Red-Indian rituals, Neanderthal cave paintings and even beyond to the point where early humanoids were amusing themselves with the primitive usage of oral communication. Pixar and Disney have mastered this art. The art of story telling is no longer a ritual, I feel sorry for that. It lives thanks to corporate exploitation of childish dreams. Who said capitalism is evil :)


The story is about a rodent hero. The one who resembles more like R2D2 than Keanu reaves. The plot is simple. The hero fulfils his dream!. The dream of savouring food in Gusteaus, a french restaurant. The way the story unfolds brings some childhood memories out. Running around kitchen, doing a shelock holmes with the whole and sole intention of finding the hidden delicacies. Aah, good times weren’t' they.

The more reminiscent words I liked were those of the antagonist Anton Ego voiced by Peter O'tole. Ego relives Gusteau’s words 'Any one can cook'. He rephrases the finer nuance and articulately gives out his criticism during at the climax. Anton declares onerous in a tone that undermines Zen masters and Yoda; that a cook can come from any where and not the superficial interpretation given to the words.

The art of oration put together with some fantastic graphics is something one shouldn’t' miss. This is one fantastic package put forth for audience of all ages.

Tuesday, October 30, 2007

Creative thinkers and Day dreamers

Creative thinking or out of box thinking is normally encouraged in technical and artisitc streams, but discouraged in managerial discipline. http://en.wikipedia.org/wiki/Peter_Principle has a good explanation of this. Creative thinking helps individuals and organisations. People raise the bar even when the results end in a catastrophy. The gains at times may be paltry but the learning is invalueable. Coupled with some pedagogic skills such a learning becomes an asset in times to come. Unfortunately, creative thinking cannot be imbibed. It is inherently psychlogical. The inquisitive nature seen in children when groomed well forms the foundation for this.

So the next time a child asks why he doesnt' have a moustache or where babies come from. Try to be creative enough to answer. Afterall child is the father of man.

Try googling for Gordian Knot, Egg of Columbus for more insights. The structure of Benzene as proposed by kekulle is another outstanding example.

Tuesday, October 23, 2007

'Memory'able Dilema

Dear God, Father of all electronic, electrical, magnetic, optical, semiconductor appliances. Conserver of all software applications built around boolean and binary representation. Help me out of dilema.

Should I opt for an 4 Gb flash drive or a 160 Gb passport hdd or a 500 Gb hdd. Give me the wisdom and guidance.

P.s: At the same time have a look at the Canon S5IS and Sony DSC-H9, so that you can let me make a decison.

Static imports

Himanshu was speaking of static imports in Jdk 5. Not surprisingly, I had something to learn over here too. Jdk 5 has come up with a feature for importing static variables; the fact that the same is applicable to methods and object references was news for me. I never thought of it before. What are the implications? Well like every feature and tool this adds a new destructive angle to the object oriented paradigm. It is better not to teach static imports to beginners. (Hey this is my blog.. don’t' contest).

With access specifiers of type 'public final static' there is no problem at all. Essentially making imported entities read only. But if we have a static object reference or method, the object oriented ness is lost. The static methods themselves are stateless. The seemingly non-object oriented way of accessing methods and references is what concerns me. The static methods themselves are stateless. We have discussed their usage in a earlier blog. The static references and methods are more of a concern to me.

These are most often seen in large scale programming applications. To start of 'Singleton' pattern is one of the most popular patterns built around static reference concept. 'Factory' pattern is another example of using static methods. The fact that

, some crazy guy wants to increase performance sends jitters.(by changing the access specifier to public, use static imports and invoke the functionality, and thus save a 'precious' method call). Do we break the paradigm for the sake of small performance gains?

All said, this adds more emphasis on code reviews and another aspect to the taken care of when carrying out code reviews.

Sunday, September 2, 2007

In Leeds

I have reached Leeds on 2nd August. Exactly 29 days passed by the time of writing this post. Leeds falls into the Midlands, precisely West-yorkshire. English weather, even in August carries a chill around, probably reminding the people around that summer is about to end.

You cannt' resist but observe the spacious dwellings and well organised parking arrangements, (especially coming from Indian cities, quite a contrast). UK is quite a place. The food, football, folks every thing and every one you come across carry a distinctly familiar undercurrent. The tallest building in Leeds is the 32 storied bridge waters buildling. It is close to the city center - a 15 min walk.

The city center is a lively place. The universities, shopping centers, Train station, bus stand all make the experience satiating. I didnt' get a chance to go around the city all by myself, but looking forth to do so. Will add more details in later posts.

Thursday, July 5, 2007

ANT TAUNTS

Another Neat Tool is what they say. What’s in the name? Shakespeare should have known better. ANT is a typical tool which comes into minds of java developers when they are supposed to package their goodies. ANT for newcomers is a utility to package, build and deploy user written software. In some sense, it is software written to manage software.
Any reasonably high-level programming language needs a compiler/interpreter. I wont' go into details of compilers/interpreters now. Rather, the focus is on ANT. Some most frequent tasks a programmer needs to do are clean up, rebuild, debug, run, test and deploy the code. The compilers/interpreters provide support for some of these tasks. Some of the tasks are dependent on the operational environment, for e.g. "rm" is used to remove files on unix where as it is "del" on windows. Let us call these "Developers utility tasks" or DUTs.
Writing a script to achieve these tasks is one way of solving this problem. ANT takes this approach further. ANT can be treated as a domain specific language intended todo these DUTs. Usage of ANT, for the most part, is declarative in nature. Essentially you dont' assign values to variables but state the task you want to achieve. It is kind of saying. "ANT, I want to clean up the mess" or "ANT, Can you compile these sources".
In an IDE driven era, most developers are not conversant with ANT. Those who do, don’t' make noise about it. I feel that, knowing how to write a good ANT script is a must for IDE independent development. Let us see a sample ANT example.
There are essentially three areas when it comes to using ANT.1. Having a clear idea of the directory structure. This is simple for most projects. The complex cases involve code level dependencies across projects. Things can be simplified by assuming presence of referred jar files rather than referred source folders. 2. Identifying and Understanding dependencies among tasks which we wish to have. 3. Writing an ANT file and populating the properties file. Properties file is a mechanism that changes a coding problem into a more manageable configuration problem. This simplifies maintenance.A sample directory structure would look like this• Project folder\ant\ • Project folder\lib\ • Project folder\src\ • Project folder\build\ • Project folder\dist\The "ant" folder is supposed to hold ant scripts. The "src" folder is self-explanatory. The "lib" folder is supposed to hold the jars on which the source files have dependency.The "build" folder contains the resultant files after compilation for e.g. ".class" files. The "dist" folder contains the packaged and ready to use bundles or jar files. "build" and "dist" can be generated by ANT and we do so in our exampleSample build.xml, copy it into your favorite editor and reformat it.################################################## < ?xml version="1.0" encoding="UTF-8"? > < project name="SomeProject" default="all" basedir=".." >
< property file="ant\build.properties"/ >
< path id="classpath" > < fileset dir="${lib.dir}"/ > < /path >
< target name="preconditons" > < echo > Displaying properties... < /echo > < echo > ${jar.name} < /echo > < echo > ${basedir} < /echo > < echo > ------------------------------ < /echo > < /target >
< target name="init" depends="preconditons" > < echo > Intializing build process... < /echo > < mkdir dir="${build.dir}" > < /mkdir > < mkdir dir="${dist.dir}" > < /mkdir > < /target >
< target name="clean" > < echo > Cleaning the ${build.dir}... < /echo > < delete dir="${build.dir}"/ > < delete dir="${dist.dir}"/ > < /target >
< target name="compile" depends="init" > < javac srcdir="${src.dir}"destdir="${build.dir}"compiler="${build.compiler}" source="${source.version}"fork="true" executable="${jdk.path}" > < classpath refid="classpath"/ > < /javac > < /target >
< target name="jar" depends="compile" > < jar destfile="${dist.dir}/${jar.name}" basedir="${build.dir}" > < manifest > < attribute name="Main-Class" value="${mainclass.name}"/ > < attribute name="Class-Path" value="${manifest.classpath}"/ > < /manifest > < /jar > < /target >
< target name="run" depends="jar" > < java jar="${dist.dir}/${jar.name}" fork="true" > < /java > < /target >
< target name="clean-build" depends="clean,compile" > < /target >
< target name="dist" depends="jar" > < copy todir="${dist.dir}" > < fileset dir="${lib.dir}" > < /fileset > < /copy > < /target > < target name="all" depends="clean,dist,run" > < /target >
< /project > ##################################################The sample properties file, please reformat the same. Remember to escape spaces using "\"################################################### Properties file jar.name=RunThisClient.jar mainclass.name=client.Main manifest.classpath=Common.jar # Taken care by the project directory structure under base dirbase.dir=.. src.dir=src lib.dir=lib build.dir=build dist.dir=dist # Compiler related informationjdk.path=C:\\Program\ Files\\Java\\jdk1.5.0_10\\bin\\javac build.compiler=javac1.5 source.version=1.5###################################################Try using this as a template and you will see that ANT really doesn’t taunt

Sunday, May 27, 2007

Indian politricks

INDIA: a land of many faces, facets, facts and fantasies. Indian ness is something very mythical. Is it lack of individualism or servitude to collectivism? The very nature of being related to India raises questions in my mind. India is not a perfect nation, No nation in the world is.

Indian politics are one (ugly) aspect that can give an understanding of how the nation thrives. Now whenever a government changes/ about to change. We see the following patterns. The time lines are drawn for upcoming elections. There is an incumbent govt. and some opposition parties. This is extreme simplification; we are ignoring internal boardroom disagreements & other issues. So the incumbent govt. starts its' campaign with bombastic antiques. They rope in movie stars, popular personas, and offer soaps. Why do they do that? Are they so scared? Scared of loosing power? Now this also involves buying advt. slots on prime time.

Here there is some sort of moderation provided by constitution in terms of Election Commission. These guys are the real heroes of democracy. They literally act like old school headmasters with a rod in their hand. They are the ones who resort sanity to the other wise completely one-sided bout.

What happens at the end of the day? Mostly the underrated opposition wins! Reason: The people know better. Now the party that wins resorts to some changes. They start appointing buerocrates who have their favor, in niche positions. The merit and past achievements are ignored. They also resort to reversing decisions made by last govt.

This may not sound ugly. But the next aspect is really ugly. The issues highlighted during campaign to power are brought into limelight. These include earlier govts. policies that were strongly criticized too. Now after a months time. These are put on backburner. One would find no difference in the attitude towards public after a year or so. The headlines also sound familiar only the names and pictures keep changing.

Wednesday, May 23, 2007

Paving Path to ClassPath and Packaging

Last fortnight vineela posed a question. Sounded silly in the first go but later found it to be not so silly. She was trying to compile java files from command prompt. Guess what happened. A disaster! Now she is not a run of the mill kind. Only issue was that she was born and brought up in the world of user-friendly IDEs. She never worked with the age old tools "javac" and java. Why should she? When was the last time I used javac? Let me guess, it is nearly four years.


There were three problems she was facing, packing the sources, compiling and running. The next step of packing the sources into directories sounds easy. What about classes? As per the practice, they also need to mimic the file structure. We need to duplicate the directory structure. What about running the app? Run it from the top-level package. Wait... Wait... why are we hurrying? Take a break and breath-in... & out... repeat it 3 times (use for loop!!)


Some references before we start.

http://java.sun.com/docs/books/tutorial/java/package/QandE/packages-answers.html http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html http://www.cs.wisc.edu/~hasti/cs368/JavaTutorial/NOTES/Packages.html



Simple Example:


Assuming we know how packages are formed we shall go ahead.

Have a directory called C:\Workarea. Now create three folders called "src", "classes". Under "src" create your package structure.

My source files are: myblog.master.Lord.java, myblog.servant.Gini.java.


There is a correlation between and packages and directory structure.

Under C:\Workarea\src create 3 directories

1.) myblog, 2.) mblog\master, 3.)myblog\servant.


Create the same structure under C:\Workarea\classes. We need to copy java sources to src directory location.

Now copy Lord.java to master and Gini.java to the servant directories. Now come to top directory i.e. C:\Workarea.


Under windows run these commands "dir /s /b *.java > a.txt" and then "javac -sourcepath src -classpath . -d classes @a.txt"

javac essentially takes parameters describing the source location, classpath info and destination where classes are to be saved. @a.txt is the file that contains the locations of .java source files


Bingo...


To run the app from C:\Workarea call "java mainclass"

Tuesday, March 20, 2007

vaio why?

Sumit left for Japan last week. He isnt' quite completely settled, but he is not a new customer. Hes been to Japan before too. Yesterday, he mailed ashish & me asking for an opinion about laptop purchase. He has already made up his mind and is giving a serious thought towards VAIO. Apple is off the radar, DELL is still within proximity range. His requirements are quite amusing. Till date I have seen guys boasting about their CPU muscle power! and enormity of memory space. This is the first time I have seen a techie someone go after really after a stylish glam doll. Ever heard of Armanis and RollsRoyce among computers, VAIO quite in the same league. VAIO has an interesting logo too. A cosine wave followed by 1 & 0 (binary notation). What does that mean? Pretty rudimentary isnt' it? Do most owners understand the significance of the symbol or is it... AAh I must be day dreaming.

Monday, March 12, 2007

Festival of colors

First things first, I am blogging this albeit late. Holi, in INDIA is also called as festival of colors. It falls in the early spring season. The colors are vibrant, so is the mood. Boys and girls have a go at each other with colors. It commemorates the ancient epic of Holica, sister of Hiranyakasipa who had a boon of being untouched by fire, being killed by Lord Vishnu when she intends to hurt his disciple Prahlad.

Children make merry throwing water balloons and spraying colors at every one. This festival is also memorialized in Raasa Leela, where Lord Krishna celebrates Holi. This year we had a gr8 time. First I was dragged into muddy pool then had colors hurled at me. Then had a chance to repeat the same unto others and finally in the afternoon went to a rain dance and danced for a long time. The colors was completely washed away by the end of the evening and I wasn’t’ sorry for that.

This is one day that stays long in memory

Yahoo! sounds

Last week I checked web for voice offerings. I was looking for cheap and reliable voice based offering. Guess what! I found that Yahoo has the best offering, I can call USA for just 1 cent per min. I had to pay 10$ for this and I have got atleast 1000min of talk time. Luckily I have a good net connection and I brag about the same :)

Skype comes close but at 2 cents per min they made my decision easier. You all know where my 2 cents went, don't' you.

Monday, March 5, 2007

The static thing

The way we think reflects what we want to achieve. Humans are inherently comfortable thinking in terms of objects. It is rather strange that I was taught structural programming than an object oriented one, earlier in my academics. I am not going to speak in detail about OOPS, but concentrate on one aspect of the OOP Languages. Usage of "static".

As a norm, object-orientation avoids unnecessary "static" declarations, any entity carrying a "static" tag needs scrutiny and the relevance of static-ness needs to be questioned. This doesn’t' mean that static needs to be strictly avoided. It should be used as per the requirement.

Question : Let us think of a MVC style program where model and view are seperated. The hierarchy of model is "GenericModel", "SpecificModel" which extends "GenericModel". For simplicity let us alias them as GM and SM. GM and SM also have attributes defined within them. Not very different from other classes you may say. Now here is the catch, What if those attributes are "static" and are to be inherited. Design an object oriented specification for the above. On the face of it, the problem is obscure. So let me elaborate.
Static nature : A brief intro on static nature. Static entities are tied up to class definition rather than objects’. So static entries are accessed using class context, rather than object context. In such a case the concept of Runtime polymorphism is irrelevant and hence for static entries, the super class definitions and references take precedence over derived class ones, i.e. if GM has attr ‘x’ and SM also has another attr’ ‘x of the same type;
GM o1 = new GM();
GM o2 = new SM();
Print(o1.x);
Print(o2.x); // value printed here is same as that in above line.

You might have already observed the oddness. Most design patterns essentially rely on the fact that interfaces are available (abstraction) and use runtime polymorphism to do the trick. The situation here is different; the super class reference determines the value one gets.

Problem version1: We had two classes called "ModelElement" and "ObjectModel", the later extending the former. “ModelElement” class was contributing an attribute called "Name" and ”ObjectModel” was contributing an attribute called "Classifier". Now we have a GUI for the properties represented by an element. All instances of the “ModelElement” are supposed to have a view like “Name :: ”, and all entities represented by “ObjectModel” are supposed to have a view similar to above and in addition contribute its own “Classifier :: ”. Clearly “Name” and “Classifier” can be logically concluded to be static.

Now the complete version: We have number of attributes to be contributed rather than one per class. So we use vectors for holding all attributes in the vector and return it.

Solution 1: Not a solution, but for discussion. As this is one possibility we run into. Make the vector in super class Model protected static. This will fail for all the cases where derived class is instantiated before super class. The vector gets filled with attributes of both derived a super and when we later want attributes specific to super class it fails to do so.

Solution 2: Create a static vector in every derived class. Also, create a non static method to return this vector in every derived class. Use super. invocation to call super class method. The polymorphic behavior calls the hierarchy of classes and returns a vector of appropriate entities.Problem with this approach: Imagine a huge hierarchy, if some class in the hierarchy doesn’t’ override this method properly with super invocation; the returned values may be drastically different.

Solution 3: Use singletons to represent objects. Now inheritance among singletons is another over head. Think of the possible cases. Singleton entities may themselves be part of some other hierarchy and what about issues with Multiple Inheritance in singletons?

Solution 4: Using reflection, identify the static entities defined in the class hierarchy and return them to the user. Problem is that this approach is possible only in languages with support for reflection. This involves certain amount of hard coding of method/attribute names.

Clearly no solution described above sufficiently addresses the current concerns, If you have a cleaner solution to handle above, please feel free to mail me.

My First Post

It is believed that Voltaire once said, "I may not agree with what you say, but I'd fight for your right to say - what you want to say".

I never thought I’d’ve a blog of mine before. In a very voltairish way, I used to enjoy reading blogs of near and dear. But, why a blog? Probably its my urge to pen my thoughts, or probably to have something to be nostalgic later on... There may be zillions of reasons, as many as the value of Avagadros' number. For me what matters most is my ability to recap my thought currents, the questions and more importantly the intriguing aspect of human psyche to keep itself intrigued.

Popular Posts

Labels

About Me

Well for a start, I dont' want to!. Yes I am reclusive, no I am not secretive; Candid? Yes; Aspergers? No :). My friends call me an enthusiast, my boss calls me purist, I call myself an explorer, to summarise; just an inquisitive child who didnt'learn to take things for granted. For the sake of living, I work as a S/W engineer. If you dont' know what it means, turn back right now.