Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail


Java Server Pages


Java Beans



Java Servlets



Java Code Examples

Interview Questions

Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting


Beginner Guide to Linux Server


Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers


Adware & Spyware Remover

Open Source Softwares



2003-03-31 The Java Specialists' Newsletter [Issue 067] - BASIC Java

Author: Dr. Heinz M. Kabutz

If you are reading this, and have not subscribed, please consider doing it now by going to our subscribe page. You can subscribe either via email or RSS.

Welcome to the 67th edition of The Java(tm) Specialists' Newsletter, sent to 6299 Java Specialists in 94 countries. I am in the process of printing a softcover book containing all the newsletters up to and including the 65th issue. The book is primarily for students on my courses, but if you would like a copy at ZAR 295, please send me an email. A softcover book is practical since you can read it while lying on the beach.

In the western world, we celebrate the 1st of April with jokes, trying to catch out unsuspecting and gullible people. Last year, I sent out a newsletter in which I announced that from that day forth, you would have to pay to become unsubscribed, and that the unsubscription fee would automatically be deducted off your credit card. Naturally, quite a few subscribers sent me emails such as: "haha, look at the date". Others sent me outraged emails telling me that they had not agreed to this and that I could not do it. My wife Helene had warned me against putting in the joke, but being a stubborn South African German, I naturally did not listen. This year, I was going to repeat my folly, but having thought about it for a while, have decided that with a hundred countries on my list, an April fool's newsletter would only serve to confuse a significant number of readers.

HOWEVER, in this newsletter I have some lighthearted material on how you can write BASIC code in Java. In the middle of March I was in Germany visiting my grandmother for her 90th birthday, and while I was there, managed to present a Design Patterns Course to a company in Frankfurt. Our friend Carl Smotricz, who used to host our newsletter on his website, was one of the 13 course participants. While Carl was taking me to the train station after the second day of lectures, Carl told me that it was possible to program GOTO in Java. Naturally I was curious, so I asked Carl to give me an example. The theme sounded like an ideal opportunity for an April 1st joke, so I will send this newsletter to you with the warning that Carl and I were basically having fun and seeing how far we could push the Java Programming Language to look like BASIC.


Carl and I have something in common. Both of us started programming in BASIC. BASIC stands for Beginners All-purpose Symbolic Instruction Code and is the easiest language in the world to understand. It is not surprising that Visual BASIC is so popular. We even have plans to produce a Design Patterns Course for Visual Basic .NET (the Delphi version is already underway - and that is not an April Fools joke ;-)

BASIC has the following advantages over Java:

  1. BASIC is for beginners. Most programmers in the world today have less than 10 years experience and therefore should be considered as beginners. Java is definitely not for beginners. It is for expert programmers. It gives you more ways of shooting yourself in the foot than an AK47. (I do not consider VB.NET to be BASIC, but rather just another flavour of Java.)
  2. BASIC allows global variables. Global variables reduce the number of instances of variables needed, they reduce the namespace. Global variables make it easy to write a program, although maintenance becomes almost impossible. Do not you believe me that global variables make coding easier? Think of a Design Pattern. Think of any Design Pattern. Any one. Name it out loud, and then please go to the end of this email and look at the P.S.
  3. BASIC supports the GOTO statement. GOTO is perhaps not the darling of Edsger W. Dijkstra but it does allow us to write interesting succinct code, which certainly ensures that we will be employed in a maintenance role for many years to come.
  4. BASIC is widely understood and supported. Say "goodbye" to expensive finder fees from recruitment agencies. Hire one of thousands of BASIC programmers and pay them very little. Or, since BASIC is for beginners, take someone straight out of arts to do the programming for you.

Consider the following BASIC program. Don't just skip over it, try to understand what is happening. If you read it carefully, you will see that it constructs a list of 10 numbers, then sorts them using the Bubble Sort algorithm. (Thanks Carl for this piece of code.)

20 I = 0
30 N(I) = INT(1000 * RND)
40 I = I + 1: IF I < 10 GOTO 30
50 S% = 1 : I = 0
60 IF N(I) < N(I + 1) GOTO 80
70 T = N(I) : N(I) = N(I + 1) : N(I + 1) = T : S% = 0
80 I = I + 1 : IF I < 9 GOTO 60
90 IF S% = 0 GOTO 50
100 I = 0
110 PRINT N(I)
120 I = I + 1 : IF I < 10 GOTO 110
130 STOP

When we run this with Microsoft QuickBasic 3.0, we see something like:


If we wanted to convert this to Java, we could either hire an expensive Java programmer (who probably would not understand the above code), or we could write a tool to automatically translate the above code to "Java". Remember the GIGO principle - Garbage in - Garbage out.

Is it possible to translate this to Java? Yessir!

public class Bubble extends Basic {
  // Original Code:
  // 20 I = 0
  // 30 N(I) = INT(1000 * RND)
  // 40 I = I + 1: IF I < 10 GOTO 30
  // 50 S% = 1 : I = 0
  // 60 IF N(I) < N(I + 1) GOTO 80
  // 70 T = N(I) : N(I) = N(I + 1) : N(I + 1) = T : S% = 0
  // 80 I = I + 1 : IF I < 9 GOTO 60
  // 90 IF S% = 0 GOTO 50
  // 100 I = 0
  // 110 PRINT N(I)
  // 120 I = I + 1 : IF I < 10 GOTO 110
  public static void main(String[] args) {
    int I=0;int S=0;int N[] = null;
    while(jump != -1) {
      try {
        switch(jump) {
          case 10: N = DIM(10);
          case 20: I = 0;
          case 30: N[I] = INT(1000 * RND());
          case 40: I = I + 1; if (I < 10) GOTO (30);
          case 50: S = 1; I = 0;
          case 60: if( N[I] < N[I + 1]) GOTO (80);
          case 70: int T = N[I] ; N[I] = N[I + 1] ; N[I + 1] = T ; S = 0;
          case 80: I = I + 1 ; if (I < 9) GOTO (60);
          case 90: if (S == 0) GOTO (50);
          case 100: I = 0;
          case 110: PRINT (N[I]);
          case 120: I = I + 1; if (I < 10) GOTO (110);
          case 130: STOP();
        // if there was no GOTO then we want to end the program
      } catch(GotoException ex) {
        // GOTO was called, and a GotoException has caused the
        // control to pass outside of the switch statement

The output would be something along the lines of:


What does the code for Basic.java look like?

public class Basic {
  // GotoException is thrown by GOTO to avoid having to call
  // "break" after the call to GOTO in the switch statement.
  // I warned you before that Exceptions were dangerous ;-)
  protected static final class GotoException
      extends RuntimeException {
    private GotoException() {}
  private static final GotoException gotoEx =
    new GotoException();

  public static int jump=10;
  public static void GOTO(int line) {
    jump = line;
    throw gotoEx;
  // STOP changes the current line to be -1, which ends the
  // program
  public static void STOP() {
    GOTO (-1);
  public static void PRINT(String s) {
  public static void PRINT(int i) {
  public static int[] DIM(int n) {
    return new int[n];
  public static double RND() {
    return Math.random();
  public static int INT(double d) {
    return (int)d;

What makes me scared is that the code runs and actually works. Perhaps one day Carl and I will write a tool to automatically convert legacy BASIC code to Java ......

Kind regards, and don't get caught out tomorrow!


P.S. You probably thought of the Singleton? The Singleton's intent is to provide a global access point to an object. Is that not a global variable?

This material from The Java(tm) Specialists' Newsletter by Maximum Solutions (South Africa). Please contact Maximum Solutions for more information.


Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials


Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.