Wednesday, December 31, 2008

Will the Paisa go the Farthing way?

A "farthing" was a British coin worth one fourth of a penny. The farthing was continued to be used until 31 December 1960.With the growing rates of inflation it seems the paisa may go the farthing way. I have come across many vendors who refuse to accept 25 paisa coins, let alone 20, 10 or 5 paisa coins.So is it time for these coins to be removed from circulation? Are they actually useful?

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

This simple java desktop application can convert Julian dates into Gregorain and Gregorian dates to Julian dates.This tool is useful for those working with both distributed and mainframes at the same time. The dates in the distributed platforms are in Gregorian format(DD/MM/YYYY) and in Julian format (YY/DDD)in the mainframes.

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;ihelloworldobtianedafterspliting=helloworldobtianedafterspliting.concat(listofchars[i]);//Concatinating strings
}
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 Red Barron is a flying ace par excellence. "Manfred Albrecht Freiherr von Richthofen " popularly known as the Red Barron attained fame by downing as many as 80 enemy aircraft during the First World war. He has been portrayed as a villainous character in many literally works probably due to fighting for the Germans.

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.