Java - Interview Questions and Answers for 'Builder' | 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

   



CareerBuilder



Link: http://www.careerbuilder.co.in/jobs/keyword/java-developer/
   




Interview Questions and Answers for 'Builder' - 14 question(s) found - Order By Newest

Very frequently asked in different variations. Frequently asked in Deloitte ( 2 feedback ) , HCL Tech ( 3 feedback ) and Coginizant (CTS)
  Q1. Explain the scenerios to choose between String , StringBuilder and StringBuffer ?

or

What is the difference between String , StringBuilder and StringBuffer ?
Core Java
Anonymous
Ans. If the Object value will not change, use String Class because a String object is immutable.

If the Object value can change and will only be modified from a single thread, use StringBuilder because StringBuilder is unsynchronized(means faster).

If the Object value may change, and can be modified by multiple threads, use a StringBuffer because StringBuffer is thread safe(synchronized).

  Sample Code for String

  Sample Code for StringBuffer

  Sample Code for StringBuilder

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

   Like      Discuss      Correct / Improve     java   string class   string   stringbuilder   stringbuffer     Cognizant (CTS)   San Jose State University (SJSU)  HCL Technologies   Deloitte  Sophos  Hitachi  JPMorgan Chase  IBM  Kony Labs  Keystone  ebay      basic        frequent

Try 3 Question(s) Test


Very frequently asked. Usually difference between String,StringBuffer and StringBuilder is asked in different variations.
  Q2. Difference between StringBuffer and StringBuilder ?Core Java
Anonymous
Ans. StringBuffer is synchronized whereas StringBuilder is not.

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

   Like      Discuss      Correct / Improve     java   string   stringbuffer   string class   stringbuilder   synchronized   basic interview question   infosys technologies     Thomson Reuters  Ludia  QualiTest  United Health Group (UHG)  Sophos  JPMorgan Chase  ebay  Infosys Technologies  Experian India      basic        frequent

Try 1 Question(s) Test


  Q3. Write a method to check if input String is Palindrome?Core Java
Admin
info@buggybread.com
Ans. private static boolean isPalindrome(String str) {

if (str == null)
return false;

StringBuilder strBuilder = new StringBuilder(str);

strBuilder.reverse();

return strBuilder.toString().equals(str);

}

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

   Like      Discuss      Correct / Improve     java   string   stringbuilder   stringbuilder   string class   code   palindrome     HCL Technologies  Hootsuite  ebay  Mobile Apps Company  TripAdvisor  Wallet Hub  Groupon  OpenText  Airbnb  Vantiv  Minted LLC  Boston Analytics  mint.com  Arista Networks  Dealer.com  the Zappos Family  Sony PlayStation  Taser  Wolters Kluwer  Wize Commerce  Hitachi Consulting  Quickr  SmartBrief  Liaison International  Monitise  Exilant Technologies  Enova  Wayfair  Amadeus  MakeMyTrip  Naggaro  Vudu  OnDeck Capital  HighRadius   thePlatform  Trimax IT Infrastructure & Services      Basic        frequent


 Q4. Difference between Factory and Builder Design Pattern ?Design
Anonymous
Ans. Builder pattern is the extension of Factory pattern wherein the Builder class builds a complex object in multiple steps.

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

   Like      Discuss      Correct / Improve     java   design pattern   factory design pattern   builder design pattern      expert


 Q5. Difference between Builder and Composite ?
Anonymous
Ans. Builder is a creational Design Pattern whereas Composite is a structural design pattern. Composite creates Parent - Child relations between your objects while Builder is used to create group of objects of predefined types.

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

   Like      Discuss      Correct / Improve     java   design pattern   builder   composite   creational design pattern   structural design pattern


 Q6. Give an Example for Builder Pattern ?Core Java
Admin
info@buggybread.com
Ans. String str = new StringBuilder().append("Buggy").append("Bread").toString();

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

   Like      Discuss      Correct / Improve     java   builder pattern   design pattern   stringbuilder   string     Power System Consultants (PSC)  Xactly Corp  BetterCloud

Try 1 Question(s) Test


 Q7. Write code for the usage of Builder Design Pattern

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=964

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

   Like      Discuss      Correct / Improve     builder design pattern  builder pattern  code  coding      intermediate


 Q8. Write a class explaining builder pattern ?Design2016-08-17 10:32:03

Ans.
public class BuggyBread { 

private String element1;

private String element2;

private BuggyBread(String element1, String element2){
this.element1 = element1;
this.element2 = element2;
}

public static class Builder {

private String element1;

private String element2;

Builder(BuggyBread buggybread){
element1 = buggybread.element1;
element2 = buggybread.element2;
}

Builder withElement1(String element1){
this.element1 = element1;
return this;
}

Builder withElement2(String element2){
this.element2 = element2;
return this;
}

BuggyBread build(){
BuggyBread buggybread = new BuggyBread(element1,element2);
return buggybread;
}
}
}


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

   Like      Discuss      Correct / Improve     builder pattern  builder class

Try 1 Question(s) Test


 Q9. Can StringBuffer and StringBuilder in Java be inherited?Core Java2017-03-15 13:54:44

Ans. No, they have been declared final and hence cannot be extended.

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

   Like      Discuss      Correct / Improve     StringBuffer  StringBuilder



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Do we have a method to reverse a string in String class ?Core Java2017-07-29 09:52:30

Ans. No but we have it in StringBuilder.

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

   Like      Discuss      Correct / Improve     String  StringBuilder  Reverse a string


 Q11. With the following code, Which is a valid way to initialize ?
public class BuggyBread {

   private String element1;

   private String element2;

   private BuggyBread(String element1, String element2){
      this.element1 = element1;
      this.element2 = element2;
   }

   public static class Builder {
   
      private String element1;

      private String element2;

      Builder(BuggyBread buggybread){
         element1 = buggybread.element1;
         element2 = buggybread.element2;
      }

      Builder withElement1(String element1){
         this.element1 = element1;
         return this;
      }

      Builder withElement2(String element2){
         this.element2 = element2;
         return this;
      }

      BuggyBread build(){
         BuggyBread buggybread = new BuggyBread(element1,element2);
         return buggybread;
      }
   }
}
Core Java
a. BuggyBread buggybread = new BuggyBread();
b. BuggyBread buggybread = new BuggyBread("element1","element2");
c. BuggyBread.Builder builder = new BuggyBread.Builder();
d. BuggyBread.Builder builder = new BuggyBread.Builder("element1","element2");

Ans.d. BuggyBread.Builder builder = new BuggyBread.Builder("element1","element2");

 Q12. Which of the following class creates immutable objects ?Core Java
a. String
b. StringBuffer
c. StringBuilder
d. None of these create immutable objects.

Ans.a. String

 Q13. Which of the following class is synchronized ?Core Java
a. String
b. StringBuffer
c. StringBuilder
d. None of these

Ans.b. StringBuffer

 Q14. Which of the following class cannot be extended or inherited ?

StringBuffer , StringBuilder
Core Java
a. StringBuffer
b. StringBuilder
c. Both cannot be extended
d. Both can be extended

Ans.c. Both cannot be extended



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

CareerBuilder: Carrier Builder is user friendly and you ... Anonymous

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: