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

Build Your Online Portfolio Without Writing Code (Skillshare) Skillshare
Skillshare

Build Your Online Portfolio Without Writing Code (Skillshare)

With the web becoming more and more involved in our daily lives, being able to create your own little corner of the web has never been more important (or exciting). In under one hour with Webflow's Mat Vogels, you'll cover a variety of different topics, including: Why you should be online in the first place; Basic web concepts, like the box model and responsive design; Building a website from scratch; Publishing a website.

Self Paced
Self-Paced
Talking to Strangers: An Introduction to User Interviews (Skillshare) Skillshare
Skillshare

Talking to Strangers: An Introduction to User Interviews (Skillshare)

Design is nothing without the user, and the best way to find out what the user wants is to talk to them face-to-face. In this class, we will cover everything you need to get started with conducting user interviews to collect valuable qualitative data that will help you humanize your designs. You’ll learn how to write a script...and how/when to veer off the script. You’ll learn how to listen to the user’s stories, and how to respond on the fly to a constantly adapting conversation.

Self Paced
Self-Paced
Introduction To HTML5 For Absolute Beginners (Skillshare) Skillshare
Skillshare

Introduction To HTML5 For Absolute Beginners (Skillshare)

Hi, welcome to this crash course on HTML5 for complete beginners. In this class, you will learn everything you need to know about getting started with web development. The first step in becoming a web developer is learning HTML. The latest version of HTML is HTML5 and I will walk you through everything you need to know to get started with it. HTML is based on tags. You write HTML content inside tags. Tags tell the browser how to display the content on the screen.

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
Introduction to PHP (Skillshare) Skillshare
Skillshare

Introduction to PHP (Skillshare)

In this course, You will learn about What is PHP and How it Works? Right after this course, you will be able to explain concepts like Client Server Model, Request Response Pattern and Describe about PHP Language in your own words. This is the second course topic that you should take which helps you to understand the basic concepts Why PHP was developed and What problem PHP language solves. This course is a Introduction to PHP and will introduce you to Core Web Concepts and PHP.

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
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
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