Java Reference
In-Depth Information
Notice that the object literal declaration of object vehicle no longer includes the color
declaration. Nevertheless, the value of property color will be initialized to Black in the
init{} code block during the object's initialization.
When you run the application, it should display:
You are driving a 2010 Black Mini Cooper!
See also
F Declaring and using variables in JavaFX
F Creating and using JavaFX functions
Creating and using variables in JavaFX
JavaFX is a statically type-safe and type-strict scripting language. Therefore, variables (and
anything which can be assigned to a variable, including functions and expressions) in JavaFX,
must be associated with a type, which indicates the expected behavior and representation of
the variable. This sections explores how to create, initialize, and update JavaFX variables.
Getting ready
Before we look at creating and using variables, it is beneficial to have an understanding of
what is meant by data type and be familiar with some common data types such as String ,
Integer , Float , and Boolean . If you have written code in other scripting languages such
as ActionScript, Python, and Ruby, you will find the concepts in this recipe easy to understand.
How to do it...
JavaFX provides two ways of declaring variables including the def and the var keywords.
def X_STEP = 50;
prntln (X_STEP);
X_STEP++; // causes error
var x : Number;
x = 100;
x = x + X_LOC;
Search WWH ::

Custom Search