Posts by:

Edge Developer

Kotlin: Class Examples

Class without a Constructor but with default variable (or properties or data) [box type=”info” align=”” class=”” width=””]In class-based object-oriented programming, a constructor is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.[/box] class Person { […]

Kotlin: Function or Methods Example

Simple Function. neither accepts nor return any variable or value fun helloWorld(){ println(“Hello World”) }  Function that takes a parameter but returns no value fun stringFunction (text : String){ for (c in text){ println(“$c “) //KOTLIN -> K O T L I N } } fun intFunction(int : Integer){ println(int) } Functions that returns a […]

Kotlin: Break and Continue Statements

Break and Continue Statements allow us to define jumps in our code and they are used inside Loops breakstatement allow us to jump to the end of the loop and halt any further iterations. This is useful whenever we  are interested in the first occurrence of something. val string = “Kotlin” for (char in string){ […]

Kotlin ArrayList and Loops Example

Kotlin ArrayList Kotlin ArrayList is also very similar to Java Arraylist. ArrayList<T> is the resizable-array implementation of the List interface. The ArrayList class has only a few methods in addition to the methods available in the List interface. val myArrayList = arrayListOf(“John”, “Fred”, “McKinsey”, “Morgan”, “Sarah”) //an arraylist of my friends val newFriendList = arrayListOf(“Musa”, “Victor”, “Timothy”) myArrayList.add(0, […]

OOP: What is an Interface?

An interface is a collection of abstract methods. It is a reference type in Java/Kotlin. It is similar to class. A class implements an interface, thereby inheriting the abstract methods of the interface. [tabs type=”horizontal”] [tabs_head] [tab_title] Java Code [/tab_title] [tab_title] Kotlin Code [/tab_title] [/tabs_head] [tab] public class HelloWorld { class Example implements InterfaceExample{ @Override public […]

Kotlin Conditional Statements

If Statements Sometimes we may want to run our code only when a condition holds true. For example, let’s hypothetically assume that we run a bar and we only want to admit users who are 18 years old and above. in the code below we’re trying to access our code with a preset age of 16,  […]