Friday, September 20, 2024

String coding questioon

 

  1. How do you reverse a given string in place? (solution)
  2. How do you print duplicate characters from a string? (solution)
  3. How do you check if two strings are anagrams of each other? (solution)
  4. How do you find all the permutations of a string? (solution)
  5. How can a given string be reversed using recursion? (solution)
  6. How do you check if a string contains only digits? (solution)
  7. How do you find duplicate characters in a given string? (solution)
  8. How do you count a number of vowels and consonants in a given string? (solution)
  9. How do you count the occurrence of a given character in a string? (solution)
  10. How do you print the first non-repeated character from a string? (solution)
  11. How do you convert a given String into int like the atoi()? (solution)
  12. How do you reverse words in a given sentence without using any library method? (solution)
  13. How do you check if two strings are a rotation of each other? (solution)
  14. How do you check if a given string is a palindrome? (solution)
  15. How do you find the length of the longest substring without repeating characters? (solution)
  16. Given string str, How do you find the longest palindromic substring in str? (solution)
  17. How to convert a byte array to String? (solution)
  18. how to remove the duplicate character from String? (solution)
  19. How to find the maximum occurring character in given String? (solution)
  20. How do you remove a given character from String? (solution)

HashMap coding and interview question


2) How do you add key-value pairs to HashMap?->using add() or addAll() method
3) How do you add given key-value pair to HashMap if and only if it is not present in the HashMap?
4) How do you retrieve a value associated with a given key from the HashMap?
5) How do you check whether a particular key/value exist in a HashMap?
6) How do you find out the number of key-value mappings present in a HashMap?
7) How do you remove all key-value pairs from a HashMap? OR How do you clear the HashMap for reuse?
8) How do you retrieve all keys present in a HashMap?
9) How do you retrieve all the values present in a HashMap?
10) How do you retrieve all key-value pairs present in a HashMap?
11) How do you remove a key-value pair from the HashMap?
12) How do you remove a key-value pair from a HashMap if and only if the specified key is currently mapped to given value?
13) How do you replace a value associated with a given key in the HashMap?
14) How do you replace a value associated with the given key if and only if it is currently mapped to given value?
15) How do you get synchronized HashMap in java?

Monday, June 19, 2023

ReactJS

 Prerequisite: 

  1. NodeJs Required & NPM
  2. Vs Code.

Vs Code extensions: 
  1. Thunder Client: as a Postman
  2.  ES7 React/Redux/GraphQL/React-Native snippets: It provides suggestion of codes.
  3. Bracket Pair Colorizer: it uses for bracket open and close (colors as same).
  4. Auto Rename Tag: It uses for tags(open and close).
  5. Live Server: run perticular page
  6. Prettier-Code formatter: 

How many way to creater Variable:

1. Var: older use

 Example: var a=55;

                 var a=45;

                   // Its valid variable declaration

2. Let: Morden use 

Example: Let a=55;

                Let a= 45;

// Its invalid variable declaration

3. Const: uses for constant something

Types of DataTypes:

1. Numbers

2. Objects

3. Booleans -> true or false

4. String

5. Undefined

6. null

Functions:

function hell(){

console.log('Hello world');

}


Objects:

let obj = {

r: 34,

m:65,

func: function myfunc(number){

console.log('Hello world'+ number);

}

}




Saturday, March 6, 2021

Multi-Threading

 Q1. What is Thread?

Ans:  Thread is a lightweight sub-process. it create by using extends Thread class and Implement Runnable interface.

Q. Why do we use Multithreading?

Ans: 

Q. What is Thread Lifecycle in Java?

Ans: Before moving on to creating a thread, we’ll first see the various phases through which the thread has to pass to complete its lifespan.

  • New
  • Runnable
  • Running
  • Non-Runnable (blocked)
  • Terminated



New- A thread is in New state when you create the instance of thread class, but the start() method is yet to get called.

Runnable- The thread is in runnable after executing the start() method. In this stage, it waits for the thread scheduler to run it.

Running- A thread picked by the thread scheduler for execution remains in running state.

