{"id":5793,"date":"2020-12-29T07:53:04","date_gmt":"2020-12-29T07:53:04","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=5793"},"modified":"2024-04-12T10:32:48","modified_gmt":"2024-04-12T10:32:48","slug":"scala-case-classes","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/","title":{"rendered":"Scala &#8211; Case Class"},"content":{"rendered":"\r\n<h2><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Scala Case Classes and Case Object&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:6145,&quot;3&quot;:{&quot;1&quot;:0,&quot;3&quot;:1},&quot;14&quot;:{&quot;1&quot;:3,&quot;3&quot;:1},&quot;15&quot;:&quot;Arial&quot;}\">Scala Case Classes and Case Object<\/span><\/h2>\r\n<p>&nbsp;<\/p>\r\n<p>A <strong>Case Class<\/strong> is actually similar to an ordinary class, which has a component for displaying unchangeable data. It is likewise valuable in pattern matching. It has been characterized with a modifier case, because of this case catchphrase, we can get a few advantages to prevent oneself from completing an areas of codes that must be remembered for some <a href=\"http:\/\/scala-lang.org\">spots<\/a> with practically zero change. As we can see under an <a href=\"https:\/\/prwatech.in\/blog\/#\">insignificant<\/a> case class needs the <strong>keyword<\/strong> <strong>case class<\/strong>, an identifier, and a parameter list which might be empty.<\/p>\r\n<p>Case classes and case objects are powerful constructs in Scala for defining data structures and modeling immutable entities. They offer concise syntax for defining immutable data with built-in support for pattern matching and structural equality.<\/p>\r\n<p><strong>Case Classes<\/strong>:<\/p>\r\n<ul>\r\n<li>Case classes are regular classes with additional compiler-generated methods, making them ideal for representing immutable data.<\/li>\r\n<li>They automatically generate methods for object construction, pattern matching, equality checks (<code>equals<\/code>), and hash code generation (<code>hashCode<\/code>).<\/li>\r\n<li>Case classes support pattern matching, enabling concise and readable code for deconstructing and matching data structures.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p><strong>Syntax:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">Case class className(parameters)<\/pre>\r\n\r\n\r\n\r\n<p><strong>Use case 1:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>     \/\/ Scala program of case class and case Object\r\n     case class course(name:String, dur:String)\r\n     object prwatech {\r\n     \/\/ Main method\r\n     def main(args: Array[String])\r\n     {\r\n     var c = course(\"BigData\", \"4 month\" )\r\n    \/\/ Display both Parameter \r\n    println(\"Name of the course is \" + c.name); \r\n    println(\"Duration of the course is \" + c.dur); \r\n     } \r\n    }<\/code><\/pre>\r\n\r\n\r\n\r\n<p><strong>OUTPUT:<\/strong><\/p>\r\n\r\n\r\n\r\n<p>Name of the course is BigData<br \/>Duration of the course is 4 month<\/p>\r\n\r\n\r\n\r\n<p><strong>Use case 2:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>    \r\n\/\/ Scala program of case class and case Object\r\ncase class Student(name:String, age:Int)\r\nobject prwatech {\r\n\/\/ Main method\r\ndef main(args: Array[String])\r\n{\r\nvar a = Student(\"Sandeep\", 25 )\r\n\/\/ Display both Parameter \r\nprintln(\"Name of the Student is \" + a.name); \r\nprintln(\"Age of the Student is \" + a.age); \r\n} \r\n}<\/code><\/pre>\r\n\r\n\r\n\r\n<p><strong>output:<\/strong><\/p>\r\n\r\n\r\n\r\n<p>Name of the Student is Sandeep<br \/>Age of the Student is 25<\/p>\r\n\r\n\r\n\r\n<p><strong>Use case 3:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>\/\/ Scala program of case class and case Object\r\n\/\/ affix a method with the name of the class\r\ncase class Course (name:String, Language:String)\r\nobject prwatech\r\n{\r\n\/\/ Main method\r\ndef main(args: Array[String])\r\n{\r\nvar Course1 = Course(\"Data Science\", \"Python\")\r\nvar Course2 = Course(\"Big Data\", \"Spark Sql\") \r\n   \/\/ Display strings\r\n    println(\"Name of the Course1 is \" + Course1.name);\r\n    println(\"Language of the Course1 is \" + Course1.Language);\r\n    println(\"Name of the Course2 is \" + Course2.name);\r\n    println(\"Language of the Course2 is \" + Course2.Language);\r\n}\r\n}<\/code><\/pre>\r\n\r\n\r\n\r\n<p><strong>output:<\/strong><\/p>\r\n\r\n\r\n\r\n<p>Name of the Course1 is Data Science<br \/>Language of the Course1 is Python<br \/>Name of the Course2 is Big Data<br \/>Language of the Course2 is Spark Sql<\/p>\r\n<p>Scala Case Classes and Case Object<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Scala Case Classes and Case Object &nbsp; A Case Class is actually similar to an ordinary class, which has a component for displaying unchangeable data. It is likewise valuable in pattern matching. It has been characterized with a modifier case, because of this case catchphrase, we can get a few advantages to prevent oneself from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[565,1698],"tags":[1229,1231,579,576,1230,1228,578,293,581,580],"class_list":["post-5793","post","type-post","status-publish","format-standard","hentry","category-scala","category-scala-modules-scala","tag-case-class-definition","tag-case-class-scala","tag-case-classes-in-scala","tag-scala","tag-scala-case-class-examples","tag-scala-case-class-use-cases","tag-scala-case-classes","tag-scala-programming-language-tutorial","tag-scala-programs","tag-what-is-case-classes-in-scala"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Scala Case Classes and Case Object - Prwatech<\/title>\n<meta name=\"description\" content=\"Master Scala Case Classes and Case Object - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scala Case Classes and Case Object - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master Scala Case Classes and Case Object - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-29T07:53:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T10:32:48+00:00\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/\",\"url\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/\",\"name\":\"Scala Case Classes and Case Object - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"datePublished\":\"2020-12-29T07:53:04+00:00\",\"dateModified\":\"2024-04-12T10:32:48+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master Scala Case Classes and Case Object - Dive deep with our expert instructors and comprehensive curriculum.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scala &#8211; Case Class\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scala Case Classes and Case Object - Prwatech","description":"Master Scala Case Classes and Case Object - Dive deep with our expert instructors and comprehensive curriculum.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Scala Case Classes and Case Object - Prwatech","og_description":"Master Scala Case Classes and Case Object - Dive deep with our expert instructors and comprehensive curriculum.","og_url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2020-12-29T07:53:04+00:00","article_modified_time":"2024-04-12T10:32:48+00:00","author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/","url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/","name":"Scala Case Classes and Case Object - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"datePublished":"2020-12-29T07:53:04+00:00","dateModified":"2024-04-12T10:32:48+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master Scala Case Classes and Case Object - Dive deep with our expert instructors and comprehensive curriculum.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-case-classes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Scala &#8211; Case Class"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/5793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=5793"}],"version-history":[{"count":8,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/5793\/revisions"}],"predecessor-version":[{"id":11384,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/5793\/revisions\/11384"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=5793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=5793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=5793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}