Visibility of Java names

Source: Internet
Author: User
Tags visibility

In all programming languages, an unavoidable problem is the control of names or names. Suppose you use a name in a module of a program, and another programmer uses the same name in another module. At this point, how do you differentiate two names and prevent two names from clashing with each other? This problem is especially prominent in C language. Because the program does not provide a good name management method. C + + classes, which are the basis of Java classes, use functions in a class so that they do not conflict with nested function names in other classes. However, C + + still allows global data and global functions to be used, so it is still difficult to avoid conflicts. To solve this problem, C + + introduced the concept of "namespaces" with additional keywords.

With a new mechanism, Java can avoid these problems completely. To generate a clear name for a library, a name similar to the Internet domain name is used. In fact, Java designers encourage programmers to reverse the use of their own Internet domain names because they are definitely unique. Since my domain name is bruceeckel.com, my utility library can be named Com.bruceeckel.utility.foibles. After the domain name is reversed, the point number can be imagined as a subdirectory.

In Java 1.0 and Java 1.1, the domain extension, com,edu,org,net, and so on are all in uppercase. So the look of the library becomes: COM.bruceeckel.utility.foibles. However, in the development of Java 1.2, designers found that doing so would create some problems. So the whole package at present is based on lowercase letters.

This special mechanism of Java means that all files are automatically present in their own namespaces. And each class in a file automatically obtains a unique identifier (of course, the class name in a file must be unique). So there is no need to learn special language knowledge to solve this problem-language itself has helped us to take care of this.

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.