From BASIC to Java: an introduction to Java for BASIC programmers (2)

(Continued from the Java for BASIC programmers introduction.)

Procedural vs event-driven programming

In a BASIC program, the general program flow was that it would "start at the beginning and work through to the end", possibly with a few subroutine calls along the way. This is a nice, easy-to-understand model for simple applications. But with today's complex, windowed, multi-tasking operating systems, the procedural model doesn't often work very well.

Instead, Java (and programming for modern operating systems in general) takes an event-driven approach. In a typical windowed application, the program sets up event handlers: pieces of code to run when something interesting happens, such as mouse click inside one of the application's windows. For much of the rest of the time, none of your code may actually be running.

Another important notion in Java programming (and again, in modern programming in general), is the notion of threads: sub-strands of a program that can run in parallel. A main program might spawn threads to perform particular jobs in the background, or break a calculation into several parts that run simultaneously. Modern computers are typically designed to allow several threads to physically run in paraellel, and beyond this the operating system can make different threads effectively run in parallel by "swapping them in and out" of the processor.

On the next page, we continue with a look at From BASIC to Java: libraries and access to the operating system.


If you enjoy this Java programming article, please share with friends and colleagues. Follow the author on Twitter for the latest news and rants.

Editorial page content written by Neil Coffey. Copyright © Javamex UK 2021. All rights reserved.