Java Study Notes (3) -- Static import, package-info, Fall-through

Source: Internet
Author: User
Tags java reference

[In the previous words] It was really relaxing for several days, without reading any books or tasks. Today is the first day of work after the end of the year, I started my learning journey again. I feel that I am not old. How can I feel more and more calm and work hard when I enter the working state? In the next year, I will not work hard? Haha. This article is my own learning process, I will always find some small knowledge points, and then I will record it here, the basic article, choose to read. [Knowledge Summary] I. static import code before static import: public class HelloWorld {public static void main (String [] args) {System. out. println ("Hello World! ") ;}} Code after static import: copy the code import static java. lang. system. out; // import java. the System class under the lang package directly uses the out object through the System class. Because out is a static PrintStream object, it can be used directly. Public class HelloWorld {public static void main (String [] args) {out. println ("Hello World! "); // You do not need to write System. out. println (" Hello World! "), Because out has been imported.} Copy Code 2. differences between import xxxx and import static xxxx: import xxxx generally imports class files such as import java. util. import static xxxx is generally used to import static object references, constants (Remember, they are static or final), and static methods such as: import static java. lang. system. out is a reference to a static object for static import. 3. Several principles for using static import: 1). You must say import static, not static import. 2) Beware of ambiguous names of static members. For example, if you perform static import on Integer and Long classes, referencing MAX_VALUE will lead to a compiler error because both Integer and Long have a MAX_VALUE constant, and Java does not know which MAX_VALUE you are referencing. 3) You can perform static import on static object references, constants (Remember, they are static or final), and static methods. = =================== 2. Study package-info.java reference material alternative package-info.java document http://strong-life-126-com.iteye.com/blog/806246 2. features: 1) It cannot be created at will, because there is a hyphen (-) that is not allowed in naming rules. Generally, you can use NotePad to create a rule and refresh it, or copy a project that has already been used. 2) The service object is very special, and the description and recording of this package information 3) the class cannot have public or private access permissions. Only classes with default access permissions can be declared in the package-info.java, that is, friendly classes. 4) There are several special features, such as the inability to inherit, the absence of interfaces, and the absence of inter-class relationships (associations, combinations, and aggregation. 3. Purpose: 1) Facilitate Annotation on the package; 2) Declare friendly classes and package constants; 3) provide the overall comments of the package. PS: here is just a simple markup note if you want to know the package-info.java in detail. Read the above references. = ============ 3. In the switch statement, Fall-through can be found in the switch statement today, if you do not understand what it means, you can learn it. The second switch in the code below finds the Fall-through phenomenon. Code: copy the public class FallTest {public static void main (String [] args) {int I = 2; switch (I) {case 1: System. out. println ("woshishuaige1"); break; case 2: System. out. println ("woshishuaige2"); break; case 3: System. out. println ("woshishuaige3"); break; default: System. out. println ("xiaosile");} switch (I) {case 1: System. out. println ("I'm handsome guy 1"); case 2: System. out. println ("I am handsome 2"); case 3: System. out. println ("I am handsome 3"); default: System. out. println ("smile dead") ;}} copy the code output: woshis?ige2 I'm handsome guy 2 I'm handsome guy 3 I laugh

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.