Introduction to Java Syntax (iii): variables

Source: Internet
Author: User
Tags character set logical operators variables

In order to store a data in Java, it must be accommodated in a variable. The data type determines what values a variable can be assigned to, and what kind of action is taken on the variable. The two basic elements of defining a variable are: type and identifier, and you can usually use the following syntax to illustrate variables:

Type Identifer[,identifer];

The statement tells the compiler to create a variable with the type of "type" and the name "Identifer". The semicolon here tells the compiler that this is the end of a descriptive statement; the commas and identifiers in the squares indicate that you can put several types of the same variables in the same statement, separated by commas in the middle of the variable names.

After you create a variable, you can assign it a value, or use an operator to perform some operations on it. A type determines the different kinds of data that a variable represents, and there are two variables in the Java language. The most basic is the simple type variable, they are not built on any other type, integers, floating-point, Boolean, and character types are all of this type (note that unlike other programming languages, where strings are present as instances of a class), Java can define another variant type: class, These types are built on a simple type, which includes numbers, variables, and methods, and is a composite structure that combines data and code.

1: Description of integer variable

Integer variables can be divided into four different types depending on the amount of memory they occupy. The shortest integer is byte, it is only eight bits long, then the short integer, it has 16 bits, the int type has 32 bits, the long integer is 64 digits, and the following is an example of these integer variables.

BYTE Bcount; (In-Memory occupancy: 8 Bits)

Short Scount; (In-memory footprint: Bits)

int ncount; (In-memory footprint: Bits)

Long Lcount; (In-Memory occupancy: $ Bits)

int nx,ny,nz; (In-memory footprint: Bits)

2: Description of Floating point variable

Floating-point types can be used to describe a float or double that floats a floating-point variable that represents a 32-bit single-precision floating-point number, and a double floating-point variable to represent a 64-bit double-precision floating-point number. The floating-point number represented by the double type is more accurate than the float type

float areas;

Double weihgt;

3: Character Variable description

Java uses a 16-bit Unicode character set. Therefore, the Java character is a 16-bit unsigned integer that holds a single character for a character variable. For example:

Char A;

A=´c´;

4: Boolean Variable description

Boolean types have True and false two logical values, and logical operators also return values of a Boolean type, for example:

Boolean OnClick;

Mouseon=true;

A Boolean type is a standalone type, and Boolean types in Java do not represent 0 and 12 integers and cannot be converted to numbers.

Related Article

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.