Get full package name
public class Main { public static String getPackageName(Class c) { String fullyQualifiedName = c.getName(); int lastDot = fullyQualifiedName.lastIndexOf('.'); if (lastDot == -1) { return ""; } return fullyQualifiedName.substring(0, lastDot); } public static void main(String[] args) { System.out.println(getPackageName(java.awt.Frame.class)); } }