.settings files are similar to .instance files, with the distinction that they specify all the superclasses/interfaces of the object represented, so that some code can ask Lookup/whatever "Do you have one of these?" without needing to actually create an instance of the object. You could call .settings files "POJO persistence".

They had a brief run of popularity as Yet Another Way To Store Settings a couple years ago, around when the new window system was being conceived. They're not bad, but a bit baroque. The main point was to avoid loading classes or creating objects just to satisfy a test like "how many object instances are there of X", "does this folder/lookup/collection contain an instance of X". For NetBeans, where there are lots of classes, this sort of thing really does make a difference in performance.

.settings files can be used for the same purposes as .instance files? - as a way of indicating that the file represents some class that should be instantiated. The main difference is that by defining all of the superclasses and interfaces of an the object they install, it is possible for the system to delay actually instantiating the object longer - more questions about the object can be answered by the system without creating it to answer the questions.

.settings files are typically not used for registering actions in the main menu and similar places, since these actions will need to be instantiated almost immediately anyway in order to determine if they should be enabled or not. A future API for declarative actions will possibly change that, but at present, it does neither harm more good, and .instance files? are simpler.

Some examples:

Declaring a system option as a .settings file from an XML layer

Have a layer entry such as this:

<folder name="Services">
    <file name="org-openide-text-PrintSettings.settings" 

      <attr name="SystemFileSystem.localizingBundle" 
      <attr name="SystemFileSystem.icon" 


Note the url attribute - it points to a file PrintSettings.settings which is in the same directory in the module jar as the layer file - it is a relative path. That settings file will look like this:

  <?xml version="1.0"?>
  <!DOCTYPE settings PUBLIC "-//NetBeans//DTD Session settings 1.0//EN" 

  <settings version="1.0">
    <instanceof class="java.beans.beancontext.BeanContextProxy"/>
    <instanceof class="org.openide.util.SharedClassObject"/>
    <instanceof class="org.openide.options.SystemOption"/>
    <instanceof class="org.openide.options.ContextSystemOption"/>
    <instanceof class="org.openide.text.PrintSettings"/>
    <instance class="org.openide.text.PrintSettings"/>

The two things to note are that the settings file declares many of the relevant parent classes of the object (so it does not need to be instantiated just to see what kind of object it is), and the layer file declares the icon and a resource bundle (for the display name) as file attributes.

Source: NetBeans FAQ

Parent Category: Other API Tips