Java tutorial
//package com.java2s; public class Main { public static String getPackageName(Class<?> klass) { if (klass == null) { return null; } String className = klass.getName(); if (className == null) { return null; } final int splitIndex = className.lastIndexOf('.'); return className.substring(0, splitIndex); } }