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

  • Home
  • SEARCH
  • 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 6078635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:51:21+00:00 2026-05-23T10:51:21+00:00

I have a java program that uses a handful of .properties files. It chooses

  • 0

I have a java program that uses a handful of .properties files. It chooses what properties file to use based on a parameter (mode) passed at runtime.
for example when the program is running in mode:a it uses a.properties file and when mode:b it’ll uses b.properties file, etc.
I want to combine all these properties files into one common.properties and instead have different namespaces. For example in common.properties I’ll have:

a.url = aaa
a.ip = aaa.aaa.aaa.aaa
b.url = bbb
b.ip = bbb.bbb.bbb.bbb

Right now, I instantiate the properties object in the main method and pass it to the other objects/methods that need to read something from the properties.But now that I’ve combined the properties I have to pass the mode: a or b as well so that they know what set of properties they should extract.
Is there a better way of creating a filtered instance of the properties file in the main method and then passing that to other object in a way that these objects are not aware of the mode: a or b, and just query the properties object for url and ip (not a.url or a.ip)

  • 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-23T10:51:22+00:00Added an answer on May 23, 2026 at 10:51 am

    Don’t pass the Properties object to other methods/objects. It’s too low-level, especially now that you have to deal with this namespace thing. Encapsulate the Properties inside a dedicated object (let’s call it “Configuration”), and pass this Configuration object.

    public class Configuration {
        private String mode;
        private Properties properties;
    
        public Configuration(String mode, Properties properties) {
            this.mode = mode;
            this.properties = properties;
        }
    
        public String get(String key) {
            return properties.getString(mode + "." + key);
        }
    }
    

    You could even extract the contract of this Configuration object into an interface, and make all objects depend on this interface rather than the concrete Configuration class, which would help in

    • changing the configuration strategy later if you want to (if you has done this from the start, you wouldn’t have to change anything in all the objects now)
    • mocking the configuration in unit tests to make it return what you want.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java client program that uses mdns with service discovery to find
I have a Java program that loads thirdparty class files (classes I did not
I have a Java program that is launched by a batch file with a
I have a Java program that opens a file using the RandomAccessFile class. I'd
I have a Java program that uses OAuth for communication with a server to
I have a Java program that uses reflection to find and invoke the main(String[]
I'm experimenting with internationalization by making a Hello World program that uses properties files
I have a program that uses java.util.TimeZone to produce the GMT offsets for various
I have a Java program that outputs some text into console. It uses print
I have a small Java program that uses ImageIcons on JLabels to display pictures.

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.