Java Basics-Variables and data types

Source: Internet
Author: User

Each language will be designed to a lot of data, so you will be exposed to different data types, the initial contact data type is also dizzy, Java language, finally a little understand, comb a bit, with June mutual encouragement.

  • The concept of variables
      • A storage area in memory
      • Variable name + Data Type
      • Can be changed within the same type range
      Why define variables:
      Using variables Note:
      • variable scope, one pair {}
      • Initialize value
  • definition The format of the variable:
    • data type    variable name = initialization value
    • eg:int x = 4
    • Note: Format fixed
    • Understanding: Variables are like unknowns in mathematics.
    • Data type :


the integer default type is :int

the decimal default type is :Double

Memory consumption and range of values

integral type

Occupy storage space (bytes)

size range

BYTE 

1

-128 ~ 127

short

2

-215 ~ 215 -1

int

4

-231 ~ 231 -1

long

8

-263   ~ 263 -1

floating-point

 

 

float

4

-3.403E38~ 3.403E38

double

8

-1.798E308~ 1.798E308

character type

 

 

char

2 ( adopted unicode encoding

 

Boolean type

 

 

boolean

1 ( 1/8byte)

 

parsing : Why byte takes one byte and the value range is -128~127

first you need to understand that in binary, the highest bit is the sign bit, 0 indicates positive, 1 represents a negative, and the other bits are data bits.

byte Total accounted 8 Bit , indicating the Number ( 2 8 ).

The maximum value is 01111111 , turn into decimal to 127

the minimum value is 10000000 , 1 is the sign bit, which represents a negative number, and turns it into decimal - . So The minimum value is -128 .

why exactly? -128 ? How are binary and decimal converted at the bottom? Will involve the original code, anti-code, complement , and listen to the next chapter analysis.

Summary:

In the final, the most important thing in software system is data, data is the core of the enterprise. Although some of the underlying things we do not need to be proficient, but only to understand these, later use can be handy, and then!

Java Basics-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.