The “.properties” file – things you should know

gprakashBlogLeave a Comment

“.properties” is a file extension name for files used for storing configurable parameters on Java technologies. This file extension is similar to “.txt” and “.doc” as used for text files on windows however in this case the parameters are saved as pairs of strings with one bearing the parameter name and the other bearing the value of the parameter.

These types of files have tremendous importance in Java related tools; for example, it can be used in internationalization and localization. Mostly used by Minecraft (sandbox block construction game) configurable parameters saved with the file extension “.properties” are used in developing application software that can be used in any region, a language without engineering. Popularly referred to as ‘Property Resource Bundle’ this phenomenon gives “.properties” files a versatile application in Java programming industry. Usually saved in plain text, this type of file is used to save the configuration of games (multi-player games) and would contain information like the number of players, IP address, etc.

Generally, the format of “.properties” files follows a specific pattern with each line storing a specific property. The general format takes the form “Key = value” where the equals sign can be replaced with a colon or space. The ‘#’ sign is used to indicate what each property line contains, in other words, it contains the comment. The exclamation sign symbol ‘!’ can also be used to indicate a comment but it must be included immediately before the texts not behind. The symbol ‘/’ can be used to create a space between texts. So a line written in the form ‘message = Welcome to Java programming’ imply the key is the ‘message’ and the value is the text string ‘welcome to programming.’

“.properties” files only supports ISO-8859-1 encoding system popularly referred to as Latin-1. However, if non-Latin-1 encoding system is to be used it must be entered using Unicode escape characters. This is important if the “.properties” file will be used as a property resource bundle for localization and internationalization. If a text file written in non-Latin-1 is to be used to create “.properties” file it must be converted using native2ascii tool or po2prop to translate it into a “.properties” file. JDK’s XML can also be used instead of Unicode escape characters but is only available from Java 1.5

.properties files are created using conventional text creation programs (notepad and WordPad for Windows and VIms for Linux operating system). For easier writing of the .property file, third-party tools can be employed.  These tools can assist in the validation of data, the creation of keys, key names and values synchronization, automatic conversion of non-latin 1 characters to ISO-8859-1, and usage with Eclipse. These tools, in general, helps in creating .properties files easily and faster.

“.properties” files can be opened using Java Virtual Machine, for example, the java.util.properties API but are accessible in a nested file folder titled “.properties”.  Other programs that can be used to open this type of file include Eclipse, Microsoft Notepad, Vim, Macromates amidst others. However, it is important to note that only Java Virtual Machines will open it as a property resource handler that it is.  Microsoft Notepad will open it in its encoded form and make it editable.

Finally, The use of “.properties” files are not limited to Java tools and programming, some other platforms also accept them. For example, Apache Flex uses “.properties” files except here a UTF encoding system is used, in this system an exclamation sign before a nonblank text is a negation indicator as opposed to comment in the Latin1 system. Perl CPAN also uses “.properties” files.

In configuration file hell? Take a look at Config, the easiest way to manage your application configuration across all your servers and environments.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.