Kotlin For Beginners: References, Immutability (Const and Val), Properties, Variables, Data Classes (Skillshare)

Offered by Skillshare,
Kotlin For Beginners: References, Immutability (Const and Val), Properties, Variables, Data Classes (Skillshare)

In this short class, you will learn the fundamentals of how to represent information virtually in a Kotlin program. About half of what we do as programmers is design data structures to represent real world information virtually, and it turns out that there are good and bad ways to do this! One of the most important takeaways of this class, is that it is critically important to separate things which change (mutable) from things which don't change (immutable).

Topics include:

  • How references work with the JVM (simplified for beginners)
  • The problem of Shared Mutable State (this is bad)
  • How to avoid Shared Mutable State by introducing Immutability (const val and val properties) to your code
  • How and when it makes sense to use var references
  • How to make classes, and the data class construct

As discussed in this class, one of the most difficult technical challenges which programmers face, is dealing with Shared Mutable State (Shared change-able data). Our first defense against such problems, is to work with Immutable Data as often as possible.
Using either the try.kotlinlang.org online IDE, or your own preferred IDE, write a simple program which has:

  • A data class of some kind with at least two val properties, such as a "User" data class
  • A main function which serves as the entry point of the program's execution

Instructions:

  1. Create a val reference of the same type as your data class (i.e. instantiate your data class)
  2. Create a second val reference from the first val reference, using the copy() function (this function comes from the data class keyword).
  3. Change at least one of the properties in this new val reference, by using default arguments within the copy() function.

The purpose of this small project is to get you used to working with immutable data and vals. At first it can appear impossible to make a working program using data classes with only val references, but by using the copy function, we can create new immutable copies based on old data, mutating only the properties we wish to!

Go to Class
MOOC List is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

Related Courses

Core Java Interview Bootcamp: Part 1 (Skillshare) Skillshare
Skillshare

Core Java Interview Bootcamp: Part 1 (Skillshare)

Hi everyone :) Having you stop here simply means you are either preparing for a core java interview or want to know the most widely asked questions in the room. This course is intended for you folks, perfectly. The course basically aims at providing an in-depth explanation to most continuously asked questions through very engaging animated PPTs. Whether it's string, or exceptions, or multi-threading, I have got your back on most asked questions from these topics. The much important thing is the clear and concise clarity in explanations that you will get from this course.

Self Paced
Self-Paced
Javascript Fun: Build a Tip Calculator! (Skillshare) Skillshare
Skillshare

Javascript Fun: Build a Tip Calculator! (Skillshare)

Welcome to the Javascript fun series! For web design or development, there are 3 must-know technologies, HTML, CSS, and Javascript. The main aim of the Javascript fun series is to take your knowledge of these 3 (only a little is required!), and put them into practice by building a series of educational, yet fun projects that show you exactly how they work perfectly together. Working on projects and solving problems is a great way to learn

Self Paced
Self-Paced
How To Make A Wordpress Website -- Complete Beginners Guide (Skillshare) Skillshare
Skillshare

How To Make A Wordpress Website -- Complete Beginners Guide (Skillshare)

Want To Learn How To Make A Website With Wordpress? In this tutorial, I go step by step to show you how to build a wordpress website step by step! After you watch this video, you will be able to create a website from scratch with no experience. I use elementor and the oceanwp wordpress theme in this tutorial!

Self Paced
Self-Paced
Website Design In WordPress For Beginners: Learn To Build a Website In 1 Hour (Skillshare) Skillshare
Skillshare

Website Design In WordPress For Beginners: Learn To Build a Website In 1 Hour (Skillshare)

Welcome to my Website Design In WordPress For Beginners: Learn To Build a Website In 1 Hour class! This class will teach you how to create a Wordpress website from scratch and will cover everything you need to know from the very beginning of buying a website domain name, all the way to installing plugins to protect your website and then finally publishing and launching your website!

Self Paced
Self-Paced
WordPress for Beginners - Understand WordPress Quickly (Skillshare) Skillshare
Skillshare

WordPress for Beginners - Understand WordPress Quickly (Skillshare)

Learn how to work with WordPress and develop a website using AIT WordPress Themes. No coding or experience required. This class presents the basics of working with WordPress and offers practical screencast tutorials to teach you how to use our themes when building a new website. In short videos, you can find answers to FAQs that beginners most often encounter when getting familiar with WordPress. The course contains more than one hour of video tutorials.

Self Paced
Self-Paced
Javascript Fun: Build a Photo Effects App! (Skillshare) Skillshare
Skillshare

Javascript Fun: Build a Photo Effects App! (Skillshare)

Welcome to the Javascript fun series! For web design or development, there are 3 must-know technologies, HTML, CSS, and Javascript. The main aim of the Javascript fun series is to take your knowledge of these 3 (only a little is required!), and put them into practice by building a series of educational, yet fun projects that show you exactly how they work perfectly together. Working on projects and solving problems is a great way to learn.

Self Paced
Self-Paced
Javascript Fun: Build a Number Match Game! (Skillshare) Skillshare
Skillshare

Javascript Fun: Build a Number Match Game! (Skillshare)

Welcome to the Javascript fun series! For web design or development, there are 3 must-know technologies, HTML, CSS, and Javascript. The main aim of the Javascript fun series is to take your knowledge of these 3 (only a little is required!), and put them into practice by building a series of educational, yet fun projects that show you exactly how they work perfectly together. Working on projects and solving problems is a great way to learn.

Self Paced
Self-Paced
Smartphone Photography - made easy (Skillshare) Skillshare
Skillshare

Smartphone Photography - made easy (Skillshare)

Want to take better photos with your Smartphone? Let’s explore some simple tips and tricks that will improve your smartphone-ography. Hi, my name is Deanna, I’m a Skillshare instructor, a photographer, and an illustrator. I’m coming to you from my live-work studio on the West Coast, I grew up on the East Coast and have been an instructor for over a decade. Today, we are going to learn how to take some great photos with our smartphones.

Self Paced
Self-Paced
Twitter API JavaScript Node Exercise (Skillshare) Skillshare
Skillshare

Twitter API JavaScript Node Exercise (Skillshare)

Twitter API JavaScript Node Exercise. Explore the Twitter Developer API connect from your local machine. Use AJAX JavaScript and Node to setup twitter search. Perfect course for beginners to explore the MASSIVE twitter API. This course will teach you how to setup a local server, connect the Twitter API and return data to output into your web page. Its amazing how much information is available on Twitter, connecting the API is easy and can provide real world working experience with JSON AJAX and APIs.

Self Paced
Self-Paced
Create a website with your own simple, custom CMS using HTML, CSS, JavaScript, Django, & Python! (Skillshare) Skillshare
Skillshare

Create a website with your own simple, custom CMS using HTML, CSS, JavaScript, Django, & Python! (Skillshare)

In the next few videos, I'm going to teach you how to create a completely custom, CMS-driven website from scratch using a Job Listing website as an example. *This is a step by step tutorial with explanations along the way. This class is mainly going to be for designers who have some HTML, CSS, and JavaScript experience, who are maybe tired of manually entering data for portfolio pages and want to create a more efficient solution.

Self Paced
Self-Paced