{"id":12975,"date":"2022-09-29T17:16:40","date_gmt":"2022-09-29T11:46:40","guid":{"rendered":"https:\/\/blog.guvi.in\/?p=12975"},"modified":"2026-03-11T17:21:41","modified_gmt":"2026-03-11T11:51:41","slug":"data-types-in-java","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/data-types-in-java\/","title":{"rendered":"Data Types in JAVA: Primitive VS Non-Primitive Data Types"},"content":{"rendered":"\n<p><span style=\"font-weight: 400;\">In case you&#8217;re going to use the JAVA programming language in your career, the first and foremost thing you need to know is how to declare a variable. Variables are nothing but reserved memory locations to store values. <\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The fundamental question arises as to what kind of data the variable stores<\/span>. So the data types in programming specify the various sizes and values that can be stored in the variable.<span style=\"font-weight: 400;\"> Basically, there are two types of data types in Java.&nbsp;<\/span><\/p>\n\n\n\n<ul>\n<li><span style=\"font-weight: 400;\">Primitive Data types &#8211; include boolean, char, byte, short, int, float, long &amp; double.&nbsp;<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">Non-primitive Data Types &#8211; include Interfaces, Classes, and Arrays.&nbsp;<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">There can be a lot of confusion about the computation of a program if the variables\u2019 data types are not known. In this tutorial blog, we are going to deconstruct both primitive and non-primitive data types in Java and go over each type.&nbsp;<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\"><strong>Primitive Data Types<\/strong><\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">The eight primitive data types in Java are int, boolean, short, long, char, double, float, and byte. Unlike non-primitive data types, these aren&#8217;t considered real objects and represent raw values. <\/span><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"775\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.31.28-PM-1200x775.png\" alt=\"data_types_in_Java\" class=\"wp-image-12984\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.31.28-PM-1200x775.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.31.28-PM-300x194.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.31.28-PM-768x496.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.31.28-PM-1536x993.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.31.28-PM-2048x1323.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.31.28-PM-150x97.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p><span style=\"font-weight: 400;\">They are predefined and available within the <a href=\"https:\/\/www.guvi.in\/blog\/learn-java-programming-language\/\" target=\"_blank\" rel=\"noreferrer noopener\">Java programming language<\/a>. Primitive data types do not interact<\/span> with other primitive data types. Without primitive data types, it will be impossible to frame programs;<span style=\"font-weight: 400;\"> they are also considered building blocks for the non-primitive data types.&nbsp;<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">They are stored directly on the stack. Now, as per the memory management in Java, we&#8217;ll take a larger look at default values, storage size, and examples of how to use each type.&nbsp;<\/span><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong><em>Before proceeding further, make sure you have a strong grasp of essential concepts in Java Full Stack Development, including <a href=\"https:\/\/www.guvi.in\/blog\/best-front-end-javascript-frameworks\/\" target=\"_blank\" rel=\"noreferrer noopener\">front-end frameworks<\/a>, back-end technologies, and database management. If you&#8217;re looking for a professional future in <a href=\"https:\/\/www.guvi.in\/blog\/java-full-stack-developer\/\" target=\"_blank\" rel=\"noreferrer noopener\">Java Full Stack<\/a> Development, consider joining HCL GUVI&#8217;s<a href=\"https:\/\/www.guvi.in\/zen-class\/java-full-stack-development-course\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=Java-data-types\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/zen-class\/java-full-stack-development-course\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=Java-interview-questions\"> Java Full Stack Development Career Program<\/a>. With placement assistance included, you&#8217;ll master the Java stack and build real-world projects to enhance your skills.<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>Also, if you&#8217;re looking for a self-paced course in Java in your language, you can go for HCL GUVI&#8217;s <a href=\"https:\/\/www.guvi.in\/courses\/programming\/java-programming\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=java-data-types\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/courses\/programming\/java-programming\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=java-data-types\">Java Course with Certification<\/a> to help you master Java from the <\/em>basics to an <em>advanced level. <\/em><\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-weight: 400;\"><strong>INT&nbsp;<\/strong><\/span><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">The first primitive data type <\/span>we&#8217;re going to uncover in the series is int.<i><span style=\"font-weight: 400;\"> <\/span><\/i><span style=\"font-weight: 400;\">Int is short for integer, and the <em>int<\/em> type holds a wide range of non-fractional number values. To be specific, <a href=\"https:\/\/www.guvi.in\/blog\/introduction-to-java\/\" target=\"_blank\" rel=\"noreferrer noopener\">JAVA<\/a> stores it using 32-bit memory. The default value of any int value is O.&nbsp;<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">In JAVA SE 8 &amp; later, one can use the <\/span><em><span style=\"font-weight: 400;\">int <\/span><\/em><span style=\"font-weight: 400;\">data type to represent an unsigned 32-bit integer, which has a value in the range <\/span><i><span style=\"font-weight: 400;\">[0, 232-1]. <\/span><\/i><span style=\"font-weight: 400;\">You can use the integer class to use the int data type as an unsigned integer.&nbsp;<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.guvi.in\/zen-class\/data-science-course\/?utm_source=Blog+&amp;utm_medium=Blog+Banner+&amp;utm_campaign=Data+Types+in+Java+&amp;utm_id=Data+Science+\"><img decoding=\"async\" width=\"1200\" height=\"628\" src=\"http:\/\/blog.guvi.in\/wp-content\/uploads\/2022\/07\/Discovery-DS3-1200_628-1200x628.png\" alt=\"Data-science \" class=\"wp-image-11191\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/07\/Discovery-DS3-1200_628-1200x628.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/07\/Discovery-DS3-1200_628-300x157.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/07\/Discovery-DS3-1200_628-768x402.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/07\/Discovery-DS3-1200_628-1536x804.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/07\/Discovery-DS3-1200_628-2048x1072.png 2048w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/a><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Syntax <\/h4>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#006b44\"><code>int x = 424_562;\nint y; <\/code><\/pre>\n\n\n\n<p>If a variable is defined in a method, you must assign a value before you can assign it in a function. You can perform all the arithmetic operations on <em>ints, <\/em>just be aware of the fact that decimal values will be minced off when performing these on integers. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Float <\/strong><\/h3>\n\n\n\n<p>For basic fractional numbers, we use <em>float <\/em>data type. This is a single-precision decimal number, which implies that if we get past six decimal points, the number will become less precise and more of an estimate. <\/p>\n\n\n\n<p>The Float data type is a single-precision 32-bit IEEE 754 floating point. Use a float (instead of double) if you need to save memory in large arrays of floating-point numbers.<\/p>\n\n\n\n<p>More or less, in most cases, we won&#8217;t care about the precision loss. But if our case requires scientific precision, we need to use specific data types designed for this work. <strong>This type is stored in 32 bits of memory just like&nbsp;<em>int<\/em>.<\/strong>&nbsp;<\/p>\n\n\n\n<p>However, because of the floating decimal point, its range is much different. It can represent both positive and negative numbers.&nbsp;&amp; the default value is <strong>o.o <\/strong>instead of <strong>o. <\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax <\/h3>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#006e46\"><code>float f = 4.156f; \nflaot f; <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Double <\/strong><\/h3>\n\n\n\n<p>Just like the name suggests, the <em>double <\/em>data type is a double-precision 64-bit floating point. This implies that it can represent a much larger range of possible numbers than float. Although It suffers from the same limitation limit as float does. The default value is also 0.0 similar to float &amp; to declare the literal as a double, we also add the letter &#8220;D&#8221; at<strong> the end<\/strong>. <\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#00754a\"><code>dobule d = 5.384094576304495056574846D; \ndobule d;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Boolean<\/strong><\/h3>\n\n\n\n<p>If you&#8217;re into programming, you would have guessed it. Boolean is the simplest primitive data type for every <a href=\"https:\/\/www.guvi.in\/blog\/easiest-programming-languages-to-hardest-ranked\/\" target=\"_blank\" rel=\"noreferrer noopener\">programming language;<\/a> in our case JAVA. It can only contain two values: True or False.  It stores its value in a single bit. However, JAVA for convenience pads the value and stores it in a single byte. <\/p>\n\n\n\n<p>Here&#8217;s how to declare boolean <\/p>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#006b40\"><code>boolean b = flase; \nboolean b;<\/code><\/pre>\n\n\n\n<p>Boolean data types are the cornerstones of controlling our program flow<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1200\" height=\"712\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.21.10-PM-1200x712.png\" alt=\"data_types_in_java\" class=\"wp-image-12983\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.21.10-PM-1200x712.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.21.10-PM-300x178.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.21.10-PM-768x456.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.21.10-PM-1536x911.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.21.10-PM-2048x1215.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-20-at-2.21.10-PM-150x89.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>char <\/strong><\/h3>\n\n\n\n<p><strong>char <\/strong>is short for the character. it is a 16-bit integer representing a Unicode-encoded character. Its range is from 0 to 65,535. In Unicode, this represents&nbsp;<em>\u2018\\u0000&#8242;<\/em>&nbsp;to&nbsp;<em>\u2018\\uffff&#8217;<\/em>.<\/p>\n\n\n\n<p>For a list of all possible Unicode values, check out websites such as <strong>Unicode Table. <\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Syntax to declare char<\/h4>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#00613e\"><code>char c = 'a';\n\nchar c = 65;\n\nchar c;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Short <\/strong><\/h3>\n\n\n\n<p>The next primitive data type in Java is <strong>short. <\/strong>In case you want to save memory and the byte is too small, we can also use halfway between byte and int short. At 16 bits of memory, it&#8217;s half the size of&nbsp;an int&nbsp;and twice the size of&nbsp;a <em>byte<\/em>. Its range of possible values is -32,768(-2<sup>15<\/sup>) to 32,767(2<sup>15&nbsp;<\/sup>\u2013 1).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Syntax <\/h4>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#017349\"><code>short s = 30_030;\n\nshort s;<\/code><\/pre>\n\n\n\n<p>Similar to other data types in Java, the default value is 0. We can also use other standard arithmetic on short as well. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Long <\/strong><\/h3>\n\n\n\n<p>Long is the last integer data type in Java. <strong><em>Long<\/em><\/strong> is a big brother of <strong><em>int<\/em><\/strong> as it stores 64 bits of memory. Compared to int, it can store a significantly larger set of possible values. <\/p>\n\n\n\n<p>The possible values of a long are between -9,223,372,036,854,775,808 (-2<sup>63<\/sup>) to 9,223,372,036,854,775,807 (2<sup>63&nbsp;<\/sup>\u2013 1).<\/p>\n\n\n\n<p>It is useful for certain occasions when <strong><em>int <\/em><\/strong>data type is not able to accommodate the desired value. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Syntax <\/h4>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#007147\"><code>long l = 1_455_568_890;\n\nlong l;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><em>Byte <\/em><\/strong><\/h3>\n\n\n\n<p><strong><em>byte <\/em><\/strong>is similar to <strong><em>int <\/em><\/strong>data type, except it only takes an 8-bit memory, that&#8217;s why it&#8217;s referred to as a byte. <\/p>\n\n\n\n<p>Because the memory size is so small,&nbsp;<em>bytes<\/em>&nbsp;can only hold values from -128 (-2<sup>7<\/sup>) to 127 (2<sup>7&nbsp;<\/sup>\u2013 1). The default value of the <strong><em>byte <\/em><\/strong>data type is 0. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Here&#8217;s how we can create&nbsp;a <em>byte<\/em>:<\/h4>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#007b4e\"><code>byte b = 69;\n\nbyte empty;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Non-Primitive Data Types in Java <\/h2>\n\n\n\n<p>Non-primitive data types in Java are also known as reference types because they refer to objects. These are the datatypes that have instances like objects. <\/p>\n\n\n\n<p>Unlike primitive data types in Java which are predefined, the non-primitive data types are created by the programmer and are not defined by the Java language. (except for string) Primitive data types are building blocks for any program, however non-primitive data types in Java are used to call methods to perform certain operations, which primitive data types can&#8217;t. <\/p>\n\n\n\n<p>The other differences found between primitive and non-primitive data types include: <\/p>\n\n\n\n<ul>\n<li>A primitive type starts with a lowercase letter, while a non-primitive type starts with an uppercase letter.<\/li>\n\n\n\n<li>A primitive type has always a value, while non-primitive types can be&nbsp;<code>null<\/code>.<\/li>\n\n\n\n<li>The size of a primitive type depends on the data type, while non-primitive types are all the same size.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-text-align-center has-medium-font-size\">They are primarily <strong><em>class, objects, strings, interfaces, or arrays.<\/em><\/strong> Let&#8217;s deconstruct them one by one. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Classes <\/h3>\n\n\n\n<p>A class is a user-defined blueprint or prototype from which objects are created. It basically represents the set of methods or properties that are common to all objects of one type. Everything in Java is associated with objects and classes. <\/p>\n\n\n\n<p>In layman&#8217;s terms, if a car is an object, The car has&nbsp;<strong>attributes<\/strong>, such as weight and color, and&nbsp;<strong>methods<\/strong>, such as drive and brake. A Class is like an object constructor or a &#8220;blueprint&#8221; for creating objects.<\/p>\n\n\n\n<p>To create a class with public access <\/p>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#006f47\"><code>public class Main {\n  int x = 5;\n}<\/code><\/pre>\n\n\n\n<p>To take it up a notch further <\/p>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#026742\"><code>public class HCL GUVI {\n  int a,\n  b,\n  c;\n Static void teach() {\n    System.out.println(\u201cHi I am teaching at HCL GUVI\u201d);\n  }\n  void learn() {\n    System.out.println(\u201cHi I am learning at HCL GUVI\u201d);.\n  }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">NOTE<\/h4>\n\n\n\n<ul>\n<li>A class can have public or default access. <\/li>\n\n\n\n<li>The class name&#8217;s should always begin with the initial letter. (capitalized for convention)<\/li>\n\n\n\n<li>The class body is always surrounded by {} braces. <\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><a href=\"https:\/\/www.guvi.in\/blog\/python-vs-java\/\" data-type=\"post\" data-id=\"11179\">Python vs. Java? Which programming language to master in 2025?<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Interface <\/h3>\n\n\n\n<p>Similar to class, an interface can have methods and variables, but with one prime difference, i.e. the methods are abstract by nature. which implies that they have no &#8220;body.&#8221; <\/p>\n\n\n\n<p>If any class is implemented as an interface, then the programmer must declare all the details to every function of the interface, if not, then we must declare the class as abstract. So basically an interface specifies what a class must do and not how. it&#8217;s the blueprint or prototype of the class. <\/p>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#005d3b\"><code>interface DataFlair {\n  void teach();\n  void learn();\n}\nclass DataFlairCls implements Zenclass {\n  public void teach() {\n    System.out.println(\"I teach at Zen Class\");\n  }\n  public void learn() {\n    System.out.println(\"I learn at ZEN Class\");\n  }\n\n  public static void main(String&#91;] args) throws IOException {\n   Zenclass Cls ob = new ZenclassCls();\n    ob.teach();\n    ob.learn();\n  }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Strings<\/h3>\n\n\n\n<p>Strings are usually known as an <a href=\"https:\/\/www.guvi.in\/blog\/arrays-vs-linked-lists\/\" target=\"_blank\" rel=\"noreferrer noopener\">array<\/a> of characters. The only difference between an array and a string is that a string is designed to hold a sequence of characters in a single variable, while an array is a collection of separate char-type elements. <\/p>\n\n\n\n<p>Unlike other programming languages such as <a href=\"https:\/\/www.guvi.in\/blog\/what-is-c-programming\/\" target=\"_blank\" rel=\"noreferrer noopener\">C<\/a><a href=\"https:\/\/www.guvi.in\/blog\/what-is-c-programming\/\"> <\/a>or C++, strings in Java do not end with a null character. Also, Java features many methods of manipulating strings such as length, substring, and many more. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How to declare strings in JAVA<\/h4>\n\n\n\n<pre class=\"wp-block-code has-border-color has-ast-global-color-8-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#006540\"><code>\/\/ Declare String without using new operator \nString s = \"HCLGUVIZENCLASS\"; \n\n\/\/ Declare String using new operator \nString s1 = new String(\"HCLGUVIZENCLASS\"); <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Array <\/h3>\n\n\n\n<p>The indexed arrays are special memory locations that are used to store a collection of homogenous (liked-type variables) data. All the variables in the array are indexed, always starting from zero. <\/p>\n\n\n\n<p>Another fascinating thing about arrays is that they can be used as a static field, a method perimeter, and a local variable. However, the direct superclass of an array type is known as an object. Unlike C &amp; C+=, the length of the array can be measured using member length. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"335\" height=\"124\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/array.gif\" alt=\"Array\" class=\"wp-image-13074\" title=\"\"><\/figure><\/div>\n\n\n<h4 class=\"wp-block-heading\">Syntax <\/h4>\n\n\n\n<pre class=\"wp-block-code has-border-color has-black-border-color has-ast-global-color-4-background-color has-text-color has-background has-medium-font-size\" style=\"color:#016a43\"><code>class Testarray{  \npublic static void main(String args&#91;]){  \nint a&#91;]=new int&#91;5];\na&#91;0]=10;\na&#91;1]=20;  \na&#91;2]=70;  \na&#91;3]=40;  \na&#91;4]=50;  \n\/\/traversing array  \nfor(int i=0;i&lt;a.length;i++)\nSystem.out.println(a&#91;i]);  \n}}  <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Summing Up<\/h2>\n\n\n\n<p>To add a conclusion, these are major data types in JAVA. Without classifying these data types in Java, it will be impossible to deconstruct various varieties of inputs and variables. Hence a solid foundational knowledge is eminent for fluid coding in Java Programming Language. <\/p>\n\n\n\n<p><strong><em>Kickstart your tech Java career now and get placed with a handsome salary package<\/em><\/strong><em><strong> with HCL GUVI&#8217;s <a href=\"https:\/\/www.guvi.in\/zen-class\/java-full-stack-development-course\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=java-data-types\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/zen-class\/java-full-stack-development-course\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=java-interview-questions\">Java Full Stack Development Career Program<\/a>, providing placement assistance. Master essential technologies including Java, Maven, Eclipse, <a href=\"https:\/\/www.guvi.in\/blog\/a-complete-guide-to-html-and-css-for-beginners\/\" target=\"_blank\" rel=\"noreferrer noopener\">HTML, CSS,<\/a> MongoDB, and more while working on practical real-world projects to enhance your expertise.<\/strong><\/em><\/p>\n\n\n\n<p><span><strong style=\"font-style: italic;\">You can also ac<\/strong><\/span><strong style=\"font-style: italic;\">celerate your career with an awesome <a href=\"https:\/\/www.guvi.in\/courses\/programming\/java-programming\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=java-data-types\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/courses\/programming\/java-programming\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=java-data-types\">course on JAVA<\/a> offered by HCL GUVI, which has 11 hours of recorded sessions and is subdivided into modules for better understanding. You must go and register now for this course and explore Java.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs <\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1664451794563\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How many primitive data types are there in Java?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>There are basically 8 primitive data types in Java. The above list has mentioned all of them. They are char, int, and double. long, short, boolean, float, and byte.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1664451809561\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is a nonprimitive data type in Java?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Non-primitive data types are the ones that have an instance-like object. Unlike primitive data types in Java which are predefined, the non-primitive data types are created by the programmer and are not defined by the Java language.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1664451819632\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How to check data type in Java?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Sometimes, we do require to check the data type of a variable to perform logical operations. To check data type in Java, use getclass() and getSimpleName() method to get class and names respectively.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1664451838179\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Is string a primitive data type in Java?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>No, it&#8217;s not. As it&#8217;s not predefined, a user has to program and declare it in code.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1664451850765\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How to find data types in Java?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>As mentioned in question no. 3, we can check the type of a variable in Java by calling getClass().getSimpleName() method via the variable.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>In case you&#8217;re going to use the JAVA programming language in your career, the first and foremost thing you need to know is how to declare a variable. Variables are nothing but reserved memory locations to store values. The fundamental question arises as to what kind of data the variable stores. So the data types [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":13090,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,720],"tags":[],"views":"15631","authorinfo":{"name":"Tushar Vinocha","url":"https:\/\/www.guvi.in\/blog\/author\/tushar\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/wp6599799-java-desktop-wallpapers-300x169.jpg","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/09\/wp6599799-java-desktop-wallpapers.jpg","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/12975"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=12975"}],"version-history":[{"count":47,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/12975\/revisions"}],"predecessor-version":[{"id":103635,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/12975\/revisions\/103635"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/13090"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=12975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=12975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=12975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}