Thursday, March 6, 2008

Disk Defragmenter in Windows Vista

Its a known fact that the disk defragmanter utility in Vista is a lil weird and theres a good third party tool which can be used in lieu of the windows disk defrag. Its called "Auslogics Disk Defrag" and is a FREE download as well! It works well ofr me and keeps my drives in good shape. the only problem with the free version is that you cannot schedule checks but thats okay for most of us I guess.

Running chkdsk in Windows Vista

I tried opening Command Prompt and running chkdsk in Windows Vista and it would not run. Then i figured out that we need to type "Command Prompt" and then right click on Command Prompt and "Run as Administrator". And, if you run chkdsk D: and find that windows detected problems in D drive, you need to run chkdsk /F D: . And if D is in use, you would get a meesage asking if you would want to unmount D. Answer with a no for that and schedule a disk check when you reboot next time.

Saturday, January 19, 2008

Jump-start Eclipse plug-ins -I - Making your first plugin

Jump-start Eclipse plug-ins -I - Making your first plugin
Recently, a friend of mine approached me with an interesting query. He told me all about the different IDEs he'd seen that were made on top of the Eclipse Platform like Flex Builder and RAD etc. and he was curious to learn how to start - rather jump start with plugin development. I suggested that he read "Contributing to Eclipse" (Gamma et al.) and "Eclipse for the Java Developer".

The following day, I got a phone call from him. He told me that he ha'd given up on that as he thought that the learning curve is too steep. That was surpising, to hear from an experienced Java developer. Upon discussing the matter with other java developers whom I knew, I was surprised to hear them echoing the same sentiment. Now, when I look at it from an unbiased newbie's standpoint, I feel that they were probably right.

An absolute newbie to eclipse development would be bewildered! And if you are impatient, it would be all the more worse. In trying to build Rome in a day, all you would get is another set of acronyms to add to the long list that you already know as a Java developer like SWT, JFace, RCP etc. But the fact is that for the impatient newbie, there isn't an "Eclipse plug-in development in 24 hours". I hope this short introduction jump-starts you into eclipse plugin development.

Without further ado, lets dive right in. Open Eclipse and then create a new Plugin Project. I'll tell you how.


1. Select File>New>Project
2. Select Plug-in Development

From the drop-down that appears, select the Plug-in Project as shown in the figure alongside. If you do not see these options in your eclipse, your version of Eclipse does not incluse the plugins for Plug-In development. You should probably go to eclipse.org and download a version of Eclipse which enables you to devlop plugins.

Ok, now onto the next screen by clicking "Next".









3. Give a name for your project. We are going to make a HTML editor here. So I have named my project as "HTMLEditor".

Dont be afraid seeing abbreviations like OSGi. OSGi is kind of a module system which helps buiding an application out of small, reusable, collaborative components. The eclipse plugin architecture conforms to OSGi, and so does the architecture of WebSphere 6.1, Spring etc. So, you now have a rough idea. It's kind of a platform which enables applicaiotns to be built by assembloing a lot of loosely coupled, reusable modules. For more information on OSGi , you can have a look at http://www.osgi.org
Onward to the next screen...








4. Type in other facny stuff.. like the provider for the plug in..

Here, I'm the provider, so Ive typed in my name. You can type in yours or your company's name. Simple isn't it? Let's click "Next" and march on..

















5. From the "Templates" screen, choose "Plug-in with an editor".

This the screen that the quick and impateint learner should extract a lot of information from. Click on each of the template types and read what they intend to create. To understand that fully, let me give you some basic information. A view is any pane on your eclipse which displays somthing. For example, the "outline", "Package Explorer", "Console", "Errors" are all views. Just try exploring the "Window>Show View" option. That enables you to show up any views which are not shown up in eclipse by default. An editor is right at the center where you edit your java files and XML files. The way Eclipse looks with all it's views and Editors is called a perspective. So, things are arranged in a particular fashin in the "Java development" perspective. The CVS Repository Exploring perspective doesn't need any file edits, so we have a different set of views arranged in anpother way. And don't you see the "Extension Used" haedline on the right hand side of every template description? That just means that this plugin is built on top another already existing plugin using whatever functionality that already exposes. In this context, it is very important to know that Eclipse is just a plug-in runner. It has a very small core program (called the Platform Runtime which is based on OSGi) which keeps executing all the plugins which are built on top of it. I suggest now that you just take a look at the Eclipse Architecture for a better idea. See the picture below for a better idea:


