Java Fundamentals (1) variables, data types

Source: Internet
Author: User
Tags binary to decimal

1. Why a variable is required

Memory is like a locker, used to store a variety of things or data, the programmer carcass, the data into memory is only the first step, but also to consider how to find the data deposited, the data stored can be modified, write the program is to do memory access, first put the data into memory, need is very good to take out. Data into memory, how do we find it? This will be based on the memory address to find the data we need, the memory address of the computer 16 binary, a long string of characters, then we can use other characters to replace this address? This character is a variable.

2. Declaration and use of variables

First step: Declare a variable to allocate space (space based on type)

Part II: Assigning Values to variables (storing data in space)

Step Three: Use variables (remove data, use)

3. Variable naming rules

Variable name = First character + remainder

First character: letter, underscore, $

Remainder: Numbers, letters, underscores, $

You should avoid keywords

According to the Hump naming method

If the name consists of multiple words, start with a second word and capitalize the first letter

4.java Data types

1,. Basic data type: Divided into Boolean type (value is true or false), numeric type

Numeric type: Divided into integer type, floating-point type

Integer type: Byte (1 bytes (8 bits)), Short (2 bytes (16 bits), int (4 bytes (32 bits)), Long (8 bytes (64 bits)), char (2 bytes (16 bit))

Floating-point types: single-precision float (4-byte (32-bit)), double-precision doubles (8-byte (64-bit))

Java has three different representations of integers

Decimal: 0-9, full 10 in one

Octal: 0-7, full 8 in one, start with 0.

Hex: 0-9,a-f, full 16 in one, start with 0 x

Basic conversion of the binary

decimal-to-binary: except 2 to take the remainder

Binary to decimal: by power of 2

octal, Binary mutual transfer: One variable three-bit, three-bit variable one

Hex, binary reciprocal: One variable four bit, four bit variable one

Binary representation of negative numbers

Corresponding positive number binary inverse plus one

Basic Type Conversions

Grammar

Automatic type conversion

The system auto-complete type conversion is also called an implicit conversion when the following conditions are true

1. Two types of compatibility

2. The target type is greater than the source type

3. For an expression, if the operand is of type double, the entire expression is promoted to type double

Forcing type conversions

Under certain conditions, the programmer manually completes the type conversion

1. Two types of compatibility

2. Generic target type less than source type

Important: Forcing type conversions will lose precision!

Java Fundamentals (1) variables, data types

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.