Prabhu Sunderaraman

Fullstack Engineer, Programmer, Writer, Trainer

prabhu.bits@gmail.com,     GitHub     Youtube     LinkedIn
  • Home
  • Profile
  • Books
  • Reading List
Browsing: / Home
Shortlink

Kotlin Video Series – String (Part 1)

By Prabhu Sunderaraman on June 13, 2018 in Kotlin, Languages

This is the fourth part of the video series on Kotlin language. Read the first, second and third parts here. In this post, let’s discuss String.

String is an immutable type in Kotlin.

fun main(args:Array<String>){
  var lang = "Java"
  println(lang) //Java
  lang = "Scala"
  println(lang) //Scala
  println(lang.javaClass) //java.lang.String
}

You can access the characters of a String using the numerical index starting from 0 on the variable itself.

  var lang = "Scala"
  println(lang[0])
  println(lang[10]) //StringOutOfBoundsException
  lang[0] = "s" //ERROR because it's immutable

In the code above, lang[0] is used to access the first letter in the string. But, we cannot change the(or any) character as string is immutable.

Multi-line strings can be created using “””…”””, where whitespace characters are preserved.You can use the pipe(|) character as the starting letter of every line and trim the leading spaces using trimMargin() method.

   var comments = """
		|Kotlin
		|is 
		|Cool
	"""	
   println(comments.trimMargin())

The trimMargin() method takes a string argument that denotes the new delimiter. For example, in the code below, we have used tilde(~) as the delimiter instead of pipe(|).

   var comments = """
		~Java
		~is 
		~Cool
                ~too
	"""	
   println(comments.trimMargin("~"))

You can find the video here.

Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Kotlin Video Series – Data Types

By Prabhu Sunderaraman on June 8, 2018 in Kotlin, Languages

This is the third part of the video series on Kotlin language. Read the first and second parts here. In this post, let’s take a look at the data types in Kotlin language.

Kotlin is a strongly typed language. In Java you have primitive and reference data types. ie., int type and a wrapper Integer class. But in Kotlin, all data types are Objects.

fun main(args:Array<String>){
   var x:Int = 10
   println(x)
   //x is an Int Object
   println(x.toString())
	
   //On the JVM x is treated as primitive type int
   println(x.javaClass) //Prints int
	
   //On the JVM b is treated as primitive type boolean
   var b:Boolean = true
   println(b.javaClass) //Prints boolean
}

As you can notice in the code above, x and b are declared as Int and Boolean types. Since they are reference types, we’re able to use the dot(.) notation on these variables. The .javaClass property returns the runtime Java class of this object.

Another cool feature of Kotlin, is Type Inference. Types can be omitted when you declare variables. Based on the value you assign, the compiler automatically infers the type of the variable.

  var y = 20
  println(y.javaClass)

In the code above, variable y is automatically inferred to be an integer. But how about type conversion. Say, you assign a number and then change it to String value. What happens?

   var a = 20
   println(a.javaClass)
   a = "now it's a string" //ERROR

In the code above, variable a is automatically inferred to be an integer based on the value assigned. But in the next line, when you assign a string value, the compiler throws an error, stating type mismatch.

You can find the video here.

Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Kotlin Video Series – Declaring variables

By Prabhu Sunderaraman on June 5, 2018 in Kotlin, Languages

This is the second part of the video series on Kotlin language. Read the first part here. In this post, let’s discuss how to declare variables in the language.

You can declare variables using var keyword as shown below.

fun main(args:Array<String>){
   var x:Int = 10
   var b:Boolean = true
   var s:String
   s = "Hello"
   var nope:Int
   println(nope)//ERROR
}

Variables have to be initialized before they can be used. You can also declare constants using val keyword.

fun main(args:Array<String>){
   val y:Int = 20
   println(y)
   y = 21    //ERROR
}

You can find the video here.

Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Kotlin Video Series – Hello Kotlin

By Prabhu Sunderaraman on June 4, 2018 in Kotlin, Languages

Kotlin is the new programming language by JetBrains. It can be compiled to Java and JavaScript. Kotlin is slowly making its mark in the Android development territory. I have started creating short 2-3 minutes code-based videos on Kotlin language. Here’s the first video that starts off with a ‘Hello World‘

Kotlin is a concise, strongly typed, modern programming language. And here’s the simple Hello World program.

//hello.kt
fun main(args:Array<String>){
	println("Hello world")
}

You can run this program by compiling it using kotlinc compiler. The code gets compiled to a HelloKt.class with a main method. You run it with kotlin runtime engine. The hello.kt file can be compiled to JavaScript say hello.js using kotlinc-js.

You can find the video here.

Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

Modern JavaScript concepts you need to know – Classes and Objects

By Prabhu Sunderaraman on April 25, 2018 in JavaScript

A number of JavaScript libraries these days, require strong understanding of the ES6 language. If you want to comfortably work with libraries like Redux, ReactJS, Relay, GraphQL it’s important to understand some of the latest concepts.

My first article/video in the series talks about Object Destructuring.
The second one, discusses Array Destructuring.
The third topic is on writing relaxed JSON.
The fourth topic is about using Rest operators.
The fifth topic is about using Spread operators.
The sixth topic discusses Template Strings.

The topic I have discussed here is classes and objects.Gone are the days of treating functions as classes and using prototype for inheritance. OO is pretty easy in JavaScript now. As you can see below, it’s pretty straightforward to create classes and objects and use inheritance.

class Employee{
	constructor(name,salary){
		this.name = name
		this.salary = salary
	}
	work(){
		return `Employee ${this.name} is yawning`
	}
}
let sam = new Employee("Sam",5000)
console.log(sam.work())

class Manager extends Employee{
	constructor(name,salary,stockOptions){
		super(name,salary)
		this.stockOptions = stockOptions
	}
	work(){
		return `${super.work()}; Manager ${this.name} is snoring`
	}
}
let john = new Manager("John",10000,100000)
console.log(john.work())

You can watch the video here


Share this on: Mixx Delicious Digg Facebook Twitter
« Previous 1 … 13 14 15 … 64 Next »

Youtube Channel




Categories

  • JavaScript (48)
    • RequireJS (5)
  • Go (44)
  • Golang (44)
  • Ext JS (23)
  • Spring (22)
  • Mobile (21)
  • Scala (20)
    • Play (3)
  • Uncategorized (19)
  • Video Sessions (18)
  • GoG (17)
  • Sencha Touch (16)
  • jQuery (14)
  • Languages (13)
  • Java 8 (12)
  • React JS (11)
  • Kotlin (11)
  • HealthyCodeMagazine (9)
  • Video (9)
  • Objective-C (8)
  • NoSQL (8)
  • Android (7)
  • MongoDB (7)
  • GWT (6)
  • Tools (6)
  • HTML 5 (5)
  • Cloud (5)
  • General (5)
  • Micro services (5)
  • Java (5)
  • Books (4)
  • AWS (4)
  • Software Architecture (4)
  • .NET (3)
  • Elixir (3)
  • Docker (3)
  • Reactive (3)
  • NodeJS (2)
  • RoR (2)
  • Backbone (1)
  • AngularJS (1)

Archives

  • 2020 (49)
  • 2019 (7)
  • 2018 (34)
  • 2017 (15)
  • 2016 (7)
  • 2015 (18)
  • 2014 (31)
  • 2013 (55)
  • 2012 (100)

Search

Subscribe




Copyright © 2025 Prabhu Sunderaraman.

Powered by WordPress and News.