Re-start learning javase_ hiding the implementation process

Source: Internet
Author: User
Tags control characters

I. Concealment of the implementation process

For the hidden implementation process, thinking in Java is very good, nothing but a good program to do as far as possible, the external public procedures, even if internal procedures change, will not affect the use of these public services

  1. Import of Class
    The classes in Java are in different packages, except that the classes in the Java.lang package can be used directly, and the classes in the other packages need to be used.
    The first way is import imports
    Import Java.util.Date So, you can use the date class in Util, if you need to use a lot of classes in a package case can import java.util.*, so you can use the Util package of the class
    The second way is to use the full class name
    Java.util.Date date=new java.util.Date ();
    I believe everyone will have the first way, but the second way is also useful. For example, in a class you first import java.util.Date, but at this time you need java.sql.Date what to do? Continue import? Then call date Date=new date ()? Sorry, the program is not clear about the kind of date you use, this time the second date you need to use Java.sql.Date date=new java.sql.Date ();
  2. Package

    The "package" is also comprised of a series of class files. Each file has a public class (which is not forced to use a public class, but this is the most typical), so each file has a component. If you want to summarize all of these components (which are in their own separate. Java and. class files), the package keyword will work).
    If you use the following code at the beginning of a file:
    Package mypackage;
    Then the package statement must appear as the first non-comment statement of the file. The purpose of this statement is to indicate that the compilation unit belongs to a library named MyPackage. Or in other words, it indicates that the public class within the compilation unit is fame under the name MyPackage. If other people want to use this name, either point to the full name or use the Import keyword with mypackage (using the options given earlier). Note that according to the Java Package (encapsulation) Convention, all the letters in the name should be lowercase, even those intermediate words. For example, assume that the file name is It means that there is one and only one public class in that file. And the name of that class must be MyClass (including case):
    Package mypackage;
    public class MyClass {
    // . . .
    Now, if someone wants to use MyClass, or if they want to use any of the other public classes within MyPackage, they must use the Import keyword to activate the names within the mypackage so that they can be used. Another option is to specify the full name: MyPackage. MyClass m = new MyPackage. MyClass ();
    The Import keyword makes it much more concise:

  3. Create a unique package name
    Using the way to write the domain name:

  4. There is an automatic compilation in Java to understand

    Automatic compilation
    When an object is first created for an imported class (or when a static member of a class is accessed), the compiler looks for the same name in the appropriate directory
    . class file (so if you create an object of class X, it should be x.class). If only x.class is found, it must be used
    of that class. However, if it finds a in the same directory, the compiler compares the date tokens of two files. Such as
    If the fruit is newer than X.class, it will automatically compile and generate an up-to-date x.class.
    For a particular class, or if it is not found in a. java file with the same name, the above processing is taken for that class.

  5. Java Access Indicator

    For each definition of each member within a class, the Java access indicator poublic,protected and private are placed at the front of them-
    -whether they are a data member or a method. Each access indicator only Controls access to that particular definition. If there's nothing in front of them, we call them default, rhetorical, friendly

    1. Private access Control
    The function of the private access control is described earlier, and if a member method or member variable name is used before the private access control, the member can only be used inside the class.
    You cannot add a private modifier before a variable declared in the method body.
    2. Default Access control character
    If no access control is used before a member method or member variable name, it is said that the member has the default access control character. The default access control members can be accessed by other classes in the package. If a child class is in a different package than its parent class, the subclass cannot access the default access control members in the parent class.
    3. Protected Access Control characters
    If the protected access control is used before a member method or member variable name, the member can be accessed either by another class in the same package or by a subclass in a different package.
    4. Public access control character
    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.

  6. Class of Access
    Public access is publicly available
    Default, can only be used in packages
    Note: No protected and private

Re-start learning javase_ hiding the implementation process

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: 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.