Java coding interview questions answers
Java coding interview questions are mostly some programming exercises which is asked to be solved in java programming language in limited time during any core Java or J2EE interview. No matter whether you have 2 years of experience or 4 years of experience, There is always some coding interview question in Java programming job you are applying. Actually questions related to Java Coding are increasingly getting popular on Java interviews for two reasons, first its difficult to crack Java coding interview questions than answering fact based questions like Why String is immutable in Java or Why main is static in Java; Second reason of popularity of Coding question in Java interviews is read need of good developers who are required to do lot of coding in projects rather than doing some maintenance works. Since Java is front line language for any server side application, and as complexity of business process and need of performance is increasing, its obvious that amount of coding skill required in Java programmers are getting increased with every passing days, which effectively mean Java coding questions are top of any list of core Java interview question. These Coding interview questions are collected from various Java interviews from friends and collegues and can be a good starting point to refresh your coding skills before appearing on any Java interviews :
Write a Java program to replace certain characters from String like
public String replace(String str, char ch)
This is a tricky Java coding interview question is asked in one of the written test my friend had appeared recently. This Java coding question can be solved in multiple way e.g. by using charAt() or subString() method but any approach throws couple of follow-up question e.g. you may be asked to write two version of this coding exercise one by using recursion and other by using Iteration. They may also ask you to write JUnit test for this function which means handling null, empty string etc.
Write a Java program to print Fibonacci series upto 100?
This is the most popular coding interview question asked in Java programming language. Even though Writing program for Fibonacci series is common, not every Java developer get it right in interview. Again interview can ask to solve this coding interview question by using recursion or Iteration. See here for complete code example of Fibonacci series in Java
Write a Comparator in Java to compare two employees based upon there name, departments and age?
This is pure Java based Coding exercise. In order to solve this Java coding interview question you need to know What is comparator in Java and How to use compare method in Java for sorting Object. This article help you to solve this Java coding question by explaining how to use comparator in Java.
Design vending machine in Java which vends Item based upon four denomination of coins and return coin if there is no Item.
This kind of Java coding interview question appear in written test and believe if you get it right, you are in. These are not easy, you need to design , developer and write JUnit test within 2 to 3 hours and only Good Java developers can solve this kind of Java coding question. What help you is to keep practicing your coding skill even before interview. See this programming exercise in Java to get yourself going.
Write a Java program to check if a number is Armstrong or not ?
Another popular Java coding interview questions which is based on programming logic. In order to solve this problem you need to know what is Armstrong number but that is not a problem because question may specify that and even provide sample input and output. see this Java program to find Armstrong Number in Java to answer this coding question
Write a Java program to prevent deadlock in Java ?
Some of the coding interview question is always based on fundamental feature of Java programming language e.g. multi-threading, synchronization etc. Since writing deadlock proof code is important for a Java developer its also a popular coding question. You can check How to fix deadlock in Java for answer and exact coding in Java
Write Java program to reverse String in Java without using API functions ?
Another classic Java coding exercise mostly asked on 2 to 5 years experienced Java interviews. despite being simple answering this coding question is not easy, specially if you are not coding frequently. Its best to prepare this question in advance, See this post which shows How to reverse String using recursion in Java
Write a Java program to find if a number is prime number or not
Similar coding question and also a very popular Java programming exercise. check this article for answer of this Java coding interview question.
These are some of the Java coding interview questions and answers which appears frequently on Java interviews. I have included link which discusses answers of these Java coding question but you can also find answers by doing google. Please share what kind of coding related question you have faced in your Java interviews.
Other Interview questions from Java67 blog
10 tricky Java interview questions - Answered
10 Linux and UNIX interview questions - Answered
Best Java Collection interview questions answers for practice
Java coding interview questions are mostly some programming exercises which is asked to be solved in java programming language in limited time during any core Java or J2EE interview. No matter whether you have 2 years of experience or 4 years of experience, There is always some coding interview question in Java programming job you are applying. Actually questions related to Java Coding are increasingly getting popular on Java interviews for two reasons, first its difficult to crack Java coding interview questions than answering fact based questions like Why String is immutable in Java or Why main is static in Java; Second reason of popularity of Coding question in Java interviews is read need of good developers who are required to do lot of coding in projects rather than doing some maintenance works. Since Java is front line language for any server side application, and as complexity of business process and need of performance is increasing, its obvious that amount of coding skill required in Java programmers are getting increased with every passing days, which effectively mean Java coding questions are top of any list of core Java interview question. These Coding interview questions are collected from various Java interviews from friends and collegues and can be a good starting point to refresh your coding skills before appearing on any Java interviews :
10 Coding Interview questions answers in Java
Here are my list of 10 Java coding interview questions and answers, which is good to look before appearing on any Java interviews. As I said Java coding questions are top of any list of tough Java interview questions, so better to get it right in first place. Any way 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 problem. Some times knowing more than one way to solve any coding problem in Java also helps to impress interviewer:Write a Java program to replace certain characters from String like
public String replace(String str, char ch)
This is a tricky Java coding interview question is asked in one of the written test my friend had appeared recently. This Java coding question can be solved in multiple way e.g. by using charAt() or subString() method but any approach throws couple of follow-up question e.g. you may be asked to write two version of this coding exercise one by using recursion and other by using Iteration. They may also ask you to write JUnit test for this function which means handling null, empty string etc.
Write a Java program to print Fibonacci series upto 100?
This is the most popular coding interview question asked in Java programming language. Even though Writing program for Fibonacci series is common, not every Java developer get it right in interview. Again interview can ask to solve this coding interview question by using recursion or Iteration. See here for complete code example of Fibonacci series in Java
Write a Comparator in Java to compare two employees based upon there name, departments and age?
This is pure Java based Coding exercise. In order to solve this Java coding interview question you need to know What is comparator in Java and How to use compare method in Java for sorting Object. This article help you to solve this Java coding question by explaining how to use comparator in Java.
Design vending machine in Java which vends Item based upon four denomination of coins and return coin if there is no Item.
This kind of Java coding interview question appear in written test and believe if you get it right, you are in. These are not easy, you need to design , developer and write JUnit test within 2 to 3 hours and only Good Java developers can solve this kind of Java coding question. What help you is to keep practicing your coding skill even before interview. See this programming exercise in Java to get yourself going.
Write a Java program to check if a number is Armstrong or not ?
Another popular Java coding interview questions which is based on programming logic. In order to solve this problem you need to know what is Armstrong number but that is not a problem because question may specify that and even provide sample input and output. see this Java program to find Armstrong Number in Java to answer this coding question
Write a Java program to prevent deadlock in Java ?
Some of the coding interview question is always based on fundamental feature of Java programming language e.g. multi-threading, synchronization etc. Since writing deadlock proof code is important for a Java developer its also a popular coding question. You can check How to fix deadlock in Java for answer and exact coding in Java
Write Java program to reverse String in Java without using API functions ?
Another classic Java coding exercise mostly asked on 2 to 5 years experienced Java interviews. despite being simple answering this coding question is not easy, specially if you are not coding frequently. Its best to prepare this question in advance, See this post which shows How to reverse String using recursion in Java
Write a Java program to find if a number is prime number or not
Similar coding question and also a very popular Java programming exercise. check this article for answer of this Java coding interview question.
These are some of the Java coding interview questions and answers which appears frequently on Java interviews. I have included link which discusses answers of these Java coding question but you can also find answers by doing google. Please share what kind of coding related question you have faced in your Java interviews.
Other Interview questions from Java67 blog
10 Linux and UNIX interview questions - Answered
Best Java Collection interview questions answers for practice


Good collection of Coding and programming question in Java. Surprised not to see Generics, Data structure's, LinkedList etc
ReplyDeleteHere is my list of Java programming interview question :
ReplyDeleteWrite a Java program to create Thread and Stop Thread (remember there is no stop method for stopping thread in Java)
Write a Java program to sort Map based on keys without using TreeMap
Write a Java program to create deadlock ? how do you fix it ?
Write a Java program to find maximum number in Array
I agree that these Java programming question are basic but in my opinion you need to be better than average programmer to be able to write code which does that correctly.
very nice collection of information and improve them.
ReplyDeleteRe question "Write a Java program to replace certain characters from String" seems like the example method is missing a replaceWith parameter no?
ReplyDeletepublic String replace(String str, char old, char new)