3
Java: Object-oriented programming for the cyber age SIAMAK HASSANZADEH CHARLES C. MOSHER Sun Microsystems ARCO Exploration and Production Technology Mountain View, California Plano, Texas A phenomenal rise in interest in the Java programming environment and World Wide Web browsers with Java capability have added a new dimension to the ever-increasing popularity of the Internet and the Web (TLE, March and July 1995). The Java programming language originated at Sun Microsystems as part of a larger project to develop advanced software for consumer electronics. These devices are small, reliable, portable, distributed, real-time embed- ded systems. Initially the intention was to use C++. But after encountering a number of problems, a new language, originally called Oak, was born. After several years of experience with the lan- guage, it was renamed to Java and was retargeted to the Internet. In a nutshell, Java is a simplified, safe, and portable version of C++. Examples of Java aware browsers are Netscape (2.0 and above) and the HotJava Browser from Sun Microsystems. The HotJava browser is actually an application writ- ten in the Java language. Web browsers with Java capabilities help make the In- ternet come alive. Java-based browsers build on the Internet and network browsing techniques established by Mosaic (TLE, March 1995) and ex- pands them by adding dynamic behav- ior that transforms static documents into dynamic applications. One of the most useful features of Java is its ability to dynamically add to its capabilities. This feature is called in- teractive content. Using Java, you can add applications that allow the user to interact dynamically with the Web page. Examples in geophysics range from interactive seismic data interpre- tation to 3-D seismic movies (dynamic visualization of 3-D seismic data); the possibilities are endless. Design goals. The Java programming language and environment are designed to solve a number of problems in mod- ern programming practice. Java is a “simple, object-oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded, and dynamic” language. (The Java language: http://java.sun.com.) From the onset of its design, Java was meant to be simple and familiar. It has the “look and feel” of C and C++, and as such it can be programmed eas- ily and without much training. The ob- jective from the beginning was that the learning curve should not be too steep. Java is object-oriented, providing fa- cilities to define and manipulate ob- jects. Objects are self-contained entities which have a state (a collection of data associated with an object) and to which messages can be sent (see Appendix A for a brief introduction to objects). A message is a mechanism by which the state of an object can be accessed or al- tered. The object-oriented facilities of Java are essentially those of C++, with extensions from Objective C. Designed for Intranet and Internet computing, Java has an extensive li- brary of routines for dealing with TCP/IP protocols like HTTP and FTP (TLE, March and July 1995). Network computing is integrated into the lan- guage and runtime system and is hence (almost) transparent. Moreover, a great deal of emphasis has been placed on se- curity. Java provides a programming environment for developing virus-free and tamper-free applications. Applica- tions written in Java are secure from in- trusions by unauthorized codes. It should be noted, however, that not all security issues of the Java language have been resolved. These issues are being addressed as the language evolves. Java is robust due to the elimination of features of programming languages such as C which lead to applications crashing at crucial moments. The single biggest difference between Java and C/C++ is that Java has a pointer model that eliminates the possibility of over- writing the memory and corrupting data. Instead of pointer arithmetic, Java has true arrays as in Fortran. In addi- tion, it’s not possible to turn an arbitrary integer into a pointer by casting. Java puts a lot of emphasis on early checking for possible problems, later dynamic (runtime) checking, and eliminating sit- uations that are error prone. Support applications of Java run on heterogeneous networked computer systems. To enable a Java application to execute anywhere on the network, the compiler generates bytecodes - an ar- chitecture neutral object file format de- signed to transport codes to multiple hardware and software platforms. In one sense, bytecodes are portable hard- ware-level machine instructions. The Java interpreter can execute bytecodes directly on any system to which the in- terpreter has been ported. With this neu- trality, most applications software written in the Java language can be run on any system. The architecture-neutral and portability of Java is often referred to conceptually as the Java Platform, a “Write Once, Run Anywhere” capabil- ity for delivering and running applica- tions on heterogeneous computing environments. High performance is achieved by translating bytecodes on the fly (at run- time) into native machine codes. For ap- plications requiring large amounts of compute power, the compute-intensive segments can be rewritten in native ma- chine codes and interfaced with the Java environment. Java also supports multi- threading; the capability to execute multiple concurrent sequences of in- structions. Multithreading allows devel- opment of high performance parallel computing applications. The inclusion of parallel computing concepts as part of the language makes Java an attractive platform for not only for interactive applications, but also for scientific com- puting applications (i.e., seismic pro- cessing) requiring large amounts of computing horsepower. A more dynamic language than C or C++, Java can adapt to an evolving en- vironment. Many functionalities needed during the execution of an application can be linked dynamically as needed. In summary, the Java language makes ob- ject-oriented programming easier and DECEMBER 1996 THE LEADING EDGE 1379

Java: Object-oriented programming for the cyber agejavaseis.sourceforge.net/documents/TLE_1996_JavaSeis.pdf · Java: Object-oriented programming for the cyber age ... Sun Microsystems

Embed Size (px)

Citation preview

Page 1: Java: Object-oriented programming for the cyber agejavaseis.sourceforge.net/documents/TLE_1996_JavaSeis.pdf · Java: Object-oriented programming for the cyber age ... Sun Microsystems

Java: Object-oriented programmingfor the cyber age

SIAMAK HASSANZADEH CHARLES C. MOSHERSun Microsystems ARCO Exploration and Production Technology

Mountain View, California Plano, Texas

A phenomenal rise in interest in theJava programming environment andWorld Wide Web browsers with Javacapability have added a new dimensionto the ever-increasing popularity of theInternet and the Web (TLE, March andJuly 1995).

The Java programming languageoriginated at Sun Microsystems as partof a larger project to develop advancedsoftware for consumer electronics.These devices are small, reliable,portable, distributed, real-time embed-ded systems. Initially the intention wasto use C++. But after encountering anumber of problems, a new language,originally called Oak, was born. Afterseveral years of experience with the lan-guage, it was renamed to Java and wasretargeted to the Internet. In a nutshell,Java is a simplified, safe, and portableversion of C++. Examples of Javaaware browsers are Netscape (2.0 andabove) and the HotJava Browserfrom Sun Microsystems. The HotJavabrowser is actually an application writ-ten in the Java language. Web browserswith Java capabilities help make the In-ternet come alive. Java-based browsersbuild on the Internet and networkbrowsing techniques established byMosaic (TLE, March 1995) and ex-pands them by adding dynamic behav-ior that transforms static documentsinto dynamic applications.

One of the most useful features ofJava is its ability to dynamically add toits capabilities. This feature is called in-teractive content. Using Java, you canadd applications that allow the user tointeract dynamically with the Webpage. Examples in geophysics rangefrom interactive seismic data interpre-tation to 3-D seismic movies (dynamicvisualization of 3-D seismic data); thepossibilities are endless.

Design goals. The Java programminglanguage and environment are designedto solve a number of problems in mod-ern programming practice. Java is a“simple, object-oriented, distributed,interpreted, robust, secure, architecture

neutral, portable, high-performance,multithreaded, and dynamic” language.(The Java language: http://java.sun.com.)

From the onset of its design, Javawas meant to be simple and familiar. Ithas the “look and feel” of C and C++,and as such it can be programmed eas-ily and without much training. The ob-jective from the beginning was that thelearning curve should not be too steep.

Java is object-oriented, providing fa-cilities to define and manipulate ob-jects. Objects are self-contained entitieswhich have a state (a collection of dataassociated with an object) and to whichmessages can be sent (see Appendix Afor a brief introduction to objects). Amessage is a mechanism by which thestate of an object can be accessed or al-tered. The object-oriented facilities ofJava are essentially those of C++, withextensions from Objective C.

Designed for Intranet and Internetcomputing, Java has an extensive li-brary of routines for dealing withTCP/IP protocols like HTTP and FTP(TLE, March and July 1995). Networkcomputing is integrated into the lan-guage and runtime system and is hence(almost) transparent. Moreover, a greatdeal of emphasis has been placed on se-curity. Java provides a programmingenvironment for developing virus-freeand tamper-free applications. Applica-tions written in Java are secure from in-trusions by unauthorized codes. Itshould be noted, however, that not allsecurity issues of the Java languagehave been resolved. These issues arebeing addressed as the languageevolves.

Java is robust due to the eliminationof features of programming languagessuch as C which lead to applicationscrashing at crucial moments. The singlebiggest difference between Java andC/C++ is that Java has a pointer modelthat eliminates the possibility of over-writing the memory and corruptingdata. Instead of pointer arithmetic, Javahas true arrays as in Fortran. In addi-tion, it’s not possible to turn an arbitraryinteger into a pointer by casting. Java

puts a lot of emphasis on early checkingfor possible problems, later dynamic(runtime) checking, and eliminating sit-uations that are error prone.

Support applications of Java run onheterogeneous networked computersystems. To enable a Java application toexecute anywhere on the network, thecompiler generates bytecodes - an ar-chitecture neutral object file format de-signed to transport codes to multiplehardware and software platforms. Inone sense, bytecodes are portable hard-ware-level machine instructions. TheJava interpreter can execute bytecodesdirectly on any system to which the in-terpreter has been ported. With this neu-trality, most applications softwarewritten in the Java language can be runon any system. The architecture-neutraland portability of Java is often referredto conceptually as the Java Platform, a“Write Once, Run Anywhere” capabil-ity for delivering and running applica-tions on heterogeneous computingenvironments.

High performance is achieved bytranslating bytecodes on the fly (at run-time) into native machine codes. For ap-plications requiring large amounts ofcompute power, the compute-intensivesegments can be rewritten in native ma-chine codes and interfaced with the Javaenvironment. Java also supports multi-threading; the capability to executemultiple concurrent sequences of in-structions. Multithreading allows devel-opment of high performance parallelcomputing applications. The inclusionof parallel computing concepts as partof the language makes Java an attractiveplatform for not only for interactiveapplications, but also for scientific com-puting applications (i.e., seismic pro-cessing) requiring large amounts ofcomputing horsepower.

A more dynamic language than C orC++, Java can adapt to an evolving en-vironment. Many functionalities neededduring the execution of an applicationcan be linked dynamically as needed. Insummary, the Java language makes ob-ject-oriented programming easier and

DECEMBER 1996 THE LEADING EDGE 1379

Page 2: Java: Object-oriented programming for the cyber agejavaseis.sourceforge.net/documents/TLE_1996_JavaSeis.pdf · Java: Object-oriented programming for the cyber age ... Sun Microsystems

*The HelloWorldApp class implements an application that*simply displays” Hello World!’ to the standard output.*/

class HelloWorldApp {public static void main(String[] args) {

System.out.println("Hello World!“); //Display the string.

IFigure 1. The ‘Hello World!’ program written in Java.

int sum (int arr[]) {int result = 0;for (int i = arr.length ; --i>=rl ;) {

results += arr{i};}return results;

}

Figure 2. The ‘Sum’ program writtenin Java.

//Iterativelong faci (int n) (

long result = 1 L;for (int i = 2; i n ; i++ ) {

results*= n:}return results;

}// Recursive

long facr (int n) {i f (n<= l ) {return 1 L;}retturn facr (n - 1) * n;

}

Figure 3. The ‘Factorial’ programwritten in Java.

provides a new powerful tool for the de-velopment of interactive, distributed,and parallel computing applications.

Language specification. Although re-lated to C and C++, Java is organizeddifferently, with some of their featuresomitted and a few from other languagesincluded. Java is intended to be a pro-duction language, not a research lan-guage, and so the design of Java hasavoided including new and untestedfeatures.

Java is strongly typed language,which means that every variable andevery expression has a type that isknown at compile time. Types limit thevalues that a variable can hold or that anexpression can produce. Types alsolimit the operations supported on thosevalues, and determine the meaning ofthe operations. This specification

clearly distinguishes between errorsthat can and must be detected at com-pile time, and those that occur at runtime. Compile time normally consistsof translating Java programs into a ma-chine-independent byte-code represen-tation. Run-time activities includeloading and linking of the classesneeded to execute a program, optionalmachine code generation and dynamicoptimization of the program, and actualprogram execution.

As in C or C++, Java is a relativelyhigh-level language. To illustrate thesimple and familiar features of Java,Figure I displays the traditional ‘HelloWorld!’ program written in Java. Thisexample declares a class thus named.Within this class, a single method called‘main’ is declared which in turn con-tains a single method invocation to dis-play the string ‘Hello World!’ on thestandard output (e.g., on the monitor).The statement that prints ‘Hello World!’does so by invoking the ‘println’method of the ‘out’ object. The out ob-ject is a class variable in the ‘system’class that performs output operations ontiles. Figures 2 and 3 show examples ofa summing operation and factorial writ-ten in Java language. More detailed in-formation and examples can beobtained from http:// java.sun.com.

JavaSeis. Seismic data processing isideally suited for parallel distributedcomputing (TLE, this issue). However,thus far there has not been a simple pro-gramming environment to provide aportable, distributed and parallel frame-work for scientific computation in gen-eral, and seismic data processing inparticular. Previous attempts at devel-oping such a framework have beenbased on C++ (POOMA: the parallelobject-oriented methods and applica-tions, http://www.acl.lanl.gov/pooma-framework).

As the basis for the JavaSeis efforts,we plan to use the ARCO seismicbenchmark suite (SBS), which has re-

00 programming 101

Object-oriented programming (incontrast to procedural techniques) isa different way of organizing soft-ware. Objects are software program-ning entities that may represent realworld items such as cars, planes,trees, oil fields, etc. Software appli-cations may also contain objectssuch as spreadsheets, menus, and soon. Thus any system can be regardedas a collection of objects.

In technical terms, object-ori-ented technology consists of a set ofnodules called classes, a set of in-heritance relations, and mapping‘unctions that associate pairs ofclasses. Each object is representedby a unique identifier and has somedata associated with it. The collec-ion of data associated with an ob-ect is called its state. The state of anobject is defined by its instance vari-ables. The functions an object per-forms are known as its behavior Anobject’s behavior is defined by meth-ods. Methods manipulate the in-stance variables to create a newstate. A class is a software constructhat defines the instance variablesand methods of an object. A class inand of itself is not an object. A classdefines how an object will look andbehave when an object is created ornstantiated from the specification

declared by the class. Inheritance isa defined relationship between twoc l a s s e s

If an object wants another objectto perform some work on its behalfit sends a message to the second ob.ject. Using the message-passing par.adigms of object-oriented pro.gramming, one can build entire net.works of objects that pass message!among themselves to change theirstates. This programming techniqueis ideal for creating a distributed andparallel framework for scientificcomputing. Appendix B contains alist of references on object-orientecprogramming.

cently been incorporated into theSPEChpc96 benchmark suite as SPEC-seis96. SBS manages seismic data asparallel distributed objects using tradi-tional procedural languages (C and For-tran). The environment is designed to beflexible and extendable, and is used ex-tensively at ARCO as a prototyping en-

Page 3: Java: Object-oriented programming for the cyber agejavaseis.sourceforge.net/documents/TLE_1996_JavaSeis.pdf · Java: Object-oriented programming for the cyber age ... Sun Microsystems

vironment. New processes are devel-oped using “inheritance by copyingtemplates.” As a result, system changesthat often require extensive modifica-tions to all copies of a few basic systemtemplates are now amended by adjust-ing only base templates. Parallelism ismanaged through an API defined by theservices required for implementingcommon geophysical data processingalgorithms .

The existing object-based structureof SBS and the well-defined parallel be-havior of many geophysical algorithmsmakes this application suite a natural fitwith the constructs defined in the Javalanguage. Currently, maintenance andportability of SBS are made more diffi-cult by lack of a coherent object modeland a consistent parallel programmingmodel. Implementation of SBS in Javawould significantly improve the porta-bility and maintainability of seismiccomputing applications, and would alsoprovide a pathway to use of networkbased parallel computing for produc-tion seismic processing.

Concluding remarks. The Java lan-guage, very simple and object-oriented,provides an extremely attractive plat-form for development of portable, dis-tributed and parallel applications forscientific computing in general andseismic data processing in particular.Java’s architecture-neutral aspectsmake it an ideal development program-ming paradigm to meet the challengesof distributing dynamically extensiblesoftware across networks of computers.

Suggestions for further reading. Anintroduction to Object-Oriented Pro-gramming, by T. Budd., Addison Wes-ley Publ i sh ing Co. inc ludes acomparison of the C++, Objective C,SmallTalk, and Object Pascal. The De-sign and Evolution of C++, by B.Stroustrop, Addison Wesley , is a de-tailed history of how we came to wherewe are with C++. Java Language Tuto-rial: Object-Oriented Programming forthe Internet, Sun Microsystems, Inc.http://www.javasoft.com/ is an on-lineguide to writing programs in the Javalanguage. The Java Language Specifi-cation, by Gosling, Joy, and Steele, SunMicrosystems, http://www.javasoft.com/. Another introduction to the objectoriented techniques is Active Java, Ob-ject-oriented Programming for theWorld Wide Web, by Freeman and Ince,Addison-Wesley. E

DECEMBER 1996 THE LEADING EDGE 1381