Online Java Compiler By
JavaTpoint.com
//import statements import java.lang.*; public class ClassgetPackageNameExample1 { public static void main(String[] args) { try { Class class1 = Class.forName("java.lang.Integer"); System.out.println("Class ::: " + class1.getName()); System.out.println("Package ::: " + class1.getPackage()); //get the package String pkgs = class1.getPackage().toString(); //convert into string System.out.println("Package Name ::: " +pkgs ); //print statement } catch(ClassNotFoundException ex) { System.out.println(ex.toString()); //print exception object ex } } }
Output