JavaFX supports various datatypes similar to Java.
JavaFX Data type | Java Data Type |
Boolean | java.lang.Boolean |
Integer | byte,short,int,long, java.math.BigInteger |
Number | java.lang.Number |
String | java.lang.String |
All the data types are declared using var. The type of the data is inferenced based on the context.
String
String can be represented in one of the following ways.
var string1 = 'Hello JavaFX';
var string2 = "Hello JavaFX";
Another String or variable can be referenced using {}. Any expression can also be put in the {}.
var string1 = 'JavaFX';
var string2 = "Hello {string1}";
Adding two strings. We can use def also to define the string
def string1 = 'Hello';
def string2 = "JavaFX";
var string3 = "{string1} {string2}";
Number and Integer
Again def or var can be used to declare.
Another String or variable can be referenced using {}. Any expression can also be put in the {}.
Another String or variable can be referenced using {}. Any expression can also be put in the {}.
var num1 = 50.0; //It's a number
var num2 = 50; //It's an integer
Explicit telling of type is possible
var num1 : Number;
var num2 : Integer;
Boolean
boolean has two states, true and false. The logic can be build using boolean value
var status=true;
if(status){
print("True");
}
Duration
Duration represents time
15ms; //15 milliseconds
15s; // 15 seconds
15m; // 15 minutes
15h; // 15 hour
Null
Null represents that the variable holds no value.
var string1 = null;
//The comparison can be done using null
if(string1 == null){
//do somethings
}
More on JavaFX
No comments:
Post a Comment