Restrictions and Requirements for Using the Java Object
The following restrictions and requirements apply when using the Java object:
• The Java object is designed to call Java methods from SAS. The Java object is not
intended to extend the SAS library of functions. Calling PROC FCMP functions is
much more efficient for fast in-process extensions to the DATA step, especially when
large data sets are involved. Using the Java object to perform this type of processing
with large data sets takes significantly more time.
• The only Java Run Time Environments (JREs) that are supported by SAS are those
that are explicitly required during the installation of the SAS software.
• The only Java options that are supported by SAS are those that are set when SAS is
installed.
• Ensure that your Java application runs correctly before using it with the Java object.
• The use of a percent character (%) in the first byte of text output by Java to the SAS
log is reserved by SAS. If you need to output a % in the first byte of a Java text line,
it must be escaped with another percent immediately next to it (%%).
Declaring and Instantiating a Java Object
You declare a Java object by using the DECLARE statement. After you declare the new
Java object, use the _NEW_ operator to instantiate the object, using the Java object
name as an argument tag.
declare javaobj j;
j = _new_ javaobj("somejavaclass");
In this example, the DECLARE statement tells the compiler that the object reference J is
of type Java. That is, the instance of the Java object is stored in the variable J. At this
point, you have declared only the object reference J. It has the potential to hold a
component object of type Java. You should declare the Java object only once. The
_NEW_ operator creates an instance of the Java object and assigns it to the object
reference J. The Java class name, SOMEJAVACLASS, is passed as a constructor
argument, which is the first-and-only argument that is required for the Java object
constructor. All other arguments are constructor arguments to the Java class itself.
As an alternative to the two-step process of using the DECLARE statement and the
_NEW_ operator to declare and instantiate a Java object, you can declare and instantiate
a Java object in one step by using the DECLARE statement as a constructor method. The
syntax is as follows:
DECLARE JAVAOBJobject-name(“java-class”, <argument-1, … argument–n>);
For more information, see the “DECLARE Statement, Java Object” in SAS Component
Objects: Reference and the “_NEW_ Operator, Java Object” in SAS Component Objects:
Reference.
Accessing Object Fields
Once you instantiate a Java object, you can access and modify its public and class fields
in a DATA step through method calls on the Java object. Public fields are non-static and
declared as public in the Java class. Class fields are static and accessed from Java
classes.
536 Chapter 22 • Using DATA Step Component Objects