{"id":224,"date":"2025-06-24T07:22:57","date_gmt":"2025-06-24T07:22:57","guid":{"rendered":"https:\/\/thetestdata.com\/blog\/?p=224"},"modified":"2025-07-16T10:27:09","modified_gmt":"2025-07-16T10:27:09","slug":"primitives-and-non-primitives-datatype-in-java","status":"publish","type":"post","link":"https:\/\/thetestdata.com\/blog\/primitives-and-non-primitives-datatype-in-java\/","title":{"rendered":"Primitives and Non-Primitives datatype in Java?"},"content":{"rendered":"\n<p>In Java, data types are split into two big families: <strong>primitive types<\/strong> and <strong>non-primitive (reference) types<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 Primitive Data Types<\/h3>\n\n\n\n<p>These are the <strong>basic building blocks<\/strong>. They&#8217;re predefined by Java and store simple values directly in memory. There are 8 of them:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"658\" src=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-8.png\" alt=\"\" class=\"wp-image-225\" srcset=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-8.png 996w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-8-300x198.png 300w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-8-768x507.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>These types are <strong>stored in stack memory<\/strong> and are fast to access.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\ud83d\udd38 Non-Primitive (Reference) Data Types<\/strong><\/h3>\n\n\n\n<p>These are more complex structures that <strong>refer to objects in memory<\/strong>. They include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>String<\/code><\/li>\n\n\n\n<li>Arrays (<code>int[]<\/code>, <code>String[]<\/code>, etc.)<\/li>\n\n\n\n<li>Classes and Objects (<code>Scanner<\/code>, <code>Random<\/code>, custom classes)<\/li>\n\n\n\n<li>Interfaces<\/li>\n<\/ul>\n\n\n\n<p>Unlike primitive types, these can <strong>hold multiple values<\/strong> or encapsulate behavior.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understand the difference between primitive and non-primitive data types in Java. Learn how each handles memory, value storage, and object references.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[17],"tags":[],"class_list":["post-224","post","type-post","status-publish","format-standard","hentry","category-java-interview-questions"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/comments?post=224"}],"version-history":[{"count":2,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/224\/revisions"}],"predecessor-version":[{"id":453,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/224\/revisions\/453"}],"wp:attachment":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/media?parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/categories?post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/tags?post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}