Posts

Showing posts from 2022

Java Interview Questions and Programs

1) Transient Variable in java? 2) Vector vs ArrayList in java? 3) Which version in java? 4) Concurrent hashmap in java? 5) Volatile keyword in java? 6) Comparable and toCompare() method in java? 1) Write syntax of Coroutines, Sealed Classes, Extension Function, Generics in kotlin fun main() = runBlocking { // this: CoroutineScope     launch { // launch a new coroutine and continue         delay(1000L) // non-blocking delay for 1 second (default time unit is ms)         println("World!") // print after delay     }     println("Hello") // main coroutine continues while a previous one is delayed } Generic in Kotlin class  Person<T>(age: T){   var age: T = age   init {   this .age= age   println(age)       }   }   fun  main(args: Array<String>){   var ageInt: Person<Int> = Person<Int>( 30 )   var ageString: Person<String> = Person<String>( "40" )   }   2) Write code for implementing constructor in kotlin class  myClass(name:

SingleTon in Java

  Singleton is a design pattern that ensures that a class can only have one object .  Define a class that has only one instance and provides a global point of access to it . Static member: It gets memory only once because of static, it contains the instance of the Singleton class. Private constructor: It will prevent instantiating the Singleton class from outside the class. Static factory method: This provides the global point of access to the Singleton object and returns the instance to the caller. Its used in Logging, Caching, thread pools, configuration settings etc.. Advantages: Saves memory because the object is not created at each request. An only a single instance is reused again and again. Thread Safe class Playground {     public static void main ( String [ ] args ) {         SingleTon singleTonClass = SingleTon . getInstance ();         System . out . println ( "Hello Java" );     } } class SingleTonClass {     private SingleTonClass (){}     private s

Angular Ionic Interview Questions

JAVASCRIPT What is hoisting? Its mechanism Variable and function declarations are moved to the top of their scope before code execution. console.log(x) //undefined var x = 10 console.log(x) // print 10 console.log(y+z) //reference error let y = 10 const z = 10 --------------------------------------------------------------------------------------------------------------------------- Difference between let and var? --------------------------------------------------------------------------------------------------------------------------- What are let, var, and const in javascript? let - block scoped, redeclared not supported in same scope const - block scoped, redeclared or redesigned are not supported var - function scoped, redeclared and redesigned are supported function scope  function test(){ var a = 10; var a = "mani";  //redeclared and redesigned are supported with the scope } block scope if(test){ let a = 10; let b = 11; //error if(tt){ let b = 12; //working } } if(test)

Android Interview Questions 2022

JAVA Why String is mutable? String str1 = 10                 String str2 = 20         str1 == str2 is this true? What String Pool in java? Difference of StringBuffer vs String? Difference of StringBuilder vs StringBuffer? What is HashMap and purpose? Difference of HashMap vs HashTable? Difference of HashMap vs HashSet? What is array vs list? What is abstract class in java? What is collections in java? What is flatmap? What is array vs arraylist? What is Interface in Java? What is polymorphism ? What is singleton class? The following variable stored in which memory?                 String str = new String()  - memory?         String str = “test”;         String str1 = “test”;            - memory? Difference of == and equals() method in java? Program: Segregate the 01 int array [0100110100] to [0000001111] Write a program for fibno series? Write a program for palindrom? Eg: 121, madam Write a program input [12345678] to output [76812345] Write a program for vowels from given string? Writ

Companion Object Vs @JvmStatic in Kotlin

 Hi guys, Now, we are going to see the difference between the companion object and @JvmStatic in kotlin. What is a companion Object in Kotlin? Kotlin language does not have static keyword like java. So, Its provide companion object {} block instead of static keyword, We can also used @JvmStatic to denote the static variable or methods. companion object is an instance of the Campanion class, So, When we call the kotlin code from java, an object of the Companion class is first instantiated behind the scenes. To understand this, let's consider a simple example. Kotlin code (Without @JvmStatic) class Car {     companion object {         fun getSeatSize() { }     } } Decompiled Java code public final class Car {    public static final Car.Companion Companion = new Car.Companion();    public static final class Companion {       public final void getSeatSize() { }       private Companion() { }    } } Java using the Car.Companion: Car.Companion.getSeatSize(); Kotlin code (With @JvmStatic)