10 Mar 1996

Native Classes

A Java source file can define a class and its methods. Method functions can perform computations and other operations based on the primitive data types, array indexing, and string concatenation. They can also create objects of other classes and call methods.

Java code cannot directly make calls to the local operating system to access disk files, run programs, use network resources, or query databases. Instead, such requests must be made indirectly through a native class.

To build a native class, the programmer starts with Java code that defines the field variables and the names and arguments of all methods. The methods contain no code. This file is then processed by a utility that converts it into C. The rest of the programming is done with the native C language and all the subroutines available through it.

A client program views the native class just like any other class in the library. However, there is an additional file that contains system-specific executable instructions. In Windows NT or Windows 95, for example, the native class is implemented by functions in a DLL module.

DLLs for the native classes are distributed with the Web browsers and stand-alone Java Interpreters. Unlike real Java class files, native classes cannot be distributed from a server through the network. Therefore, a Java user is assured that Java applications are constrained to use only services provided by the native classes that the user himself installed on his own machine prior to running the application.

The Java language group at Sun Microsystems is rather keen on keeping the language pure and avoiding native classes whenever possible. Widely recognized requirements, such as database access, will be handled through an evolving set of language standards, such as JDBC. Proprietary native classes may be generated to meet application specific requirements. For example, Oracle allows Java programs to run on its Web Server, and supplies these programs with native classes to access the PL/SQL packages and stored procedures in the Oracle database.

Continue Back PCLT

Copyright 1996 PC Lube and Tune -- Java H. Gilbert

This document generated by SpHyDir, another fine product of PC Lube and Tune.