Java data types and definitions of variables

Source: Internet
Author: User

One: Java data types have basic data types, reference data types

Two: 8 Basic data types:

1. Integer type: Byte, Short,long

2. Floating-point data type: float,double

3. Character type: Char

4. Boolean Type: Boolean

A. The default type of integer type is int

B. Define a long type of data, which must be appended with L or L

C. Floating-point number type, the default data is double

D. Define data of type float. You have to add F and f to the data.

E.double, you can add D or D after the data. is generally omitted

F.char represents a character type, and the data is placed in ' value ' when the value is assigned

G.string represents a string type, and when assigned, the data is placed in "value"

Three: Steps to use a variable

First step: Declare variables, both "In memory request space based on data type"

Data type variable name; int money

Step Two: Assign values to "store data in the corresponding memory space"

Variable name = value; money=1000;

The first and third steps merge

Data type variable name = value; int money=1000;

Step three: Use variables to both remove data using

Four: Variable name specification

1. The first letter of the variable name must be a letter, underscore, dollar sign, the rest of the numbers, letters, underscores, dollar signs

2. Short can clearly indicate the role of the variable, usually the first word of the initial capital letter

3. Variables are declared and assigned before they can be used

4. Declaring two variables of the same name cannot be duplicated

Five. Scope of the variable

From defining the variable place to the end of the current "}", the variable will be recycled if it is out of scope

VI: Basic data type conversions

1. Automatic type conversion (implicit type conversion): From small to large types can be automatically completed

2. Coercion of type conversions: large-to-small types require a cast character, resulting in loss of precision or overflow

Byte-->short-->int-->long-->float-->double

From left to right small type to large type, can be automatic type conversion

To the left large type to small type, you need to force type conversion

Java data types and definitions of variables

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.