Java Class.getPackage()

Syntax

Class.getPackage() has the following syntax.

public Package getPackage()

Example

In the following code shows how to use Class.getPackage() method.


//from www.j  av a2 s.  co m
public class Main {

  public static void main(String[] args) throws Exception {

    Class cls = Class.forName("java.lang.Integer");

    // returns the name and package of the class
    System.out.println("Class = " + cls.getName());
    System.out.println("Package = " + cls.getPackage());

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable