

{"id":14222,"date":"2018-04-21T06:18:40","date_gmt":"2018-04-21T06:18:40","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=14222"},"modified":"2026-05-07T12:52:48","modified_gmt":"2026-05-07T07:22:48","slug":"literals-in-java","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/literals-in-java\/","title":{"rendered":"Literals in Java &#8211; Integral, Floating-Point, Char, String, Boolean"},"content":{"rendered":"<p>Literals are an integral part of a Java programmer\u2019s day-to-day life. This is a concept that every programmer must know before beginning their journey into the world of Java programming. In this article, we will take a look at literals and their types, and also a few rules that we need to follow while writing and declaring a literal.<\/p>\n<h3>What are Literals in Java?<\/h3>\n<p>Literals have a constant value and a fixed data type and are often known as constants in Java. Generally, Literals are assigned to a variable to provide a value to the variable.<\/p>\n<p>Let&#8217;s see, an example of assigning a literal to a variable is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int age = 21;<\/pre>\n<p>In the above code snippet, int is the datatype, age is the variable name, and 21 is the literal. Hence, we can say that the literal is providing the variable with a value of 21.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/what-are-literals.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109022\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/what-are-literals.webp\" alt=\"what are literals\" width=\"579\" height=\"244\" \/><\/a><\/p>\n<h3>Types of Literals in Java<\/h3>\n<p>Generally, 5 types of literals can be further expanded into various other literals. Hence, we will take a look at them vividly in this section.<\/p>\n<p><strong>The five main types of Literals in Java are:<\/strong><\/p>\n<ul>\n<li>Integer Literal<\/li>\n<li>Float\/Double Literal<\/li>\n<li>Character Literal<\/li>\n<li>Boolean Literal<\/li>\n<li>String Literal<\/li>\n<\/ul>\n<h4>Integer Literal in Java<\/h4>\n<p>Integer literals are basically a number sequence that doesn\u2019t contain any decimal point in between them.<\/p>\n<p><strong>There are four types of Integer Literals:<\/strong><\/p>\n<h5>1. Decimal Integer<\/h5>\n<p>They are integers having a base value of 10; i.e, containing values between 0 to 9. Therefore, it can be a positive value(+) or a negative value(-) but it cannot contain any point in between them. Example: 1000, 1234, +78, -82, etc.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int decimal_int=1234;<\/pre>\n<h5>2. Octal Integer<\/h5>\n<p>They are integers having a base value of 8; i.e, containing values between 0 to 7. Therefore, all octal numbers must start with a 0. Example: 012, 077,075, etc.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int octal_int=077;<\/pre>\n<h5>3. Hexadecimal Integer<\/h5>\n<p>They are integers having a base value of 16; i.e, containing values between 0 to 15. It is a special type of integer that contains both digits as well as characters. Thus, the digits range from 0 to 9, and the numbers 10 to 15 are replaced by characters a to f. However, any integer starting with 0x or 0X is considered to be a hexadecimal integer. Example: 0xff, 0x2a, 0xf1f2, etc.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int hexadec_int=0x1ff2;<\/pre>\n<h5>4. Binary Integer<\/h5>\n<p>They are integers with a base value of 2; i.e; contains only two digits, 0 and 1. However, Binary integers start with a 0b indicating that it is a binary digit. Example: 0b100101, 0b1010101, etc.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int binary_int=0b1010101;\r\n<\/pre>\n<p>Note: Binary literals can be created only on Java SE 7 and above.<\/p>\n<p><strong>Program Showing all the integer literals:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.Literals;\r\npublic class Literals_Integers\r\n{\r\n    public void main()\r\n    {\r\n        int decimal_int=1234;\r\n        int octal_int=077;\r\n        int hexadec_int=0x1ff2;\r\n        int binary_int=0b1010101;\r\n        System.out.println(\"This is a Decimal Literal: \"+decimal_int);\r\n        System.out.println(\"This is an Octal Literal: \"+octal_int);\r\n        System.out.println(\"This is a Hexa Decimal Literal: \"+hexadec_int);\r\n        System.out.println(\"This is a Binary Literal: \"+binary_int);\r\n    }\r\n}\r\n<\/pre>\n<p><strong>The output of the above code:<\/strong><\/p>\n<div class=\"code-output\">This is a Decimal Literal: 1234<br \/>\nThis is an Octal Literal: 63<br \/>\nThis is a Hexa Decimal Literal: 8178<br \/>\nThis is a Binary Literal: 85<\/div>\n<h4>Floating Point Literals in Java<\/h4>\n<p>Floating-point literals are values that contain a decimal point between them. Floating-point literals are generally of the double data type by default. Also, we can assign them to float data types by adding an f at the end of the value.<\/p>\n<p><strong>Example of declaring a float literal in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">float val_float=1.7732f;<\/pre>\n<p><strong>Example of declaring a double literal:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">float val_double=1.7732; \/\/By default the compiler assigns double datatype.\r\nfloat val_double=1.7732d;\r\ndouble val_double=1.7732;\r\n<\/pre>\n<p>Floating-point Literals can also have an exponent part. This exponential part can be declared as follows:<br \/>\n123E-45f<\/p>\n<p>A few points to remember while declaring floating-point literals are:<br \/>\n1. If no suffix is present, the default data type is double.<br \/>\n2. F or f suffix represents a floating data type.<br \/>\n3. D or d suffix represents a double data type.<\/p>\n<p>Few legal and illegal floating literals:<\/p>\n<ul>\n<li>123.45\/\/Legal<\/li>\n<li>122.32E5\/\/Legal<\/li>\n<li>231.12F\/\/Legal<\/li>\n<li>1\/4 \/\/ Illegal Symbol Used \u201c\/\u201d<\/li>\n<li>1.7.5 \/\/Illegal, as two decimal points are used.<\/li>\n<li>1,234.56\/\/ Illegal, as commas are not allowed<\/li>\n<li>123.E4\/\/Illegal, as E cannot precede the point.<\/li>\n<li>321E\/\/Illegal, as the exponent part is incomplete.<\/li>\n<\/ul>\n<p>Also, floating-point literals cannot have commas in between the digits.<\/p>\n<p><strong>Program Showing all the floating literals:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.Literals;\r\npublic class Literals_Float\r\n{\r\n    public void main()\r\n    {\r\n        float val_float=1.7732f;\r\n        double val_double=1.7732d;\r\n        float val_exponent=123E4f;\r\n        System.out.println(\"This is a Floating Point Literal\"+val_float);\r\n        System.out.println(\"This is a Decimal Literal\"+val_double);\r\n        System.out.println(\"This is an Exponential Literal\"+val_exponent);\r\n    }\r\n}\r\n<\/pre>\n<p><strong>The output of the above code:<\/strong><\/p>\n<div class=\"code-output\">This is a Floating Point Literal1.7732<br \/>\nThis is a Decimal Literal1.7732<br \/>\nThis is an Exponential Literal1230000.0<\/div>\n<h4>Boolean Literal in Java<\/h4>\n<p>A boolean literal is a literal that contains only two values, true and false. It is declared using the keyword boolean. Although it is a very useful literal to declare flag variables in different programs to terminate a looping sequence.<\/p>\n<p><strong>Program showing the Boolean Literals:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.Literals;\r\npublic class Literals_boolean\r\n{\r\n    public void main()\r\n    {\r\n        boolean flag1=true;\r\n        boolean flag2=false;\r\n        System.out.println(\"This is a boolean true flag variable\"+flag1);\r\n        System.out.println(\"This is a boolean false flag variable\"+flag2);\r\n    }\r\n}<\/pre>\n<p><strong>The output of the above code:<\/strong><\/p>\n<div class=\"code-output\">This is a boolean true flag variabletrue<br \/>\nThis is a boolean false flag variablefalse<\/div>\n<h4>String Literals in Java<\/h4>\n<p>A string is basically an array of characters. In Java, we have a special class for strings that allows users to implement strings in a program very easily. As a result, Anything written inside a double quote (\u201c \u201d) is a string.<\/p>\n<p><strong>Example of Java String Literal:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">String Company = \u201cDataFlair\u201d;\/\/Valid String Literal\r\nString Company = DataFlair;\/\/Invalid as there is no double quote.<\/pre>\n<h4>Null Literal in Java<\/h4>\n<p>Strings in Java can also be declared void with a special literal known as a null literal. Moreover, it is basically equivalent to an integer value of 0.<\/p>\n<p><strong>Program showing implementation of String Literal:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.Literals;\r\npublic class Literals_string\r\n{\r\n    public void main()\r\n    {\r\n    String company=\"DataFlair\";\r\n    String null_Literal=null;\r\n    System.out.println(\"This is a String Literal: \"+company);\r\n    System.out.println(\"This is a null Literal: \"+null_Literal);\r\n   }\r\n}\r\n<\/pre>\n<p><strong>The output of the above code:<\/strong><\/p>\n<div class=\"code-output\">This is a String Literal: DataFlair<br \/>\nThis is a null Literal: null<\/div>\n<h4>Character Literals in Java<\/h4>\n<p>Character Literals in Java are represented with a single quote. Therefore, the general difference between a string literal and a character literal is that a character literal contains only one character, whereas a string literal contains a set of characters.<\/p>\n<p>A character literal can be represented in four ways:<\/p>\n<p><strong>1. Single quote character<\/strong><\/p>\n<p>In this, a single character is represented by being enclosed in a pair of single quotes (\u2018 \u2019).<\/p>\n<p><strong>Example of single quote character in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">char ch = \u2018A\u2019;\r\n<\/pre>\n<p><strong>2. Character Literal as an Integer Literal<\/strong><\/p>\n<p>In Java, each character has a numeric value assigned to it. By using those integer values, as a result, we can display the characters. Let\u2019s see with an example given below.<\/p>\n<p><strong>Example of character literal as integral literal in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">char number = 0065;<\/pre>\n<p><strong>3. Unicode representation of character Literal<\/strong><\/p>\n<p>We can also represent the character literals using Unicode. Hence, Unicode is a special code assigned to the character, usually represented by \u2018\/u\u2019 with a hexadecimal digit.<\/p>\n<p><strong>Example of the Unicode representation of a character literal in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">char uni = \u2018\\u0065\u2019;<\/pre>\n<p><strong>4. Escape Sequence in Java<\/strong><\/p>\n<p>It is a special kind of character literal which is preceded by a \\. Also, every escape sequence has a special feature. Some of the most used escape sequences are:<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Escape Sequence\u00a0<\/b><\/td>\n<td><b>Functionality<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\n<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to insert a new line.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\t<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to insert a horizontal tab.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\b<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to insert a blank space.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\v<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to insert a Vertical tab.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\a<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to add a small beep sound.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to add a single quote inside a string.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\"> \\\u201d<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to add double quotes inside a String.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\\\<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to add a backslash<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\r<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used for carriage return.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\?<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to add a Question mark<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\0n<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to represent an octal number<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\xHn<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to represent a hexadecimal number<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\uHn<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to represent a Unicode character through its hex code.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\0<\/span><\/td>\n<td><span style=\"font-weight: 400\">Null Character<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">\\f<\/span><\/td>\n<td><span style=\"font-weight: 400\">Used to represent formfeed<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Few Valid Character Literals:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">char ch = \u2018A\u2019;\r\nchar ch =\u2019\\u0065\u2019\r\nchar ch= 0065\r\nchar ch=\u2019\\\\\u2019\r\nchar ch=\u2019%\u2019\r\n<\/pre>\n<p><strong>Program implementing Character Literal<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.Literals;\r\npublic class Literal_Char\r\n{\r\n    public void main()\r\n    {\r\n        char ch='A';\r\n        char number= 0065;\r\n        char uni='\\u0065';\r\n        System.out.print(\"\\nThis is a character Literal:\\b\"+ch);\r\n        System.out.print(\"\\nThis is a character Literal as Integer:\\b\"+number);\r\n        System.out.print(\"\\nThis is a character Literal as Unicode:\\b\"+uni);\r\n    }\r\n}\r\n\r\n<\/pre>\n<p><strong>The output of the above code:<\/strong><\/p>\n<div class=\"code-output\">This is a character Literal:A<br \/>\nThis is a character Literal as Integer:5<br \/>\nThis is a character Literal as Unicode:e<\/div>\n<h4>Class literals in Java<\/h4>\n<p>There&#8217;s also a special kind of literal called a class literal, which is formed by taking a type name and appending &#8220;.class&#8221; to it; for example, String.class.Therefore, this refers to the object (of type Class) that represents the type itself.<\/p>\n<p><strong>Example of a class literal in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Class&lt;String&gt; c = String.class; \r\n<\/pre>\n<p><strong>Rules to Use Underscore in Literals<\/strong><\/p>\n<ul>\n<li>In the beginning, end, or in between the numbers.<\/li>\n<li>Adjacent to a decimal point in a floating-point literal.<\/li>\n<li>Prior to an F or L suffix.<\/li>\n<li>At positions where a string of digits is expected<\/li>\n<\/ul>\n<p><strong>Some invalid use of Underscore<\/strong><\/p>\n<ul>\n<li>1_.234<\/li>\n<li>1._234<\/li>\n<li>65_<\/li>\n<li>12_34_56_78_90_L<\/li>\n<li>0_x77<\/li>\n<li>0x_77<\/li>\n<li>0x77_<\/li>\n<\/ul>\n<h3>Why Use Literals?<\/h3>\n<p>Literal is very useful for implementation in the code as it reduces declaring constants and adding labels by doing it on the same line. Additionally, Literals in Java are a way of representing text, characters, and numerical values.<\/p>\n<h3>How to use Literals in Java?<\/h3>\n<p>As we saw earlier, as well in the discussed topics, a literal is declared along with a data type and a variable name. Also, a literal has an = sign before it, which assigns the value of the literal to the variable.<\/p>\n<h3>Conclusion<\/h3>\n<p>In addition, Literals are the basic foundation of programming, and grasping their concept is essential for implementation. Therefore, without literals, creating a program is next to impossible. Also, we have talked about different literals and their uses, and how to implement them in our code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Literals are an integral part of a Java programmer\u2019s day-to-day life. This is a concept that every programmer must know before beginning their journey into the world of Java programming. In this article, we&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":108852,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[1989,2161,2464,3617,4189,4797,5625,6850,7584,9198,12911,13905,15074,15145],"class_list":["post-14222","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-binary-literals","tag-boolean-literals-in-java","tag-char-literals-in-java","tag-decimal-literals","tag-escape-sequence","tag-floating-point-literals-in-java","tag-hexa-decimal-literals","tag-integral-literals","tag-java-literals","tag-octal-literals","tag-single-quote","tag-string-literals-in-java","tag-types-of-java-literals","tag-unicode-representation"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Literals in Java - Integral, Floating-Point, Char, String, Boolean - DataFlair<\/title>\n<meta name=\"description\" content=\"Literals in Java hold the value of variables. Learn 5 types of literals- integer, char, floating-point, boolean, string with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/literals-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Literals in Java - Integral, Floating-Point, Char, String, Boolean - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Literals in Java hold the value of variables. Learn 5 types of literals- integer, char, floating-point, boolean, string with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/literals-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-21T06:18:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-07T07:22:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/literals-in-java.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Literals in Java - Integral, Floating-Point, Char, String, Boolean - DataFlair","description":"Literals in Java hold the value of variables. Learn 5 types of literals- integer, char, floating-point, boolean, string with examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/literals-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Literals in Java - Integral, Floating-Point, Char, String, Boolean - DataFlair","og_description":"Literals in Java hold the value of variables. Learn 5 types of literals- integer, char, floating-point, boolean, string with examples.","og_url":"https:\/\/data-flair.training\/blogs\/literals-in-java\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-04-21T06:18:40+00:00","article_modified_time":"2026-05-07T07:22:48+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/literals-in-java.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/literals-in-java\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/literals-in-java\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Literals in Java &#8211; Integral, Floating-Point, Char, String, Boolean","datePublished":"2018-04-21T06:18:40+00:00","dateModified":"2026-05-07T07:22:48+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/literals-in-java\/"},"wordCount":1394,"commentCount":3,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/literals-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/literals-in-java.webp","keywords":["Binary Literals","Boolean literals in Java","Char Literals in Java","Decimal Literals","Escape Sequence","Floating-Point Literals in Java","Hexa-Decimal Literals","Integral literals","Java Literals","Octal Literals","Single Quote","String literals in Java","Types of Java Literals","Unicode Representation"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/literals-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/literals-in-java\/","url":"https:\/\/data-flair.training\/blogs\/literals-in-java\/","name":"Literals in Java - Integral, Floating-Point, Char, String, Boolean - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/literals-in-java\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/literals-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/literals-in-java.webp","datePublished":"2018-04-21T06:18:40+00:00","dateModified":"2026-05-07T07:22:48+00:00","description":"Literals in Java hold the value of variables. Learn 5 types of literals- integer, char, floating-point, boolean, string with examples.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/literals-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/literals-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/literals-in-java\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/literals-in-java.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/literals-in-java.webp","width":1200,"height":628,"caption":"literals in java"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/literals-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Java Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/java\/"},{"@type":"ListItem","position":3,"name":"Literals in Java &#8211; Integral, Floating-Point, Char, String, Boolean"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/14222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=14222"}],"version-history":[{"count":20,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/14222\/revisions"}],"predecessor-version":[{"id":148250,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/14222\/revisions\/148250"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/108852"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=14222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=14222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=14222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}