Import in Java

Source: Internet
Author: User

What is the use of Java package.

In fact, the package name is like our surname, and the class name is like our name. There are many package names, such as the surname. For example, java. Lang. String is the class of Java. Lang with the name of string. java. Io. inputstream is the class of Java. io with the name of inputstream.

If the category does not use the suite name, different categories with the same name will cause great problems.

 

Because the name of many suites is very long, it takes a lot of time to write more characters when writing a program. For example

Java. io. inputStream is = java. lang. system. in; </p> <p> java. io. inputStreamReader isr = new java. io. inputStreamReader (is); </p> <p> java. io. bufferedReader br = new java. io. bufferedReader (isr); </p> <p>

It is not beautiful and troublesome. So Sun thought of a solution, namely import.

Import java. lang. system; <br/> import java. io. inputStream; <br/> import java. io. inputStreamReader; <br/> import java. io. bufferedReader; </p> <p>

So the original program becomes

InputStream = System. in; </p> <p> InputStreamReader isr = new InputStreamReader (is); </p> <p> BufferedReader br = new BufferedReader (isr ); </p> <p>

Some people may think that too many imports is a waste of time, So Sun provides another method.

Import java. lang. *; </p> <p> import java. io. *; </p> <p>

Can I be more lazy, just write?

Import java .*;

History tells us that people can be lazy, but not too lazy. When it comes to food, you can't be too lazy to open your mouth...

 

Although people cannot be too lazy, sun is still a little lazy to help us. Because Java. lang is too often and too often used, and almost no program needs to use it, so whether or not you write the import Java. lang;, the compiler will automatically help you complete, that is to say, the compiler will automatically go to Java as long as it sees a class without a surname. find out in Lang to see if this category belongs to this suite. So we don't need to import java. Lang.

 

 

 

 

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.