Interview Questions and Answers for 'Nakisa' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 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.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Nakisa' - 3 question(s) found - Order By Newest

Very frequently asked. Among first few questions in almost all interviews. Among Top 5 frequently asked questions. Frequently asked in Indian service companies (HCL,TCS,Infosys,Capgemini etc based on multiple feedback ) and Epam Systems
  Q1. Difference between == and .equals() ?Core Java
Ans. "equals" is the method of object class which is supposed to be overridden to check object equality, whereas "==" operator evaluate to see if the object handlers on the left and right are pointing to the same object in memory.

x.equals(y) means the references x and y are holding objects that are equal. x==y means that the references x and y have same object.

Sample code:

String x = new String("str");
String y = new String("str");

System.out.println(x == y); // prints false
System.out.println(x.equals(y)); // prints true

  Sample Code for equals

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string comparison   string   object class   ==    equals   object equality  operator   == vs equals   equals vs ==     Asked in 294 Companies      basic        frequent

Try 6 Question(s) Test


Related Questions

 What is the difference between = and == in Java ?
 How is == operator different for objects and primitive types ?
 What will be the output of following code

Integer x = 1;
Integer y = 2;
System.out.println(x == y);

What if you change 1 to "1" and Integer to String?


Advanced level question. Frequently asked in High end product companies. Frequently asked in Google , Cognizant and Deloitte ( Based on 2 feedback )
  Q2. Why is String immutable in Java ?Core Java
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 :   

   Like         Discuss         Correct / Improve     java   oops   string   string class   immutable  immutability   advanced     Asked in 39 Companies      expert        frequent

Try 4 Question(s) Test


Related Questions

  Why Char array is preferred over String for storing password?
 How does making string as immutable helps with securing information ? How does String Pool pose a security threat ?
 How is string object immutable if we can concat a string to it ?
  How to implement an immutable class ?
  What is an immutable class ?
  What is an Immutable Object ?
  Does Declaring an object "final" makes it immutable ?
 Is String final in Java ?
  What are stateless objects ? How are they different from immutable objects ? Which of these two is thread safe ?


  Q3. Which are the different segments of memory ?Core Java
Ans. 1. Stack Segment - Contains primitives, Class / Interface names and references.

2. Heap Segment - Contains all created objects in runtime, objects only plus their object attributes (instance variables), Static variables are also stored in heap.

3. Code Segment - The segment where the actual compiled Java bytecodes resides when loaded

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   memory   memory management   stack memory   heap memory   code segment memory   advanced     Asked in 9 Companies      expert        frequent

Try 6 Question(s) Test


Related Questions

  Does garbage collection guarantee that a program will not run out of memory?
  What are different ways to create String Object? Explain.
  Describe, in general, how java's garbage collector works ?
  Describe what happens when an object is created in Java ?
  What are various types of Class loaders used by JVM ?
 Why two types of memory - stack and heap are required by Java ?
  Should we override finalize method ?
  What are strong, soft, weak and phantom references in Java ?
  Which memory areas does instance and static variables use ?
  Can we call the garbage collector explicitly ?



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: