Get package name in Java

Description

The following code shows how to get package name.

Example


/*  w ww .j  a  v a 2 s  .c  om*/
public class Main {

    public static void main(String[] args) {
        System.out.println(Main.class.getPackage());
    }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Reflection »




Annotation
Array
Class
Constructor
Field
Generics
Interface
Method
Modifier
Package
Proxy