Java Interview Questions
- 0of 0 votes
Answeri) Difference between HashMap & HashTable
- hulk April 26, 2014 in India
ii) How will you implement your own sorting algorithm in java?| Report Duplicate | Flag | PURGE
Collective Software Engineer / Developer Java - 1of 1 vote
AnswersInput will be a matrix consiting of only 1's n 0's.
- im.akki90 April 21, 2014 in India
The 1's represent the lines and 0's its absence.
For eg a matrix 6X7 is shown
0 0 0 1 1 1 1
0 1 1 1 0 1 1
0 1 0 1 0 1 1
0 1 0 1 0 1 1
0 1 1 1 0 1 1
0 0 0 1 1 1 1
In the above matrix, the sequence of 1’s represents the lines. These eight lines constitute three
rectangles.
Conditons :
1. The rectangles will always enclose some 0’s. e.g. last two vertical lines does not constitute a
rectangle.
2. A rectangle can contain multiple rectangles
Output : should be no. of rectangles formed in the matrix(intersecting rectangles are also counted).| Report Duplicate | Flag | PURGE
McAfee Senior Software Development Engineer Java - 1of 3 votes
AnswersGiven a number N, find the smallest even number E such that E > N and digits in N and E are same.
- jerinsebastian.punnamada April 08, 2014 in United States
Print NONE otherwise.
Sample:
Input
N = 34722641
Output
E = 34724126
Input
N = 8234961
Output
E = 8236194 (instead of 8236149)
Java solution| Report Duplicate | Flag | PURGE
Yahoo Applications Developer Algorithm Java - 1of 1 vote
AnswersGiven two words, determine if the first word, or any anagram of it, appears in consecutive characters of the second word. For instance, tea appears as an anagram in the last three letters of slate, but let does not appear as an anagram in actor even though all the letters of let appear in slate.
- jerinsebastian.punnamada April 08, 2014 in United States
Return the anagram of the first word that has appeared in the second word.
Sample Input 1
tea
slate
Sample Output1
ate
Sample Input 2
let
slate
Sample Output2
NONE
java solution| Report Duplicate | Flag | PURGE
Yahoo Applications Developer Algorithm Java - 1of 1 vote
AnswersGiven a string, complete the given function to recursively remove the adjacent duplicate characters and return the resultant string. If there are no characters left in the resultant string, return "-1" (without quotes).
- jerinsebastian.punnamada April 08, 2014 in United States
Sample Test Cases
Sample Input: ABCCBCBA
Output: ACBA
Explanation: (ABCCBCBA --> ABBCBA --> ACBA)
Sample Input: AA
Sample Output: -1
Java solution| Report Duplicate | Flag | PURGE
Yahoo Applications Developer Algorithm Java - 0of 2 votes
AnswersClass A
- PKT April 06, 2014 in India
{ void print(){}
}
Class B extends A
{ void print(){}
public static void main(String args[])
{
B b = new A();
}
}
Whats wrong with the above piece of code?
will below mentioned line work?
B b = (B)new A();| Report Duplicate | Flag | PURGE
Citigroup Java - 0of 0 votes
AnswerUnable to get what exactly the Question Is?
- jsd.learner April 02, 2014 in India
so What is the whole logic behind this question .It seems to be complete Math problem to me.
There is a Grasshopper in a tropical forest. The grasshopper can jump only vertically and horizontally, and the length of jump is always equal to x centimeter. A GRasshopper has found herself at the center of some cell of the chess board of the size pxq centimeters(each cell is 1x1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. the only restriction is that she cannot jump out of the board.
The grasshopper can count the number of cells that she can reach from the starting position(x,y). Let's denote this amount by dx,y. your task is to find the number of such starting position(x,y), which have the maximum possible value of dx,y
Input
The integer array contains three integers p,q,x
p= length of the board
q= width of the board
x=length of the grasshoppers jump.
Output
Output the only integer - the number of the required starting position of the Grasshopper
Example
input 2 3 1000000
output 6
input 3 3 2
output 4
Regards,
JSD| Report Duplicate | Flag | PURGE
Algorithm Brain Teasers Ideas Java Knowledge Based Math & Computation - 0of 0 votes
AnswersWe can start a Thread using either of two methods start() and run().What is the difference between these two?
- searchingviswa March 15, 2014 in India for 100| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java - -1of 3 votes
Answershow to print this pattern
- premnath.velmurugan March 08, 2014 in India
input N=4
output :
4444444
4333334
4322234
4321234
4322234
4333334
4444444
input N=3
output :
33333
32223
32123
32223
33333| Report Duplicate | Flag | PURGE
Software Trainee Algorithm C# Data Structures Applications Developer Java - -3of 3 votes
AnswerString pool, equals method, create immutable class Person
- arun.md12 March 04, 2014 in India
collection Concurrency, blocked collection, dQueue, multi threading| Report Duplicate | Flag | PURGE
Morgan Stanley Software Engineer / Developer Java - 1of 1 vote
AnswersConstruct an iterator of iterator
- varunumesh77 February 26, 2014 in United States
Here is the below question format:
// E next();
// Boolean hasNext();
// input: Iterator<Iterator<E>>
// output: Iterator<E>
// [[1], [2, 3]] => [1, 2, 3]| Report Duplicate | Flag | PURGE
Amazon Intern Java - -1of 1 vote
AnswersWhat are the different ways of sorting the arrays in Java which is other than Arrays.sort(a1)
- deepak.us7 February 26, 2014 in United States| Report Duplicate | Flag | PURGE
Java - 3of 5 votes
AnswersA professor wants to see if two students have cheated when writing a paper. Design a function : hasCheated(String s1,String s2, int N) that evaluates to true if two strings have a common substring of length N. Additional question after implementation. Assume you don't have the possibility of using String.contains() and String.substring(). How would you implement this?
- dke.ade February 25, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Java - 4of 4 votes
AnswersGiven a list of 4 billion integers, find an integer not in the list using 4MB of memory. (interview was in Java)
- dke.ade February 25, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Java - -2of 2 votes
AnswersMake a JAVA program for an array of classes.
- Kanha February 24, 2014 in United States
class should have 4 or 5 attribute and Array should contain 10 data which all have that 4 or 5 attribute of class. And Retrieve each attribute from all data. (Like Array of structure in C).| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersMake a Java/C program that takes n as input and gives you all sequence of n by using recurssion. For example if n=3, output will be:
- Kanha February 22, 2014 in United States
111
112
113
121
.........
........
331
332
333.| Report Duplicate | Flag | PURGE
Java - -1of 3 votes
AnswersWhat is polymorphism? what does it do?
- barrysingh1108@googlemail.com February 01, 2014 in UK| Report Duplicate | Flag | PURGE
Sage Software Intern Java - 0of 0 votes
AnswersThere are 2 arraylists each consisting of 1 million records.
- kmkswamy January 28, 2014 in India for Algorthims
Give me the same objects present in both the lists.
The objects in the list can be any thing of our choice.| Report Duplicate | Flag | PURGE
Algorithm Java - 0of 0 votes
Answersi have 2 class class employee which has empname and Title(manager,team lead) and class person which has name age and gender.. now i need to create a hasmap which has key and value pair as employee and person and if i give employee as key it should give me person values and if i give person as key it should give me employee value
- sandesh udupi January 26, 2014 in India| Report Duplicate | Flag | PURGE
Java Developer Java - 1of 1 vote
AnswersHow do you write a custom error handler in Java?
- A.K. January 15, 2014 in United States for Shared file| Report Duplicate | Flag | PURGE
Citrix System Inc Software Engineer / Developer Java - 0of 0 votes
Answerswhat happens when you re-throw an exception in Java?
- A.K. January 15, 2014 in United States for Shared file| Report Duplicate | Flag | PURGE
Citrix System Inc Software Engineer / Developer Java - 1of 1 vote
AnswersWhat is SOAP? What is REST? What are the major differences between SOAP & REST?
- A.K. January 15, 2014 in United States for Shared file| Report Duplicate | Flag | PURGE
Citrix System Inc Software Engineer / Developer Java - 7of 7 votes
AnswersYou need to develop the game Snake. What data structures will you use? Code your solution.
- GeorgyBoy December 30, 2013 in Israel| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm Coding Java Problem Solving - 0of 0 votes
AnswersAs a member of the cab finder app team, you are tasked with implementing a CabFinder class that has the following minimal public interface:
- ACE CA December 30, 2013 in United States
class CabFinder implements CabStatusListener {
/**
* Initiates CabFinder. Called only once per app startup.
* @app An application object providing services implemented by
* the rest of the application.
* @maxCabs Nearest number of cabs that can be returned to the user
*/
public void initialize(CabApp app, int maxCabs) {
//Insert code here...
}
/**
* Gets nearest cabs within 1km of the current user’s location.
* These must be the *nearest possible* @maxCabs in the 1km area.
* @return An unordered list of the nearest cabs.
*/
public Cab[] getNearestCabs() {
//Insert code here...
}
/**
* Asynchronous Callback per CabStatusListener (see below). Called when the position of a cab has changed.
*/
void onCabPositionChanged(Cab cab) {
//Insert code here…
}
/**
* Asynchronous Callback per CabStatusListener (see below). Called when a cab’s availability changes.
* @cab The cab whose availability has changed
* @isAvailable true if the cab is now available, false otherwise
*/
void onCabAvailabilityChanged (Cab cab, boolean isAvailable) {
//Insert code here…
}
}
Supporting Classes:
Here are the classes and utilities that are available for your use (you are not required to write any implementation for these classes)
/**
* Coordinates on a 2D map with a one meter granularity.
*/
class Position {
public int x;
public int y;
}
interface Cab {
/**
* Unique identifier of a cab.
*/
int getID();
/**
* Gets the current position of the cab
*/
Position getCabPosition();
/**
* Returns whether or not the cab is available
*/
boolean isAvailable();
}
/**
* Provides services implemented by the rest of the Cab Application.
*/
interface CabApp {
/**
* Gets the current location of the user
*/
Position getUserPosition();
/**
* Returns an iterator that gives access to the list of all cabs in the city
*/
Iterator<Cab> getCabs();
/**
* Registers a CabStatusListener object for change notifications of cab object data.
*/
void register(CabStatusListener listener);
}
/**
* The CabStatusListener interface
*/
interface CabStatusListener {
/**
* Called when the position of a cab has changed.
* @cab The cab object
*/
void onCabPositionChanged(Cab cab);
/**
* Called when a cab’s availability changes.
* @cab The cab object
* @isAvailable true if the cab is available, false otherwise
*
*/
void onCabAvailabilityChanged (Cab cab, boolean isAvailable);
}| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersA String is given ilke--abdecadc...szx..any thing..like this...element in this given pattern can be any this(like int also and letter till z also)
- amit.grynch December 28, 2013 in India
you have to arrange in pattern--aabbcclike....ie.same charactor together...| Report Duplicate | Flag | PURGE
EMC Java Developer Java - 1of 1 vote
AnswersImplement data structure for garbage collector in java
- shrey.chaturvedi2525 December 23, 2013 in India| Report Duplicate | Flag | PURGE
Deshaw Inc SDE1 Java - 0of 0 votes
AnswersWe have a fictitious multi-level marketing scheme where a member can recruit one or more other members. At the end of the month, member’s payout is calculated at 10% of his direct sales (items the members sells
themselves) and 4% of sales generated by his recruits and their recruits.
Write a function that calculates the monthly compensation for all members given the original member. You can assume a member can only be recruited by a single existing member.
Given the following interface, please implement the MemberPayoutUtil.calculatePayout function.
- Albert1981 December 15, 2013 in United Statespublic interface Member { public double getMonthlySales(); private Collection<Member> getRecruitedMembers(); } public class MemberPayoutUtil { public static double calculatePayout(Member member) { // Implement me! } }
| Report Duplicate | Flag | PURGE
Amazon SDE1 Java - 0of 0 votes
Answersyou have the string ={ aabb, aafd,acff,aacg,.....} , if i am writing a as first char or first two char or first three char and so on, it should show the all unique combination of words started with the that characters for eg. say if iam writing aa then it show that aabb or aafd
- sandy December 10, 2013 in India
i have tried using hashmap is it increase my complexity or should i have to use list| Report Duplicate | Flag | PURGE
Samsung Network Engineer Algorithm Java - -2of 2 votes
Answerswhat is green thread in java..??
- s.sameer2606 December 05, 2013 in India| Report Duplicate | Flag | PURGE
Igate Java Developer Java