Vai al contenuto principale
ProdottiStrumenti desktopTASTECADVisualizzazione disegniTASTEFILESGestione fileTASTEFTPTrasferimento fileTASTESSHSpazio di lavoro remotoTASTEZIPCompressione ed estrazioneStrumenti per sviluppatoriTASTECODEAmbiente di sviluppo integrato per RustTASTESTUDIOAmbiente integrato di sviluppo e testTASTEETLIntegrazione dati (ETL)ServerTASTEREMOTEServer di desktop remotoTASTEGEOServer geospazialeTASTEMAILSpazio di lavoro emailIniziaDownloadDocumentazioneAcquistaTutti i prodotti
Marketplace
Notizie
TecnologiaNotizieNotizie di sviluppo di oggiDocumentazioneLinguaggi di programmazioneRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFramework frontend webNext.jsReactVue.js · NuxtSvelteKitAngularFramework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFramework per app e desktopTauriFlutterReact NativeElectronAlgoritmiBasi degli algoritmiAlgoritmi fondamentaliAlgoritmi avanzatiAlgoritmi pratici
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrinaGuida alla community
CollaboraTrasferimento tecnicoRealizzazione del sito webRealizzazione di app desktopPipeline di rilascio e pagamentoPartner commercialeContatti
ServiziDesktop remotoPacchetti di installazione su misura
TASTEDEV
Prodotti

Strumenti desktop

TASTECADApri con leggerezza anche i disegni più complessiTASTEFILESSolo i file che servono, alla massima velocitàTASTEFTPLa via più ordinata per i tuoi fileTASTESSHUn legame più solido tra te e i tuoi serverTASTEZIPComprimi più veloce, estrai più sicuro

Strumenti per sviluppatori

TASTECODEModifica, compila, esegui il debug e testa app Rust in un'unica finestraTASTESTUDIODalla modifica ai test remoti e alle correzioni IA approvateTASTEETLSposta i dati guardando i valori

Server

TASTEREMOTEUn desktop remoto che gira sul tuo serverTASTEGEOUn server geospaziale compatibile con GeoServer, ricostruito in RustTASTEMAILRiprendi il controllo della tua posta

Inizia

DownloadUltime versioni di ogni prodottoDocsCome usare ogni prodottoAcquistaAbbonamenti e licenze perpetueTutti i prodottiTutti i prodotti a colpo d’occhio
Tutti i prodotti
MarketplaceNotizie
Tecnologia

Notizie

Notizie di sviluppo di oggiAnnunci ufficiali su linguaggi, framework, GitHub e IADocumentazioneGuide a linguaggi, framework e algoritmi

Linguaggi di programmazione

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Framework

Framework frontend webNext.jsReactVue.js · NuxtSvelteKitAngular
Framework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Framework per app e desktopTauriFlutterReact NativeElectron

Algoritmi

Basi degli algoritmiAnalisi della complessità · Ordinamento · Ricerca · Strutture dati di base · Alberi e heapAlgoritmi fondamentaliVisita dei grafi · Cammini minimi e alberi ricoprenti · Programmazione dinamica · Algoritmi greedy · Divide et impera · BacktrackingAlgoritmi avanzatiAlgoritmi sulle stringhe · Matematica e teoria dei numeri · Manipolazione dei bit · Alberi di segmenti · Union-FindAlgoritmi praticiStrategia per colloqui di programmazione · Cache LRU · Rate limiting · Hashing consistente
Tutta la documentazione di sviluppo
Community
ProgettiScopri sviluppatori e lavoriLog di sviluppoDecisioni e lezioni appresePromptIstruzioni riutilizzabiliProblemi degli strumenti di IAProblemi e alternative di Claude, Codex, GeminiVetrinaRisultati completatiGuida alla communityCome sviluppiamo in modo aperto
Collabora
Trasferimento tecnicoApp native in Rust ed eguiRealizzazione del sito web10 lingue, account, documentazione e downloadRealizzazione di app desktopRust ed egui, senza WebViewPipeline di rilascio e pagamentoFirma, MSI, deb, rpm, AppImage, hashPartner commercialeConsigliaci e ricevi il 30%ContattiSviluppo, partnership e investimenti
Servizi
Desktop remotoRaggiungi il tuo computer dal browserPacchetti di installazione su misuraSolo il necessario, impostazioni precaricate
Acquista
IT
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Accedi
Accedi
TASTEDEV

Dai piccoli strumenti a uno sviluppo migliore.

support@tastedev.netSostieni TASTEDEV
ProdottiGamma di prodottiAcquistaDocsDownloadMarketplaceAssistenza
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrina
NormeInformativa sulla privacyTermini di servizioCondizioni di abbonamentoRimborsiLinee guida della community
AccountAccediRegistrati
Visitatori
Oggi
012345678901234567890123456789012345678901234567890123456789
Ieri
012345678901234567890123456789012345678901234567890123456789
Visualizzazioni totali
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
Società
GXSOFT
Rappresentante
CHOI YOUNG GU
Numero di registrazione
853-44-00368
Indirizzo
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefono
+82-10-4404-1523
E-mail
whitecalvin@tastedev.net
Responsabile privacy
CHOI YOUNG GU

