

{"id":6222,"date":"2018-01-22T07:05:22","date_gmt":"2018-01-22T01:35:22","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=6222"},"modified":"2026-05-07T12:26:25","modified_gmt":"2026-05-07T06:56:25","slug":"java-data-types","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/java-data-types\/","title":{"rendered":"Java Data Types &#8211; Primitive &amp; Non-Primitive Data types with Examples"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2167,&quot;href&quot;:&quot;https:\\\/\\\/introcs.cs.princeton.edu\\\/java\\\/14array&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251211003833\\\/https:\\\/\\\/introcs.cs.princeton.edu\\\/java\\\/14array\\\/&quot;,&quot;redirect_href&quot;:&quot;https:\\\/\\\/introcs.cs.princeton.edu\\\/java\\\/14array\\\/&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 03:49:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-14 10:40:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-18 05:01:03&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2025-12-23 08:54:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-28 12:41:16&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-31 13:13:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-03 17:21:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-07 19:24:12&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-13 01:58:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-17 12:24:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-21 08:09:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-28 02:55:42&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-01 14:02:05&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-06 12:43:52&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 02:55:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-16 16:37:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 11:24:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-23 16:24:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-26 20:14:22&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-03-02 07:20:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-05 10:11:09&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-09 00:08:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-12 14:17:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-17 05:50:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-20 13:26:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-24 02:18:09&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-30 07:50:13&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-05 10:40:18&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-09 12:14:15&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-12 13:53:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-17 06:43:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-20 16:40:27&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-26 22:57:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-30 05:16:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-03 09:06:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-07 23:27:18&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-05-12 05:55:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-16 10:21:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-19 15:41:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-22 19:15:13&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-26 10:17:33&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-05-29 16:49:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-02 13:57:31&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-06-06 06:18:16&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-06 06:18:16&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>Variables store data. But a fundamental problem arises as to what kind of data is the variable stores? There can be a lot of confusion about the computation of a program if the variables\u2019 individual data types are not known. Hence, the concept of data types arises. In this tutorial, we will learn Java Data Types with examples.<\/p>\n<h3>Java Data Types<\/h3>\n<p>Every individual bit of data that is processed every day is categorized into types. The type of data is known as a datatype. Java uses various kinds of data types.<\/p>\n<p><strong>However, the data types are mainly of two categories:<\/strong><\/p>\n<p><strong>a. Primitive Data Types-<\/strong> These data types are already hard-coded into the compiler to be recognized when the program is executed. Examples are- int,float etc.<\/p>\n<p><strong>b. Non-Primitive Data Types-<\/strong> These data types are special types of data which are user-defined, i,e, the program contains their definition. Some examples are- classes, interfaces, etc.<\/p>\n<h3>Primitive Data Types in Java<\/h3>\n<p>Java primitive data types are the ones that are predefined by the programming language, which in this case is Java. Without primitive data types, it would be impossible to frame programs. Primitive data types are also the building blocks of Non-primitive data types.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Primitive-Data-Types-DF.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78478\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Primitive-Data-Types-DF.jpg\" alt=\"Java Primitive Data Types\" width=\"690\" height=\"390\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Primitive-Data-Types-DF.jpg 690w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Primitive-Data-Types-DF-300x170.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Primitive-Data-Types-DF-150x85.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Primitive-Data-Types-DF-520x294.jpg 520w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/a><\/p>\n<p>There are 8 types of Java primitive data types, namely:<br \/>\n<strong>1.<\/strong> Int<br \/>\n<strong>2.<\/strong> Float<br \/>\n<strong>3.<\/strong> Char<br \/>\n<strong>4.<\/strong> Boolean<br \/>\n<strong>5.<\/strong> Byte<br \/>\n<strong>6.<\/strong> Short<br \/>\n<strong>7.<\/strong> long<br \/>\n<strong>8.<\/strong> Double.<\/p>\n<h4>1. Integer Datatype in Java<\/h4>\n<p>int is used for storing integer values. Its size is 4 bytes and has a default value of 0. The maximum value of an integer is 2^31, and the minimum value is -2^31. It can be used to store integer values unless there is a need for storing numbers larger or smaller than the limits<\/p>\n<p>Example- int a=56;<\/p>\n<h4><strong>2. Float Datatype in Java<\/strong><\/h4>\n<p>float is used for storing decimal values. Its default value is 0.0f and has a size of 4 bytes. It has an infinite value range. However its always advised to use float in place of double if there is a memory constraint. Currency should also never be stored in the float datatype. However, it has a single-precision bit.<\/p>\n<p>Example- float a=98.7f;<\/p>\n<h4>3. Character Datatype in Java<\/h4>\n<p>char, as the name suggests, is useful for storing single-value characters. Its default value is \u2018\\u0000\u2019 with the max value being \u2018\\uffff\u2019 and has a size of 2 bytes.<\/p>\n<p>Example- char a=\u2019D\u2019;<\/p>\n<p>It must be confusing for you to see this new kind of data \u2018\/u000\u2019. This is the Unicode format, which Java uses in place of ASCII.<\/p>\n<h4>4. Boolean Datatype in Dava<\/h4>\n<p>boolean is a special datatype that can have only two values: \u2018true\u2019 and \u2018false\u2019. It has a default value of \u2018false\u2019 and a size of 1 byte. It comes in use for storing flag values.<\/p>\n<p>Example- boolean flag=true;<\/p>\n<h4>5. Byte Datatype in Java<\/h4>\n<p>It&#8217;s an 8-bit signed two\u2019s complement. The range of values is -128 to 127. It is space-efficient because it is smaller than the integer datatype. It can be a replacement for int datatype usage, but it doesn&#8217;t have the size range of the integer datatype.<\/p>\n<p>Example- byte a = 10;<\/p>\n<h4>6. Short Datatype in Java<\/h4>\n<p>This datatype is also similar to the integer datatype. However, it&#8217;s 2 times smaller than the integer datatype. Its minimum range is -32,768, and its maximum range is 32,767. It has a size of<\/p>\n<p>Example- short a = 54;<\/p>\n<h4>7. Long Datatype in Java<\/h4>\n<p>This datatype primarily stores huge amounts of numeric data. It is a 64-bit integer and ranges from -2^63 to +(2^63)-1. It has a size of 8 bytes and is useful when you need to store data that is longer than the int datatype.<\/p>\n<p>Example- long a= 1273762;<\/p>\n<h4>8. Double Datatype in Java<\/h4>\n<p>This is similar to the float datatype. However, it has one advantage over the float datatype, i.e., it has two-bit precision over the float datatype, which has one bit precision. However, it still shouldn&#8217;t be used for precision-sensitive data such as currency. It has a range of -2^31 to (2^31)-1.<\/p>\n<p>Example- double DataFlair=99.987d;<\/p>\n<p><strong>Java program to illustrate the different types of data:<\/strong><\/p>\n<p>import java.io.IOException;<br \/>\nclass <strong>TypeVariable<\/strong><\/p>\n<p><strong>&lt;class names should be meaningful and never start with a lowercase letter, refer to the naming convention of a class&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">{\r\n  public static void main(String[] args) throws IOException {\r\n    int a = 10;\r\n    short s = 2;\r\n    byte b = 6;\r\n    long l = 125362133223l;\r\n    float f = 65.20298f;\r\n    double d = 876.765d;\r\n    System.out.println(\"The integer variable is \" + a);\r\n    System.out.println(\"The short variable is \" + s);\r\n    System.out.println(\"The byte variable is \" + b);\r\n    System.out.println(\"The long variable is \" + l);\r\n    System.out.println(\"The float variable is \" + f);\r\n    System.out.println(\"The double variable is \" + d);\r\n\r\n  }\r\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The integer variable is 10<br \/>\nThe short variable is 2<br \/>\nThe byte variable is 6<br \/>\nThe long variable is 125362133223<br \/>\nThe float variable is 65.20298<br \/>\nThe double variable is 876.765<\/div>\n<h3>Non-primitive Data Types in Java<\/h3>\n<p>These are the datatypes that have instances like objects. Hence, they are called reference variables. They are primarily classes, arrays, strings or interfaces.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Non-Primitive-Data-Types-DF.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78479\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Non-Primitive-Data-Types-DF.jpg\" alt=\"Java Non-Primitive Data Types\" width=\"386\" height=\"446\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Non-Primitive-Data-Types-DF.jpg 386w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Non-Primitive-Data-Types-DF-260x300.jpg 260w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Non-Primitive-Data-Types-DF-130x150.jpg 130w\" sizes=\"auto, (max-width: 386px) 100vw, 386px\" \/><\/a><\/p>\n<h4>Classes in Java<\/h4>\n<p>These are the special user-defined data types. It has member variables and class methods.<\/p>\n<p>Classes are used for creating objects. Moreover, classes describe the behaviours and attributes of the object, like methods, and many more. A class is like a capsule that holds variables, methods, and attributes inside it. It is a foundation of object-oriented programming.<\/p>\n<p>A class is declared by using the keyword \u201cclass\u201d in Java.<\/p>\n<p><strong>Java program to illustrate classes:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class DataFlair {\r\n  int a,\r\n  b,\r\n  c;\r\n  void teach() {\r\n    System.out.println(\u201cHi I am teaching at DataFlair\u201d);\r\n  }\r\n  void learn() {\r\n    System.out.println(\u201cHi I am learning at DataFlair\u201d);.\r\n  }\r\n}<\/pre>\n<h4>Interfaces in Java<\/h4>\n<p>These are similar to classes. However, there is one prime difference, i,.e the methods are abstract by default. i.e, they have no body.<br \/>\n<strong>Similarly, like objects, interfaces are also the blueprints of a class.<\/strong><\/p>\n<p>If the class implements an interface, then it is supposed to add detail to every function of the interface. If not, then we must declare the class as abstract.<\/p>\n<p><strong>Example program to illustrate interfaces in Java:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">interface DataFlair {\r\n  void teach();\r\n  void learn();\r\n}\r\nclass DataFlairCls implements DataFlair {\r\n  public void teach() {\r\n    System.out.println(\"I teach at DataFlair\");\r\n  }\r\n  public void learn() {\r\n    System.out.println(\"I learn at DataFlair\");\r\n  }\r\n\r\n  public static void main(String[] args) throws IOException {\r\n    DataFlairCls ob = new DataFlairCls();\r\n    ob.teach();\r\n    ob.learn();\r\n  }\r\n}<\/pre>\n<h4>Strings in Java<\/h4>\n<p>You may know a string as a collection of characters, but in Java, String is a completely different class altogether. It&#8217;s located in java.lang.String. However, strings end with a \u2018\\0\u2019 character.<\/p>\n<p>Java has a lot of methods for manipulating strings, such as substring, length and many more.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>String s=\u201dDataFlair is a fun place to learn\u201d;<br \/>\nString sub=s.substring(0,9);<br \/>\nSystem.out.println(sub);<\/p>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">DataFlair<\/div>\n<h4>Arrays in Java<\/h4>\n<p>Arrays are special memory locations that can store a collection of homogeneous data. They are indexed. Arrays always start indexing from 0. Dynamic allocation of arrays is available in Java. <strong><a href=\"https:\/\/introcs.cs.princeton.edu\/java\/14array\/\" target=\"_blank\" rel=\"noopener\">Arrays in Java<\/a><\/strong> can be passed as method parameters, local variables and static fields.<\/p>\n<p>Example- int arr[] = new int[100];<\/p>\n<p>This creates a storage space for 100 integers.<\/p>\n<p><strong>Java program to explain the concept of arrays:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import java.io. * ;\r\nimport java.util. * ;\r\nclass DataFlairArray {\r\n  public static void main(String[] args) throws IOException {\r\n    int i;\r\n    Scanner sc = new Scanner(System. in );\r\n\r\n    int arr[] = new int[] {\r\n      1,\r\n      2,\r\n      3,\r\n      4,\r\n      5\r\n    };\r\n    int arr1[] = new int[5];\r\n    for (i = 0; i &lt; 5; i++) {\r\n      System.out.println(\"Enter your number\");\r\n      arr1[i] = sc.nextInt();\r\n    }\r\n    System.out.println(\u201cThe array which was previously assigned\u201d);\r\n    for (i = 0; i &lt; 5; i++) {\r\n      System.out.println(arr[i]);\r\n    }\r\n    System.out.println(\"\");\r\n    System.out.println(\"The array you entered is:\");\r\n    for (i = 0; i &lt; 5; i++) {\r\n      System.out.println(arr1[i]);\r\n    }\r\n  }\r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Enter your number<br \/>\n4<br \/>\nEnter your number<br \/>\n1<br \/>\nEnter your number<br \/>\n2<br \/>\nEnter your number<br \/>\n3<br \/>\nEnter your number<br \/>\n4The array which was previously assigned:1<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n5The array you entered is:<br \/>\n4<br \/>\n1<br \/>\n2<br \/>\n3<br \/>\n4<\/div>\n<h3>Selecting the Proper Data Type<\/h3>\n<p>A key component of writing accurate and efficient Java code is choosing the right data type for your variables. When making decisions, keep the following important factors in mind.<\/p>\n<p><strong>1. Data Range:<\/strong> Decide what kind of values your variable can hold. For instance, the byte data type is effective if you need to store whole numbers between -128 and 127. But depending on the exact range, you&#8217;ll have to select between int, long, or even double if you need to store bigger values.<\/p>\n<p><strong>2. Memory Efficiency:<\/strong> The memory sizes of primitive data types are predetermined. Compared to byte or short, int and long require more memory, even though they can hold a wider range of numbers. When dealing with sizable datasets or settings with memory constraints, think about utilizing smaller data types whenever you can.<\/p>\n<p><strong>3. Requirements for Precision:<\/strong> Data types such as float and double provide different levels of precision for values in decimal. Although double requires more memory than float, it offers higher precision. Float may be a better option if you don&#8217;t require very accurate computations.<\/p>\n<p><strong>4. Maintainability and Readability:<\/strong> Code readability can be improved by using names for data types that are descriptive. For example, it would make more sense to use a variable called productId rather than int to store product IDs. For you and other developers, this enhances code maintainability.<\/p>\n<h3>Summary<\/h3>\n<p>Summing up, these are major league Data types in Java. Without data types, it would be impossible to classify different varieties of inputs and variables. Hence, a solid concept of data types is a must for fluid coding in Java.<\/p>\n<p>Hope you created a string base with this Java Tutorial. <strong>Do not forget to share feedback in the comment section.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Variables store data. But a fundamental problem arises as to what kind of data is the variable stores? There can be a lot of confusion about the computation of a program if the variables\u2019&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":78477,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[16453,7401,7410,7416,7450,7452,7550,7586,20587,20586,7679],"class_list":["post-6222","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-data-types-in-java","tag-java-boolean","tag-java-byte","tag-java-char","tag-java-data-types","tag-java-datatypes","tag-java-int","tag-java-long","tag-java-non-primitive-data-types","tag-java-primitive-data-types","tag-java-short"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Data Types - Primitive &amp; Non-Primitive Data types with Examples - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn the solid concept of Java, that is, data types in Java. Also, explore how you can create your own data type and types of data type.\" \/>\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\/java-data-types\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Data Types - Primitive &amp; Non-Primitive Data types with Examples - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn the solid concept of Java, that is, data types in Java. Also, explore how you can create your own data type and types of data type.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/java-data-types\/\" \/>\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-01-22T01:35:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-07T06:56:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/data-types-in-java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\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":"Java Data Types - Primitive &amp; Non-Primitive Data types with Examples - DataFlair","description":"Learn the solid concept of Java, that is, data types in Java. Also, explore how you can create your own data type and types of data type.","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\/java-data-types\/","og_locale":"en_US","og_type":"article","og_title":"Java Data Types - Primitive &amp; Non-Primitive Data types with Examples - DataFlair","og_description":"Learn the solid concept of Java, that is, data types in Java. Also, explore how you can create your own data type and types of data type.","og_url":"https:\/\/data-flair.training\/blogs\/java-data-types\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-01-22T01:35:22+00:00","article_modified_time":"2026-05-07T06:56:25+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/data-types-in-java.jpg","type":"image\/jpeg"}],"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\/java-data-types\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/java-data-types\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"Java Data Types &#8211; Primitive &amp; Non-Primitive Data types with Examples","datePublished":"2018-01-22T01:35:22+00:00","dateModified":"2026-05-07T06:56:25+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/java-data-types\/"},"wordCount":1355,"commentCount":7,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/java-data-types\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Java-Data-Types-DF.jpg","keywords":["Data types in Java","Java boolean","Java byte","java char","Java Data Types","Java Datatypes","java int","java long","Java Non- Primitive Data Types","Java Primitive Data Types","java short"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/java-data-types\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/java-data-types\/","url":"https:\/\/data-flair.training\/blogs\/java-data-types\/","name":"Java Data Types - Primitive &amp; Non-Primitive Data types with Examples - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/java-data-types\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/java-data-types\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Java-Data-Types-DF.jpg","datePublished":"2018-01-22T01:35:22+00:00","dateModified":"2026-05-07T06:56:25+00:00","description":"Learn the solid concept of Java, that is, data types in Java. Also, explore how you can create your own data type and types of data type.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/java-data-types\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/java-data-types\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/java-data-types\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Java-Data-Types-DF.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Java-Data-Types-DF.jpg","width":1200,"height":628,"caption":"Java Data Types"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/java-data-types\/#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":"Java Data Types &#8211; Primitive &amp; Non-Primitive Data types with Examples"}]},{"@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\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":false,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6222","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\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=6222"}],"version-history":[{"count":32,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6222\/revisions"}],"predecessor-version":[{"id":148246,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6222\/revisions\/148246"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/78477"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=6222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=6222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=6222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}