variables, data types, and operators for Java

Source: Internet
Author: User

2.1.1 Variable

Variables are derived from mathematics and are abstract concepts that can store computational results or represent values in a computer language. Variables can be accessed by variable names. In an instruction language, variables are usually mutable, but in a purely functional language (such as Haskell), variables may be immutable (immutable). In some languages, variables can be explicitly defined as abstractions that can represent mutable states, with storage space, such as in Java and Visual Basic, but others may use other concepts, such as objects in C, to refer to this abstraction without strictly defining the exact extension of the "variable"

2.1.2 Data types

The eight basic data types for 1.Java are:

Integral type

byte byte 1 byte 8bit the maximum amount of storage data is 255, the data range stored is between -128~127

Short 2-byte 16bit maximum data storage is 65536, data range is -32768~32767

int integer 4 byte 32bit maximum data storage capacity is 2 of 32 minus 1, the data range is negative 2 of 31 times to positive 2 square minus 31

Long integer 8 bytes 64bit maximum data storage capacity is 2 of 64 minus 1, the data range is negative 2 of 63 to positive 2 square minus 63

Floating point Type

Float single Precision 4 byte 32bit data range in 3.4e-45~1.4e38, direct assignment must be preceded by a number F or f

Double dual precision 8 byte 64bit data range in 4.9e-324~1.8e308, you can add D or D when you assign a value or do not add

Character type

char character type with single quotation mark

Boolean type

Boolean Boolean true/false (two results only true)

Knowledge description of the data domain:

1. A bit is the smallest unit of data stored in the computer's postgraduate examination. That is, 1 bits, which can only be 0 or 1.

2. A byte is made up of eight bits, which is eight bits, which can represent 256 integer values, and because Byte is signed in Java (that is, positive and negative), the range bit -128~127.

3. A char consists of two bytes in Java, which is used to represent a character, Unicode encoding, that is an unsigned type.

4.int and float are made up of 4 bytes in Java.

5. Each long or double variable occupies eight bytes of storage space.

6.1t=1024g,1g=1024m,1m=1024k,1k=1024b

Be careful:

1. Integers in the program are int by default, that is, a specific integer value that is passed directly to the method invocation, which by default is int.

2. The type of small range can be automatically converted into a large range. A large range cannot be converted directly into a small range, but can be implemented by forced conversion.

eg

BYTE a=10;

Int

I=a;

(The program is working properly, the output of I is 10)

Eg:int a=10;

Byte

I= (Byte) A;

(The program is working properly, the output of I is 10)

If the value of a is outside the upper or lower bounds of the byte type, the value can be output, but the data of the value will change, changing the following rule:

Suppose a is an int and B is a byte type (other things can be analogous!). ~

If a is greater than the upper value of byte, it should subtract its range n times until the final value falls between -128~127, for example: int a=1000;

Byte

B= (Byte) a;//1000-256-256-256-256=-24

(The output of B is-24)

3. Floating-point conversion to integer is not rounding, but directly truncating the fractional part. Such as:

Double

b=12.5;

Int

i= (int) 12.5;

(The output value is 12 instead of 13!) )

4. Scientific representation of floating-point numbers:

For example: 1.2e+12f (indicates 1.2 times 10 of 12 power)

1e-21f (indicates 1 times 10-21 power)

(2) Object data type (Application data type, class type)

All with Class,interface,abstract

class defined by class;

String is a class defined by Java.

String data is stored in a way that is consistent with Java's basic data types.

How string is defined

String

str= "ABC";

String

Str-new String ();

2.2.2 Operator Precedence and description

variables, data types, and operators for Java

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.