![]() numeric order for number, and alphabetic order for String, while Comparator can define any arbitrary sorting.Ī good follow-up question can also be the difference between Comparator and Comparable in Java, so be ready for that. Just remember that Comparable has compareTo() method and use to sort object based upon there natural order e.g. This article helps you to solve this Java coding question by explaining how to sort object in Java using Comparable and Comparator. Sorting is one of the most logical and practical question on technical interview and ability to sort Java object is must to code in Java. In order to solve this Java coding or programming interview question, you need to know What is a Comparator in Java and how to use compare method in Java for sorting Object. This is a pure Java based Coding exercise. Write a Comparator in Java to compare two employees based upon there name, departments, and age? Here is a sample Java program to solve the FizzBuzz problem : ![]() This question is very basic but can be very trick for programmers, who can't code, that's why it is used to differentiate programmers who can do coding and who can't. This is also one of the classical programming questions, which is asked on any Java programming or technical interviews. For numbers which are multiples of both three and five print " FizzBuzz" But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". FizzBuzz problem : Write a Java program that prints the numbers from 1 to 50. See here for complete code example of Fibonacci series in JavaĤ. This Java programming question also test your problem-solving skills and if you come up with an original solution, that may even help. By the way this programming question is quite common on technical interviews not just Java but also C, C++ or Scala, but knowing API definitely helps to produce better solution quickly.Īgain interview can ask to solve this programming interview question, by using recursion or Iteration. They may also ask you to write JUnit test for this function which means handling null, empty string etc. This Java coding question can be solved in multiple way like by using charAt() or substring() method, but any approach throws couple of follow-up question like you may be asked to write two version to solve this coding exercise, one by using recursion and other by using Iteration. This is a tricky Java coding interview question and it was asked in one of the written test my friend had appeared recently. Public String replace(String str, char ch) Write a Java program to replace certain characters from String like This list mainly contains basic programs asked on Interviews.ġ. Sometimes knowing more than one way to solve any programming question or coding problem in Java also helps to impress the interviewer. As I said Java coding questions are mostly based on programming, logical analysis and problem-solving skill and are on top of any list of tough Java interview questions, so better to get it right in first place.Īnyway, you may be able to solve and find answers of these Java coding questions by yourself, but if you stuck do a google, and you can get many alternative ways to solve these problems. Here are my list of 10 Java coding interview questions and answers, which is good to prepare before appearing on any Java interviews. ![]() 16 Programming Assignments, Homeowrk, and Coding Interview questions answers in Java
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |