More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. 1. String Pool - When a string is created and if it exists in the pool, the reference of the existing string will be returned instead of creating a new object. If string is not immutable, changing the string with one reference will lead to the wrong value for the other references.
Example -
String str1 = "String1";
String str2 = "String1"; // It doesn't create a new String and rather reuses the string literal from pool
// Now both str1 and str2 pointing to same string object in pool, changing str1 will change it for str2 too
2. To Cache its Hashcode - If string is not immutable, One can change its hashcode and hence it's not fit to be cached.
3. Security - String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. The value received from hashcode() is used as bucket number for storing elements. This bucket number is the address of the element inside the set/map. when you do contains() then it will take the hashcode of the element, then look for the bucket where hashcode points to and if more than 1 element is found in the same bucket (multiple objects can have the same hashcode) then it uses the equals() method to evaluate if object are equal, and then decide if contain() is true or false, or decide if element could be added in the set or not.
Help us improve. Please let us know the company, where you were asked this question :
Ans. The Java runtime environment deletes objects when it determines that they are no longer being used. This process is known as garbage collection. The Java runtime environment supports a garbage collector that periodically frees the memory used by objects that are no longer needed. The Java garbage collector is a mark-sweep garbage collector that scans Java dynamic memory areas for objects, marking those that are referenced. After all possible paths to objects are investigated, those objects that are not marked (i.e. are not referenced) are known to be garbage and are collected.
Help us improve. Please let us know the company, where you were asked this question :
Ans. import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.*;
public class Common {
public static void main(String ar[])throws Exception
{
File f=new File("a.txt");
File f1=new File("x.java");
System.out.println(f.exists());
FileInputStream fin = new FileInputStream(f);
FileInputStream fin1 = new FileInputStream(f1);
Ans. In terms of compute options and configurations, Reserved Instances and On Demand instances are the same. The only difference between the two is that a Reserved Instance is one you rent (reserved) for a fixed duration, and in return you receive a discount on the base price of an On Demand instance.
Help us improve. Please let us know the company, where you were asked this question :
Ans. 1. Fault Tolerance
2. Better Access by bringing the application closer to the users.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  Google Cloud Computing (GCP)  Amazon Web Services (AWS)  Availability Zones  Regions and Zones  Infrastructure
Ans. Yes, Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they're currently authenticated.
Help us improve. Please let us know the company, where you were asked this question :
Q14. If you have access to a function that returns a random integer from one to five, write another function which returns a random integer from one to seven.
Ans. Fail-fast iterators detect illegal concurrent modification during iteration and fail quickly and cleanly rather than risking arbitrary, non deterministic behavior at an undetermined time in future. Example could be of an Iterator failing if it smells ConcurrentModificationException.
Help us improve. Please let us know the company, where you were asked this question :
Ans. public class Class{
public static void main(String[] args){
String string1 = "Hello I am Jack. I live in United States. I live in california state.";
String string2 = "I live in";
int startIndex = 0;
int endIndex = string1.length()-1;
Ans. We can simply find it by checking the criteria of a tree. A tree will not contain a cycle, so if there is any cycle in the graph, it is not a tree. We can check it using another approach, if the graph is connected and it has V-1 edges, it could be a tree. Here V is the number of vertices in the graph
Help us improve. Please let us know the company, where you were asked this question :
Ans. A Virtualization is software that virtualizes your hardware into multiple machines while Cloud computing is the combination of multiple hardware devices. In Virtualization, a user gets dedicated hardware while in Cloud computing multiple hardware devices provide one login environment for the user.
Help us improve. Please let us know the company, where you were asked this question :
This question was recently asked at 'Bristlecone,Amazon Lab126,Amazon,Microsoft,Facebook,NCR,Google'.This question is still unanswered. Can you please provide an answer.
Help us improve. Please let us know the company, where you were asked this question :