The main difference can be found in the fact that they return:
getClassLoader.getURLs()
Gets the URL search path for loading classes and resources. This includes the initial list of URLs specified by the constructor, as well as any URLs subsequently added by the addURL () method, see link
System.getProperty("java.class.path")
The path used to search directories and JAR archives containing class files. Class path elements are separated by a platform-specific character specified in the path.separator property, see link
Looking at the definition, here are the differences:
- First returns an array of URLs, and the second returns String.
- Firstly, any URLs added at runtime using the API will also be returned, and secondly, this will not include.
More or less, it depends on what you are trying to achieve, when you need to decide which one to choose.
Greetings!
source share