The first day of Java learning

Source: Internet
Author: User

1.java Data types

Basic data: Numeric type (byte,short,int,long,float,double), Word 4, public access control

If the public access control is used before a member method or member variable name, the member can be accessed by all classes, regardless of whether the access class is in the same package as the class being accessed. Finally, we use a graph to summarize the permissions of the above access control.
Type (char), Boolean (Boolean)

Reference data types: Classes (Class), interfaces (interface), arrays

2. Data output

Byte,short,int,long--------------%d Int,long-----------------%x

Float,double---------------%f

Char---------------%c

String---------------%s

3. Shaping constants

An integer default of four bytes, if the value exceeds 4 bytes, must add L, otherwise error;

Long i = 1000000000000000000000l;//not plus l will error

4. Floating-point constants

A real number is a double type by default, and if you assign a double directly to float it will give an error, you must add f or force type conversion

float x = 2.2f; or float x = (float) 22;


5. Variable occupies storage space

Byte 1 bytes

Short 2 bytes

int 4 bytes

Long 8 bytes

Float 4 bytes

Double 8 bytes

Char 2 bytes

Boolean 1 bytes

6. You cannot force type conversions on a Boolean type

7. Class access control: Public, protect, default, private

1.Private access control

If the private access control is used before a member method or member variable name, the member can only be used inside the class;

2. Default Access control

If no access control is used before a member method or member variable name, we call this member the default (default), or a friend (friendly), or package type. For the default access control member, it can be accessed by other classes in the package.

3.protected access control

If the protected access control is used before a member method or member variable name, the member can be accessed by other classes in the same package or by subclasses in different packages.
4. Public access Control

If the public access control is used before a member method or member variable name , the member can be accessed by all classes. Whether the access class and the class being accessed are in the same package .

8. When an object is created, the member variable is automatically initialized to the value:




The first day of Java learning

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.