Interview Questions and Answers for 'Reference' | 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 'Reference' - 20 question(s) found - Order By Newest

 Q1. What are the common uses of "this" keyword in java ?Core Java
Ans. "this" keyword is a reference to the current object and can be used for following -

1. Passing itself to another method.

2. Referring to the instance variable when local variable has the same name.

3. Calling another constructor in constructor chaining.

  Sample Code for this keyword

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

   Like         Discuss         Correct / Improve     java   this   object reference   constructor chaining      intermediate        rare

Try 3 Question(s) Test


 Q2. What will this code print ?

String a = new String ("TEST");
String b = new String ("TEST");
if(a == b) {
System.out.println ("TRUE");
} else {
System.out.println ("FALSE");
}
Core Java
Ans. FALSE. == operator compares object references, a and b are references to two different objects, hence the FALSE. .equals method is used to compare string object content.

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

   Like         Discuss         Correct / Improve     string   string class   java   ==   object references   coding     Asked in 2 Companies      basic        frequent

Try 1 Question(s) Test


  Q3. Difference between SAX and DOM Parser ?Xml
Ans. A DOM (Document Object Model) parser creates a tree structure in memory from an input document whereas A SAX (Simple API for XML) parser does not create any internal structure.

A SAX parser serves the client application always only with pieces of the document at any given time whereas A DOM parser always serves the client application with the entire document no matter how much is actually needed by the client.

A SAX parser, however, is much more space efficient in case of a big input document whereas DOM parser is rich in functionality.

Use a DOM Parser if you need to refer to different document areas before giving back the information. Use SAX is you just need unrelated nuclear information from different areas.

Xerces, Crimson are SAX Parsers whereas XercesDOM, SunDOM, OracleDOM are DOM parsers.

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

   Like         Discuss         Correct / Improve     java   xml   parsers   sax   dom parser   difference   architecture   technical lead   technical architect  markup language   sax vs dom     Asked in 14 Companies        frequent

Try 1 Question(s) Test


 Q4. There are two objects a and b with same hashcode. I am inserting these two objects inside a hashmap.

hMap.put(a,a);
hMap.put(b,b);

where a.hashCode()==b.hashCode()

Now tell me how many objects will be there inside the hashmap?
Core Java
Ans. There can be two different elements with the same hashcode. When two elements have the same hashcode then Java uses the equals to further differentation. So there can be one or two objects depending on the content of the objects.

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

   Like         Discuss         Correct / Improve     java   hashcode   map   hashmap   object reference   advanced     Asked in 1 Companies


 Q5. What are strong, soft, weak and phantom references in Java ?Core Java
Ans. Garbage Collector wont remove a strong reference.

A soft reference will only get removed if memory is low.

A weak reference will get removed on the next garbage collection cycle.

A phantom reference will be finalized but the memory will not be reclaimed. Can be useful when you want to be notified that an object is about to be collected.

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

   Like         Discuss         Correct / Improve     java   memory management   jvm   garbage collections   references   strong reference   soft reference   weak reference   phantom reference   architecture     Asked in 2 Companies


 Q6. When we say final x = 10, is the reference final or the value ?Core Java
Ans. final keyword have meaning only to referenced and not the value. It means that the specified reference cannot be dereferenced. It doesn't control the value assigned to the memory that's being referenced. This is the reason that final object references doesn't mean that the object is immutable but means that the reference cannot be changed to point to new object.

In case of primitive types too, when we assign a reference to another, values are passed and not the object reference, and hence a new placeholder is created in memory with the same value. That is why final to that context means that you cannot change the assigned memory and there is no way we can have that memory place have another value.

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

   Like         Discuss         Correct / Improve     final keyword  final variables  references


 Q7. Difference between a Pointer and a Reference ?
Ans. We can't get the address of a reference like a pointer. Moreover we cannot perform pointer arithmetic with references.

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

   Like         Discuss         Correct / Improve     java   pointer   reference   at&t


  Q8. How are values passed in Java ? By value or reference ?Core Java
