The official language definition given in the preface to the Java Programming Language Specification is:
“The Java programming language is a general-purpose concurrent class-based object-oriented programming language, specifically designed to have as few implementation dependencies as possible. It allows application developers to write a program once and then be able to run it everywhere on the Internet.” ~ Preface, The Java Language Specification, 2nd Edition
These two sentences say a lot, but I will focus on two important language features: objects and “write once, run anywhere” (WORA).
Objects
Java is an object-oriented language. In the context of the definition above, an object is an instance of a class. A class is an entity which encapsulates data, referred to as variables, and functions that operate on data, referred to as methods. However the ability to define and create class instances is insufficient to call a language object-oriented. The implications of object-orientation are that the language supports inheritance. Inheritance is the ability of one class to extend the variables and methods of another to create class hierarchies. An often-cited advantage of an object-oriented language is that it facilitates code reuse.
How Objects Apply to GIS
If you have used some of the scripting languages shipped with commercial GIS software, such as ESRI’s Avenue or MapInfo’s MapBasic, then you have probably acquired some feeling for how the ability to manipulate objects shields you from low level details and ultimately makes you more productive. If you have spent time writing C code for GRASS GIS which uses a lot of nested struct types, the nested relationships between these types may be ideal candidates for replacement with an inheritance hierarchy.
Free weekly newsletter
Fill out your e-mail address to receive our newsletter!
By entering your email address you agree to receive our newsletter and agree with our privacy policy.
You may unsubscribe at any time.
Write Once, Run Anywhere (WORA)
A second important feature of Java is “write once, run anywhere” (WORA). In non-interpreted programming languages, such as FORTRAN, C, or C++, a person must have a compiler change the human-readable source code into lower level machine-readable binary code. For each different architecture that a person wants to execute the binary code on, they must perform a separate compilation. This often means that the source code must be rewritten to accommodate differences in machines. Java avoids this inconvenience by having the compiler produce binary code that is in an intermediate form between source and binary code, called bytecode. In order to execute bytecode on a particular machine architecture, a Java interpreter must exist for that architecture. Unlike non-interpreted languages, only a single copy of Java source code and bytecode exists, but there are interpreters for almost every machine architecture on the planet including cell phones, desktop PCs, Macintosh computers, and Linux and UNIX workstations. As the world becomes more digitally connected, heterogeneity in the types and architectures of devices that must communicate will only increase.
How WORA Applies to GIS
Inevitably the organization that you do GIS for will want to participate in the expanding web of communication, perhaps by serving some of your organization’s data and maps on the Internet or by collecting information on the geographic position of assets or customers in the field. The “write once, run anywhere” philosophy of the Java platform means that anytime the architecture of the devices you need to communicate with is heterogeneous or unknown, Java will be the lingua franca. Finally, if you are a business which develops GIS applications, then you can use Java to ensure that the applications you create are portable to as many platforms as your customers demand, without expensive code rewrites.
What Else Is There?
I have not mentioned some of the other language features such as garbage collection, threads, and exceptions, but visit the New To Java Programming Center for more information. Also check out the companion article, “Learning Java, A GIS Perspective” for a guide to resources on the web that can help you learn the Java language.