Java Developer Interview Questions
- 0of 0 votes
AnswersGiven below code snippet, what would be the output?
- Flash May 13, 2017 in Indiapublic class DemoThread extends Thread { private int x = 2; public static void main(String[] args) throws Exception { new DemoThread().method(); } public DemoThread(){ System.out.println("test"); x = 5; start(); } public void method() throws Exception { join(); x = x - 1; System.out.println(x); } public void run(){ System.out.println("run"); x *= 2; } }
| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java - 0of 0 votes
AnswersFor code snippet given below, what would be the output?
- Flash May 13, 2017 in IndiaString s8 = "AB"; String s9 = s8.intern(); if(s9.equals(s8) && s9 == s8) System.out.println("All Equal"); if(s9.equals(s8) && s9!=s8) System.out.println("equals Equal"); if(!s9.equals(s8) && s9==s8) System.out.println("== Equal"); if(!s9.equals(s8) && s9!=s8) System.out.println("Nothing Equal");
| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java - 0of 0 votes
Answerswhat is the time complexity for java.util.Random.nextInt()
- ajay.raj May 05, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswersJamie is walking along a number line that starts at point 0 and ends at point n. She can move either one step to the left or one step to the right of her current location , with the exception that she cannot move left from point 0 or right from point n. In other words, if Jamie is standing at point i,she can move to either i-1 or i+1 as long as her destination exists in the inclusive range [0,n]. She has a string ,s , of movement instruction consisting of the letters 1 and r , where 1 is an instruction to move one step left and r is an instruction to move one step right.
- Ashish Dass May 01, 2017 in India for Java
Jamie followed the instructions in s one by one and in order .For Example if s=‘rrlr’,she performs the following sequence of moves :one step right ->one step right ->one step left -> one step right .Jamie wants to move from point x to point y following some subsequence of string s instruction and wonders how many distinct possible subsequence of string s will get her from point x to point y. recall that a subsequence of a string is obtained by deleting zero or more characters from string .
it has four parameters
A String , s giving a sequence of eduction using the characters l( i.e. move left one unit ) and r (i.e. move right one unit)
An integer n, denoting the length of the number line.
An integer x, denoting jamie’s starting point on the number line
An integer y , denoting Jamie’s enidng point on the number line.
The function must return an integer denoting the total number of distinct subsequence of string s that will lead Jamie from point x to point y as this value cab be quite large .
Sample Input
rrlrlr
6
1
2
out put =7| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Algorithm - 0of 0 votes
AnswersWhat design pattern is used to implement a SynchronizedHashMap?
- ajay.raj April 17, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswersIn product System , we receive lots of data and in some case data contains duplicate .
- Ashish Dass March 28, 2017 in India for CRM
In order to process the data correctly we need to identify the row which contains the duplicate .
In this problem , You are receiving data onto 2d Array (m*n ) formate
you and need to find the number of row containing duly data based on on criteria .
Opretaion 1 Return the number of row containing the duplicate data in rows ( minimum count of duplicates can vary ) .
Opreation 2 Retrun the number of rows wherever there are duplicates in the column across the row
(minimum count of of duplicates to consider the row can varry )
if none of the above operating the program will return - 1 .
static int findDuplicates(int[][] data, int operation, int numOfDuplicates) {
}
Example
1,3,5,9
1,2,1,2
1,4,7,9
20,25,20,35
Operation 1 answer = 2
Operation 2 numOfDuplicate=2 then answer = 1| Report Duplicate | Flag | PURGE
Adjetter Media Network Pvt Ltd. Java Developer - 0of 2 votes
AnswersThere is an island surrounded by oil mines. You will be given n companies and m oil mines having values. You have to distribute the mines to "n" companies in fair manner. Remember the companies can have oil mines adjacent to each other and not in between of each others.After distributing them compute the differnce of oil mines from the company getting highest and company getting lowest. This number should be minimum.(then only the distribution can be termed as fair).
- sunny.1rn12cs113 March 26, 2017 in India
Example
Input
2
2 4
6 13 10 2
2 4
6 10 13 2
output
5
1| Report Duplicate | Flag | PURGE
Samsung Java Developer Data Structures - 0of 0 votes
AnswersI had one hour to write a simple object oriented java program of Student registration and de registration to a course . A particular course has some max slots that can be allocated to students . Question was simple enough but due to time constraint could not complete .Godspeed
- Hermione February 01, 2017 in United States| Report Duplicate | Flag | PURGE
Allegient Java Developer Object Oriented Design - 0of 0 votes
AnswerImplement Java Set using TDD
- steelrahul January 18, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswersSituation - You have millions of records(Strings) and user is typing "abc" in search box . Your task is to display strings from records in the sequence.
- surendrapandey3788 January 12, 2017 in India
e.g String in the record contain "abc" starting should appear first, then string which has "abc" in the second, should apprear later as below.
String - fabcsdf,asdfabc,dfadsfsdfabc,abckdf,ddfabc...
Displays suggestion like....
abckdf
fabcsdf
ddfabc
asdfabc
dfadsfsdfabc
Question - Which data structure you would use to stor this ?
And how will you implement to get this(shorted) result| Report Duplicate | Flag | PURGE
Nagarro Java Developer Java - -2of 2 votes
Answers - sivathespark November 17, 2016 in United States for 1| Report Duplicate | Flag | PURGE
Java Developer - 0of 0 votes
AnswersDesign a rules engine. It should run in at least linear time and should efficiently handle repetitive attributes in different rules. E.g.,
- angshu1986 September 18, 2016 in India
Attributes:
1. Digit check
2. Character check
Rule:
1. Rule 1 - input should be digit
2. Rule 2 - input should be digit and = 3
3. Rule 3 - input should be digit and between 2 and 5
4. Rule 4 - input should be character and value should be 'A'
5. Rule 5 - input should be character and value should be 'B'
Design rule matrix and process a stream of inputs. More than one rule may be applicable for a given input.| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Algorithm Object Oriented Design - 0of 0 votes
AnswersE-commerse website having billions of items with image .What would be the best way to reduce the size of image ?will you use an API or do with HTML or use Hadoop or use simple bash script
- namrata.rohit22 September 13, 2016 in United States| Report Duplicate | Flag | PURGE
Java Developer Software Design - -4of 4 votes
AnswersNew technologies will cause end of JAVA, Is it right or wrong? And why reason.?
- tahmina August 12, 2016 in United States| Report Duplicate | Flag | PURGE
Java Developer - -1of 1 vote
Answersconsole.log(a(4)(5)(6));
- chaturvediprerna03 August 01, 2016 in India for book
How I can get values in function a()?| Report Duplicate | Flag | PURGE
Intuit Java Developer Application / UI Design - 0of 0 votes
AnswersMario wants to reach to his princess who is waiting for him in a castle. But the way to the castle is full of dragons. Each dragon is an enemy of the dragon who is located just before him on that path. The dragons in this world are quite peculiar. They have some number of diamonds each. Although they are dragons, they won't burn, instead they will give Mario their diamonds, but if and only if, Mario didn't take any diamonds from the dragon standing directly before the current one. If Mario does, then that dragon will burn him. Mario is in your control. You have to make Mario collect maximum number of diamonds for his princess and reach castle safely.
- shraddha9jain July 28, 2016 in India
Input- Each test case starts with a number N, the number of dragons, 0 <= N <= 10^4. The next line will have N numbers, number of diamonds each dragon has, 0 <= The number of diamonds with each dragon <= 10^9. Dragons described in the order they are encountered on the way to the castle.
Output- Print the maximum number of diamonds you can collect (and reach to castle safely).
Sample Input
5 1 2 3 4 5
Sample Output
9
Explanation
Input - 5 ==> Represents number of Dragons 1 2 3 4 5 ==> Represents the diamonds each of the Dragon has consecutively. The first dragon has 1 , the second has 2 and so on....
Output- 9
Explanation- If Mario collects diamonds from 1st, 3rd and 5th dragon (1+3+5). He will get 9 diamonds which is the maximum number of diamonds he can collect. Two of the other possible ways in which he can collect diamonds is, from 2nd and 4th dragon, (2+4),i.e.(6) or from 2nd and 5th dragon (2+5) i.e.,7 . He can’t obtain more than 9 diamonds in any case.
Therefore the output would be 9, the maximum he can collect.| Report Duplicate | Flag | PURGE
Walmart Labs Java Developer - 0of 0 votes
AnswersYou are given a limit buffer class that has two parameters - window in milliseconds and a threshold of the buffer. This means that the buffer can hold threshold amount of items within window in milliseconds.
There is a stream of data that consists of an event name:
call_backup, retrieve_data, call_backup, log_info, backup_log...
which is added onto the LimitBuffer. Write a logic that calls alert(..) when the buffer exceeds the threshold for a given window.
- dmachop June 11, 2016 in United Statesclass LimitBuffer { public LimitBuffer(long windowMs, int threshold) { } private void alert(String eventName) { } public void addEvent(String eventName) { } } /*class LimitBufferTester { LimitBuffer buffer = new LimitBuffer(2000, 30); while(true) { String randomStr = null; buffer.addEvent(randomStr); } }*/
| Report Duplicate | Flag | PURGE
Hired.com Java Developer - -1of 1 vote
AnswersThe input is being read in from a file called input.txt, in this format: 22|Data Structures|45
- nik April 01, 2016 in India
23|English|52
22|English|51
26|Data Structures|72
23|Data Structures|61
21|English|81
Each line consists of three fields "Student ID," "Subject," and "Marks." "Student ID" and "Marks" are integers and "Subject" is a string that does not contain '|' or newlines. There can be any number of students and up to 6 subjects. The fields are separated by the '|' character.
Currently, the existing program reads the input and creates an ArrayList<String> from the lines of input. Then it calls a method processData on this ArrayList, and prints the returned data to the output file. Unfortunately, processData currently does not do anything useful - it just returns an empty `Map.
You have to modify processData to compute the marks scored in each subject by the student with the lowest ID (who has actually appeared for that test). Thus, processData will returns a Map that maps each Subject to the marks scored. In other words, the map will contain each subject name as a key, and the marks scored by the student with the lowest ID as the value for that entry.
If your program is run with the input given above, it should produce the following output:
Data Structures: 45
English: 81
Please read this expected output carefully to understand exactly what you're expected to compute.
Plz help me solve urgent.| Report Duplicate | Flag | PURGE
Java Developer Java - 0of 0 votes
Answersinput[] ={"ab","cd","f","ab","ef","abc"}
- samkou February 14, 2016 in India
if we search in string s ="ab"; then
output 3| Report Duplicate | Flag | PURGE
Persistent Systems Java Developer - 0of 0 votes
Answersinput ={"p","q","r"},{"p","s","w"}
- samkou February 14, 2016 in India
return intersection value {"p"}
output:{"p"}| Report Duplicate | Flag | PURGE
Persistent Systems Java Developer - 0of 0 votes
AnswersHow to create whatapp database ?
- ajju January 27, 2016 in India| Report Duplicate | Flag | PURGE
Infibeam Java Developer - 0of 0 votes
AnswersWrite a program to display 1st, 2nd and 4th multiples of 7which also gives the remainder 0 (ZERO) when it divided by 2,3,4,5 and 6.
- D PRAVEEN KUMAR December 10, 2015 in India| Report Duplicate | Flag | PURGE
PRATIAN Java Developer C - 0of 0 votes
AnswersWrite a program to display the series 1,2,6,15,31,56,......,N
- D PRAVEEN KUMAR December 10, 2015 in India| Report Duplicate | Flag | PURGE
PRATIAN Java Developer C - 0of 0 votes
AnswersThere are two admins, trying to update product page at the same time. It happens like admin1 has updated just 2ms ago but admin2 is unaware of this and on his page he is having the previous data. Now how can we prevent admin 2 to update on description which is one step older?
- mabimal December 01, 2015 in Canada| Report Duplicate | Flag | PURGE
CGI-AMS Java Developer Web - 1of 1 vote
AnswersWAP in java to find duplicate element in array in one scan.
- swapbhikule83 November 29, 2015 in India| Report Duplicate | Flag | PURGE
xyz Java Developer Arrays - 0of 0 votes
AnswerWhat is Static class in Java? What is singleton class? How are they different.
- Joey November 21, 2015 in India| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer - 0of 0 votes
AnswersIs java pass by value or pass by reference?
- Joey November 21, 2015 in India
Then he asked various question related to this.
What if i pass integer, array list or object will the change reflect in the original function.
In case of object will we have different behavior when i set it to null in the called function or when I call its method(setName("") for example ).| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Java - 0of 0 votes
AnswersFind if the characters of the sample string is in the same order in the text string.. Give a simple algo..
- sachin.and3 October 18, 2015 in United States
Eg.. TextString: abcNjhgAhGjhfhAljhRkhgRbhjbevfhO
Sample string :NAGARRO| Report Duplicate | Flag | PURGE
Nagarro Java Developer Algorithm Arrays Brain Storming Brain Teasers Coding Hash Table String Manipulation - 0of 0 votes
AnswersFind the value of (x, y) in Pascal's triangle. I wrote code to construct the Pascal's triangle upto the required (x, y). Then interviewer asked me to change code so that I dont have to calculate the whole triangle but only the necessary parts.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
For example, in order to calculate f(4, 1) which is 4, we only need to calculate f(3, 0) and f(3, 1). And for f(3, 1) we need to calculate f(2, 0) and f(2, 1) and so on. After getting the hint, I wrote the recursive code and then he asked my for complexity of the code.
- killdos October 11, 2015 in United Statesint pascals(int x, int y){ if(x == 0 or x == y) return 1; return(pascals(x - 1, y) + pascals (x- 1, y - 1); }
| Report Duplicate | Flag | PURGE
Walmart Labs Java Developer - 0of 0 votes
AnswersImplement pow(x, y) which should return x^y. Both iterative and recursive.
- killdos October 11, 2015 in United States| Report Duplicate | Flag | PURGE
Walmart Labs Java Developer