Search this site


 Home  Howto index  Getting started with Java  Java for C programmers  Java for BASIC programmers

From BASIC to Java: an introduction to Java for BASIC programmers

If you're starting out with Java but have programmed in some variety of BASIC before, this page outlines some major differences between the two. When I talk about "versions of BASIC", I'm thinking mainly about the varieties found on typical home computers in the 1980s. It's true that later versions, notably Microsoft's Visual BASIC, actually break away from some of the limitations of BASIC that I mention here (all though some of the comparisons I make still hold).

Structure

It's probably fair to say that BASIC doesn't generally encourage much structure, especially early versions of BASIC. A typical BASIC program consists of a single, long program or file. In early versions, it was not uncommon to use a GOTO command to jump to arbitrary points in the program. At best, many have a GOSUB command or some way of jumping to part of a program that will then jump "back" again after the subroutine is completed. But there is often no formal way to organise a large BASIC program into sections to deal with particular parts of the application, or to deal with different types of data.

Many versions of BASIC provide no sophisticated means to organise data. If you wanted a fixed-size list of variables of the same type, then an array would just about do. For anything more sophisticated, e.g. a list of (x,y) coordinates, clumsy workarounds had to be found such as having two arrays, with nothing formal to link an x co-ordinate with its associated y co-ordinate. About the most structured things got was the ability (e.g. in BBC BASIC) to declare an array of "raw" bytes, into which you could put whatever group of data you wanted.

In Java, things are very much more structured. The whole language is thought around the idea of structured pieces of data, accompanied by the subroutines or methods that manipulate them. This combination of data structure plus methods to manipulate it is called a class. Classes can be extended. For example, you can create a class to store and manipulate a 2D co-ordinate. Then you can extend this class to deal with a 3D co-ordinate. In the latter class, you would generally need to add only the "extra" data and methods that differentiate a 2D co-ordinate from a 3D co-ordinate. This structured approach is generally what is meant by object-oriented programming, and turns out to be a powerful means of creating complex applications.

On the next page: From BASIC to Java: procedural vs event-driven programming.

comments powered by Disqus

Written by Neil Coffey. Copyright © Javamex UK 2012. All rights reserved.