THE ECLIPSE PLUG-IN ARCHITECTURE
The white box right at the bottom is the PlatForm Runtime and the rest are all plug-ins built on top of it. Each plugins carries with it a set of packages and each plug-in extends from Extension Points of the plug-ins which are used to build it. Imagine it like a piece of a jigsaw - it has holes to fit in other pieces and it also has projections which perfectly fit into fissures of the same shape in the adjacent piece. The holes are the extension points of the plug-in which can be used to fit other plug-ins on top. And the projection fits into another already existing hole - that hole is the extension point of some already existing plug-in which was used by our plug-in. So our editor plug-in uses the extension points of the org.eclipse.ui.editors plugin and extends from it. Okay, onto the final screen now.

6. Fill in other details.
Name your Editor Class. I have named it as HTMLEditor. And in the file extension, I have typed in html because our editor is going to be associated with html files. Click finish. And we have our basic HTML Editor ready!



Now that we have some key concepts in the bag. Let's take a breather now. I'll see you in the next part for adding more features into it.

Monday, November 19, 2007

Saying Hello (cliched, but effective)

Without much ado, let us get our first java program going. I'm going to assume here that you'll just blindly key in the programs given below without jumping the gun and getting too curious (beacuase curiousity killed the cat). From now on, things are going to be less theoretical. Our first program is going to have two flavours. You can try them out and see the difference.
Any program in this book would start with the name of the program file and a number prefixed by P. So our first program , has it's title as P1: HelloJava.java:

P1 : HelloJava.java

public class HelloJava {
public static void main(String args[]){
System.out.println("Hello Java");
}
}

P2 : HelloJavaWindow.java

import javax.swing.*;

public class HelloJavaWindow {
public static void main(String args[]){
JFrame jfHello=new JFrame("Hello Java Window");
jfHello.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfHello.setSize(300,400);
jfHello.setVisible(true);
}
}

Any procedure will be a paragraph with a heading prefixed by PR and will have a number and a short name describind what we do in that procedure. So, we have our first procedure PR1 below:

PR 1: Compiling HelloJava program
Have you tried compiling P1 and P2 ? Be sure that P1's filename is as I have mentioned: "HelloJava.java". Create a file HelloJava.java with the program in P1 above as it's content. To compile P1, type in "javac HelloJava.java" from the command line window (or terminal in Linux) after navigating it to the directory where you have the file HelloJava.java. this should create a file called HelloJava.class in the same directory.To execute this, type "java HelloJava" (and not java HelloJava.class or java hellojava) in the same command window. You should see the text "Hello Java" printed on screen.

Repeat the PR1 and read "HelloJavaWindow" for HelloJava and P2 for P1. What output do you see now, on running "java HelloJavaWindow" ?

Next Section >> Explanation of the hello java program

Friday, October 26, 2007

Esperanto and Artificial Languages

Artificial Languages


Since the language you speak influences your thoughts, speak some unusual languages and open your mind to unusual thoughts.

A conlang is a constructed language, more commonly known as an artificial language. Unlike C and Java, which are artificial languages created by humans for computers to use, conlangs are created by humans for humans to use.

Over the centuries, hundreds of conlangs have been created, and certainly many more projects that are private have never been published. Many conlangs were created with a specific purpose in mind, such as J.R.R. Tolkien's Elvish languages Sindarin and Quenya, which were created for their sheer beauty. Others were created for a laugh or to be used in movies or books.

Some languages are working languages, however, designed to liberate and empower human minds in a specific way. Esperanto, for example, was designed to break down cultural barriers between people of different cultures, and Lojban was designed to remove as many limitations on human thought as possible.

In Action

Here are six well-known constructed languages that can help you think and express yourself in novel ways.

Esperanto

