Wednesday, December 31, 2008
Will the Paisa go the Farthing way?
Australia and New Zealand removed their 1 and 2 cent coins in the early1990s. In 2006, Newzealand went ahead and demonetized the 5 cent coins as well.
The 25 paise coin with the a Rhinoceros was issued in 1994, while aluminium20 paisa coin has 1988, the stainless steel 10 paisa has 1988. The square 5paisa is surprisingly from 1993.Even the latest of these coins are more than a decade old.
The Indian Coinage lists the 10 paisa and 25 paisa as part of the Contemporary Coins. Although 25 paisa may still hold its utility. The 10 paisa may have outlived its useful life.
Monday, December 22, 2008
Java GUI to convert Julian date to Gregorain and vice versa
The conversion makes use of the below functions to do the calculations.
public boolean isleapyear(int year){
if ((year%4!=0)||(year%4==0)&&(year%100==0)&&(year%400!=0))
return false;
else
return true;
}
public void jultogreg() {
int gdate,gmonth;
int mondays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int jyear=Integer.parseInt(jTextField1.getText());
int jdate=Integer.parseInt(jTextField2.getText());
if(jyear>=10 && jyear<100){jTextField3.setText("20"+jyear);}
else if(jyear>0 && jyear<100){jTextField3.setText("200"+jyear);}
else {JFrame mainFrame = JulianToGregorianApp.getApplication().getMainFrame(); JOptionPane.showMessageDialog(mainFrame, "The Julian Year is out of range. Enter a value greater than 1 and less than 99.", "Input Error", JOptionPane.ERROR_MESSAGE);} if(jdate<1 ||jdate >367){
JFrame mainFrame = JulianToGregorianApp.getApplication().getMainFrame(); JOptionPane.showMessageDialog(mainFrame, "The Julian Date is out of range. Enter a value greater than 1 and less than 367.", "Input Error", JOptionPane.ERROR_MESSAGE);} if((isleapyear(jyear))){mondays[1]++;}
gdate=jdate; for(gmonth=0;gmonth<12;gmonth++){
if((gdate-mondays[gmonth])<1){ gmonth++;
if ((gdate-mondays[gmonth])==0) {gdate=mondays[gmonth];} jTextField4.setText(gmonth+"");
jTextField5.setText(gdate+""); break;}
gdate-=mondays[gmonth]; } }
public void gregtojul() {
int i;
int gmondays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int ggyear=Integer.parseInt(jTextField3.getText());
int ggmonth=Integer.parseInt(jTextField4.getText());
int ggdate=Integer.parseInt(jTextField5.getText());
if((isleapyear(ggyear))){gmondays[1]++;} ggmonth--;
for(i=0;i<ggmonth;i++){ ggdate+=gmondays[i]; }
jTextField2.setText(ggdate+""); }
The conversion takes into consideration if the year is a leap year or not to do the calculations. The leap year or not function is very handy in determining if a given year is leap or not.
Tuesday, December 16, 2008
Simple Java Program to understand String Manipulation
------------------------------------------------------------------------
Simple Java Program to understand String Manipulation
------------------------------------------------------------------------
*/
class VeryComplexHelloWorld{
public static void main(String args[]){
int i,j;
String helloworldmessage=" HelloWorld ";
String helloworld="H-E-L-L-O-W-O-R-L-D";
String[] listofchars;
String helloworldobtianedafterspliting="";
listofchars= helloworld.split("-");//splitting a string based on a delimiter
j=listofchars.length;//getting the length of an array
System.out.println("This Program does numerous manipulations to generate the Hello World message");
for(i=0;i
}
helloworldmessage=helloworldmessage.trim();//to remove leading and trailing spaces
helloworldmessage=helloworldmessage.toUpperCase();//Converting all characters of string to uppercase
if(helloworldmessage.equals(helloworldobtianedafterspliting)){//to compare two strings
System.out.println(helloworldmessage);
}
}
}
/*
------------------------------------------------------------------------
Output of Complex Hello World
------------------------------------------------------------------------
C:\Users\flower\Documents\javaprogs>javac VeryComplexHelloWorld.java
C:\Users\flower\Documents\javaprogs>java VeryComplexHelloWorld
This Program does numerous manipulations to generate the Hello World message
HELLOWORLD
------------------------------------------------------------------------
*/
Saturday, December 13, 2008
Simple Java Program to understand threading
------------------------------------------------------------------------
Simple Java Program to understand threading
------------------------------------------------------------------------
*/
public class ThreadingExample{
private static class createdthread implements Runnable{
public void run(){
int i;
String threadname=Thread.currentThread().getName();//to get the name of current thread
System.out.format("%s is executing\n",threadname);
try{
for(i=0;i<4;i++){
Thread.sleep(1000);//pausing the thread for 1 second
System.out.format("%s",threadname+":"+i+"\n");
}
}catch(InterruptedException e){
System.out.format("%s is Interrupted\n",threadname);
}
}
}
public static void main(String args[]) throws InterruptedException{
int timeforexecutingt0;
timeforexecutingt0=Integer.parseInt(args[0]);
Thread t0 = new Thread(new createdthread());
Thread t1 = new Thread(new createdthread());
t0.start();//start executing thread 0
t1.start();//start executing thread 1
t0.join(timeforexecutingt0);//wait for thread 0 to finish within 'timeforexecutingt0'
t0.interrupt();//interrupt thread 0
}
}
/*
------------------------------------------------------------------------
Time for thread 0 will differ from one system to another. It may also differ based on the load on the system at the time of execution.Try finding whats the optimal time for your setup.
------------------------------------------------------------------------
C:\Users\flower\Documents\javaprogs>javac ThreadingExample.java
------------------------------------------------------------------------
Output when the execution time for thread 0 is not sufficient
------------------------------------------------------------------------
C:\Users\flower\Documents\javaprogs>java ThreadingExample 3000
Thread-0 is executing
Thread-1 is executing
Thread-1:0
Thread-0:0
Thread-1:1
Thread-0:1
Thread-0 is Interrupted
Thread-1:2
Thread-1:3
------------------------------------------------------------------------
Output when the execution time for thread 0 is sufficient
------------------------------------------------------------------------
C:\Users\flower\Documents\javaprogs>java ThreadingExample 5000
Thread-0 is executing
Thread-1 is executing
Thread-0:0
Thread-1:0
Thread-0:1
Thread-1:1
Thread-1:2
Thread-0:2
Thread-1:3
Thread-0:3
C:\Users\flower\Documents\javaprogs>*/
Simple java program to understand compiling and running a program inside a package
Simple java program to understand compiling and running a program inside a package
---------------------------------------------------------------------------------------*/
package javaprogs.basic;
class helloworld{
public static void main(String args[]){
System.out.println("Helloworld in basic package");
}
}
/*
---------------------------------------------------------------------------------------
Output of compiling and running a package
---------------------------------------------------------------------------------------
C:\Users\flower\Documents\javaprogs\basic>javac helloworld.java
C:\Users\flower\Documents\javaprogs\basic>cd ..
C:\Users\flower\Documents\javaprogs>cd ..
C:\Users\flower\Documents>java javaprogs.basic.helloworld
Helloworld in basic package
*/
Friday, December 12, 2008
Simple Java Program to understand finally Block
Simple Java Program to understand finally Block
------------------------------------------------------------------------*/
class finallyexample{
public static void main(String args[]){
int i,total=0;
try{
for(i=0;i<3;i++){
System.out.println(args[i]);
total+=Integer.parseInt(args[i]);//converting string to integer
}
System.out.println(" The total is " + total);
//this block is executed only when number of arguments is 3 or more }
catch (ArrayIndexOutOfBoundsException a){
//this block is executed only when number of arguments is less than 3
System.out.println("A minimum of 3 arguments are required");
} finally{
//this block is executed irrespective of the number of arguments passed to the program
System.out.println(" The total is " + total); } }}
/*------------------------------------------------------------------------
Output with the "finally" block
------------------------------------------------------------------------
C:\j2sdk1.4.2_04\bin>javac finallyexample.java
C:\j2sdk1.4.2_04\bin>java finallyexample 1 2 3
1
2
3
The total is 6
The total is 6
C:\j2sdk1.4.2_04\bin>java finallyexample 1 2
1
2
A minimum of 3 arguments are required
The total is 3
------------------------------------------------------------------------*/
Thursday, December 11, 2008
Simple Java Program to understand Exception Handling
Simple Java Program to understand Exception Handling
------------------------------------------------------------------------*/
class exceptionexample{
public static void main(String args[]){
int i;
try{
for(i=0;i<3;i++){
System.out.println(args[i]);
}
} catch (ArrayIndexOutOfBoundsException e){
System.out.println("A minimum of 3 arguments arerequired");
} }}
/*------------------------------------------------------------------------
Output without the "try" block
------------------------------------------------------------------------
C:\j2sdk1.4.2_04\bin>javac exceptionexample.javaC:\j2sdk1.4.2_04\bin>java exceptionexample 1 2 3 4123C:\j2sdk1.4.2_04\bin>java exceptionexample 1 212Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at exceptionexample.main(exceptionexample.java:5)
------------------------------------------------------------------------
Output with the "try" block
------------------------------------------------------------------------
C:\j2sdk1.4.2_04\bin>java exceptionexample 1 212A minimum of 2 arguments are required
------------------------------------------------------------------------*/
Saturday, December 6, 2008
Red Barron - the flying ace
The nickname Red Barron originates from the fact that he flew a red colored plane and was actallly from royalty. The German title "Freiherr" roughly translated to the english title of "Barron". He is credited with coming up with "The Flying Circus", highly mobile and brightly colored aircraft which were useful in the Dog fights of the First world war.
Red Barron's Autobiography "The Red Battle Flyer" is anintresting read. The eight chapters of the book place before us the various stages of his life. It provides a view of the world war I throught the eyes of soldier who fought pretty well. His liking for sports and winning seems to have continued into the battlefield. It was all about winning trophies and not just the war.
Thursday, November 13, 2008
Lexical analysis
Tokens created by lexical analysis have two parts, one is the block of text corresponding to the token(Known as lexeme) and the other is the token type. So to give an example, a sequence like "a=1+2" after tokenisation will look like
The lexer generators take a input file with details about the required characteristics of a lexer and generate the lexer. One lexer that seems to be popular is "flex". The input file for flex consists of 3 parts, the definiton part, the rules part and the user code section.
Each of the parts is separated by "%%". So a simple program in flex would be like
%%sayhello printf("Hello");
This just makes "sayhello" a token that has the action printf("Hello");. The flex has much much more that can be done. There are features to optimise the memory usage to suit the lexer u design.
Wednesday, November 12, 2008
The Rainmaker
With its various sub-plots involving everything from underworld runaways to will changing grannies it has the reader turning pages.The best part is the anticipation of big money squezed out of a big bad insurance company.
It has very good ending, which lets the reader wanting for more.
Friday, November 7, 2008
Cascading error loss in Software
Consider the example of a special character in the input a program. The special character will miss all the given conditions and will go to a error handling mechanism. The error handling mechanism may again fail due to the special character. This leads to a cascading error condition.
Now coming to the serious problem of error loss. A very serious error may get lost in the cascading error due to reduction in error severity. The severity of the error may get reduced in each step of the cascade and finally end up as a info alert. Although programming languages like Java have dedicated error handling mechanisms, the very nature of cascading errors makes it difficult to catch them. Thus, its better to have a catch all exceptions condition that reports the error that has been caught as the highest possible error severity, as the severity might have got reduced during the cascade.
Let me tell you a story to explain how cascading error loss occurs. A shop catches fire at night and starts burning. The onlookers see the burning shop and the news about the fire starts to spread. By the time the news reaches the owner of the shop, the location of the shop is not very clear. The shop owner comes to know about a shop on fire but does not realise that its his own shop. Similarly a very serious error can be overlooked due to cascading errors.
Thursday, October 16, 2008
Sunday, October 12, 2008
Sanjivini Park or Happy man park
Saturday, October 4, 2008
Friday, October 3, 2008
3 mistakes of my life by Chetan Bhagat
The book follows the lives of these 3 Gujarati's through the earthquake, through the Godhra Carnage and into the present(2005 AD). With an unusually dark beginning just like 5 point someone, the book begins with a suicide!!. The book appeals to the masses :) as the 3 friends could be anybody, not just IIT'ians.
The story is continous except for the wonderfully bizzare beginning. We dont get the idea that Govind Patel is a big fan of Chetan. So its kind of surprising that he sends the letter to Chetan in the first place. Apart from such to good to be true situations... the book is a good read.
Thursday, September 25, 2008
Saturday, September 13, 2008
Tuesday, September 2, 2008
Monday, September 1, 2008
Sunday, August 31, 2008
Go Kiss the world
The book is autobiographical and traces the life of Subroto Bagchi from being born in rural India to go onto co-found Mindtree, a very successful software services company.
The book is split into 3 parts, each reflecting the 3 different phases of Subroto Bagchi's life. The first part is all about growing up in rural India and travellingfrom one city to another, one town to another town and one village to another. The second part is about growing from a clerk in a government office to making Wipro Grow. The third part is about taking the risk and plunging into the brave world of Entrepreneurship to form MindTree.
Apart from its obvious autobiographical appeal, it also is a very good book to see how a person like Subroto Bagchi thinks and lives. May the gardner make more flowers to bloom.
Saturday, August 30, 2008
Yellow zerbera - see the effect of the shadow
Sunday, July 27, 2008
Mobile Payment - the electronic wallet
With the coming of internet banking and wide spread use of Mobiles, it was only a question of time before Mobile banking solutions started blooming.
Lets compare few of the major providers of Mobile payment solutions. Oxicash is making progress with its product. The concept is that of a prepaid card that can be used to make purchases. This is different from Obopay which allows you to link your mobile to your bank or credit card acount. While Obopay promises to be a money transfer solution, the features offered by ngpay are that of a mobile mall.
The companies are drawing in more and more merchant partners who support the mobile payment model. The model being used by oxycash, ngpay or mcheck is not much different in that all are offering the options to make payments through SMS, through the browser or through a customised application.
Although each of these methods has its own pros and cons as well as its own set of users. Any of these providers should provide features like:
- Flexibility in the methods of recharging or adding cash to the e-wallet.(It should be as easy as getting your mobile phone recharged)
- The e-wallet should not b restricted to a select set of merchnats alone.Pay to any mobile option should be available.
The future seems bright for mcommerce, the challenge is in presenting the idea to the user in the best way.
Saturday, June 28, 2008
Creating views in SQL server 2005
Expand the database in which the view has to be created and right click on the Views.Select the create new View option and you will be presented with the above screen with the list of tables that are present in the database.We select the emp_table and click on add and then close this window.
After the above window is closed the below window appears. It has four different parts. The top most part contains the list of columns in the emp_table which can be added to the view.The next part provides various options to customise the view. The columns to be included and the alias name that have to be given to those columns in the view, the table in which the column is present, the way the column has to be sorted in the view, the sort order to be followed in the
view, any filters to be used in the view and other options such as the use of aggregate functions etc.
The third part shows the actuall query that is to be run. Once we have choosen the required query either by directly editing the query or using the interface provided, the query can be tested by clciking on the execute button that is highlighted in the above window.The output of the query(either the view or the error message)appears in the fourth part.Once the view of your choice is ready the view can be saved by chossing the save view option under the file menu.
Sunday, June 22, 2008
Robin without a hood is not robinhood
More and more birds are flocking to the garden with growing foliage.
Robin must not be confused with robinhood who actaully is from nottingham in england and is rather popular in literature.
Friday, June 20, 2008
46893711600000 - what does this number signify?
Restoring database backup in SQL server 2005
- Expand the database tab to display all the databases running in SQL server.
- Right click the database that has to be backed up and select the "Tasks" option.
- In the "Tasks" option the Restore database option has to be selected.
The below screen comes up after selecting the option.
The database that has to be restored is to be slected in the to database menu.The time upto which the restoration has to be done can be selected based on the type of backup that was taken earlier.
The source and location from which the backup data can be obtained has to be specified. The options tab provides various Restore options and Recovery states which are selected based on the needs of a particular restore operation.Creating database backup in SQL server 2005
- Expand the database tab to display all the databases running in SQL server.
- Right click the database that has to be backed up and select the "Tasks" option.
- In the "Tasks" option the Backup databse option has to be selected.
The below screen comes up after selecting the option.
The database that has to be backed up is to be slected under source and the recovery model of the selected database is automatically filled in.
The backup types that can be selected for a particular recovery model are availbale in Backup type option.
The component that has to be selected(database in this case) has to be choosen.Note that file group backups can also be taken.
The Backup set details such as Name of the backup set, its description, the expiry date of the backup set and destination of backup set are to be selected. The contents button will show the various components of the database that are being backed up in the particular database.
when a backup already exsists the options tab can be used to specify wehter the earlier backup has to be overwritten or apended to.Reliability checks such as Verification of the baclup when finished and performing checksum before writing to the media can also be specified to ensure the reilability of the backup.
Monday, May 12, 2008
Creating a table in SQL server 2005
After creating a database, you need to create tables in your database.Its as simple as creating the database. Expand the database in which you want to create tables in and select the tables tab. Right click on the tables tab to get an option "New Table".
When you click the new table option, you are presented with the column creation page. In this page the column names, datatype and null or not null characters can be specified.
Although you can create columns with spaces, it will cause issues later as it cant be used in many operations. So dont leave spaces in column names.
After adding the required number of columns the table can saved by clicking on the save button.
The table is saved to the database and can be seen under the tables tab under the database you had selected.
Three types of constraints can be set on columns for restricting the entry of data into them.They are:
- Check Constraint - This is used to set a constraint against which data is validated before entry
- Default Constraint - This sets a default value to be filled in a column when no value is specified by the insert command
- Unique Constraint - when the unique constraint is set on a column, it cant have duplicate values.
A check constraint can be set by selecting the "Constraint" tab under the database of choice. A Check Constraint box opens up asking you to specify the Constraint expression.
Ex: (column_name like '[0-9]')
once the constraint is added, only values that match the constraint can be added to the table. In this case only values from 0 to 9 can be added to this column.
The default value can be set by selecting the table in design mode and choosing the column on which the default value has to be set. This can be done while creating the table as well. The Default value or binding can be set as below
The unique constraint can be set by running the update query to set a column as unique.
EX: Alter Table_name Add Constraint Constraint_name Unique(column_name)
Saturday, May 10, 2008
SQL server 2005 - recovery model
- Full - The full recovery model is used in production settings as default recovery model. In this recovery model the database as well as the transaction logs are backed up. So the database can be recovered back to any point in time.
- Bulk Logged - The bulk logged recovery model can be used while doing bulk insert."BULK INSERT" will insert large amounts of data from various types of files.When the bulk logged recovery model is set the bulk inserts are not saved in the transaction logs, as it can be very taxing to save in the transaction log.
- Simple - This does not take any transaction log back up. Suited for a development environment.
Friday, May 9, 2008
Create a database using SQL server 2005
The SQL Server Management Studio Express can be downloaded for free and installed after installing MSXML 6.0. This can be used to connect to the sql server installation. The login screen such as is one comes when you open the Management Studio express.
The authentication mode, server name, username and password have to be filled up to login to the server.The options about the connectivity can be filled into suit your needs. These are network protocol, packet size, connection time-out,Execution time out and also encryption. After connecting to the server, select the "Databases" in the object Explorer and right click to get a list of options. The first otpion is for creating a New database. Select the option to create a new database as given below.
The SQL New database options screen is opened up. The name, location and size of the data and transaction log files can be chosen in the General screen.
The Growth option and owner can also be set in the general option. If you want to add/remove files to the database, they can be added /removed using the add/remove button at the right bottom corner.
Various other options such as the recovery model, file groups and other options can be set while creating the database, but can also be changed later.Each of these options are important and need to be dealt with separately. To start with using the defaults does not cause any problems.
Tuesday, May 6, 2008
SQL server 2005 error and usage report
The SQL server install has an option to send error and usage reports to Microsoft. The option to send or not send is prompted during install. The screen presented during install is rather plain.
The option can be changed after installation is completed. In the programs menu select Microsoft SQL server 2005. Select Configuration tools in Microsoft SQL server 2005.In that select "Error and Usage Report Settings".
Details such as the location of error and usage reports can be specified for each of the different instances.
The error and usage reports can be sent only for a specific instance or all. You can also check the Privacy statement of SQL server 2005 from Microsoft in this screen.
However, will this report generation have a performance impact due to the extra overhead is something that is to be checked.
Monday, May 5, 2008
Uninstall SQL server by instance
If you have installed SQL server, you will want to remove it from the system. Its as easy as removing a program using "Add or Remove programs" from Control Panel. Just remove the Microsoft SQL server 2005.
If one or more instances of the server are installed on the same machine, the instances can be removed individually or as a whole. The option to choose the instances to be removed is provided.
The various components that need to be removed can also be selected for selective removal. The screen to choose is as below.
After the various components that are to be removed and the instances that are to be removed are ticked, the confirmation screen showing components and instances that will be removed are shown. After confirmation the uninstall is done. If two or more instances are running, one instance can be removed without affecting the execution of another instance. However, its better to have a fall back plan in case the other instnace is affected due to system hanging.
Friday, May 2, 2008
SQL Server 2005 Express Edition Install - Part -3
- The "Domain User account" is used when the "service must interact with network services"
- "Local Service account" has "same level of access to resources and objects as members of the Users group"
- "Network Service account" is same as local service account, but the network services can be accesed using the credentials of users group.
- "Local System account" is a highly privileged account and must be used with caution!!
The services that are to be started at end of installation can be choosen in this screen itself.
The next screen allows the "Authentication Mode" to be choosen.If the server is to be on a network with all systems having a Windows domain account, the Windows authentication mode can be choosen, else the Mixed mode has to be selected and a password has to be specified for "sa" logon.
The colation settings define the sorting behaviour for the server and are rather important.Generally the colaltion settings are of utmost importance when upgrading from a previous version of SQL server.
SQL Server 2005 Express Edition Install - Part 2
The install gets intresting from the next screen :). You have to provide some registration information Name and Company. Well thats not the intresting part, below the comapany name there is a check box thats ticked by default saying "Hide Advanced Configuration options". Make sure you uncheck this check box if you plan on configuring the service account type or collation settings. The next screen allows us to select which components to install. The amount of space each component takes up can be checked before installing the component.
The "database serices" installs the SQL server Database engine, tools for managing relational and XML data and replication.
The client components installs command line tools, connectivity components, programming models, management tools and development tools.Choose the components that are best suited for your needs.
SQL Server 2005 Express Edition Install
After the "Next " button is clicked, the system is scanned for coniguration settings.The welcome screen is presented after the system configuration is scanned.
The setup files have now been copied to the local machine from the installation media, either the disk or the installation file.
The instalaltion and configuration will start from the next step. Its better to make sure that the system meets all hardware requirements before moving on to the next step.
Friday, April 25, 2008
Java - switch example
The output will be :This is three when x=3
This is default when x not equal to 1 or 2 or 3
class DefSwitch{
public static void main(String args[]){
int x=3;
switch(x){
case 1:
System.out.println("This is one");
default:
System.out.println("This is default");
case 2:
System.out.println("This is two");
case 3:
System.out.println("This is three");
}
}
}
Knowmax - our intelligence hub
Tuesday, April 22, 2008
Monday, April 21, 2008
Jew Town Kochi
Simple PERL counter
#!/usr/bin/perl
print "Content-type:text/html\n\n";
open (MYFILE, 'counter.txt');
chomp($count=
close (MYFILE);
$count++;
print $count;
open (MYFILE, '>counter.txt');
print MYFILE "$count\n";
close (MYFILE);
A simple script to demonstrate reading from and writing to a file using PERL.