Java properties
   HOME

TheInfoList



OR:

.properties is a
file extension A filename extension, file name extension or file extension is a suffix to the name of a computer file (e.g., .txt, .docx, .md). The extension indicates a characteristic of the file contents or its intended use. A filename extension is typically d ...
for files mainly used in
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mos ...
-related technologies to store the configurable parameters of an application. They can also be used for storing strings for
Internationalization and localization In computing, internationalization and localization (American) or internationalisation and localisation (British English), often abbreviated i18n and L10n, are means of adapting computer software to different languages, regional peculiarities and ...
; these are known as Property Resource Bundles. Each parameter is stored as a pair of strings, one storing the name of the parameter (called the ''key''), and the other storing the value. Unlike many popular file formats, there is no RFC for .properties files and specification documents are not always clear, most likely due to the simplicity of the format.


Format

Each line in a .properties file normally stores a single property. Several formats are possible for each line, including key=value, key = value, key:value, and key value. Single-quotes or double-quotes are considered part of the string. Trailing space is significant and presumed to be trimmed as required by the consumer.
Comment Comment may refer to: * Comment (linguistics) or rheme, that which is said about the topic (theme) of a sentence * Bernard Comment (born 1960), Swiss writer and publisher Computing * Comment (computer programming), explanatory text or informa ...
lines in .properties files are denoted by the
number sign The symbol is known variously in English-speaking regions as the number sign, hash, or pound sign. The symbol has historically been used for a wide range of purposes including the designation of an ordinal number and as a ligatured abbreviati ...
(#) or the
exclamation mark The exclamation mark, , or exclamation point (American English), is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings or to show emphasis. The exclamation mark often marks the end of a sentence, f ...
(!) as the first non blank
character Character or Characters may refer to: Arts, entertainment, and media Literature * ''Character'' (novel), a 1936 Dutch novel by Ferdinand Bordewijk * ''Characters'' (Theophrastus), a classical Greek set of character sketches attributed to The ...
, in which all remaining text on that line is ignored. The backwards slash is used to escape a character. An example of a properties file is provided below. # You are reading a comment in ".properties" file. ! The exclamation mark can also be used for comments. # Lines with "properties" contain a key and a value separated by a delimiting character. # There are 3 delimiting characters: '=' (equal), ':' (colon) and whitespace (space, \t and \f). website = https://en.wikipedia.org/ language : English topic .properties files # A word on a line will just create a key with no value. empty # White space that appears between the key, the value and the delimiter is ignored. # This means that the following are equivalent (other than for readability). hello=hello hello = hello # Keys with the same name will be overwritten by the key that is the furthest in a file. # For example the final value for "duplicateKey" will be "second". duplicateKey = first duplicateKey = second # To use the delimiter characters inside a key, you need to escape them with a \. # However, there is no need to do this in the value. delimiterCharacters\:\=\ = This is the value for the key "delimiterCharacters\:\=\ " # Adding a \ at the end of a line means that the value continues to the next line. multiline = This line \ continues # If you want your value to include a \, it should be escaped by another \. path = c:\\wiki\\templates # This means that if the number of \ at the end of the line is even, the next line is not included in the value. # In the following example, the value for "evenKey" is "This is on one line\". evenKey = This is on one line\\ # This line is a normal comment and is not included in the value for "evenKey" # If the number of \ is odd, then the next line is included in the value. # In the following example, the value for "oddKey" is "This is line one and\#This is line two". oddKey = This is line one and\\\ # This is line two # White space characters are removed before each line. # Make sure to add your spaces before your \ if you need them on the next line. # In the following example, the value for "welcome" is "Welcome to Wikipedia!". welcome = Welcome to \ Wikipedia! # If you need to add newlines and carriage returns, they need to be escaped using \n and \r respectively. # You can also optionally escape tabs with \t for readability purposes. valueWithEscapes = This is a newline\n and a carriage return\r and a tab\t. # You can also use Unicode escape characters (maximum of four hexadecimal digits). # In the following example, the value for "encodedHelloInJapanese" is "こんにちは". encodedHelloInJapanese = \u3053\u3093\u306b\u3061\u306f # But with more modern file encodings like UTF-8, you can directly use supported characters. helloInJapanese = こんにちは In the example above, (line 5) would be a key, and its corresponding value would be . While the number sign (#) and the exclamation mark (!) marks text as comments, it has no effect when it is part of a property. Thus, the key (line 37) has the value and not ! All of the whitespace in front of line 38 is excluded. Before Java 9, the encoding of a .properties file is ISO-8859-1, also known as Latin-1. All non-ASCII characters must be entered by using
Unicode Unicode, formally The Unicode Standard,The formal version reference is is an information technology standard for the consistent encoding, representation, and handling of text expressed in most of the world's writing systems. The standard, wh ...
escape characters, e.g. \uHHHH where HHHH is a hexadecimal index of the character in the Unicode character set. This allows for using .properties files as
resource bundles This is a list of file formats used by computers, organized by type. Filename extension it is usually noted in parentheses if they differ from the file format name or abbreviation. Many operating systems do not limit filenames to one extension s ...
for
localization Localization or localisation may refer to: Biology * Localization of function, locating psychological functions in the brain or nervous system; see Linguistic intelligence * Localization of sensation, ability to tell what part of the body is a ...
. A non-Latin-1 text file can be converted to a correct .properties file by using the native2ascii tool that is shipped with the
JDK The Java Development Kit (JDK) is a distribution of Java Technology by Oracle Corporation. It implements the Java Language Specification (JLS) and the Java Virtual Machine Specification (JVMS) and provides the Standard Edition (SE) of the Java ...
or by using a tool, such as po2prop, that manages the transformation from a bilingual localization format into .properties escaping. An alternative to using unicode escape characters for non-Latin-1 character in ISO 8859-1 character encoded Java *.properties files is to use the JDK's XML Properties file format which by default is
UTF-8 UTF-8 is a variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode'' (or ''Universal Coded Character Set'') ''Transformation Format 8-bit''. UTF-8 is capable of ...
encoded, introduced starting with Java 1.5. Another alternative is to create custom control that provides custom encoding. In Java 9 and newer, the default encoding specifically for property resource bundles is UTF-8, and if an invalid UTF-8 byte sequence is encountered it falls back to ISO-8859-1.


Editing

Editing .properties files is done using any
text editor A text editor is a type of computer program that edits plain text. Such programs are sometimes known as "notepad" software (e.g. Windows Notepad). Text editors are provided with operating systems and software development packages, and can be ...
such as those typically installed on various Operating Systems including
Notepad A notebook (also known as a notepad, writing pad, drawing pad, or legal pad) is a book or stack of paper pages that are often ruled and used for purposes such as note-taking, journaling or other writing, drawing, or scrapbooking. History ...
on Windows or Emacs, Vim, etc. on Linux systems. Third-party tools are also available with additional functionality specific to editing .properties files such as: *
Data Validation In computer science, data validation is the process of ensuring data has undergone data cleansing to ensure they have data quality, that is, that they are both correct and useful. It uses routines, often called "validation rules", "validation cons ...
* Creating new keys * Synchronization of key names * Automatic bi-directional conversion of non-
ASCII ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Because ...
symbols to support non-
Latin Latin (, or , ) is a classical language belonging to the Italic branch of the Indo-European languages. Latin was originally a dialect spoken in the lower Tiber area (then known as Latium) around present-day Rome, but through the power of the ...
languages * Integration with Eclipse


Non-Java uses and exceptions

Apache Flex Apache Flex, formerly Adobe Flex, is a software development kit (SDK) for the development and deployment of cross-platform rich web applications based on the Adobe Flash platform. Initially developed by Macromedia and then acquired by Adobe Syste ...
uses .properties files as well, but here they are UTF-8 encoded. In Apache mod_jk's uriworkermap.properties format, an exclamation mark ("!") denotes a Negation operator when used as the first non blank character in a line.
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offic ...
CPAN The Comprehensive Perl Archive Network (CPAN) is a repository of over 250,000 software modules and accompanying documentation for 39,000 distributions, written in the Perl programming language by over 12,000 contributors. ''CPAN'' can denote eit ...
contains Config::Properties to interface to a .properties file.
SAP Sap is a fluid transported in xylem cells (vessel elements or tracheids) or phloem sieve tube elements of a plant. These cells transport water and nutrients throughout the plant. Sap is distinct from latex, resin, or cell sap; it is a separ ...
uses .properties files for localization within their framework SAPUI5 and its open-source variant
OpenUI5 OpenUI5 is a JavaScript application framework designed to build cross-platform, responsive, enterprise-ready applications. It is an open-source project maintained by SAP SE available under the Apache 2.0 license and open to contributions. OpenUI ...
There are many Node.js (JavaScript/TypeScript) options available on Npm's package manager.
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group. ...
also has many package options available.


See also

*
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable ...
, JSON and
YAML YAML ( and ) (''see '') is a human-readable data-serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted. YAML targets many of the same communications applications as Ext ...
are used by some for more complex configuration formats.


References


External links

* - gives the precise semantics of well-formed Java property files * - describes property resource bundles *{{Javadoc:SE, package=java.util, java/util, Properties - explains Java properties in a simple XML format.
MultiProperties
- It is an Eclipse plugin for editing multiple key-value based files with similar content. This kind of file format can be Properties for example in Java programming language, which is frequently used for backing a ResourceBundle.
Bracket Properties
- a refresh of the Properties concept while keeping the ubiquitous .properties file format intact.
Java Properties Editor (Application + Eclipse plugin)
- useful utility to view and to edit properties files in a whole project.
DOKSoft Properties Editor Eclipse plugin
- i18n tool for installing into Eclipse IDE.
Message Editor
- it manages i18n for Java application. It generates XML property files. It includes two stylesheets for .properties and .xml property generation at compile time (Ant based.)
JLokalize
- open source Java properties editor with reversal function and spell check
Config::Properties
- Perl CPAN.
Jackson Properties module
is a library that allows mapping Properties file contents into Java Objects and back, similar to how
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable ...
and JSON is commonly mapped
SAPUI5
- Use of Localized Texts in Applications
Properties Property is the ownership of land, resources, improvements or other tangible objects, or intellectual property. Property may also refer to: Mathematics * Property (mathematics) Philosophy and science * Property (philosophy), in philosophy an ...
Configuration files Java (programming language)
PROPERTIES Property is the ownership of land, resources, improvements or other tangible objects, or intellectual property. Property may also refer to: Mathematics * Property (mathematics) Philosophy and science * Property (philosophy), in philosophy an ...