JavaFX in simple and simple (iv) variables, functions

Source: Internet
Author: User
Tags constant integer

JavaFX variables and functions have a different place than traditional Java syntax.

First, variables and constants

1. Statement

var variable name: type = variable value;

DEF constant name: type = constant value;

Where the: type is optional and the compiler automatically determines the type.

var I:integer = 12;var I1 = 11;//automatically judged as Integer

def name:string = "Hello"; def name1 = "Hello";//automatically judged as String

The constants declared by DEF cannot be modified after they are assigned, but if the constant is an object type, his members can change, for example:

def P:person = new Person (); p. Name= "renamed";//can modify members

2, type

In JavaFX, there are three types of variables and constants:

Script level

Members of a class

Temporary variable in a function or block

3. Visibility

Package Variables can only be accessed within a defined package.
Protected A variable can be accessed within a defined package, or as a subclass of a defined class.
Public Variables can be accessed arbitrarily.
Public-read Variables defined by Var can be accessed arbitrarily.
Public-init Variables that are defined by Var can be initialized or read-access-free.

4. System Predefined variables

__file__ represents the URL that currently loads the __file__ script.

__dir__ represents the URL of the directory where the __dir__ script is currently loaded.

__PROFILE__ returns "mobile", "desktop" or "browser" depending on the environment in which it is run

Second, function

1, the definition of the function

Function name (parameter name: argument type, ...). ): return type {

function body

}

The return type can be Void or any other type if it is not specified: return type, the system will automatically judge according to the type returned if there are no returns statements, the system defaults to return null void the first letter is uppercase

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.