1

What is the purpose of the * in java.io.*?

import java.io.*;
class Trial{
     public static void main(String[]args){
         System.out.println("Hello,World!");
     }
}
Pshemo
  • 122,468
  • 25
  • 185
  • 269
shemj
  • 31
  • 1
  • 3
  • 2
    It will import all classes from java.io. – Steffen Jan 13 '14 at 00:44
  • 3
    I am not being able to find: "require minimum understanding of the problem being solved". I was searching it: because the way you asked(including your code) tells me that you want to know about packaging system of java but yet the question is vague(asking about purpose of a specific import!) – Sage Jan 13 '14 at 00:46
  • @Sage: reference: http://meta.stackexchange.com/questions/215596/are-code-questions-without-an-attempt-now-on-topic – Anil Jan 13 '14 at 00:47
  • 1
    This question appears to be off-topic because it is about a simple misunderstanding on the OP's part, that has nothing to do with I/O. – Sergey Kalinichenko Jan 13 '14 at 00:48
  • possible duplicate of [Use of \* in Import Statement in Java](http://stackoverflow.com/questions/14897448/use-of-in-import-statement-in-java) – sashkello Mar 06 '14 at 23:54

3 Answers3

1

The * tells the compiler to import all top-level classes in java.io on demand. The construct is called a type-import-on-demand declaration.

From JLS §7.5.2:

A type-import-on-demand declaration allows all accessible types of a named package or type to be imported as needed.

TypeImportOnDemandDeclaration:
    import PackageOrTypeName . * ;

So, for example, since you've included that import statement, you can use a class like java.io.File without having to prefix the type name with java.io; you can use the simple name File.

arshajii
  • 127,459
  • 24
  • 238
  • 287
0

The star indicates that all classes from the java.io package should be imported.

E. Anderson
  • 3,405
  • 1
  • 16
  • 19
0

A wildcard in a package name import is used to include all the classes contained in that specific package. Check official documentation.

In addition you are able to import inner static classes to be able to refer to them without a fully qualified name, eg:

import org.package.MyClass;

//MyClass.InnerClass inner; not needed
InnerClass inner;
Jack
  • 131,802
  • 30
  • 241
  • 343