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 839655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:30:02+00:00 2026-05-15T05:30:02+00:00

Trying to understand resources in java-land. I believe the following is true: Resources loaded

  • 0

Trying to understand resources in java-land. I believe the following is true:

  • Resources loaded via the classpath have no namespace, they only have a file name.
  • It’s wisest to always load resources via the classpath, never via the file system, even in unit tests.

Therefore, resources must always have unique file names, or collisions will occur.

Are there flaws in my assumptions or my conclusion?

  • 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-05-15T05:30:03+00:00Added an answer on May 15, 2026 at 5:30 am

    Assumption 1) Resources loaded via the classpath have no namespace, they only have a file name.

    Resources loaded from the classpath are actually identified by a pathname not a simple filename. You could view the directory parts of the pathnames as forming namespaces.

    Also if you load using Class.getResourceAsStream(String pathname), a pathname that does not start with a “/” will be interpreted as relative to the pathname for the classes package.

    The classpath mechanism works by overlaying the namespaces of each JAR file, etc on the classpath. So you could have multiple resources in different JARs with the same pathname, but only one will be actually visible. (You describe this later as a “collision”.) But from the perspective of the set of pathnames that are visible, each pathname uniquely identifies a resource.

    Assumption 2) It’s wisest to always load resources via the classpath, never via the file system, even in unit tests.

    If we are talking about the resources of the application, then loading from the classpath has definite advantages. However, if we are talking about resources that are created and managed by the application, then loading via the classpath has problems … because you cannot write resources to the classpath.

    Also, even with a clarification of what you mean by “resource”, I don’t think it is correct to say that it is always wisest to load resources via the classpath. We cannot possibly anticipate all scenarios / use-cases, and therefore cannot say that there may not be some scenario / use-case where the wisest approach is to load the resource some other way. (However, if you were to say “generally” or “usually” instead of “always” I would agree with the assumption.)

    Conclusion 3) Therefore, resources must always have unique file names, or collisions will occur.

    If resources coming from different JARs on the classpath have non-unique pathnames, then you do get a kind of collision and one or other of the resources will not be loadable (at least, not via the normal classloader APIs). But this may be exactly what you may want to happen!

    Are there flaws in my assumptions or my conclusion?

    • Assumption 1) is false on the face of it, but it can be reinterpreted in a way that makes it true.

    • Conclusion 3) logically follows from the reinterpreted assumption 1).

    • Assumption 2) is also false, but can be reinterpreted in a way that makes it true: i.e. relax “always”, and define what you mean by “resource”. However, this assumption is not logically required for the conclusion.

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

Sidebar

Related Questions

Just trying to understand that - I have never used it before. How is
I am trying to understand JavaScript minification and compression processes and have couple of
I'm trying to understand how the new try-with-resources statement works by recreating it using
I am trying to understand how Mach-o files work, and have made a good
I'm trying to clean up resources in my application before it shuts down, following
I'm trying to understand the purpose of Django Intermediary Models . Conceptually, they seem
I am trying to understand the following things: When I make an EJB project
I've seen some examples, but trying to better understand how Resource files work, such
Trying to understand an fft (Fast Fourier Transform) routine I'm using (stealing)(recycling) Input is
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults

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.