© 2026 TASTEDEVLe informazioni sui prodotti si basano su fonti di sviluppo verificate.Rilasciato · in miglioramento

Documentazione di Java
Java
Getting StartedSyntax BasicsTypes and DataModules and PackagesErrors and TestingKey Concepts
Discussioni

Guida a Java · 4/6

Modules and Packages

Per ora questo capitolo è disponibile solo in inglese.

As a program grows you need to split it up, pull in third-party libraries, and produce something you can ship. In Java, packages organize classes, Maven or Gradle handle builds and dependencies, the module system can enforce stricter boundaries when you want them, and the usual deliverable is a JAR file.

Packages and imports

A package is a namespace for classes. Declare it with package at the top of the file and keep the directory structure in sync with the package name. To avoid collisions, the convention is to start with a reversed domain name you control, such as com.example.

// src/main/java/com/example/shop/order/OrderService.java
package com.example.shop.order;

import java.time.LocalDate;
import java.util.List;
import com.example.shop.product.Product;
import static java.lang.Math.max; // static import

public class OrderService {
    public int totalQuantity(List<Product> products) {
        int total = 0;
        for (Product p : products) total += max(0, p.quantity());
        return total;
    }

    public LocalDate today() {
        return LocalDate.now();
    }
}

Classes in java.lang (String, Math, Integer, and friends) are imported automatically. You can import a whole package with import java.util.*;, but many teams prefer explicit single-type imports so it is obvious where each name comes from. Classes and members declared without an access modifier are visible only within their own package.

Building with Maven

Maven describes the project, its dependencies, and its plugins in a single pom.xml. Each dependency is identified by three coordinates (group ID, artifact ID, and version) and is downloaded automatically from a repository such as Maven Central.

<project xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>shop</artifactId>
  <version>1.0.0-SNAPSHOT</version>

  <properties>
    <maven.compiler.release>21</maven.compiler.release>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>${gson.version}</version>
    </dependency>
  </dependencies>
</project>

Set maven.compiler.release to the Java release you target (replace the 21 with whatever LTS your team uses), and define properties like ${gson.version} with the current version listed on Maven Central. The commands you will run most often:

mvn compile # compile main sources
mvn test # run the tests
mvn package # build a JAR into target/
mvn dependency:tree # show the resolved dependency tree
Domande su questo capitolo?
Capitolo precedenteTypes and DataCapitolo successivoErrors and Testing

Building with Gradle

Gradle builds are configured with a Kotlin or Groovy script. Projects normally check in the Gradle wrapper (gradlew), so everyone builds with the same Gradle version without installing it separately.

// build.gradle.kts
plugins {
    application
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.google.code.gson:gson:<version>")
    testImplementation(platform("org.junit:junit-bom:<version>"))
    testImplementation("org.junit.jupiter:junit-jupiter")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

java {
    toolchain { languageVersion = JavaLanguageVersion.of(21) }
}

application {
    mainClass = "com.example.shop.App"
}

tasks.test { useJUnitPlatform() }

implementation dependencies are available at compile time and runtime, while testImplementation ones are visible only to tests. ./gradlew build compiles, tests, and packages in one go, and ./gradlew run launches the configured mainClass. To scaffold a fresh project, run gradle init.

Module system basics

Packages alone cannot stop other code from reaching into your internals. The Java Platform Module System (JPMS) adds a module-info.java file that states what a module depends on (requires) and which packages it makes available (exports). A package that is not exported is off limits to other modules, even if its classes are public.

// src/main/java/module-info.java
module com.example.shop {
    requires java.net.http; // a JDK module
    requires com.google.gson; // a library module
    exports com.example.shop.api; // the public API
    opens com.example.shop.model to com.google.gson; // allow reflection
}

opens grants reflective access, which serialization libraries need in order to read private fields. Modules are optional: without a module-info.java, your code runs on the classpath just as it always has. Many applications start without modules and adopt them later, typically when publishing a library or building a trimmed runtime image with jlink.

JAR files

A JAR is a ZIP archive of compiled classes and resources. If its manifest names a Main-Class, you can start it with java -jar. Here is how to build one by hand without a build tool:

javac -d out $(find src/main/java -name "*.java")
jar --create --file app.jar --main-class com.example.shop.App -C out .
java -jar app.jar

A plain JAR does not include your third-party dependencies. Either put them on the classpath at launch, for example java -cp "app.jar:libs/*" com.example.shop.App (use ; as the separator on Windows), or let your build produce a distribution that bundles them, such as a shaded JAR from the Maven Shade plugin or Gradle's installDist output.

Summary

  • Keep package names and directories in sync, and use import to reference classes from other packages.
  • Maven declares builds in pom.xml; Gradle uses build.gradle.kts. Both fetch dependencies for you.
  • module-info.java uses requires and exports to make module boundaries explicit.
  • Ship code as a JAR run with java -jar, and decide how dependencies travel with it.

0 commenti

Commenti principaliPrima i più recenti

Accedi · Accedi per lasciare un commento.