Ans. Java only provides pass by value.

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

   Like         Discuss         Correct / Improve     ebay   pass by value   pass by reference   method call   methods   functions   function call     Asked in 10 Companies      basic        frequent


 Q9. what will be the output of this code ?

public static void main(String[] args){
   StringBuffer s1=new StringBuffer("Buggy");                       
   test(s1);                    
   System.out.println(s1);              
}       

private static void test(StringBuffer s){      
   s.append("Bread");   
}
Core Java
Ans.  BuggyBread

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

   Like         Discuss         Correct / Improve     java   code   coding   stringbuffer   string   method calling   pass by reference


 Q10. what will be the output of this code ?

public static void main(String[] args)    {          
   String s1=new String("Buggy");                         
   test(s1);                    
   System.out.println(s1);              
}       

private static void test(StringBuffer s){      
   s.append("Bread");   
}
Core Java
Ans.  Buggy

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

   Like         Discuss         Correct / Improve     java   code   coding   stringbuffer   string   method calling   pass by reference


 Q11. what will be the output of this code ?

public static void main(String[] args)    {          
   StringBuffer s1=new StringBuffer("Buggy");                         
   test(s1);                    
   System.out.println(s1);              
}       

private static void test(StringBuffer s){      
   s=new StringBuffer("Bread");   
}
Core Java
Ans.  Buggy

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

   Like         Discuss         Correct / Improve     java   code   coding   stringbuffer   string   method calling   pass by reference


 Q12. Why is null == null returns true ?Core Java
Ans. Any reference in java that doesn't point to any object , gets assigned null i.e is a reference to null. Two object references in java are treated equal if they point to the same memory. That's Why null == null results true.

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

   Like         Discuss         Correct / Improve     java   null   equality   references


 Q13. What is RI or Reference Implementation ?
Ans. RI or Reference Implementation is a sample implementation provided for the API's / Specs, usually by their developers. This is usually a part of API documentation.

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

   Like         Discuss         Correct / Improve     reference implementation   help docs   helpdocs   api    apis    api specs   documentation        rare


 Q14. What is the default value of a declared object reference ?Core Java
Ans. Null

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

   Like         Discuss         Correct / Improve     object reference  null     Asked in 1 Companies      basic


 Q15. What is a method reference in Java ?Core Java
Ans. Introduced with java 8 , Method References help us to point to methods by their name.

A method references is described using :: symbol

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

   Like         Discuss         Correct / Improve     method reference  java 8  lambda expressions


 Q16. What is the difference between reference and object ?Core Java
Ans. Object is an entity in Java , i.e which has a state ( instance variables ) and methods attached to it ( static or non static , through class definition ). References are the identifiers that are used to point to objects.

For example -

Employee emp = new Employee();
emp = new Employee();

In this code, emp is the reference that gets assigned to the new object created by the new operator. In the second line , we have assigned the same reference to another object. So with these 2 lines of code, we have 2 objects in memory with reference emp now pointing to second object.

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

   Like         Discuss         Correct / Improve     reference  object  reference vs object      Basic        frequent


 Q17. What happens when you assign a pre initialized reference some other object ?Core Java
Ans. Now the reference points to a new object in memory. If that was the only reference for the previous object , it will be marked for garbage collection.

Foe example -

Object obj = new Object();
obj = new Object();

object created in first line will be eligible for garbage collection after line 2 as it looses all it's handlers.

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

   Like         Discuss         Correct / Improve     references  objects  garbage collection     Asked in 1 Companies


 Q18. What is meant by "Locality of Reference" or "Cache Locality" ?Core Java
 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 :   

   Like         Discuss         Correct / Improve     Cache Locality  Locality of Reference


 Q19. In Java, what is the closest thing to pointers?Core Java
Ans. References.

Unlike pointers in C , Java references are strongly typed and we cannot do pointer arithmetics with them.

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

   Like         Discuss         Correct / Improve     pointers  pointers in java  references     Asked in 1 Companies


 Q20. What is a weak reference ?Core Java
Ans. A weak reference is a reference that gets removed on the next garbage collection cycle.

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

   Like         Discuss         Correct / Improve     weak reference  garbage collection     Asked in 1 Companies        rare



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: