Java Learning Note II (Basic syntax)

Source: Internet
Author: User

1 Java is a strongly typed language, and the basic data types provided in 8 have the following categories:
BYTE: Byte type, one byte, signed 8-bit integer. When the byte type participates in the operation, it is converted to the int type.

byte b;b=3;b= (Byte) (b*3); The second assignment here has to be forced type conversion, or it will compile with an error.

Short:2 bytes, byte can be directly assigned to short, but in turn requires a forced type conversion.

A signed integer of the int:4 byte type.

Long:8 symbolic shaping of a byte type

Char:2 the unsigned type of a byte. The encoding format used is Unicode, there are two methods of assignment: Integer Assignment (the Asscall code of the corresponding character), and the character ' a ' to assign the value.

FLOAT: variable of floating-point number; note that the decimal constant in Java is a double type and cannot be assigned a value directly to a floating-point variable. You need to add f,1.2f after the decimal. expressed in 4 bytes.

Double: expressed in 8 bytes. Higher accuracy;

Boolean: Only two of the values in Java are false and true, and other variables are assigned to the Boolean variable with an error. Only Boolean types can be used to determine in a Java judgment statement.

2 arrays

One-dimensional array: int num[]; When the definition of an array is not able to allocate space, the definition then uses new to allocate space size for the array, num=new int[3];

The array can be assigned directly at the time of definition, int [] num={1,2,3};int [] num=new int[] {n/a};

Two-dimensional array: defines an int [] [] num;num=new[3][4];//defines a two-dimensional array and allocates space.

A two-dimensional array can contain different columns per row. int [] [] num;num=new int[3][];num[0]=new int[5];num[0]=new int [4];

Initialization of two-dimensional arrays:int [][]arr2=new int[][]{{1,2,3},{4,5,6}}; int [][]arr3={{1,2,3},{2,3,4}}; Neither of these methods requires the size of the specified array.

3 Basic Statements

if () {};

while (true) {};

Do{}while (TRUE);

for (int i=0;i<10;i++) {}

4 bit operations in Java

Bitwise AND:&

Bitwise OR: |

Bitwise XOR: ^

Bitwise COUNTER: ~

Move left:<<

Signed right-shift:>>

Right shift without symbols:>>>

          

Java Learning Note II (Basic syntax)

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.