Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8054681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:12:12+00:00 2026-06-05T08:12:12+00:00

Does anybody knows if it’s possible (is there a library) to know if a

  • 0

Does anybody knows if it’s possible (is there a library) to know if a Class<?> variable is included in the JRE or not ?

Here is what I would want :

Class<String> stringClass = String.class;
System.out.println(TheMagickLibrary.isJREClass(stringClass)); // should display true

Class<AnyClass> anotherClass = AnyClass.class;
System.out.println(TheMagickLibrary.isJREClass(anotherClass)); // should display false
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:12:13+00:00Added an answer on June 5, 2026 at 8:12 am

    I can offer you 2 solutions.

    1. Get class package and check whether it starts with java., sun., com.sun.
    2. Get the class’ class loader:
    Returns the class loader for the class.  Some implementations may use
    null to represent the bootstrap class loader. This method will return
    null in such implementations if this class was loaded by the bootstrap
    class loader.
    

    As you can see they say “some implmentations may return null”. It means that for these implementations clazz.getClassLoader() == null means that the class is loaded by bootstrap class loader and therefore belongs to JRE. BTW this works on my system (Java(TM) SE Runtime Environment (build 1.6.0_30-b12)).

    If not check the documentation of ClassLoader#getParent():

     Returns the parent class loader for delegation. Some implementations may
     use <tt>null</tt> to represent the bootstrap class loader. This method
     will return <tt>null</tt> in such implementations if this class loader's
     parent is the bootstrap class loader.
    

    Again, some implementations will return null if current class loader is a bootstrap.

    Finally I’d recommend the following strategy:

    public static boolean isJreClass(Class<?> clazz) {
        ClassLoader cl = clazz.getClassLoader();
        if (cl == null || cl.getParent() == null) {
            return true;
        }
        String pkg = clazz.getPackage().getName();
        return pkg.startsWith("java.") || pkg.startsWith("com.sun") || pkg.startsWith("sun."); 
    }
    

    I believe this is good enough for 99% of cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know how i would go about forcing a panel to be square.
does anybody know what are for PG and GG variables here: module sum(S, Cout,PG,GG,A,B,Cin);
Does anybody knows when there will be more updated information than the following info
Does anybody knows, if there is an (free) IFRAME like ASP.NET server control ?
Does anybody knows what happen with QCheckListItem in qt 4? I included this header
Does anybody know if there is a shortcut for the following statement in PHP?
does anybody knows if there is a Jenkins /Hudson plugin that when the build
Does anybody knows when will feed v2 leave trusted tester stage? There are some
Does anybody knows whether it is possible to measure utilization of a server CPU
Does anybody knows if it is possible to set up admin user accounts so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.