In methods, you can use any5 of the primitive or composite data types available in Java and the Java libraries. Many of the Application Builder built-in methods make use of primitive or composite data types. For example, the
timeStamp() method provides a
long integer as its output.
The constants 5,
5.0, and
true are literals. Java distinguishes between the literals
5 and
5.0, where
5 is an integer and
5.0 is a double (or float).
In the last line, 14 is seen as an integer literal and the automatic conversion to a double is happening after the integer division
14/41, which results in
0.
In the last line, 14.0 is seen as a double literal and the automatic conversion to a double is happening before the division and is equivalent to
14.0/41.0.
The String data type is a Java object. This is an example of how to declare a string variable:
The resulting string a is
"string A and string B". From an object-oriented perspective, the variable
a is an instance of an object of the class
String. The method
concat is defined in the
String class and available using the
a.concat() syntax.
Comparing string values in Java is done with the equals method and not with the
== operator. This is due to the fact that the
== operator compares whether the strings are the same when viewed as class objects and does not consider their values. The code below demonstrates string comparisons:
In the application tree, the Declarations node directly supports 1D and 2D arrays of type string (
String), integer (
int), Boolean (
boolean), or double (
double). A 1D array may be referred to as a vector and a 2D array referred to as a matrix, provided that the array is rectangular. A nonrectangular array is called jagged or ragged. In methods, you can define higher-dimensional arrays as well as arrays of data types other than string, integer, Boolean, or double.
If you choose not to use the Declarations node to declare an array, then you can use the following syntax in a method:
Arrays are indexed starting from 0. This means that
dv[0] is the first element of the array in the examples above, and
dv[11] is the last element.
where the value of, for example, dm[1][0] is
4.14. This array is a matrix since it is rectangular (it has same number of columns for each row). You can declare a ragged array as follows: