Java Basic program Design structure

Source: Internet
Author: User

1. Notes

Single-line Comment--//

Multiline Comment--/* */

 1  public  class   Main { 2   Public  static  void   main (string[] args) { 3  //  This is a single-line comment  4  5  /*   * This is a multiline comment  7  8  }  9 } 

2. Data type

Integral type

In Java, numbers are signed integers, there are no unsigned integers, and numbers can be encoded in a computer in three ways:

The original code: the highest bit is the sign bit, the remaining bits are the binary representation of the absolute value of the number.

[1] Original =[0000 0001] original [-1] Original =[1000 0001] Original

Anti-code: The highest bit is the sign bit, the remaining bit if the number is positive is its original code value, if the number is negative, on its original code based on the bitwise negation.

[1] anti-=[0000 0001] anti-[-1] anti-=[1111 1110] anti-

complement: The highest bit is the sign bit, the remaining bit if the number is positive is its original code value, if the number is negative in its inverse code technology plus 1.

[1] complement =[0000 0001] complement [-1] complement =[1111 1111] complement

Based on the simplification of CPU hardware design, the subtraction operator is integrated into the addition operator, so that in the computer, the numbers are basically stored in the form of their complement .

For numbers represented by a-bit bits, 0<=m<2 (A-1), 0<m<2 (A-1), M-n=m+2 (A-1)-n-2 (A-1). where 2 (A-1)-N is the complement of-N.

For signed integers, a carry operation is generated only if the number of two identical symbols is an addition operation. And if the sign bit also participates in the calculation according to the ordinary bits, if only the secondary high has the carry operation or only the sign bit has the carry operation, the value that indicates the result already exceeds the value range that the A-bit binary can represent.

When writing numbers, you can use hexadecimal to denote numbers with a 0x prefix, use octal for numbers with a 0 prefix, use binary notation numbers with 0b prefixes (java7+), and use decimal notation for numbers.

Byte

Use 1 bytes to store numbers.

Short

Use 2 bytes to store numbers.

Int:

Use 4 bytes to store numbers.

Long

Use 8 bytes to store numbers.

Floating point Type

In Java, floating-point numbers are stored as standard floating-point numbers in IEEE754-defined floating-point notation, a scientific notation that is represented by symbols, exponents, and mantissa.

Float

Use 4 to store numbers directly, 1-bit bits as the sign field, 8-bit bits to exponential, 23-bit bits to decimal, and exponential offset to 127.

Double:

Use 8 to store numbers directly, 1-bit bits as the sign field, 11-bit bits to exponential, 52-bit bits to decimal, and exponential offset to 1023.

There are three special constant values in a Double class, double.positive_infinity-positive infinity, double.negative_infinity-negative infinity, Double.nan-is not a number, the corresponding method needs to be called for validation when the corresponding validation is performed.

Character type

In different encoding sets, the encoding scheme of the characters varies.

Code point: Refers to a code value that corresponds to a character in an encoded table.

Code units: In the basic multi-lingual level, each character is represented by 16 bits, which is often referred to as a code unit.

Char

In Java, the char type describes a unit of code with UTF-16 encoding, where characters in the auxiliary plane need to be represented by a pair of char. After JAVA5 , support for the supplemental character set is started.

A Unicode specification involves two steps:

    1. Defines a specification that assigns a unique number to all characters.
    2. The numbers corresponding to the characters are saved in the computer.

In Unicode, the code points are divided into 17 planes, each of which contains 65,536 code bits. The first plane is called the basic multi-text plane, and the rest of the plane is called the secondary plane. Within a basic multi-text plane, the code-bit segments from u+d800 to U+DFFF are persisted, not mapped to characters.

In UTF-16, the characters in the auxiliary plane are encoded as a pair of 16-specific code elements called proxy pairs. The first part is called high-level agent or check-in agent, code bit from u+d800 to U+DBFF. The second part is called Status Agent or rear agent, code bit from u+dc00 to U+DFFF.

The conversion mode is:

    1. Subtract the character value from 0x10000, and the result range is 0x0000 to 0xFFFFF.
    2. The high 10 bits of the result and the 0xd800 do the logic or operation, the lower 10 bits and the 0xdc00 do the logic or the operation.
    3. Combining the two parts together is the UTF-16 encoding of the character value.

The UTF-8 encodes Unicode using one byte or two bytes or three bytes.

0xxxxxxx, using a byte to represent a Unicode code point that can represent 128 characters.

110xxxxx 10xxxxxx, which represents a Unicode code point using two bytes and can represent 2048 characters.

110xxxxx 10xxxxxx 10xxxxxx, which represents a Unicode code point using three bytes and can represent 65,536 characters.

EF BB BF UTF-8

FE FF Utf-16/ucs-2,little Endian

FF FE Utf-16/ucs-2,big Endian

FF FE xx utf-32/ucs-4,little endian

XX FE FF utf-32/ucs-4,big endian

Boolean type

Boolean

Used for logical operations, with a value of true and false two.

Resources:

Http://www.cnblogs.com/zhangziqiu/archive/2011/03/30/ComputerCode.html

Http://www.cnblogs.com/effulgent/archive/2011/10/30/two_s_complement.html

http://blog.csdn.net/shangboerds/article/details/7498317

Http://www.cnblogs.com/kingcat/archive/2012/10/16/2726334.html

http://www.ibm.com/developerworks/cn/java/j-unicode/

Java Basic program Design structure

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.