Esperanto is the most widely spoken conlang on Earth, with an estimated 2 million speakers, putting it on par with Lithuanian, Icelandic, and Hebrew.1 It was designed in 1887 by Dr. L.L. Zamenhof as a kind of neutral, universal second language that would allow native speakers of all languages to meet one another on even ground, with none having an intrinsic fluency advantage.

Esperanto is extremely simple, regular, and easy to learn. It's also extremely flexible. To quote Esperantist Ken Caviness, "It's been used in all conceivable circumstances for over 100 years. Whatever you have to say, you can say it in Esperanto."

One common complaint about the vocabulary of Esperanto is that it is too Indo-European, and most Esperanto words do indeed come from West European languages. However, Esperanto's agglutinative grammar is more akin to other language families. In any case, Esperanto speakers come from all over the world—it's especially popular in China—and I have had mind-opening, preconception-destroying conversations on many subjects with people from many lands in Esperanto.

Esperanto has a wealth of translated world literature, and it can literally open doors for you with its Pasporta Servo, an amazing international hospitality service of friendly people in many different countries who make free lodging available for traveling Esperantists. A wide variety of Esperanto learning materials is available on the Web, as are volunteers who will teach it to you free of charge via email. If you're waiting for an engraved invitation to the world, one of those could probably be arranged, too—with an Esperanto postage stamp.

Lojban

Lojban is an elaborate constructed language that was designed to test the Sapir-Whorf hypothesis (see the "How It Works" section of this hack). It's the more robust descendant of the original Loglan project, which was designed by Dr. James Cook Brown. The project forked because of an intellectual property dispute; you might say Lojban is to Loglan as GNU/Linux is to Unix.

Lojban is designed to remove as many restrictions as possible on "creative and clear thought and communication." To this end, its grammar is based on propositional logic, and it has a culturally neutral vocabulary that was algorithmically derived from the six human languages with the most speakers (Mandarin Chinese, English, Hindi, Spanish, Russian, and Arabic).

Lojban's grammar is more regular than even Esperanto's, so much so that it can be fully specified on a computer with a program such as YACC. This highly regular grammar leads to Lojban's famous audiovisual isomorphism, meaning that spoken Lojban can be unambiguously transcribed; you even pronounce punctuation. Lojbanists speculate that this feature might be useful for human-computer communication. Science fiction has beaten them to it, however; the characters in Robert Heinlein's 1966 novel The Moon Is a Harsh Mistress use Loglan for just that purpose.

In short, Lojban is a kind of super-language designed to shoot off your Sapir-Whorfean linguistic shackles and blow your mind open. Give it a try.

Klingon

Klingon is another popular conlang. Professional linguist Marc Okrand developed it for the Star Trek movies, as the language of the Klingons, an alien race.

Dr. Okrand explicitly designed Klingon to be alien, to stretch the human brain by violating human linguistic universals. For example, its syntax uses a word order seldom observed among human languages. Dr. Okrand has a puckish sense of humor and has added other features that are hard for humans to wrap their minds, lips, and larynxes around, but despite this, Klingon has a devoted fan base.

Here's an example of how Mark "Captain Krankor" Mandel, Chief Grammarian of the Klingon Language Institute, hacked his mind with Klingon. You can, too!

Mandel offers a story about the way Klingon makes him feel. During one of the annual qep'a', he went out on a mission to pick something up for the convention. A light rain was falling; he felt wet, tired, and a little droopy. But he strengthened his resolve by saying a Klingon phrase to himself: jISaHqo', which he says could be translated as "I refuse to care," "I will not care," and "I refuse to let this bother me." In English he would only have had the weaker phrase, "I don't care," which wouldn't have conveyed the strength of his intentions. He smiles at the memory. Thinking in Klingon reminded him that being irritated by a little rain was the sort of thing only a foolish human would do.2

AllNoun

More a constructed grammar than a constructed language, Tom Breton's AllNoun has a vocabulary and a grammar that consist entirely of English nouns, thus embodying an idea first proposed in Jack Vance's 1958 science fiction novel, The Languages of Pao.

An AllNoun sentence is a web of relationships with a weirdly static, timeless feel. Here's an example of a sentence written in AllNoun:

act-of-throwing:whole Joe:agent ball:patient

And here's a rough transliteration:

