Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What packages does 1) Java and 2) Groovy automatically import?

Having programmed in Groovy quite a bit I know classes in certain packages are automatically imported. What's the scoop for 1) Java and 2) Groovy? Is there a definitive list of ones you don't need to specify an import for for each of these languages?

like image 356
JGFMK Avatar asked Feb 06 '11 08:02

JGFMK


People also ask

Which Java package is automatically imported?

java. lang package is automatically imported.

Why does Java Lang package automatically import?

While in every program Collection classes are not used while basic datatypes are essential for every java program. To avoid unnecessary load of other classes in program other packages are not auto imported while essential package java. lang is auto imported.

Can groovy import Java classes?

In order to refer to any class you need a qualified reference to its package. Groovy follows Java's notion of allowing import statement to resolve class references.

Does importing a package imports its sub package as well in Java?

No you will have to import the subpackages explicitly. Importing com. MyTest. * will import classes in the package MyTest only.


2 Answers

In Java, the only package imported by default is

java.lang.*

This is where objects such as String and Object reside.

According to here, the list of packages for groovy are

java.io.*
java.lang.*
java.math.BigDecimal
java.math.BigInteger
java.net.*
java.util.*
groovy.lang.*
groovy.util.*
like image 188
Codemwnci Avatar answered Oct 02 '22 19:10

Codemwnci


AFAIK, java only imports

java.lang.*

wheras groovy imports:

java.io.*
java.lang.*
java.math.BigDecimal
java.math.BigInteger
java.net.*
java.util.*
groovy.lang.*
groovy.util.*

According to https://groovy-lang.org/differences.html#_default_imports

like image 28
tim_yates Avatar answered Oct 02 '22 19:10

tim_yates