Core Java - Interview Questions and Answers for 'Coding' | 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 - Order By Newest

   
 Q101. Given a string with multiple opening and closing brackets, determine if the string is valid or not ( to see if the string has all closing brackets for each opening bracket ) ?Core Java
 This question was recently asked at 'Amazon'.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     code  coding     Asked in 1 Companies


 Q102. Write a method, that compare two numbers and return the bigger one ?Core Java
Ans. int compare(int a, int b) {
a>b? return a: return b;
}

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

   Like         Discuss         Correct / Improve     code  program  coding     Asked in 1 Companies      basic


 Q103. Write a Program for insertion sort.Core Java
 This question was recently asked at 'Ola Cabs'.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     program  code  coding  insertion sort   sort     Asked in 1 Companies


 Q104. How to calculate lcm of two numbers ?Core Java
 This question was recently asked at 'HCL Tech'.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     coding  code     Asked in 1 Companies


 Q105. Write a Program to find age by birth date ?Core Java
Ans. LocalDate today = LocalDate.now();
LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1);
Period p = Period.between(birthday, today); //Now access the values as below
System.out.println(period.getDays());
System.out.println(period.getMonths());
System.out.println(period.getYears());

  Sample Code for LocalDate

  Sample Code for Period

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

   Like         Discuss         Correct / Improve     coding  code  date  LocalDate  Period     Asked in 1 Companies


 Q106. What will be the output of following code

class TestMain {
public static void main(String[] args) {
String s1 = "ravi";
String s2 = new String("ravi");
Integer i = 10;
Integer a1 = new Integer("10");
System.out.println(s1 == s1);
System.out.println(i == a1);
}
}
Core Java
Ans. false
false

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

   Like         Discuss         Correct / Improve     object equality  ==  coding  code     Asked in 1 Companies


 Q107. Write a Program to check if the entered number is a Duck Number ( Number having 0 in it ) ?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     code  coding  duck number


 Q108. Suppose we have a string "Java is object oriented language" and we have to reverse every alternate word in string. How would we do that using Java program.Core Java
 This question was recently asked at 'datalake solutions'.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     string manipulation  code  coding     Asked in 1 Companies


 Q109. A Kid can go up 1, 2 or 3 stairs in one step. Write a method that takes number of steps in a stair will print all possible ways he can take.

For example , printAllCombinations(3) should print

111
12
21
3

Similarly , printAllCombinations(4) should print

1111
121
13
211
22
31
4
Core Java
Ans. public static String findStep(int n) {
if (n == 1 || n == 0)
return 1;
else if (n == 2)
return 2;
else
return findStep(n - 3) + findStep(n - 2) + findStep(n - 1);
}

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

   Like         Discuss         Correct / Improve     coding     Asked in 1 Companies


 Q110. Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.Data Structure
 This question was recently asked at 'Amazon'.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     arrays  coding  code     Asked in 1 Companies


 Q111. Create a custom hashmap using synchronization.Core Java
 This question was recently asked at 'Deutsche Bank'.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     hashmap  coding     Asked in 1 Companies      advanced


 Q112. Write a Program to find number of lines , words and characters in a File.Core Java
Ans. import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class FileUtility {

public static void main(String[] args) {
System.out.println(printFile("/home/userme/notes"));
}

private static int printFile(String filePath) {
int wordCount = 0;
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line = null;
String[] wordsArray = null;

while ((line = br.readLine()) != null) {
wordsArray = line.split(" ");
wordCount = wordsArray.length;
}
} catch (IOException e) {
e.printStackTrace();
}
return wordCount;

}
}

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

   Like         Discuss         Correct / Improve     code  coding     Asked in 2 Companies


 Q113. Write code to get count of every 5 letter word in a string using lambda expression

Core Java
Ans. String str = "I had been saying that he had been there";

Map<String,Long> countWords = Arrays.asList(str.split(" ")).stream().filter(p->p.length() = 5).collect(Collectors.groupingBy(p->p,Collectors.counting()));

System.out.println(countWords);

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

   Like         Discuss         Correct / Improve     Collectors  lambda  filter  coding  java 8


  Q114. Find Intersection/union between two arrays.Core Java
 This question was recently asked at 'Bristlecone,Amazon Lab126,Amazon,Microsoft,Facebook,NCR,Google'.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     arrays  code  coding     Asked in 7 Companies        frequent


 Q115. Design a Program to clone an object and all it's children.
Design
 This question was recently asked at 'Bloomberg'.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     code  coding  cloning  design pattern   cloning design pattern     Asked in 1 Companies


 Q116. Given a String with letters , numbers and special characters , extract Tokens from it. The rules for Token extraction are ac follows

1. Should for token of all characters till a number or special character is found
2. Should form token of all numbers till a character or special character is found
3. Special character in itself is a token
4. Ignore white spaces

For example - Bob Said "He is here"

should result in

Bob A
Said A
" S
He A
is A
here A
" S

where a is specifying alphabet and S as special character
Design
 This question was recently asked at 'Bloomberg'.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     code  coding  string     Asked in 1 Companies


 Q117. How many bytes a character takes with UTF-8 encoding ?Encoding
Ans. it takes 1 to 4 bytes

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

   Like         Discuss         Correct / Improve     utf  unicode  utf-8     Asked in 1 Companies


 Q118. How to calculate string length without using inbuilt functionCore Java
 This question was recently asked at 'Softenger'.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     code  coding  design  string length     Asked in 1 Companies      basic


 Q119. in the following class:
class A {
void methoda(Object o) {
Sysout("Object");
}

void methoda(String s) {
Sysout("String");
}

public static void main(String []args) {
A a = new A();
a.methoda(null);
}
}

what will be printed?
Core Java
Ans. String

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

   Like         Discuss         Correct / Improve     Code  Coding  method overloading     Asked in 1 Companies


 Q120. Can you share your experience with encoding and encryption ?Encoding
 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     encoding  encryption


 Q121. What is the difference between html encoding and url encoding ?Encoding
Ans. HTML Encoding escapes special characters in strings used in HTML documents whereas url Encoding replaces special characters with characters so that they can sent within url.

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

   Like         Discuss         Correct / Improve     


 Q122. Does spaces get's encoded in html encoding ?Encoding
Ans. Yes they get html encoded. i.e &nbsp; instead of empty space.

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

   Like         Discuss         Correct / Improve     


 Q123. What will be the output of following code ?

public class BuggyBread {

   private int x;

   private BuggyBread(int x){
      x = x;
   };

   public static void main(String[] args){
      BuggyBread buggybread = new BuggyBread(5);
      System.out.println(buggybread.x);
   }
}
Core Java
a. compilation error
b. undefined
c. 0
d. 5

Ans.c. 0

previous 30   

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: