Aliquis
Aliquis

Reputation: 2319

Is there a difference between Java's and Kotlin's module system?

As both a Java and Kotlin beginner, I'm quite confused about the module system and wanted to know if there is a difference between Java and Kotlin.

What exactly is a module? Oracle says the following:

Modularity adds a higher level of aggregation above packages. The key new language element is the module—a uniquely named, reusable group of related packages, as well as resources (such as images and XML files) and a module descriptor specifying

  • the module’s name
  • the module’s dependencies (that is, other modules this module depends on)
  • the packages it explicitly makes available to other modules (all other packages in the module are implicitly unavailable to other modules)
  • the services it offers
  • the services it consumes
  • to what other modules it allows reflection

Source: https://www.oracle.com/corporate/features/understanding-java-9-modules.html

And in Kotlin's book a module is:

a module is a set of Kotlin files compiled together:

  • an IntelliJ IDEA module;
  • a Maven project;
  • a Gradle source set (with the exception that the test source set can access the internal declarations of main);
  • a set of files compiled with one invocation of the <kotlinc> Ant task.

Source: https://kotlinlang.org/docs/reference/visibility-modifiers.html#modules

My questions:

Upvotes: 5

Views: 1580

Answers (1)

GhostCat
GhostCat

Reputation: 140641

It seems that the kotlin team unfortunately decided to use the same term to organize a set of things that get build together.

The "real" Java module rather defines a concept that defines grouping of classes at runtime within the jvm! It is a much larger method to architecture. It is intended for slicing large(r) applications into components, with a complex system to handle dependencies between these components.

In other words: same word, but two different meanings, not really related to each other. From that point of view, you have to study both concepts in depth to understand where each one is applicable.

From that point of view: when you are a Kotlin programmer, and you intend to deploy a large application that will run on a Java9 (or newer) JVM, then you definitely want to ensure that your deliverables are grouped in reasonable "Java modules". Otherwise, if you are doing plain Kotlin development, without specific requirements towards the execution environment, you probably worry mainly (only) about "Kotlin modules".

Upvotes: 6

Related Questions