The Java programming language is a common topic in legacy system modernization and in modern application development in general. The biggest selling point for Java is its platform independence. This means that Java code can run on any platform for which there is a Java Virtual Machine (JVM), as opposed to the platform-dependent code used by most legacy systems. HistoryJava, an object-oriented programming language and runtime environment, was developed by a group headed by James Gosling at Sun Microsystems starting in 1991 [Sun 97b]. Java was originally intended for programming electronic consumer devices. Later, in 1995, when the explosion of interest in the Internet began , it became clear that Java was a suitable programming language for Internet applications [van Hoff 96]. Java addresses issues of interoperability, security, portability, and trustworthiness . General StructureA Java program is essentially a class. A class defines the data (state) and methods (behavior) of the specific concrete objects that are subsequently constructed from that class. Figure 7-1 shows a simple class, called Point , that has two data elements, x and y , also called attributes; a constructor, Point() ; and eight methods: setX() , getX() , setY() , getY() , moveRight() , moveLeft() , moveUp() , and moveDown() . A Java program uses the new statement to create an object, or instance, from the Point class as follows : Point p = new Point(); When an instance of a class is created, its constructor is invoked, in this case Point() . The initial values for the Point object just created are x=0 and y=0 , corresponding to the code inside the constructor. Objects communicate with one another through method calls. A fragment of a program that creates an instance of the Point class, moves the point in several directions and uses elements of the Java API to display the values of X and Y follows: Point p = new Point(); // Displays X=0, Y=0 System.out.println("X=" + p.getX() + ", Y=" + p.getY()); p.moveRight(5); // Displays X=5, Y=0 System.out.println("X=" + p.getX() + ", Y=" + p.getY()); p.moveUp(10); // Displays X=5, Y=10 System.out.println("X=" + p.getX() + ", Y=" + p.getY()); The Java PlatformThe Java platform has two components : the Java Virtual Machine and the Java application programming interface. Figure 7-1 Example of a Java classclass Point { private int x; private int y; public Point() { x=0; y=0; } public void setX(int value) { x = value; } public int getX() { return x; } public void setY(int value) { y = value; } public int getY() { return y; } public void moveRight(int value) { setX(x+value); } public void moveLeft(int value) { setX(x-value); } public void moveUp(int value) { setY(y+value); } public void moveDown(int value) { setY(y-value); } } Java Virtual MachineThe JVM is what makes platform independence possible. A Java program is compiled into bytecodes on any platform that has a Java compiler. These bytecodes can then be run on any implementation of the JVM, be it a development tool, the command line version of the JVM, or a Web browser that can run applets. The JVM parses and runs each Java bytecode instruction. Compilation happens only once; interpretation occurs each time the program is executed. This means that as long as a computer has a JVM, the same program written in the Java programming language can run on it. Java Application Programming InterfaceThe Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets. The Java API is grouped into packages of related classes and interfaces. As a platform-independent environment, the Java platform can be slower than code that is compiled for a specific platform, that is, native code. However, there are mechanisms, such as just-in-time bytecode compilers, that convert bytecode to native code on the fly. These compilers can bring performance close to that of native code without threatening portability. Characteristics of the Java LanguageBesides platform independence, the Java language has several other attractive characteristics [Gosling 97]. Object OrientationJava is an object-oriented programming language. A well-designed application can benefit from inheritance, encapsulation, polymorphism, and dynamic binding ”the claims to fame of object orientation. InterpretedThe JVM can be thought of as a bytecode interpreter. Code is compiled once and interpreted on the fly. Classes can be compiled individually, as opposed to the usual compile-link-load cycle that performs these operations for the whole application every time a change is made. PortabilityIn theory, applications will run without modification across multiple platforms because of the JVM. However, JVM versions must be compatible for guaranteed portability. Memory ManagementThe Java runtime environment (JRE) provides memory management and automatic garbage collection. Once memory is allocated for an object, the runtime system tracks the object's status and automatically reclaims memory when the object is no longer in use, freeing memory for future use. There is no explicit use of pointers. MultithreadingThe multithreading built into the Java programming language and runtime platform supports concurrent threads of activity. Dynamic Loading and BindingClasses are linked as required and can be downloaded from across networks. Incoming code goes through bytecode verification before being passed to the JVM for execution. SecurityThe Java runtime environment provides security at multiple levels, from class file verification to access control mechanisms and algorithms [Gong 02]. Types of Java ProgramsThe Java API contains packages that allow you to write several types of programs:
Java Application Programming Interfaces (APIS)Java specifies a core set of application programming interfaces (APIs) required in all Java implementations , as well as an extended set of APIs covering much broader functionality. Some APIs of particular interest to the case study are the following. Java Native InterfaceThe JNI allows Java code that runs within a JVM to operate with applications and libraries written in other languages, such as C and C++. In addition, the Invocation API allows you to embed the JVM into your native applications [Sun 99a]. Remote Method InvocationRMI enables the programmer to create distributed Java-to-Java applications. In these applications, the methods of remote Java objects can be invoked from other JVMs, possibly on different hosts . A Java program can make a call on a remote object after obtaining a reference to the remote object, either by looking up the remote object in the bootstrap naming service provided by RMI or by receiving the reference as an argument or a return value. A client can call a remote object in a server, and that server can also be a client of other remote objects [Sun 02a]. Object Request BrokerAn ORB has been integrated with the Java runtime environment since JDK v1.2. The Java 2 Platform, Standard Edition, v1.4, provides an ORB and two CORBA interface mechanisms ”RMI-IIOP and Java IDL ”that can use the Java CORBA ORB and Internet Inter-ORB Protocol (IIOP) [Sun 02b]. ProductsThe virtual machine for the Java platform on OS 2200 is an implementation of the JDK v1.2.2 code, adapted to the 2200 Series architecture. The implementation of the Java runtime environment allows pure Java-server applications to run under OS 2200. Databases, such as DMS and relational data management system (RDMS), may be accessed by using Java database connectivity (JDBC). The Java Core Classes are included, as well as the virtual machine. Unisys provides OS 2200 proprietary Java classes for interfacing to OS 2200 services. The JNI service allows existing OS 2200 applications, including COBOL programs, to call Java programs running in the JVM. JNI also allows Java application programmers to create wrappers to make use of other OS 2200 services, if required. RMI is supported, allowing the OS 2200 JVM to interwork with other JVMs. These facilities provide considerable scope for using off-the-shelf Java components in OS 2200 environments. The JVM also supports Java servlets, complying with the Java Servlet v2.2 specification and the JavaServer Pages v1.1 specification [Unisys 00]. |