def x = 2 //evaluated when called

val y = 2 //evaluated immediately

lazy val z = 2 //evaluated once when needed

def callByValue(x: Int)// Evaluates the funtion argument(x)’s before calling the function

def callByName(x: => Double)// Evaluates the funtion then evaluates funtion argument(x)s if needed

object EvaluationRulesScala {
def main(args: Array[String]): Unit = {
//valVarDeclaration 2
println(“****starting the app***”) // ****starting the app***
val defVarDeclarationCall1 = defVarDeclaration // defVarDeclaration 1
val defVarDeclarationCall2 = defVarDeclaration // defVarDeclaration 1

val valVarDeclarationCall1 = valVarDeclaration //
val valVarDeclarationCall2 = valVarDeclaration //

val lazyValVarDeclarationCall1 = lazyValVarDeclaration // lazyValVarDeclaration 3
val lazyValVarDeclarationCall2 = lazyValVarDeclaration //


An Auxiliary constructor is a method with this name, which is used to create an instance without passing all the required parameters.

class Student(id: Int,name: String) {
def this(id: Int) {
this(id,“Name”)
println(“auxiliary constructor”)
}
}

The object can be created by passing only id i.e new Student(10) or by passing id and name i.e. new Student(10, “sudarshan”)

Use case

Consider a repository class RepoClass that takes 2 arguments database configuration, entity info. And this class can create database configuration object based on entity info.

class RepoClass(dbConfig: DataBaseConfiguration, entity: Entity){…}

Now Class1 service layer class can create and pass database configuration, entity…


/***
* Following Integer
*
* You are writing out a list of numbers. Your list contains all numbers with exactly i digits in its decimal representation which are equal to i,
* for each i between 1 and 9, inclusive. You are writing them out in ascending order. For example, you might be writing every number with two '1's and one '5'.
* Your list would begin 115, 151, 511, 1015, 1051. Given N, the last number you wrote, compute what the next number in the list will be.
* The number of 1s, 2s, ..., 9s is fixed…

import java.util.*;
/**
* Print n Longest Lines
* Programming challenge description:
* Write a program that finds the N longest lines from standard input.
* Input:
* Your program should read lines of text from standard input.
* The first line contains the value of N, which will be a positive integer.
* Ignore empty lines in the input. You can assume that your program will receive at least N non-empty lines.
* Output:
* Print to standard output the longest N lines from the input, sorted from longest line to shortest.
* Ensure that there are no trailing spaces…

Sudarshan Kasar

JVM developer Java Scala

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store