Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterating through all JDK classes

I'm making a code editor and I'm working on the autocomplete. I want to programmatically get a list of all the classes that come with the JDK.

Examples include:

java.io.File
java.util.ArrayList
javax.swing.Action

I've found ways to get classes for a specific package. For instance, I can get all classes that start with com.mypackage.foo. The problem is that I'm trying to get classes that were loaded with the Bootstrap ClassLoader. And on the OSX JDK, that classloader shows up as null. For instance, if I do String.class.getClassLoader(), that is null.

Any ideas?

like image 698
satnam Avatar asked May 02 '15 07:05

satnam


People also ask

How do I use an iterator in Java?

To use an Iterator, you must import it from the java.util package. The iterator () method can be used to get an Iterator for any collection:

How to iterate through the elements of LinkedHashSet in Java?

Iterate through the elements of LinkedHashSet using the iterator method. We will use the hasNext () method and the next () method along with the while loop to iterate through LinkedHashSet elements. E – the type of elements maintained by this set.

What are the two main interfaces of Java collection classes?

The Collection interface (java.util.Collection) and Map interface (java.util.Map) are the two main “root” interfaces of Java collection classes. How to iterate through Collection Objects?

What happened to map class in Java?

This class is deprecated and subject to removal in a future version of Java SE. This class implements the Map interface with a hash table, using reference-equality in place of object-equality when comparing keys (and values). Deprecated, for removal: This API element is subject to removal in a future version.


Video Answer


1 Answers

You can open rt.jar with java.util.jar.JarFile and iterate over its entries. This is how can get URL to rt.jar : URL url = Object.class.getResource("String.class");

like image 167
Evgeniy Dorofeev Avatar answered Oct 05 '22 21:10

Evgeniy Dorofeev