MOCKSTACKS
EN
Questions And Answers

More Tutorials









Scala Packages

Examples

Package structure


package com {
 package utility {
 package serialization {
 class Serializer
 ...
 }
 }
}

Packages and files


The package clause is not directly binded with the file where it is found. It is possible to find common elements of the package clause in diferent files. For example, the package clauses bellow can be found in the file math1.scala and in the file math2.scala.

File math1.scala

package org {
 package math {
 package statistics {
 class Interval
 }
 }
}

File math2.scala

package org {
 package math{
 package probability {
 class Density
 }
 }
}

File study.scala

import org.math.probability.Density
import org.math.statistics.Interval
object Study {
 def main(args: Array[String]): Unit = {
 var a = new Interval()
 var b = new Density()
 }
}

Package naming convension


Scala packages should follow the Java package naming conventions. Package names are written in all lower case to avoid conflict with the names of classes or interfaces. Companies use their reversed Internet domain name to begin their package names—for example,

io.super.math


Conclusion

In this page (written and validated by ) you learned about Scala Packages . What's Next? If you are interested in completing Scala tutorial, your next topic will be learning about: Scala Parallel Collections.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.