Javascript - Interview Questions and Answers for 'At' - 6 question(s) found - Order By Newest Very frequently asked in HCL Tech ( Based of 4 inputs ) Q1. Write a Program to reverse a string iteratively and recursively Core Java
Ans. Using String method -
new StringBuffer(str).reverse().toString();
Iterative -
Strategy - Loop through each character of a String from last to first and append the character to StringBuilder / StringBuffer
public static String getReverseString(String str){
StringBuffer strBuffer = new StringBuffer(str.length);
for(int counter=str.length -1 ; counter>=0;counter--){
strBuffer.append(str.charAt(counter));
}
return strBuffer;
}
Recursive -
Strategy - Call the method with substring starting from 2nd character recursively till we have just 1 character.
public static String getReverseString(String str){
if(str.length <= 1){
return str;
}
return (getReverseString(str.subString(1)) + str.charAt(0);
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string  StringBuffer  recursion  for loop  control statements  loop statement  stringbuffer.append  java.lang.String  java.lang.StringBuffer  String Manipulation Asked in 8 Companies   frequent Ans. A cookie is a small piece of text stored on a user's computer by the browser for a specific domain. Commonly used for authentication, storing site preferences, and server session identification. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  cookie   javascript   web application   session management   browser   j2ee Asked in 16 Companies basic   frequent Q3. What is event handling ? What is event propagation ? JavaScript
Ans. LinkedIn Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  event habdling  event propagation  events Asked in 1 Companies Ans. == compares values === is used in scripting languages for comparing two values as well as there data tpe. like in js,php. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ==  ===  == vs === Asked in 13 Companies basic   frequent Asked in General Electric online assignment. Q5. Write a Program for coin changer application. The program should set the cash box with available currency and then should render the exact change. If enough cash is not available , it should present the appropriate message. Core Java
Ans. import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
public class CoinChanger {
enum Currency {
DOLLAR(1),QUARTER(.25),DIME(.10),NICKEL(.05),PENNY(.01);
private double currencyValue;
Currency(double value){
currencyValue = value;
}
double getCurrencyValue(){
return this.currencyValue;
}
}
private static Map<Currency, Integer> cashBox;
private static Map<Currency, Integer> change;
static {
cashBox = new TreeMap<Currency, Integer>();
change = new TreeMap<Currency, Integer>();
initializeCashBox();
}
public static void main(String[] args) {
double amountToReturn = 18.79f; // Set the amount to be changed here
for(Entry<Currency, Integer> entry:cashBox.entrySet()){
Currency currency = (Currency)entry.getKey();
int coinCount = (int)(amountToReturn/(entry.getKey().getCurrencyValue()));
int availableCurrency = (int)(entry.getValue());
if(coinCount > availableCurrency){
coinCount = availableCurrency;
}
change.put(currency, coinCount);
if(coinCount > 0){
amountToReturn = amountToReturn - (coinCount * entry.getKey().getCurrencyValue());
}
}
System.out.println(change);
if(amountToReturn > .1){
System.out.println("Not enough cash");
}
}
private static void initializeCashBox(){
//set the cash box
cashBox.put(Currency.DOLLAR, 50);
cashBox.put(Currency.QUARTER, 0);
cashBox.put(Currency.DIME, 50);
cashBox.put(Currency.NICKEL, 50);
cashBox.put(Currency.PENNY, 50);
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  coin changer application  coin changer app Asked in 1 Companies Q6. Write a Program to right shift single character in a string
Ans. public class RightShiftCharacter {
public static void main(String args[]) {
String str = "Hello";
char[] charArray = str.toCharArray();
for(int count=charArray.length-1;count>0;count--){
charArray[count] = charArray[count-1];
}
String newString = new StringBuilder().append(charArray).toString();
System.out.println(newString);
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string manipulation.right shift character Q7. How can we create objects if we make the constructor private ? Core Java
a. We can't create objects if constructor is private b. We can only create objects if we follow singleton pattern c. We can only create one object d. We can create new object through static method or static blockAns.d. We can create new object through static method or static block
Q8. What will be the output of executing following class ?
public class BuggyBread {
static {
System.out.println("Static Block");
}
{
System.out.println("Initialization Block");
}
BuggyBread(){
System.out.println("Constructor");
}
public static void main(String[] args){
System.out.println("Main Method");
}
}
Core Java
a. Static Block
Main Method b. Static Block
Instance Initialization Block
Main Method c. Static Block
Constructor
Main Method d. Static Block
Instance Initialization Block
Constructor
Main MethodAns.a. Static Block
Main Method
Q9. What will be the output upon executing following class ?
public class BuggyBread {
static {
System.out.println("Static Block");
}
{
System.out.println("Instance Initialization Block");
}
BuggyBread(){
System.out.println("Constructor");
}
public static void main(String[] args){
System.out.println("Main Method");
new BuggyBread();
}
} Core Java
a. Instance Initialization Block
Constructor
Static Block
Main Method b. Static Block
Instance Initialization Block
Constructor
Main Method c. Main Method
Static Block
Instance Initialization Block
Constructor d. Static Block
Main Method
Instance Initialization Block
ConstructorAns.d. Static Block
Main Method
Instance Initialization Block
Constructor
Q10. 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");
Q11. What will be the output of following ?
public class BuggyBread {
private int x;
private Integer y;
BuggyBread(int x,int y){};
public static void main(String[] args){
BuggyBread buggybread = new BuggyBread(1,2);
System.out.println(buggybread.x);
System.out.println(buggybread.y);
}
} Reference Core Java
a. 0 0 b. 0 null c. null 0 d. null nullAns.b. 0 null
Q12. Which of the following is true for == operator ? Core Java
a. For primitives, == checks if the variables on left and right have same data type b. For primitives, == checks if the variables on left and right have same value c. For Objects, == checks if the references on left and right have same data type d. For Objects, == checks if the references on left and right have same valueAns.b. For primitives, == checks if the variables on left and right have same value
Q13. Which of the following is equivalent to following logic ?
Not X && Not Y Core Java
a. x || Y b. Not(X || Y) c. Not(X && Y) d. Not X && YAns.b. Not(X || Y)
Q14. Which of the following http response means the resource is not found ? Java EE
a. 500 b. 200 c. 404 d. 400Ans.c. 404
Q15. What is Dirty Read in Database Transactions ? Database
a. Data Read by Transaction 2 which hasn't yet updated by Transaction 1 b. Data Read by Transaction 2 which has been updated and commited by Transaction 1 c. Data Read by Transaction 2 which has been updated but not commited by Transaction 1 d. Inability of Transaction 2 to read Data when Transaction 1 is updating.Ans.c. Data Read by Transaction 2 which has been updated but not commited by Transaction 1
Q16. Which of following annotation is used to initialize objects before executing set of tests ? Reference Junit
a. @Test b. @Ignore c. @After d. @BeforeAns.d. @Before
a. Static members are shared by all objects of the class. b. We can override static methods. c. Static methods operate on static variables only. d. Static Elements are accessed using class name.Ans.b. We can override static methods.
a. Feature to load the dependencies from Cache b. Feature to load all objects and relationships in advance before they can be used c. Feature to not load dependencies and relationship in advance and load when required d. Feature to not load the dependencies and relationships at allAns.c. Feature to not load dependencies and relationship in advance and load when required
Q19. Which of the following is not the benefit of Lazy Initialization in Hibernate ? Hibernate
a. Laod When required provides better performance b. Object stays lighter c. Less number of Database calls d. Less load on DatabaseAns.c. Less number of Database calls
Q20. The use of volatile keyword facilitates .. Core Java
a. Making Use of Cache for better Performance b. Avoiding use of Cache c. Making use of Backward as well as Forward Cache d. Keeping only one copy of variable in CacheAns.b. Avoiding use of Cache
Q21. Static Polymorphic in Java is achieved through .. Core Java
a. Method Overloading b. Method Overriding c. Variable Overloading d. Variable OverridingAns.a. Method Overloading
Q22. Which of following are serialized ? Core Java
a. static variables b. transient variables c. instance variables d. method local variablesAns.c. instance variables
Q23. Which of the following is not true for Hibernate Cache ? Hibernate
a. First level cache is enabled by default b. First level Cache is Session specific c. First level cache is considered global d. First level Cache came with Hibernate 1.0Ans.c. First level cache is considered global
Q24. Which of the following is not an Hibernate Annotation Hibernate
a. @Id b. @JoinTable c. @ManyToMany d. @AutowiredAns.d. @Autowired
Q25. Which of following is not Spring MVC annotation ? Spring
a. @Autowired b. @Controller c. @JoinColumn d. @TransactionalAns.c. @JoinColumn
Q26. In majority of the cases, the following join will give maximum number of results ? Reference Database
a. Inner Join b. Outer Join c. Left Join d. Right JoinAns.b. Outer Join
a. Left Join and Right Join gives equal number of Results b. Outer Join and Inner Join gives equal number of Results c. Inner Join gives maximum number of results records d. Inner Join gives minimum number of result recordsAns.d. Inner Join gives minimum number of result records
Q28. Listeners are example of .. Design
a. Factory design Pattern b. Abstract Factory Design Pattern c. Singleton Design Pattern d. Observer Design PatternAns.d. Observer Design Pattern
Q29. Which of the following is a configuration management tool ? Tool
a. Github b. Jira c. Tomcat d. EclipseAns.a. Github
Q30. Which of following is not a configuration management tool ? Tool
a. SVN b. Jira c. GitHub d. ClearcaseAns.b. Jira