Basic Java Knowledge

Source: Internet
Author: User

  • Package

    1. Role: Avoid conflicts of class names

    2. The package name can have a hierarchy (the domain name is reversed.) Name of the project. Module name)

    3. Name of the class: package name. class name. The class of the same package cannot have the same name.

    4. Recommendation: Package name all letters lowercase.


    Import

    1 classes in the same package can be accessed directly,

    Classes of different packages cannot be accessed directly, there are 2 ways to access

    1. First import declares the class to be used again.

    2. Full-name access to the class. Not recommended

  • Access Control Modifiers:

    1.public: Public, any class can be accessed.

    2.protected: Protected, this class, different packages and the same bun class, the same package class can be accessed.

    3. Default: Nothing to write, this class, with the Bun class, the same package class can be accessed.

    4.private: Private, this class can be accessed.

  • Description

    1. The access adornments for the class are public or default

    2. The access adornments of the members in the class can be as above four kinds


    3.final: Final, non-changing

    1. Modifier variable: variable cannot be modified

    2. Modification method: Method cannot be overridden

    3. Modifier class: class cannot be inherited




    4.static

    1 Static variables:

    1.1 Modified by static

    1.2 belongs to the class, stored in the method area, only one copy

    1.3 Often accessed through the class name

    1.4 When to use: Data shared by all objects (Pictures, audio, video, etc.)


    2. Static methods

    2.1 Modified by static

    2.2 belongs to the class, stored in the method area, only one copy of the

    2.3 Static methods do not have an implicit this pass

    Instance members cannot be accessed directly in a static method

    2.4 When to use: the operation of the method is only relevant to the parameter and is not related to the object

    3. Static block

    3.1 belongs to the class, which executes automatically during the class being loaded, because the class is only loaded once, so the static block is only executed once

    3.2 When to use: Load/Initialize static resources (Pictures, videos, audio, etc.)


    Basic Java Knowledge

    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.