java coding programming interview questions

java coding programming interview questions

top 40 java coding interview questions: It’s common whenever a fresh candidate (s) give interview then after theoretical of java they ask for write program on java base. The program can be anything like “Array sorting”, “swiping values between two variables”, “Fibonacci Series” etc. In this series I have tried to solve each and every most common question which is asked by interviewer by fresher or intermediate programmers on interview.

1

Fibonacci series

Solution

In this test, interviewer may ask write a program which print a “Fibonacci Series” or interviewer may ask that write a program which get input from user and print “Fibonacci Series” of given input. Here is just example of “Fibonacci Series” if user give input 10 then given 10 number “Fibonacci Series” will be e.g. 1 1 2 3 5 8 13 … . up to a given number.

2

A prime number

Solution

In this test, Interviewer may ask write a program which prints “Prime Number” after theoretical questions. Prime number is a number that is greater than 1 and divided by 1 or itself only. In other words, prime numbers can’t be divided by other numbers than itself or 1.

For example 2, 3, 5, 7, 11, 13, 17…. are the prime numbers.

3

String Palindrome

Solution

This test is most common which most time interviewer may asks to write a program which prints given String or number is “Palindrome” or not. Interviewer may ask “String Palindrome” or number “Palindrome” without using any library (pre define function).

For example, “Palindrome” means if you reverse given String or number then output will be same as previous/ original form. E.g given String is abba and your are checking abba is palindrome or not the if you reverse to given String then output will be same so that means it’s palindrome String.

4

Integer Palindrome

Solution

This question is same as asked by interviewer by “String Palindrome”. In this test (program) interview may ask write a program which show given number is “Palindrome” or not.

For example, given number is 1221 then you have to check is it “Palindrome” or not? In our condition 1221 it’s is “Palindrome” number.

5

Avoiding deadlock in Java

Solution

Mostly asked question by 2 to 3 years of experienced programmers or higher. The interviewer simply asked you to write code where a resource is accessed by multiple threads. Where you need to write code in such a way that no deadlock should occur. The trick to solving this problem is acquiring resources in order and release them in reverse order. I will try to define by several ways which make easy to understand.

For Example, first acquire resource R1 and only if you have got R1 to go for R2. This way, you can avoid deadlock.

6

Factorial

Solution

This question most time asked by interviewer by fresher candidate (s), interviewer generally judge the candidate (s) that he/she can write a simple program or not.

7

Reverse a String

Solution

This is most common question which asked by fresher candidate (s). Interviewer may ask after some theoretical questions that write a program which get input string value from user and print reverse of given string. Or simple interviewer may give you any string value and ask print reverse of given string without using any library (pre define function).

8

Remove duplicates from an array

Solution

This question is mostly highlighted question which asked by fresher and 1-2 years of experienced programmers or higher. Interviewer may ask write a program which contain numbers of elements in array, if there is duplication in elements then remove duplications from array. Array elements can be integer type, numeric type or character type. Programmer hasn’t allowed use any collection framework API.

9

Print Pyramid Pattern

Solution

This question mostly asked by fresher programmers in interview. Interviewer ask to write a program which print “Pyramid Patter” in Java, C, C++, Php, Python or any language.

Note: there are several “Pyramid Patterns” which interviewer will give you any pattern and that pattern programmers have to show through the programming. In this series I have tried to define each Pattern which is most common in interview.

10

Print repeated characters of String?

Solution

This is common question which mostly asked by fresher to write a program which print repeated characters from String. Interviewer may not give permission for using any pre define function (API).

11

How to check leap year

Solution

This question mostly asked by fresher programmers to write a program which print that given year is leap year or not. Some case interviewer may ask, get year input from user and print that user given input is leap year or not?

12

String Anagram

Solution

An anagram of a string is another string that contains the same characters, only the order of characters can be different.

For example, “abcd” and “dabc” are an anagram of each other. Interviewer may ask to write a program which print both string are “Anagram” or not, if both string are Anagram then return true otherwise false. This question mostly asked by experience programmers.

java coding programming interview questions

13

Reverse a number

Solution

Write a program which reverse given number without using any API method. This question asked by fresher or 1-2 years experienced programmer.

14

Sort array without using API method.

Solution

Most common question asked to fresher or experienced programmers. Interviewer may ask are give you an array with multiple elements and ask to sort given array element without using any API method.

For example: If interviewer give {6, 2, 8, 1, 7, 4, 3} then after sorting output will be {1, 2, 3, 4, 6, 7, 8}.

15

Swap two numbers without using third variable

Solution

Most common question asked by interviewer to programmers. Interviewer may ask swap two values without using third variable.

For example: int a = 10; int b = 20; after swapping a variable value will be 20 and b variable value will be 10.

16

Swap two numbers using third variable

Solution

This question asked by fresher or internee programmers to write a program which swap two values using third variable.

17

Password contain special characters

Solution

This question is most highlighted question which most time asked by experienced programmers. Interviewer may ask write a program which get string input from user (as password) and print true if given input contain special characters else return false.

For example: If user is given input is “admin” at runtime then return false because there is not any special character in given input. Else if user given input is “Admin123” then it return true because there is Uppercase, lowercase and digit in given password.

18

Count Vowel and consonant from String.

Solution

Most common question which asked by interviewer to write a program which count total number of characters, Number of vowels and Number Consonants from String. Interviewer may give you a String value (paragraph) then programmers have to write a program to find total characters, vowels and consonants.  

For example: Given value is “hello world” then program have to find total characters, vowels and consonants.

19

find the second-highest number in an array

Solution

Always common question which asked by interviewer to write a program which find the second highest number (element) from array. Remove all white spaces from a string without using API method. This question mostly asked to fresher and experienced programmers to write a program which remove white spaces from given string without using API method.

For example: If String is “hello world” then after removing white space output will be “helloworld”.

20

Convert Lowercase to Uppercase and Uppercase to Lowercase without using API method?

Solution

This question asked by interviewer to fresher and experienced programmers to write a program which print uppercase letters to lowercase and lowercase to upper.

For example: If given string (value of string variable) is “HeLLo World” then output will be “hEllO wORLD”.

21

Find the Maximum/ highest value (element) from Array without using API method

Solution

For example: there is an array {1,7,50,12,48}, then the answer should be 50 as it is the maximum/ highest value in the given array.

22

How to Convert Math number to equivalent readable word in java?

Solution

This question most time asked by interviewer to fresh and experience programmers to write a program which convert math numbers to words.

For example: if given numbers are “527” then output will be “five hundred twenty seven”.


Follow Us on Facebook group & YouTube

BATTLES OF ISLAM MCQS BATTLES OF ISLAM MCQS

Leave a Reply

Your email address will not be published. Required fields are marked *