In some context, there is an act of throwing, and the agent of that act is Joe, and the patient is some ball.

which conveys this basic intended meaning:

Joe throws the ball.

You might think that act-of-throwing is an attempt to smuggle a verb into the sentence, but in a full constructed language, as opposed to the prototype project that AllNoun is, that hyphenated word would be a timeless, tenseless noun in its own right.

With only one part of speech, AllNoun's grammar is extremely simple. Paradoxically, if you try hacking your mind with AllNoun, you might find its simplicity to be the most difficult, yet most rewarding, aspect of this language.

Solresol

Solresol was developed in 1817 by Jean Francois Sudre. It was the first international auxiliary language comparable to Esperanto to receive serious attention. Its most salient feature is that it is composed entirely of musical notes. For example, its name, which means simply language, consists of the notes sol-re-sol from the Western solfege scale (do, re, mi, fa, sol, la, ti (or si), do).3

Although the principle of forming antonyms by reversing the notes in a word is interesting (for example, fasimisi means advance and simisifa means retreat), there's probably not much in Solresol to broaden your mental horizons.

Its real value instead comes from enabling you to communicate multimodally. You can express Solresol syllable-notes via singing, playing a musical instrument, flashes of light, semaphore, spoken language, written language, musical notation, and so on. You can even use it to add another information "channel" for modifying the meaning of verbal language.

How It Works

