Thursday 26 October 2017

How to get the package information of the class using Java Reflection | Reflection in java


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=qmFeRSOSJFU&list=UUhwKlOVR041tngjerWxVccw

ReflectionDemo.java
import java.util.ArrayList;

public class ReflectionDemo
{
    public static void main(String[] args)
    {

        Class<ArrayList> classObj = ArrayList.class;
        /*
         * Gets the package for this class. The class loader of this class is
         * used to find the package.
         */
        Package packageObj = classObj.getPackage();
        /*
         * Returns:The fully-qualified name of this package
         */
        System.out.println("Package Name = " + packageObj.getName());
        /*
         * Returns:the title of the implementation, null is returned if it is not known.
         */
        System.out.println("ImplementationTitle = "+packageObj.getImplementationTitle());
        /*
         * Returns:the version of the implementation, null is returned if it is not known.
         */
        System.out.println("ImplementationVersion = "+packageObj.getImplementationVersion());
        /*
         * Returns:the specification vendor, null is returned if it is not known.
         */
        System.out.println("SpecificationVendor = "+packageObj.getSpecificationVendor());
        
        /*
         * Returns:the specification title, null is returned if it is not known.
         */
        System.out.println("SpecificationTitle = "+packageObj.getSpecificationTitle());
    }

}
Output
Package Name = java.util
ImplementationTitle = Java Runtime Environment
ImplementationVersion = 1.8.0_144
SpecificationVendor = Oracle Corporation
SpecificationTitle = Java Platform API Specification

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/ReflectionDemo_package_info.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ReflectionDemo_package_info

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/6c95796df09abfb09587d07613e2e6d5f9ad024e/BasicJava/ReflectionDemo_package_info/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment