Java Basics-Learning notes (ii)

Source: Internet
Author: User

1. Common Java Data types

Data type Key words Number of bytes occupied
Boolean type Boolean 1
BYTE type Byte 1
Character type Char 1
Short-integer Short 2
Integral type Int 4
Long integer type Long 8
Floating point Type Float 4
Double-precision Type Double 8

2, the conversion between ordinary data types, an example to illustrate the situation

1  Public Static voidMain (String args[])2     {3         intX=1;4         floatf=2.0f;//if no f is added, the default is double type5         DoubleE=f;//implicit type conversion assignment variable byte < assigned variable byte6         byteB= (byte) x;//coercion type conversion assignment variable byte > assigned variable byte7         CharC= ' A ' +1; 8         //b=b-1; Error shaping defaults to int type9e=x+f+b;TenSystem.out.println (e);//Output 4.0 Output result Select the type of the highest byte in an expression OneSystem.out.println (c);//Output B A}

3. Java Rules for identifiers

    • Consists of letters, numbers, underscores (_), Dollar signs ($);
    • Identifiers cannot begin with a number.

4. Overloading of functions

It is possible to have more than one function of the same name in the same class, as long as the number of arguments or the data type is different, as shown in the following example:

1  Public Static voidMain (String args[])2     {3Add (3,4);4Add (3,4,5);5Add (1.0,2.0,3.0);6     }7      Public Static intAddintXinty)8     {9System.out.println (x+y);Ten         returnx+y; One     } A      Public Static intAddintXintYintz) -     { -System.out.println (x+y+z); the         returnx+y+Z; -     } -      Public Static DoubleAddDoubleXDoubleYDoublez) -     { +System.out.println (x+y+z); -         returnX+y+z;

5. Arithmetic operators (small places to note)

1  Public Static voidMain (String args[])2     {3         intx=5,y,z=312;4         floatF;5Y=x%-2;6System.out.println (y);//Output 1, indicating that the residual result is not affected by the negative sign7y=z/300*300; 8System.out.println (y);//output 300 Instead of 312, because Z is an integer, divided by 300, the result is 1.9F=x/2;TenSystem.out.println (f);//output 2.0, because F is a floating-point type One         intA=1,c=1, b,d; Ab=a++;//after the first operation , the self-increment -System.out.println ("a=" +a+ ", b=" +b)//Output A=2,b=1 -D=++c;//first self-increment after operation theSystem.out.println ("c=" +c+ ", d=" +d);//Output c=2,d=2 -}

Java Basics-Learning notes (ii)

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.