The controversial Sapir-Whorf hypothesis4 states that there is a direct relationship between the categories that are available in a language and the way the speakers of that language think and act. While if it were true that language completely determined thought, people would never have any thoughts that they could not express (and we know that's not true), there have nevertheless been some suggestive experiments in this area. For example, it was recently shown that one Amazonian tribe without words for numbers greater than two cannot count reliably higher than two or three.5 Skeptics have pointed out that causation may run the other way: the tribe never developed words for numbers because they never needed to develop the concepts.6

As mentioned earlier, Lojban was designed to be a comprehensive test of the Sapir-Whorf hypothesis that enabled its speakers to think logically, clearly, and creatively. However, it's doubtful that there will ever be a full-scale experiment of the sort its designers envisioned, because there may never be many fluent speakers of Lojban, and the number of native speakers is approximately none.

Design Your Own

You can learn a lot about language and the human mind by creating your own language. Does that sound audacious? The Language Construction Kit web site7 by Mark Rosenfelder explains how to create your own language sounds, alphabets, words, grammar, even speaking and writing style, as well as an imaginary history for your language, and a family of related languages.

Here are a few tips for doing so, partially inspired by Newitz and Palmer's flowchart in The Believer 8 but mostly indebted to the Language Construction Kit. For a crash course in linguistics and cross-cultural human thought styles, and much more information than I can possibly convey here, please visit that site.

Models

First, you'll need a basic model and approach for designing your new language:

  • Decide whether you want your language to be "natural" (full of irregularities, like English), or "unnatural" (simple and logical, like Esperanto and Lojban).

  • Steal from some languages very different from English, such as Quechua, Swahili, and Turkish.

Sounds

Give some thought to how you want your language to sound when spoken:

  • Learn something about the disciplines of phonetics and phonology, so as not to make newbie mistakes with the sounds of your language.

  • Learn about how vowels and consonants work, including how to invent new ones.

  • Decide how your language stresses words.

  • Decide whether your language uses tones (like Mandarin Chinese) and, if so, how they work.

  • Design your conlang's phonological constraints. For example, tkivb could never be an English word, but it might be OK in another language.

  • Are you designing a language for aliens? If so, make sure your conlang sounds really weird.

Alphabets

Every written language needs an alphabet, the basic building blocks of words:

  • Develop a Roman orthography—that is, a way of spelling your language with the Roman alphabet.

  • If appropriate (for example, for a fantasy language), develop a new alphabet, too.

  • Use diacritics and accent marks if you want, but not haphazardly.

  • Alternatively, invent pictograms, logograms, a syllabary, or some other way of writing your language.

Word building

Once you've got your alphabet, consider how the letters will be used to form words:

  • Determine whether you want a small or a large vocabulary.

  • Develop a vocabulary that respects your conlang's phonological constraints. You can write a computer program to generate random words within those constraints.

  • Determine whether you want to borrow words from other languages a little, a lot, or not at all.

  • Decide whether your language uses onomatopoeia and other sound symbolism (e.g., buzz, tinkle, gong, rumble, etc.).

  • Be careful not to just reinvent English idioms.

Grammar

Grammar is one of the most complex aspects of a conlang, and even the Language Construction Kit doesn't address it fully. Here are a few issues you'll have to face:

  • Determine whether you have nouns, verbs, and adjectives. (Lojban makes do with one part of speech for all three, and adverbs, too.)

  • Determine your pronouns: I, you, he, she, it, and many more are possible.

  • Determine the order in which parts of speech appear in sentences (in English we use SVO, or subject-verb-object).

Style

Give your language a distinct personality and feel:

  • How is politeness expressed in your language?

  • What forms does poetry use in your language? Rhyme and meter? Alliteration, as in Old English? Counting syllables, as in Japanese haiku?

Language families

Assign your language to a group of speakers:

  • If your language belongs to an imaginary people, is it derived from other imaginary languages? Tolkien's languages were related in a huge imaginary tree.

  • Does your language have dialects?

Speaking and writing

Once you've created your language and formed a group, get communicating!

End Notes

  1. Esperanto: Frequently Asked Questions. 1999. "How many people speak Esperanto?" http://www.esperanto.net/veb/faq-5.html.

  2. Newitz, Annalee. 2005. "The Conlangers' Art." The Believer, May 2005. http://www.believermag.com/issues/200505.

  3. Wikipedia. 2005. "Solfege." http://en.wikipedia.org/wiki/Solfege.

  4. Wikipedia. 2005. "Sapir-Whorf hypothesis." http://en.wikipedia.org/wiki/Sapir-Whorf_Hypothesis.

  5. Gordon, P. 2004. "Numerical Cognition Without Words: Evidence from Amazonia." Science, 306: 496–499. http://faculty.tc.columbia.edu/upload/pg328/GordonSciencePub.pdf.

  6. Gordon, P. 2005. "Author's Response to 'Crying Whorf'." Science, 307: 1722.

  7. Rosenfelder, Mark. 2005. "The Language Construction Kit." http://www.zompist.com/kit.html.

  8. Newitz, Annalee, and Chris Palmer. 2005. "Build Your Own Conlang." The Believer, May 2005. http://www.believermag.com/issues/200505.

See Also

Wednesday, October 24, 2007

Making a JEditorPane to honor fonts

Almost always, I have got frustrated weith the JEditorPane. It's support ofr HTML is good (not the best.. dont try anything extravagant).. but it was not able to change the Font when i tried using setFont(). That was simply not working. After days of searching, googling and endless frustration , Sun java forums got me what I needed. HEre's how you do it:

Setting the HONOR_DISPLAY_PROPERTIES client property on the editor pane will allow you to use setFont and setBackground.

Like this:
JEditorPane pane = new JEditorPane();
pane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
pane.setFont(SOME_FONT);


That one line of code does the trick! I tried a Greek font and it worked!

Saturday, September 1, 2007

CD1 - Compiling a java program

Concept Discussion 1: Compiling a java program

It's the black box or the magician which converts your file which has the System.out.print("hello"); statement you typed to a program which prints "hello". So, we are going to type our java programs in any text editor you like - Notepad or Wordpad or Vi or Emacs (the later two are popular text editors in the Linux operating system). And, then we are going to use our compiler or the black box i told you earlier about and do that magic thing called compilation that will process the program that we have written and then generate a new file called the class file. This is then fed to what is called the Java interpreter - a program which understands and processes these class files and then generates the machine instructions (the language of only 1 and 0 which our computer understands) for doing the particular task. Ok, was that too much to digest? Let's do a quick recap. Getting your program running involves the following steps:

1. Type it out it in your favourite text editor.
2. Feed in your typed file to the Java compiler to generate the class file.
3. Feed this class file to the Java interpreter to see your actual program in action.


So, for steps 2 and 3 above, you need the java compiler and java interpreter in your machine. To know whether you have any of these already ( there is a good chance that you have the java interpreter if you browse a lot and have used a lot of applets on the web), follow steps below depending on whether you are a windows or Linux user.

For Windows users
1. Go to Start>Run and type "cmd" and click "OK".
2. In the black window tat appears, type "java" and hit the enter key.
3. If you a get a long list of options, you have the Java Interpreter or the Java Virtual Machine installed in your computer.
4. If you get back a message like 'java' is not recognized as an internal or external command, you probably don't have the Java Interpreter or the Java Virtual Machine.
5. Repeat steps 1 and 2. But hits time type "javac" instead of "java" in step 2.
6. If you get a list like in step 3, you have the Java compiler as well in your system.
7. If you get a message as in step 4, you do not have the Java Compiler in your system as well.

For Linux users:
1. Open a terminal (an XTerm) and type java
2. If you a get a long list of options, you have the Java Interpreter or the Java Virtual Machine installed in your computer.
3. If your shell says 'java:command not found ', you do not have the java compiler.
4. Repeat step 1. But hits time type "javac" instead of "java" .
5. If you get a list like in step 3, you have the Java compiler as well in your system.
6. If you get a message as in step 4, you do not have the Java Compiler in your system as well.

And before we go and check the results of what you tried above, i need to tell you one fundamental thing here. There were two important files, about which we discussed in Concept Discussion 1. From here on I will refer to concept discussions with CD (in bold). So the three files in CD1 were:

1. Your file typed in your favourite text editor with the java commands.
2. Your class file generated by the compiler.

You call the file in 1 as your java source code or simply java code or java source. And the file in 2 as your java program or java class.

So what do you do if do not have either of the Java compiler of the Java Interpreter (Java Virtual Machine)? You need to get it. How can you get either or both of them? Before answering these questions, you need to know a basic difference between the compiler and interpreter.

Definition
The compiler for any language is a program which translates programs written in that language to a from which can be executable binary machine language or some intermediate "ready-to-interpret" language or even another language. Don't worry if you have not understood this sentence. Keep reading.

Definition
The interpreter is the program which takes the output of the compiler if it's in the "ready-to-interpret" form (as said in the definition of a compiler above) and interprets it to machine language form and executes it on the target machine on which it is run.

In case of java, we have the following sequence:

java source -> java compiler -> class file containing bytecode -> java interpreter -> machine language.

This should make it clear to you that to actually execute java programs on your machine, you need to compile them and then execute the compiled bytecode using the java interpreter. So you actually need two programs. The compiler program is actually called "javac" and the java interpreter is "java" (nicknamed by many as the "Java Virtual Machine" or "JRE" or "Java Runtime"). The compiled bytecode is actually called as a class file.

If you have not understood the difference between the compiler and the interpreter from the discussion we had above, it's high time you understood that before going any further. So your tools to start with java are:
1. Your favourite text editor for writing your java programs.
2. A java compiler to compile programs that you write using the text editor in step 1 above
3. The java interpreter to interpret and run the bytecode or class files that you generate using the compiler in 2 above.

Item 1 above can be anything from your notepad program in windows or Vi or Emacs in Linux. You'd definitely have it if you had an operating system of any kind. The easiest way to get the compiler and interpreter (items 2 and 3 above) is to download the JDK or J2SE, which is basically the Java Development Kit which comes with both the compiler and the Virtual Machine. Beware if someone tells you the JRE has everything. It doesn't . It has just the interpreter - that means you can run class files you may have with you, but you cannot compile your java programs. This explains why people having the JRE are able to run java applets (because they are just class files) but not compile java programs.

For everything in the world there are rules. So is the case with Java. You always need to name your file which you write in Notepad with a .java extension. If you don't know what an extension is, let me tell you that filenames which you see commonly have two parts - for eg: myexpenses.txt . This is a text file. How did I know that without seeing the file content ? I knew that because of the file extension. The extension is that part of the filename which comes after the dot - in the example, that was "txt". So if i need to name a file with java extension, i would name it as myprogram.java. There are very commonly used extensions like mp3. So the song "Nothing else Matters" on your computer might probably have the filename "Nothing Else Matters.mp3". We can say that an extension of a file helps it to be classified as a file of a particular type. So an extension of "java" classifies it as a text file containing a java program.