Java - Interview Questions and Answers for 'Reference' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Reference' - 19 question(s) found - Order By Newest

 Q1. What are the common uses of "this" keyword in java ?Core Java
Anonymous
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
Anonymous
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      basic        frequent

Try 1 Question(s) Test


  Q3. Difference between SAX and DOM Parser ?Xml
Admin
info@buggybread.com
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      First Advantage  Wellington Management  Chase Reference Data Distribution  System Soft Technologies  TD Bank Canada  JPMorgan Chase  Tata Consultancy (TCS)  PayPal  Citibank  Free Doctor Helpline  Wells Fargo  Huawei Technologies        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
Anonymous
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


 Q5. What are strong, soft, weak and phantom references in Java ?Core Java
Admin
info@buggybread.com
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     Travelocity  Patni Computers


 Q6. Difference between a Pointer and a Reference ?
Admin
info@buggybread.com
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


 Q7. 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
Admin
info@buggybread.com
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


 Q8. 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
Admin
info@buggybread.com
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


 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=new StringBuffer("Bread");   
}
Core Java
Admin
info@buggybread.com
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



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Why is null == null returns true ?Core Java
Admin
info@buggybread.com
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


 Q11. What is RI or Reference Implementation ?
Admin
info@buggybread.com
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


 Q12. How are values passed in Java ? By value or reference ?

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     Trustwave      basic        frequent


 Q13. What is the default value of a declared object reference ?Core Java2017-01-12 11:05:03

Ans. Null

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

   Like      Discuss      Correct / Improve     object reference  null     HCL Technologies      basic


 Q14. What is a method reference in Java ?Core Java2017-01-29 13:55:22

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


 Q15. What is the difference between reference and object ?Core Java2017-05-13 20:20:48

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


 Q16. What happens when you assign a pre initialized reference some other object ?Core Java2017-05-22 08:31:02

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     UST Global


 Q17. What is meant by "Locality of Reference" or "Cache Locality" ?Core Java2017-05-29 09:56:51

 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


 Q18. In Java, what is the closest thing to pointers?Core Java2017-06-23 13:16:07

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     Jim Beam Luxury


 Q19. When we say final x = 10, is the reference final or the value ?Core Java2017-07-29 13:27:04

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




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

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:
         

X Close this

8 person from are looking for questions for 'Reference'. Connect with them to better prepare for your interview.Click here and post a message

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: