In a Programming language, a package is a collection of classes and interfaces, and objects, and based on the requirement a developer can import the package into his program.
In Scala, There following three packages are imported implicitly.
- java.lang._
- scala._
- scala.Predef._
Scala Package Creation
In Scala, packages are created by declaring one or more package names at the top of a Scala file.
package package_name
// classes
// traits
// objects..
Scala Package Import
Import clauses are used to import packages. It can be used anywhere in the program as an independent statement which Java does not allow.
import admin._ // This statement will import everything from the admin package
import admin.User // This statement will import the class User
import admin.{User, UserPreferences} // This statement will only imports selected members
import admin.{UserPreferences => UPrefs} // This statement will import and rename for