﻿---
title: Literals
description: Use a literal to specify a value directly in an operation. Use an integer literal to specify an integer type value in decimal, octal, or hex notation...
url: https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/139365/reference/scripting-languages/painless/painless-literals
products:
  - Painless
---

# Literals
Use a literal to specify a value directly in an [operation](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/139365/reference/scripting-languages/painless/painless-operators).

## Integers

Use an integer literal to specify an integer type value in decimal, octal, or hex notation of a [primitive type](/elastic/elasticsearch/pull/139365/reference/scripting-languages/painless/painless-types#primitive-types) `int`, `long`, `float`, or `double`. Use the following single letter designations to specify the primitive type: `l` or `L` for `long`, `f` or `F` for `float`, and `d` or `D` for `double`. If not specified, the type defaults to `int`. Use `0` as a prefix to specify an integer literal as octal, and use `0x` or `0X` as a prefix to specify an integer literal as hex.
**Grammar**
```text
INTEGER: '-'? ( '0' | [1-9] [0-9]* ) [lLfFdD]?;
OCTAL:   '-'? '0' [0-7]+ [lL]?;
HEX:     '-'? '0' [xX] [0-9a-fA-F]+ [lL]?;
```

**Examples**
- Integer literals.
  ```java
  0     <1>
  0D    
  1234L 
  -90f  
  -022  
  0xF2A 
  ```


## Floats

Use a floating point literal to specify a floating point type value of a [primitive type](/elastic/elasticsearch/pull/139365/reference/scripting-languages/painless/painless-types#primitive-types) `float` or `double`. Use the following single letter designations to specify the primitive type: `f` or `F` for `float` and `d` or `D` for `double`. If not specified, the type defaults to `double`.
**Grammar**
```text
DECIMAL: '-'? ( '0' | [1-9] [0-9]* ) (DOT [0-9]+)? EXPONENT? [fFdD]?;
EXPONENT: ( [eE] [+\-]? [0-9]+ );
```

**Examples**
- Floating point literals.
  ```java
  0.0      
  1E6      
  0.977777 
  -126.34  
  89.9F    
  ```


## Strings

Use a string literal to specify a [`String` type](/elastic/elasticsearch/pull/139365/reference/scripting-languages/painless/painless-types#string-type) value with either single-quotes or double-quotes. Use a `\"` token to include a double-quote as part of a double-quoted string literal. Use a `\'` token to include a single-quote as part of a single-quoted string literal. Use a `\\` token to include a backslash as part of any string literal.
**Grammar**
```text
STRING: ( '"'  ( '\\"'  | '\\\\' | ~[\\"] )*? '"'  )
      | ( '\'' ( '\\\'' | '\\\\' | ~[\\'] )*? '\'' );
```

**Examples**
- String literals using single-quotes.
  ```java
  'single-quoted string literal'
  '\'single-quoted with escaped single-quotes\' and backslash \\'
  'single-quoted with non-escaped "double-quotes"'
  ```
- String literals using double-quotes.
  ```java
  "double-quoted string literal"
  "\"double-quoted with escaped double-quotes\" and backslash: \\"
  "double-quoted with non-escaped 'single-quotes'"
  ```


## Characters

Character literals are not specified directly. Instead, use the [cast operator](/elastic/elasticsearch/pull/139365/reference/scripting-languages/painless/painless-casting#string-character-casting) to convert a `String` type value into a `char` type value.