Posts

Showing posts with the label kotlin

How to Create a REST API With Kotlin and Helidon SE?

Image
Hello everyone, Today, we will show you how to create a simple REST API with  Helidon SE and  Kotlin . Quick Overview: Helidon SE is designed to be a microframework that fortifies the reactive programming model. Helidon SE features three core APIs to engender a microservice -- a web server, configuration, and security -- for building microservices-predicated applications.  Helidon's web server is an asynchronous and reactive API that runs on top of Netty. The WebServer interface includes support for configuration, routing, error handling, and building metrics and health endpoints. The Config loads and processes configuration properties(application.properties or application.yaml) in key/value format.  The Security class provides support for authentication, sanction, and audit. Let's begin, Final Project Directory: Maven [pom.xml]: <?xml version = "1.0" encoding = "UTF-8" ?> <project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi

Build REST CRUD APIs with Kotlin, Spring Boot and MyBatis

Image
Hello everyone, today we will learn how to develop REST-style CRUD APIs with Spring Boot, Kotlin, MyBatis, and H2 Database.  You can download the source code from our Github repository. What is MyBatis? MyBatis is a persistence framework with support for custom SQL, stored procedures and advanced mappings. MyBatis eliminates almost all of the JDBC code and manual setting of parameters and retrieval of results. MyBatis can use simple XML or Annotations for configuration and map primitives, Map interfaces and Java POJOs (Plain Old Java Objects) to database records. Some of the features of  MyBatis : In memory object filtering Fortifies clustering and simultaneous access by other applications without loss of transaction integrity Query Caching - Built-in support Fortifies disconnected operations Support for Remoting. Distributed Objects. Technologies used : Spring Boot 2.5.4 Spring  5.3.9 MyBatis  Kotlin Gradle After completing this tutorial what we will build?  We will build REST API  C

Kotlin - Map with Multiple Keys - Example

Image
Today we will show you how to implement a  Map with Multiple Keys.  Solution 1: Using Kotlin Custom Key Class Solution 2: Using Google's Guava Solution 3: Using Apache Commons Collections  Example 1: Using Kotlin Custom MultiMapKey  Here we created a custom MultiMap Key class, we can use MultiMap as a Key to map a value. object MultiKeyDemo { @JvmStatic fun main(args: Array<String>) { // Declaring the Map val table: MutableMap<MultiMapKey, String> = HashMap() // Declaring the key objects val key1 = MultiMapKey( "raw1" , "col1" ) val key2 = MultiMapKey( "raw1" , "col2" ) val key3 = MultiMapKey( "raw1" , "col3" ) // Putting the values table[key1] = "Java" table[key2] = "Kotlin" table[key3] = "Android" // Getting value by key val value2 = table[key2] println(value2)

Kotlin - Finding largest & smallest element in an Array, List & Set

Example 1: Finding the largest element in an Array import java.util.* /* Kotlin Program to find the largest number in an Array. */ object Demo { @JvmStatic fun main (args: Array < String >) { val numbers = intArrayOf ( 2 , 6 , 7 , 9 , 5 , 155 , 66 , 99 ) val largestNumber = Arrays .stream( numbers ).max(). asInt println ( "Largest Number= $ largestNumber " ) } } Output: Largest Number= 155 Example 2: Finding the largest element in a List import java.util.* /* Kotlin Program to find the largest number in a List. */ object Demo { @JvmStatic fun main (args: Array < String >) { val numbers = listOf ( 2 , 6 , 7 , 9 , 5 , 155 , 66 , 99 ) val largestNumber = numbers .stream().max( Comparator . comparing { i: Int ? -> Integer .valueOf(i!!) } ).get() println ( "Largest Number= $ largestNumber " ) } } Output: Largest Number= 15