Non-Runnable (blocked)- In this state, the thread remains alive, but it is not eligible to run. It may be due to some sleep operation, waiting for any File I/O to finish or in the locked state, etc.

Terminated- A thread is said to be in the terminated state when it’s Run() method exits.


wait() - Tells the current thread to release the lock and go to sleep until some other thread enters the same monitor and calls notify().

notify() - Wakes up the single thread that is waiting on this object's monitor.

notifyAll() - It wakes up all the threads that called wait() on the same object.

Synchronization:- 1. Synchronized is the keyword applicable for methods & blocks but not for classes and variables.

2. If a method or block declared as the Synchronized then at a time only one thread is allow to execute that method or block on the given Object.

3. The main advantages of synchronized keyword is we can resolve data inconsistency problems.

4. But the main disadvantage of synchronized keyword is it increases waiting time of the thread and effects performance of the system.

Friday, March 5, 2021

Basic Programs asked in Interview

 Q. Write a program to find Second largest number in the array?

Ans: Method:-

public static void secondLargestNumber(int arr){

int first = Integer.MIN_VALUE;

int second = Integer.MIN_VALUE;

for(int i=0;i<arr.length;i++){

if(arr[i] > first){

        second = first;

        first = arr[i];

      }else if(arr[i] > second){

        second = arr[i];

      }

}

System.out.println(" Second Largest Number = " + second);

}

Differences and sheet questions

 Q. What are the difference between @Controller and @RestController?

Ans: 1. The @Controller is a common annotation that is used to mark a class as Spring MVC Controller while @RestController is a special controller used in RESTFul web services and the equivalent of @Controller + @ResponseBody.

Q. What are the use of @PathVariable?

Ans: @PathVariable is used to bind method parameter to the value of URI template variable

ex: @RequestMapping(value="login/{id}",method=RequestMethod.post)

Q. What are difference between Abstract class and Interface in java?

Ans: 1. Abstract classes have partial implementation whereas Interface have only methods declaration/signature.

2. Abstract classes are used when parent classes need to provide some default behavior(method) and child classes need to provide some specialized behavior(method) whereas Interfaces are used in design phase when multiple behaviors from a subsystem are expected. OR I use interfaces when I see that any subsystem of my design will change frequently for example if my application need to support multiple databases then I will define interfaces and write implementation classes for each database.

Q. What are differences between String and StringBuffer classess?

Ans: 1. String is immutable whereas StringBuffer is mutable.

Q. What are differences between StringBuffer and StringBuilder classess?

Ans: 1. StringBuffer is synchronized whereas StringBuilder is not synchronized.

Q. Does Serializable interface have any method?

Ans: No, It is a marker interfaces.

Q. What is transient variable?

Ans: Attributes defines as transietn will not be serialized.

Q. What type of Variables are declared as transient?

Ans: Calculated filed, memory point and database pointer objects like ResultSet.

Q. Does cloneable interface have any method?

Ans: No, It is a marker interfaces.

Q. What are the difference between Overloading and Overriding?

And: Overloading vs Overriding in Java

-----------------------------------------------------------------------------------

OverloadingOverriding 
1. More than one method with same name, different prototype in name scope is called method overloading1. More than one method with same name, same prototype in different scope is called method overriding
2. In case of method overloading, parameter must be different.2. In case of method overriding, parameter must be same.
3. Method overloading is performed within class3. Method overriding occurs in two classes.
4. In case of method overloading, return type can be same or different.4. In case of method overriding, return type must be same.

Method Overloading:- If a class has multiple method having same name but different in parameter list, it is known as method overloading.

Method Overriding:- If child class have same method as declared in parent class, it is known as method overriding in java

Q. What is immutable object?

Ans: When object values can be initialized once and can never be changed, It is called immutable object.


Wednesday, March 3, 2021

Clone concept

 Q. What is object clone in java?

Ans: The object cloning is a way to create an exact copy of an object. The clone method of  an object class is used to clone an object. The clonneable interface must be implemented by a class whose object clone to create.

String coding questioon

  How do you reverse a given string in place? ( solution ) How do you print duplicate characters from a string? ( solution ) How do you chec...