My First Java Applet (2002)

by Neil Rieck

Unlike many Java Applet Calendars which are based upon the "Date" function, this one
is based upon the "GregorianCalendar" function which was introduced in JDK1.1

The "correction date" is defaulted to October 15, 1582
where Pope Gregory authorized the removal of 10 days.
(along with special leap-year cases for 100 and 400 year boundaries)


If you can read this, then...
1. your browser might not be Java enabled
2. you might not have a JVM installed
Click here to download one for free

click here if the applet doesn't initialize
(will never initialize with JRE 1.7.0.51 (2014) due to security issues)

Gregorian Calendar Notes:

Neapolitan astronomer Aloysius Lilius noticed that the Julian calendar (which had a leap year every 4 years ) was too long by 11 minutes and 14 seconds per year1 which translated into a discrepancy of almost 9.8 days2a by the year 1582. In order to make the calendar keep in sync with the heavens, he suggested that centuries which are evenly divisible by 100 should not be leap years except those which are evenly divisible by 400.

Easter was originally linked to Passover, but in the year 325 AD at the council at Nicaea, it was decided that Easter would be celebrated on the first Sunday following the first full moon on, or after, the vernal equinox (the passing from winter into spring). In the year 325, the vernal equinox was assumed to be fixed at March 21.

Due to inaccuracies in the Julian calendar, by the 16th century the vernal equinox was occurring on March 11. This caused problems for the church in Rome because most Christians outside of Rome were using the calendar date of "March 21" to calculate the day of Easter rather than the "vernal equinox" event. (sometimes bad weather combined with a lack of local astronomers make the calendar method the only practical choice). This had the effect of pushing the celebration day of Easter closer toward summer.

Note: Christmas was a relatively unimportant church event in those days and was created only to obscure pagan rituals like The Feast of Saturnalia etc. The changing of these calendars is one reason why eastern Europe celebrates Christmas on Jan 6 but I'll leave that for another time partly because that correction involves 12 days.
Pope Gregory XIII assigned the problem to a Jesuit astronomer named Christopher Schlussel (a.k.a. Clavius) who suggested that the equinox problem could be solved by removing 10 days from the current year but from that time forward, the Christian world should adopt the idea proposed by Aloysius Lilius. The plan was approved by Pope Gregory who decreed that October 4, 1582  would be followed by October 15. The peasants revolted thinking that their lives had been shortened by that much. The new calendar was named the Gregorian calendar after the pope who approved the changes.

This so-called "continental calendar" wasn't adopted by England, or its colonies including America, until 1752. At that time, 11 days3b needed to be removed. (10 for the original correction, 1 for 1600)

Superscript Notes:

  1. The Romans thought the Earth required 365.25 days to orbit the Sun and so added an extra day to February every fourth year. These "extra day" calendars are called "leap years" because the calendar leaps to catch up with Earth's orbital position relative to the sun.
     
  2. The Earth actual requires 365.242193 days to orbit the Sun rather than 365.25 as is commonly believed. Skipping a leap year every century gets us much closer. Skipping the century exclusion every 400 years gets us really close.

    Gregorian leap year rules employing positive logic:
    rule test result leap year? calendar
    1 current year/400  = 0
    <> 0
    yes (exit algoithm)
    ??? (do next test)
    Gregorian
    2 current year/100  = 0
    <> 0
    no  (exit algorithm)
    ??? (do next test)
    Gregorian
    3 current year/4  = 0
    <> 0
    yes
    no
    Julian
    Note: Since rule #1 takes precedent over rule #2, then 2000 was a leap year.

    Gregorian leap year rules employing negative logic to reduce computational overhead:
    1. if not a fourth year then exit immediately (LY=no)
    2. if not a century then exit immediately (LY=yes)
    3. make final decision based upon  400-year test  
    rule test result leap year? calendar
    1 current year/4 <> 0
     = 0
    no  (so exit)
    ??? (so do next test)
    Julian
    2 current year/100 <> 0
     = 0
    yes (so exit)
    ??? (so do next test)
    Gregorian
    3 current year/400 <> 0
     = 0
    no
    yes
    Gregorian
     
  3. Correction Calculations (1582 is the main reference point):  
      Year 2 Year 1 year
    difference
    sec/year
    error
    total seconds
    error
    equiv
    days
    notes
    a 1582 AD 325 AD  1257 x 676 =  847218 09.805763889 Europe
    b 1752 AD 325 AD  1427 x 676 =  961798 11.1319213 England and America
    Note: 11 minutes and  14 s = 676 seconds

More Calendar Links:


Debugging Java Applet Problems

User Tips:

Possible Failure Modes:

Click here to download a free JVM from the Sun web site.
Note: "JVM 1.3"  and "JVM 1.4" only support "Netscape Navigator 6" and any version of Internet Explorer. You shouldn't be using any version of Netscape Navigator that is pre version 6 (unless the web page uses the <Object> tag rather than the <Applet> tag)

Programmer Tips:

Old Browsers and/or JVMs

In a business environment your clients are usually on a high speed intranet and it's not unreasonable to to expect that everyone will have the latest browser and JVM (Java Virtual Machine). In this environment you may use the latest Java programming techniques and the latest JVMs. However, on the public internet you must assume that many people are using:

For this reason if you don't want to ostracize certain segments of the public, you must program using JDK 1.1 which means you must use general graphics classes rather than Swing graphics etc.

Please note that this might be a little harder than it sounds. The calendar applet above was first written using SDK 1.3 with Swing graphics. To modify it for use with SDK 1.1 I had to do the following:

Old Browsers with new JVMs

Some older browsers like Netscape 4.x have a built in JVM 1.1 while other browsers don't support Java at all. You can force a browser to use an external JVM by replacing the <Applet> tags on your web pages with <Object> tags. Fortunately, this conversion is done for you when you run a program called HtmlConverter in the JDK bin directory.

Legend:

Nemonic Description
JAR Java Archive
Java An object oriented programming language produced by Sun
JavaScript A browser scripting language produced by Netscape (not related to Java in any way)
JDK Java Development Kit
JRE Java Run-time Environment (JVM and support files but no compiler or debugger)
JVM Java Virtual Machine
SDK Software Development Kit
Swing 2nd generation graphics

Java Rev Numbers:

SDK (JDK) Marketing Basic Features Miscellaneous Notes
1.0 1.0 Introduction   
1.1 1.1 Graphics
Built into Netscape Navigator 4.x
1.2 Java2 Swing Graphics Swing graphic classes contain a 'J' prefix.
eg. Panel becomes JPanel, Applet becomes JApplet, etc.
1.3 Java2 CORBA ORB JApplet requires 3 methods: start(), stop(), init()
a second Timer() method was added
Support for Open-JVM Interface (Netscape 6)
1.4 Java2 Unicode 3, XML JApplet requires 1 method: init()

Back to Home
Neil Rieck
Kitchener - Waterloo - Cambridge, Ontario, Canada.