Posts

Micronaut REST Exception Handling - Global

Image
Hello everyone, today we will learn how to handle exceptions in the Micronaut REST application using ExceptionHandler . You can download the source code from our Github Repository. Project Directory: Pom.xml: <?xml version = "1.0" encoding = "UTF-8" ?> <project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelVersion> 4.0.0 </modelVersion> <groupId> com.knf.dev.demo </groupId> <artifactId> micronaut-global-exception-handling </artifactId> <version> 0.1 </version> <packaging> ${packaging} </packaging> <parent> <groupId> io.micronaut </groupId> <artifactId> micronaut-parent </artifactId> <version> 3.1.3 </version> </pa

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

Kotlin: Print Odd & Even Numbers from Array, List & Set

Example 1: Kotlin program to print odd numbers from a List import java.util.stream. Collectors /*Kotlin Program to find Odd Numbers from a list*/ object DriverClass { @JvmStatic fun main (args: Array < String >) { val numbers = listOf ( 1 , 4 , 8 , 40 , 11 , 22 , 33 , 99 ) val oddNumbers = numbers .stream(). filter { o: Int -> o % 2 != 0 } . collect( Collectors .toList()) println ( oddNumbers ) } } Example 2: Kotlin program to print even numbers from a List import java.util.stream. Collectors /*Kotlin Program to find Even Numbers from a list*/ object DriverClass { @JvmStatic fun main (args: Array < String >) { val numbers = listOf ( 1 , 4 , 8 , 40 , 11 , 22 , 33 , 99 ) val evenNumbers = numbers .stream(). filter { o: Int -> o % 2 == 0 } . collect( Collectors .toList()) println ( evenNumbers ) } } Example 3: Kotlin program to print eve

How to iterate over words of String in Go Language?

Hello everyone, in this tutorial we will show you how to iterate over all the words of String in the Go Programming language. How to iterate over all the words of the string in Go Language? Using for-range loop package main import ( "fmt" "strings" ) func main() { teststr := "This is a sample sentence." str := strings.Fields(teststr) for _, word := range str { fmt.Println(word) } } Output: This is a sample sentence. More Go language topics, How to make a delay in Go Language How to iterate over all the characters of the string in Go Language Trim a string in Go Language Check if a String is an Integer in Go Language Sort a String Array/Slice in Go Language Program to check if a string contains the substring How to Split a String by Space in Go Language? Trigonometry with Go - Sin, Cos, Tan Functions Examples How to iterate over a map in Go? Go Arrays - Program to Find Largest & Smallest Element Go Arrays - Program t

Spring Boot - Spring Security - Okta OAuth2 Login - Example

Image
Hello everyone, Today we are going to learn how to integrate the Okta OAuth2 Sign-In by utilizing the Spring Boot application. M ore Spring Security topics: Registration and Login with Spring Boot + Spring Security + Thymeleaf Spring Boot-Authentication and Authorization with Spring Security & JWT Spring Security -GitHub OAuth2 Login - Example   Generate Okta OAuth2 credentials   1.  Register Okta developer account  -   click here 2. Customize your goals 3.  After clicking the Customize Goals, one modal will pop up "Tell Us About Yourself" Save the details 4. Create a Web Application(Java) 5.  Create New App 6.  After clicking the Create New App, one modal will pop up "Create a new  app integration" Click the 'Next' Button 7. C hange the Redirect URI to http://localhost:8080/login/oauth2/code/okta  8.  After clicking the Save button, System will generate the Client ID and Client Secret and Okta domain. Now we have successfully created the auth client in