For quick answer, three packages are imported by default for each source file. First, the package with no name. Second, the
java.lang package. And third, the current package (the package in which the current file is defined).
In every Java program there can be one unnamed package, which is simply a package with no name. If you omit the
package statement while writing the class definition, the class name is placed into the default package, which has no name. Java compiler automatically imports this package.
java.lang package is imported implicitly. Java is a pure object oriented programming language where code is written in form of classes. These class components are called types. Types in Java come in two flavours: built-in or primitive types and types from components. Primitive types can be used directly while component types must usually be ordered from a library by importing them from the appropriate package. The technical term for ordering a component from a library is bringing a component into scope. The Java standard libraries include
java.lang package by default, which contains a number of components that are used very commonly in Java programs. Java is useless without much of the functionality in
java.lang, that's why
java.lang is implicitly imported by the compiler for all programs.
However, one can import the same package or same class multiple times. If you explicitly import
java.lang in your program then neither compiler nor JVM complains anything about it, but JVM internally loads the required class only once, no matter how many times you import the same class.
Third, the current package is the one in which the class in execution is defined. Current Java package is automatically imported by Java compiler.
Hope you have enjoyed reading about by default imported packages in Java. Please do write us if you have any suggestion/comment or come across any error on this page. Thanks for reading!
Developers launch a new app to help pregnant women get a seat on public transport while commuting.How we built India's biggest robot companyPosted on Sunday January 22, 2017
GreyOrange is India's biggest robotics company, making machines which support the country's booming online retail industry.Nintendo signals end for Wii UPosted on Friday January 20, 2017
Nintendo signals the "end of life" for its Wii U games console, which was first released in 2012.Courtesy BBC News