Java Interview Questions
- 0of 0 votes
AnswersCan we overload the main() method?
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 0of 0 votes
AnswersWhat is the difference between constructor and method?.
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 0of 0 votes
AnswersDoes java supports multiple inheritance?
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 0of 0 votes
AnswersWhat is the method overriding?
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 0of 0 votes
AnswersWhat is the method overloading in java?
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 0of 0 votes
AnswersWhat is polymorphism in java?
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 0of 0 votes
AnswersWhat is constructor overloading? What is the use of constructor overloading?
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 0of 0 votes
AnswersWhat do you mean by inheritance in java?
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 0of 0 votes
AnswersWhat are the fundamental principles of object oriented programming? / What are the OOPS concepts?
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 0of 0 votes
AnswersWhat are the main features of Java?
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 0of 0 votes
AnswersCan main() method in Java can return any data?
- mythili.vestino April 30, 2021 in India for HR| Report Duplicate | Flag | PURGE
vestino technologies HR Executive Java - 1of 1 vote
AnswersYou have an integer array. Starting from arr[startIndex], follow each element to the index it points to. You continue to do this until you find a cycle. Return the length of the cycle. If no cycle is found return -1
- rock January 26, 2021 in United States
forexample {1, 0}, 0) => 2
{1, 2, 0}, 0) => 3| Report Duplicate | Flag | PURGE
Goldman Sachs Senior Software Development Engineer Java - 0of 0 votes
AnswersIf ( a = True){
- 11gupt October 10, 2020 in United States
If (b = True){
Approve credit card;
}
Else {
Disapprove credit card;
}
}
Else {
If(C=False){
IF(D=True){
Approve Credit card;
}
else {
Diapprove credit card;
}
}
}
Simplify above written code.| Report Duplicate | Flag | PURGE
Data Engineer Java - 0of 0 votes
AnswersA Fibonacci sequence is defined recursively by:
- Manoj September 17, 2020 in India for Senior Software Engineer
F0 = 0
F1 = 1
Fn = Fn − 1 + Fn − 2, for integer n > 1.
One way of generalizing the Fibonacci sequence is by starting with any pair of numbers and extending to negative values of n.
Given two terms of a generalized Fibonacci sequence Fp and Fq, their positions p and q respectively and a position r, find Fr.
Input Format
The first line of the input contains an integer t denoting the number of test cases.
Each test case contains three lines.
First line of each test case contains two space separated integers p and Fp
Second line contains two space separated integers q and Fq
Third line contains an integer r
Output Format
For each test case, print Fr which is the term of the sequence at position r.
If Fr is not an integer, represent it as an irreducible fraction in the form a/b where b > 0.
Sample Input
0 1
6 13
10
3 65
6 315
-10
0 11
1 -6
2
9 36
15 646
-5
11 72
20 5473
6
Sample Output
89
4620
5
-1/4
13/2| Report Duplicate | Flag | PURGE
Sap Labs Senior Software Development Engineer Java - 0of 0 votes
AnswersJava:
- roxanadaniela35 April 10, 2020 in United States
Managing extreme sports locations:
In such locations, are period of the year when this actities can be performed(ski December - February, Kiting May August, ATV all year), each sport /location usually has an average cost/day.
The sports have hierarcal structure and countaind the country, region and city, we need an ADD, REMOVE, UPDATE; GET a location and all its informations.
exemple:
Switzerland:
Zurich:sky(dec, feb), price 12 $
Berna:ATV - all time , price 10$| Report Duplicate | Flag | PURGE
JDA Java Developer Java - -1of 1 vote
AnswersAs you know, most Operating Systems are written in Java, what’s special about pointers in Java ? *
- donk August 26, 2019 in United States for Engineering| Report Duplicate | Flag | PURGE
Notfamous Technical Support Engineer Java - 1of 1 vote
AnswersUse synchronized, wait() and notify() to write a program such that below mentioned conditions are fulfilled while reading and writing data to a shared resource.
- neer.1304 July 26, 2019 in United States
When a write is happening, no read or other write should be allowed(read and write threads should wait)
When a read is happening, no write should be allowed (write threads should wait) but. other read threads should be able to read.
Donot use any API classes e.g. ReadWriteLock, AtomicInteger etc..| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Java - 1of 1 vote
AnswersShopping Cart Programming test.
- Vimal July 11, 2019 in India
There are multiple types of customer(Regular, Premium) they have been given a discount based on their purchase amount. for e.x
Premium Customer
1) 0-$5000 0%
2) $5000-$10000 10%
3) 10000 - above 20%
Regular Customer
1) 0-$4000 10%
2) $4000 - $8000 15%
3) $8000 - $12000 20%
4) $12000 - above 25%
Read input from console:
Input:
Regular
$5000
Output:
$5000
Input:
Premium
$7000
Output
$8000| Report Duplicate | Flag | PURGE
CDK Global Backend Developer Java - 1of 1 vote
AnswersYou have three Arrays.
- monowar1993 June 14, 2019 in Netherlands for Android
A = {2, 5, 3, 2, 8,1}
B = {7, 9, 5, 2, 4, 10, 10}
C = {6, 7, 5, 5, 3, 7}
make an array from this three arrays which elements is present in at least two array.
This question was followed by instead of three arrays. If you have a list of array then what will be the solution? Also what will be the time complexity?| Report Duplicate | Flag | PURGE
Booking.com Android Engineer Java - 5of 5 votes
AnswersA happy number is defined by the following process. Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers.
- sk2244 March 19, 2019 in India
Input:
Your program should read lines of text from standard input. Each line contains a single positive integer, N.
Output:
If the number is a happy number, print 1 to standard output. Otherwise, print 0.| Report Duplicate | Flag | PURGE
Sabre Holdings Java Developer Java - 0of 0 votes
AnswersYou have oracle database table , and AURORA AWS table with same fields , write a java lambda function to migrate data from oracle table to aurora. Also it should be realtime, if a new record is added to oracle it should update aurora db table as well.
- Brucewratner January 29, 2019 in United States| Report Duplicate | Flag | PURGE
Amazon Backend Developer Java - 0of 0 votes
AnswersMaximum Pairs
You are given N pencils. You have to make pairs of pencils.
The condition for making pairs is:
If(a,b) is any pair of pencils then b >= 2 * a. Here a and b are the sizes of pencils.
Now you have to find out the number of such pairs and the number of pencils which could not be paired with any pencils.
Note:
You need to pair the pencils in such a manner that the maximum number of pairs are formed.
Input Format:
The first line consists of number of test case T.
Each test case consist of:
- First line consists of a single integer N.
- Second line consists of N space-separated integers denoting the size of pencils Si.
Output Format:
For each test case, print two space-separated integers, first denoting the number of pairs formed and second denoting the number of unpaired pencils.
Answer for each test case should come in a new line.
Constraints
1<T<=10
1<=N<=10^5
0<=Si<=10^5
Sample Input
2
5
1 2 3 4 5
4
1 2 4 4
Sample Output
2 1
2 0
Explanation
In the first test case:-
we can form the following pairs:
(1, 3), (2, 4) and 5 remains unpaired hence maximum pairs are 2
In second test case:-
(1, 4), (2, 4) are two pairs hence no pencil left unpaired
- Karan Khosla January 04, 2019 in United States for 4public class Test { public static void main(String[] args) { } static int[] solve(int[] arr) { // the value at first index of array to be returned is number of pairs // formed and value at second index is unpaired swords. } }
| Report Duplicate | Flag | PURGE
Java Developer Java - 1of 1 vote
AnswersInt minSemsToFinishAllCourses(Map<string, list<string>)
Given a map containing courses and the list of prerequisites for that course in no particular order, determine the least number of semesters to finish all the courses.
- stevejabs November 22, 2018 in United States
You have to take all prerequisites before you take a given course.
Eg.
Calculus : English, math2
Math2: math 1, Arabic, english
Math1: english
English: <>
Arabic:<>
Give an algorithm for the above and code using java| Report Duplicate | Flag | PURGE
Algorithm Java - 1of 1 vote
AnswersGiven the arraylist<meals> input, find the number of dishes with unique ingredients.
class meals{ String cuisine; ArrayList<String> dish = new ArrayList<String>(); meals(String s, String[] arr){ cuisine = s; for(String i:arr){ dish.add(i); } } }
Example:
- venkataratnamkumar7777 September 18, 2018 in United States
Input: [
{
"cuisine" : "American",
"dish" : ["lettuce", "cheese", "olives", "tomato"]
},
{
"cuisine" : "Mexican",
"dish" : ["lettuce", "cheese", "pepper", "tomato"]
},
{
"cuisine" : "French",
"dish" : ["lettuce", "cheese", "pepper", "tomato"]
},
{
"cuisine" : "Continental",
"dish" : ["lettuce", "cheese", "olives", "tomato"]
},
]
Output: 2
Because there are two unique ingredient-dishes; {Mexican, French} and {American, Continental}.
I have tried different methods, but could not get to the solution. Thank you!| Report Duplicate | Flag | PURGE
Yelp Software Engineer Java - 9of 9 votes
Answersprint hockey stick number in pascal triangle where row of triangle can be upto 30000 and length of stick can be upto 100.
- Randhir September 09, 2018 in India| Report Duplicate | Flag | PURGE
Wissen Technology Software Developer Coding Data Structures Dynamic Programming Java - 0of 0 votes
AnswersTwo players and are playing a game.They are given binary numbers as input. Each binary number is represented as a string of characters '0' or '1'. The string always ends at '1'. In one move each player decides a bit position . Then he visits all the numbers and if their bit at that position is '1' then he changes it to '0'. It is mandatory to flip(change '1' to '0') bit of atleast one number in each move. The player who is unable to make a move loses. Player begins the game.
- fordosianDevil August 19, 2018 in United States
Input
First line contains a number as input. Next lines contain a binary string each.
Output
Print A if player A wins , B otherwise. In the next line print the move number of the last move of the winning player.| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswerI want to implement a simple HTTP Denial-of-Service protection. There are clients that can send HTTP request to a Server (i.e. a GET Method of http://10.1.1.2:8080/?clientId=7)
- Patrick July 18, 2018 in United States
if in an interval of 10 seconds more then 10 request comes from a specific client the 11th, 12th.. requests will get blocked. until 10 seconds from the first request will pass and then a new time windows of 10 seconds will be open. the idea is no more than 10 requests per 10 secs.
The time frame starts on each client’s first request and ends 10 seconds later.
I want to implement this logic on the server. Which data structures/collection/custom made object would you build to implement such a logic...
it is also important to have a threats safe solution.. and performances is also a factor here..
Thanks.| Report Duplicate | Flag | PURGE
Dropbox Software Trainee Java - 0of 0 votes
AnswersRound 3- Find the first duplicate occurence of a number in an array
- prashant.tah July 03, 2018 in India| Report Duplicate | Flag | PURGE
Oracle Senior Software Development Engineer Java - 0of 0 votes
AnswersRound 3 - Write a java program to print a matrix in spiral
- prashant.tah July 03, 2018 in India| Report Duplicate | Flag | PURGE
Oracle Senior Software Development Engineer Java - 0of 0 votes
AnswersRound 2 - Write a java program to determine if a 10 digit number is magic number.A number is magic number if it has all digits between 1 to 6 occuring in it or if it has any number between 0 to 9 occuring thrice or if it contains three consecutilvely increasing or decreasing digits differing by 1 example 345 or 543
- prashant.tah July 03, 2018 in India| Report Duplicate | Flag | PURGE
Oracle Senior Software Development Engineer Java