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. |
|
| ||||
Core Java - Interview Questions and Answers for 'Code optimization' - 3 question(s) found - Order By Rating | ||||
| ||||
Ans. if x==y turns out to be true x.equals(y) will be true too. If x.equals(y) could be true even if x==y is true or not. So the only possible outcomes are 1 || 1 = 1 0 || 1 = 1 0 || 0 = 0 i.e the outcome of x.equals(y) check for x==y is not required in this if statement. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  if statement  control statements  == and equals  ==  .equals   code optimization | ||||
Try 1 Question(s) Test | ||||
Related Questions | ||||
Difference between == and .equals() ? | ||||
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? | ||||
| ||||
Ans. x==y means that both references have same type and are pointing to same memory location and hence would always mean that they have same value. x.equals(y) is not required in this case. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  if statement  control statements  == and equals  ==  .equals   code optimization | ||||
Try 2 Question(s) Test | ||||
Related Questions | ||||
Difference between == and .equals() ? | ||||
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? | ||||
This question can be asked in different variants like performace improvement of an application, improving performance for DB communication etc. | ||||
| ||||
Ans. This depends on entirely upon the code type. For example 1.If its just logic, we can try it to short circuit or put the if / switch case with maximum probability in the beginning. 2. Can use faster data structures, for eg - random retrieval instead of sequence / iterator 3. Working with primitive types or even bytes instead of Objects, even though it may result in marginal improvement. 4. If its service call, then service call with bulk load can help 5. If DB Operation, then with use of Indices , Views or using ORM , cache etc. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  performance improvement  code optimization Asked in 1 Companies | ||||
Related Questions | ||||
What things you would care about to improve the performance of Application if its identified that its DB communication that needs to be improved ? | ||||