java--variables and data types

Source: Internet
Author: User

Variable

A variable is a space for temporarily storing data. So we have the data in the memory space inside, how to take it?

To illustrate:

We can think of the hotel room as a storage space, the name of the room "101" as the variable name, the room type "Standard room", "business" as the variable type, the guest of the occupancy as a variable value.

If we can quickly through the room variable name to know the number of guests staying in the room ( variable value ). Then we can also quickly find the data stored by the variable name.

Summary: Declaring a variable is a space in memory that is used to store data.

Basic data types

In Java, you can divide data types into two kinds of numeric types and Boolean types:

  

It is worth pointing out that a string is not a data class, and a string type is a class, that is, a reference type.

Integral type

int shaping

"Long Integer type

"Bype a byte 8bit value range: -128--127

"Short shorter integer type"

Floating point Type

Double-precision floating-point type

"Fload single-precision floating-point type

Boolean type

"Booleam true and False return values are true and false

Character type

"Char character stores a single character

Variable name

Simply put, like a human name, can be called "Zhang San" or "John Doe", in the programming we have to take some meaningful variable names.

Variable naming rules

1. Variables must begin with a letter, an underscore "-" or a "$" symbol

2. Variables can include numbers, but cannot start with a number

3. In addition to the "-" or "$" symbols, variable names cannot contain special characters.

4. Keywords that cannot be used in the Java language, such as int, class, public, etc.

Specification: The variable name is short and can clearly indicate the function of the variable, which can be composed of one or more words, usually the first letter in lowercase, followed by the first letter of the word capital.

For example:

     

Note Frequently Asked Questions:

1. Variables not assigned value first use

    

2. Use of illegal variable names

    

3. Variable cannot have duplicate name

    

java--variables and data types

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.