Empaquetar el método getPackages() en Java con ejemplos

El método getPackages() de la clase java.lang.Package se usa para obtener los paquetes definidos por el cargador de clases de la persona que llama. El método devuelve los paquetes como una array de objetos Package.

Sintaxis:

public boolean getPackages(String desiredVersion)

Parámetro: Este método no acepta ningún parámetro.

Valor de retorno: este método devuelve los paquetes como una array de objetos de paquete .

Los siguientes programas muestran el método getPackages().

Ejemplo 1:

// Java program to demonstrate
// getPackages() method
  
public class Test {
    public static void main(String[] args)
    {
  
        // get the Packages using getPackages() method
        Package[] packages = Package.getPackages();
  
        // print all packages, one by one
        for (int i = 0; i < packages.length; i++) {
            System.out.println(packages[i]);
        }
    }
}
Producción:

package sun.reflect, Java Platform API Specification, version 1.8
package java.util, Java Platform API Specification, version 1.8
package sun.reflect.annotation, Java Platform API Specification, version 1.8
package java.lang.annotation, Java Platform API Specification, version 1.8
package java.nio, Java Platform API Specification, version 1.8
package sun.nio, Java Platform API Specification, version 1.8
package java.security.cert, Java Platform API Specification, version 1.8
package java.util.zip, Java Platform API Specification, version 1.8
package sun.launcher, Java Platform API Specification, version 1.8
package sun.security.action, Java Platform API Specification, version 1.8
package java.nio.file, Java Platform API Specification, version 1.8
package java.nio.charset, Java Platform API Specification, version 1.8
package sun.net.www, Java Platform API Specification, version 1.8
package java.lang.ref, Java Platform API Specification, version 1.8
package java.net, Java Platform API Specification, version 1.8
package sun.net.www.protocol.file, Java Platform API Specification, version 1.8
package java.lang.invoke, Java Platform API Specification, version 1.8
package sun.util.locale, Java Platform API Specification, version 1.8
package sun.reflect.generics.repository, Java Platform API Specification, version 1.8
package sun.misc, Java Platform API Specification, version 1.8
package java.lang.reflect, Java Platform API Specification, version 1.8
package sun.net.util, Java Platform API Specification, version 1.8
package java.security, Java Platform API Specification, version 1.8
package sun.net.www.protocol.jar, Java Platform API Specification, version 1.8
package java.util.concurrent, Java Platform API Specification, version 1.8
package java.util.concurrent.atomic, Java Platform API Specification, version 1.8
package java.util.concurrent.locks, Java Platform API Specification, version 1.8
package sun.util, Java Platform API Specification, version 1.8
package java.lang, Java Platform API Specification, version 1.8
package java.io, Java Platform API Specification, version 1.8
package sun.reflect.misc, Java Platform API Specification, version 1.8
package sun.nio.ch, Java Platform API Specification, version 1.8
package java.util.jar, Java Platform API Specification, version 1.8
package sun.nio.cs, Java Platform API Specification, version 1.8
package java.util.function, Java Platform API Specification, version 1.8
package java.nio.charset.spi, Java Platform API Specification, version 1.8
package sun.security.util, Java Platform API Specification, version 1.8

Referencia: https://docs.oracle.com/javase/9/docs/api/java/lang/Package.html#getPackages–

Publicación traducida automáticamente

Artículo escrito por guptayashgupta53 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *