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

   



Core Java - Interview Questions and Answers for 'Coding' - 122 question(s) found - Order By Rating

next 30
 Q1. Does spaces get's encoded in html encoding ?Encoding
Ans. Yes they get html encoded. i.e   instead of empty space.

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

   Like         Discuss         Correct / Improve     


 Q2. 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     


 Q3. 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


 Q4. 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


 Q5. Write code to create a folder if it doesn't exist.Core Java
Ans. File folder = new File(path);
      
if(!folder.exists()){
try {
folder.mkdir();
            
} catch (Exception e) {}
}

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

   Like         Discuss         Correct / Improve     code  coding  file handling      basic


 Q6. 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


 Q7. 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


 Q8. 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


 Q9. 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


  Q10. 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


 Q11. 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


 Q12. 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


 Q13. Find different combination of given String and trace the output

Core Java
Ans. private void permutation(String prefix, String sufix)
{
int ln = sufix.length();
if(ln == 0) {
System.out.println(prefix);
} else {
IntStream.range(0, ln).forEach(i->permutation(prefix sufix.charAt(i), sufix.substring(0,i) sufix.substring(i 1, ln)));
}
}

call:permutation("", "abcdef");

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

   Like         Discuss         Correct / Improve     String  code  coding     Asked in 1 Companies


 Q14. 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


 Q15. 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


 Q16. 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


 Q17. 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


 Q18. 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


 Q19. 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


 Q20. Write code to find second largest number in an array of integers.Core Java
Ans. int arr[]={1,3,5,6,4,8,9,2,10};
Arrays.sort();
System.out.println(arr[arr.length-1]);

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

   Like         Discuss         Correct / Improve     code  coding  find in array     Asked in 1 Companies


 Q21. 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


 Q22. 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


 Q23. 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


 Q24. 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


 Q25. 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


 Q26. Write a Program to convert a binary to number ?Core Java
Ans. int convert(int binaryInt) {
int sumValue=0;
int multiple = 1;
while(binaryInt > 0) {
binaryDigit = binaryInt;
binaryInt = binaryInt /10;
sumValue = sumValue (binaryDigit * multiple);
multiple = multiple * 2;
}

return sumValue;
}

 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      basic


 Q27. How can you extract integers from string values and add (sum it up) all the extracted integers? e.g "James34long4island322in3rdAvenue" ---> 34 4 322 3 = 363Core Java
 This question was recently asked at 'Horizon 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     coding  code     Asked in 1 Companies


 Q28. Implement stack using generics in Java.Data Structure
 This question was recently asked at 'Bind Software Innovations'.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     oding  cod     Asked in 1 Companies


 Q29. Write a program for 0 and cross games? Core Java
 This question was recently asked at 'Compro Technologies'.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.0 and cross game     Asked in 1 Companies


 Q30. Write a program to reverse words of a sentence.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


next 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: