Java Object Language Elements |
Valid in: | DATA step |
Syntax | |
Arguments | |
Details | |
Comparisons | |
Examples | |
See Also |
Syntax |
object-reference = _NEW_ JAVAOBJ ("java-class", <argument-1 , ... argument-n>); |
Arguments |
specifies the object reference name for the java object.
specifies the name of the Java class to be instantiated.
Requirement: | The Java class name must be enclosed in either double or single quotation marks. |
specifies the information that is used to create an instance of the java object. Valid values for argument depend on the java object.
See Also: | Details |
Details |
To use a DATA step component object in your SAS program, you must declare and create (instantiate) the object. The DATA step component interface provides a mechanism for accessing the predefined component objects from within the DATA step.
If you use the _NEW_ operator to instantiate the java object, you must first use the DECLARE statement to declare the java object. For example, in the following lines of code, the DECLARE statement tells SAS that the object reference J is a java object. The _NEW_ operator creates the java object and assigns it to the object reference J.
declare javaobj j; j = _new_ javaobj("somejavaclass" );
Note: You can use the DECLARE statement to declare and instantiate a java object in one step.
A constructor is a method that is used to instantiate a component object and to initialize the component object data. For example, in the following lines of code, the _NEW_ operator instantiates a java object and assigns it to the object reference J. Note that the only required argument to a java object constructor is the name of the Java class to be instantiated. All other arguments are constructor arguments to the Java class itself. In addition, the Java classname, testjavaclass, he constructor and the values 100 and .8 are constructor arguments.
declare javaobj j; j = _new_ javaobj("testjavaclass", 100, .8);
For more information about the predefined DATA step component objects and constructors, see Using DATA Step Component Objects in SAS Language Reference: Concepts.
Comparisons |
You can use the DECLARE statement and the _NEW_ operator, or the DECLARE statement alone to declare and instantiate an instance of a java object.
Examples |
In the following example, a Java class is created for a hash table. The _NEW_ operator is used to create and instantiate an instance of this class by specifying the capacity and load factor. In this example, a wrapper class, mhash, is necessary because the DATA step's only numeric type is equivalent to the Java type DOUBLE.
/* Java code */ import java.util.*; public class mhash extends Hashtable; { mhash (double size, double load) { super ((int)size, (float)load); } }
/* DATA step code */ data _null_; declare javaobj h; h = _new_ javaobj("mhash", 100, .8); run;
See Also |
Statements: | |||
Using DATA Step Component Objects in SAS Language Reference: Concepts |
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.